Monday, May 4, 2009

Timeless quotes ...

Hi all !

I was looking for interesting quotes every week since I started my last job and now that I've collected a lof of them I want to share it. For some of the quotes I am not sure to whom it belongs, so I decided to let you google for the atributions :)

Enjoy it !

  • Realize that declarative programing is as easy as the 1300 pages manual is showing it is :)
  • Everything should be made as simple as possible, but not simpler
  • Imagination is more important than knowledge
  • Don't let your victories go to your head, or your failures go to your heart
  • When the only tool you have is a hammer, everything looks like a nail
  • Certified coffee addict !
  • The question of whether computers can think is like the question of whether submarines can swim
  • Knowledge talks, Wisdom listens
  • UNIX motto: Provide mechanisms, not policy
  • In theory, there is no difference between theory and practice, but in practice, there is :(
  • An expert is someone who has made all possible mistakes in a very narrow field
  • Before we work on artificial intelligence why don't we do something about natural stupidity ?
  • C makes it easy to shut your foot if you want, C++ makes it a little bit harder, but when you finaly do, it blows out your whole leg !
  • Imposible, es solo una opinion.
  • Style distinguishes excellence from accomplishment
  • Simplicity is prerequisite for reliability
  • You are finally taking a shower ... now your phone rings ... and when you reach your phone to answer ... it was a wrong number
  • A documented bug is not a bug, it is a feature
  • Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away
  • Weeks of programming can save you hours of planning
  • Computer science is an immature discipline, and I aim to keep it that way
  • The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones
  • A good developer will understand the business implications of technical decisions
  • Always code as if the person who will maintain your work is a serial killer that knows where you live
  • Simplicity carried to the extreme becomes elegance
  • A good developer can translate words and ideas into code, a good engineer creates those words and ideas
  • In order to understand recursion, one must first understand recursion :)
  • We follow two rules in the matter of optimization: Rule 1. Don’t do it. Rule 2 (for experts only). Don’t do it yet—that is, not until you have a perfectly clear and unoptimized solution
  • One mistake and you have to support it for the rest of your life
  • Working with communities is more productive
  • Once you get started, you’ll only stop because you’re exhausted
  • It takes another experienced person to really appreciate what you’re doing
  • One little thing going wrong can ruin everything.
  • Truly great programmers do not exist, there are only those who claim to be great, and those who know they are not great
And these ones comes from wikipedia Seven habits of higly effective people 
  1. Be Proactive: Principles of Personal Choice
  2. Begin with the End in Mind: Principles of Personal Vision
  3. Put First Things First: Principles of Integrity & Execution
  4. Think Win/Win: Principles of Mutual Benefit
  5. Seek First to Understand, Then to be Understood: Principles of Mutual Understanding
  6. Synergize: Principles of Creative Cooperation
  7. Sharpen the Saw: Principles of Balanced Self-Renewal
[UPDATE]
  • Typing is not now and never has been the bottleneck in writing code
  • Software entities should be open for extension, but closed for modification.
  • Buy the best, build the rest
  • The most difficult thing in the world is to know how to do a thing and to watch someone else do it wrong without comment.
  • Use the simplest thing that could possibly work

Wednesday, March 11, 2009

Where do you host your website to scale ?

I have been talking to some colleagues about how to start a project that you know it will probably need to scale in a couple of months, think of a heavy text content site. [update: like a lyrics site with kind of social features added to it, with urls that makes the search engines happy]

Actually what we have as far as I know are services like google appengine, that provides you with a full api where you can build your web site. You know they give you processor time, storage space in their datastore, kind of non-relational ( but scalable ) database and a lot of network throughput. What I like about this service is that you pay very little money for a lot of resources, at least as far as know.

Then you have virtualization services like linode and amazon ec2 and other services that I like more because it gives you full control of how to program your site without limiting you with a closed api or closed vendeor.

Microsoft also offer public cloud computing services called azure and I think yahoo also.

But here are some things to have in mind. I don't have a good feeling about who's the real owner of your application since you upload your code to google appengine for example. Or then you fear that they'll say you that your application violates some policies you were supposed to follow. Well, I think you understand.

I think comparing services like appengine and the ones that offer virtualization creates you another problem if for any reason you need to move from one to another, because you probably will need to re-enginer the urls if you'll change the way you are programing and you know, there goes all your page ranking and you'll have broken links if you gained some of them before wanting to move your application.

I am sorry if my English is irritating you, but this is as far as I can talk, what I want to know from you is what will be your thoughts on this topic. What will be the service you'll choose and why. Which services are you using and what is your experience in it.

Thanks

Monday, November 24, 2008

An approach to configurable parameters

It is annoying how much work you need to do just to get all the properties from the file mapped to a class catching all the exceptions and repeating many times the same keys thorough the configuration files. For example, normally I had before a class that has static String variables each one mapping a key in the property file and then I use those variables when loading the properties and validating, etc.

When you need to load some properties from a file to your application in order to have some configurable parameters normally you use an external file in case of having a Java SE application or a resource bundled in your Java package such as yourwar/META-INF/applicationProperties.xml.

I have write some dirty (ugly) code just to give you an idea of how that can be easier.

Supose the next scenario.
you have a applicationProperties.xml file
---

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">

<properties>
<comment>
The good thing of using the xml version of properties file is that
it is "easy" to see the whitespaces that normally endup at the end of
the strings and most of the times we forget to use value.trim() ...
and then some time is spent for that stupid bug
</comment>

<entry key="connectionString">jdbc:h2:file:c:\h2db\dbName</entry>
<entry key="user">sa</entry>
<entry key="password">saadmin</entry>
<entry key="poolSize">7</entry>
<entry key="timeoutMillis">7000</entry>
<entry key="retryInterval">3</entry>

</properties>

---

and the next class mapping your file properties
---

public class ConfigurableParameters {


   public String _connectionString;
   public String _user;
   public String _password;
   public Integer _poolSize;
   public Long _timeoutMillis;
   public Integer _retryInterval;
   
   private static ConfigurableParameters instance;
   public static ConfigurableParameters getInstance() {
      if (instance == null) {
         instance = new ConfigurableParameters();
      }
      return instance;
   }
}

---

You see, the only time where you repeated the keys are in the name of the variables of the class. Now, wouldn't it be nice to load all the properties like this ?

---

public static void main(String[] args) {
      boolean confSuccess = ConfigurationHelper.mapConfigurableProperties(
                           ConfigurationSource.FILE,
                           "applicationProperties.xml",
                           ConfigurableParameters.getInstance());
      if (!confSuccess) {
         System.out.println("Error loading configuration");
         return;
      }
      
      System.out.println(ConfigurableParameters.getInstance()._connectionString);
      System.out.println(ConfigurableParameters.getInstance()._user);
      System.out.println(ConfigurableParameters.getInstance()._password);
      System.out.println(ConfigurableParameters.getInstance()._poolSize);
      System.out.println(ConfigurableParameters.getInstance()._timeoutMillis);
      System.out.println(ConfigurableParameters.getInstance()._retryInterval);
   }

---

The reason I make that the function recognizes all the fields starting with an underscore is just to make it clear that it will expect that those fields have a key in the properties file.

Actually You can make the fields of ConfigurableParameters class to be private and just provide public getters, it will still set the parameters. Also you can load the properties from a bundle file resource of the packaged jar, just call the method with ConfigurationSource.RESOURCE, and your sourceAddress would be something like "/META-INF/applicationProperties.xml", depending where did you put the file.


The implementation for the ConfigurationHelper is here

---

public class ConfigurationHelper {


   public enum ConfigurationSource {
      RESOURCE, FILE
   }


   public static boolean mapConfigurableProperties(ConfigurationSource configurationSource, String sourceAddress, Object target) {


      if (configurationSource == null || sourceAddress == null || target == null )
         return false;
      
      try {
         Properties sourceProperties = 
            getSourceProperties(configurationSource, sourceAddress, target);


         if (sourceProperties.isEmpty())
            return false;


         for (Field f : target.getClass().getDeclaredFields()) {
            String fieldName = f.getName();
      
            if (!fieldName.startsWith("_"))
               continue;


            fieldName = fieldName.substring(1);


            if (!sourceProperties.containsKey(fieldName))
               continue;


            boolean originalAccesibleValue = f.isAccessible();


            f.setAccessible(true);
            f.set(target, getConvertedValueForType((String) sourceProperties.get(fieldName), f.getType()));
            f.setAccessible(originalAccesibleValue);
         }


      } catch (Exception e) {
         e.printStackTrace();
         return false;
      }
      return true;
   }


   private static Properties getSourceProperties(ConfigurationSource configurationSource, String sourceAddress, Object target) {
      Properties prop = new Properties();
      try {
         InputStream is = 
            configurationSource == ConfigurationSource.FILE ? 
               new FileInputStream(sourceAddress) : 
                  target.getClass().getResourceAsStream(sourceAddress);
               
         prop.loadFromXML(is);
         is.close();
      } catch (Exception e) {
         e.printStackTrace();
      }


      return prop;
   }


   private static Object getConvertedValueForType(String sourceValue, Class c) {
      Object convertedValue = null;
      if (c == String.class) {
         convertedValue = sourceValue;
      } 
      else if (c == Long.class) {
         convertedValue = new Long((String) sourceValue);
      }
      else if (c == Integer.class) {
         convertedValue = new Integer((String) sourceValue);
      } 
      else if (c == BigDecimal.class) {
         convertedValue = new BigDecimal((String) sourceValue);
      }


      return convertedValue;
   }


}

---

This all may seem out of the standard conventions and I just didn't think of another way of doing this. It is just an idea of how can you make the work of loading configurable properties easier.

Have fun trying it and please give me feedback about how you are doing it.

  © Blogger template 'Minimalist A' by Ourblogtemplates.com 2008

Back to TOP