Monday, November 28, 2011

Best practice for SOA based process-centric design

Pointers from one of the white paper I read:
  1. Apply the componentization principle: Avoid embedding business rules into the application so that a tightly coupled design doesn’t constrain business. 
  2. Apply granularity, modularity, and reuse principle: Reduce time to market by enabling modifications to the business rules and process flows quickly and independent of the application code. 
  3. Apply the loosely coupled invocation principle and interoperability along with service consumption pattern: Seamlessly integrate other systems like payment services, booking etc. and also consume functionality from other systems as services. 
  4. Apply service identification, design, and consumption principle: Expose the repetitive business tasks as services. For example, retrieving member information, generating reward certificates, etc. 
  5. Apply process design, granularity and composite-ability principle: Design the desired flight reward booking process and other optimal sub-processes. 
  6. Apply process metrics, analyze the metrics and improve the business processes: Compute the number of reward booking made in a day, loss of business due to not allowing purchase of shortage miles, etc. 
  7. Apply versioning principle: Define process and service validity and manage old and new versions of processes and services so that they co-exist for a certain period of time before new processes and services fully take over.

Thursday, October 27, 2011

Hibernate Configuration

Currently, I would prefer separating hibernate configuration into 2 files. With this, we can use spring to integrate and reuse the properties stated with EL. Hibernate will load the properties into config automatically as long as u name the file and variable correctly. Next post, I will show how to use EL to inject into bean automatically and the optimal setup for xml.

hibernate.cfg.xml
<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">
<mapping resource="com/gl/dao/Country.hbm.xml">
</mapping></session-factory>
</hibernate-configuration>

hibernate.properties
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://127.0.0.1:3306/glapp
hibernate.connection.username=root
hibernate.connection.password=password
hibernate.current_session_context_class=thread
hibernate.query.factory_class=org.hibernate.hql.classic.ClassicQueryTranslatorFactory
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=true

Sunday, April 3, 2011

Presentation skills

You may wonder why I am touching something that is quite unrelated to programming. The truth is even for programming requires human interaction and to a certain extend good presentation is a must to bring your point forward, and not only that, one should aim to impress and sell the product well. The choice of words, the tone and especially the pace is all damn important. And so time to share one of the blogs I am reading everyday.

[Presentation Zen]
1. Chunking and exposure.
Identify and break down your presenting challenges into small manageable chunks, and deliberately expose yourself to each of them step by step.
2. Rehearsal.
Beyond just practicing your slide timings, actually visualize and hear yourself say the words with your slides. You see yourself in front of the crowd and rehearse your presentation to a variety of audience reactions, both positive and negative.
3. Self-talk.
Anxiety grabs onto self-critical talk such as “I’ll do a terrible job. What happens if the slide show fails. What happens if they don’t laugh at my jokes.” Your task is not to feed your anxiety with this type of talk, but to change it into “I can do this. I will follow my rehearsed plans. This is manageable.”
4. Arousal control via diaphragmatic breathing.
Calm your brain’s fear center with slow, deliberate breaths with slightly longer exhales. Slower rhythm (rather than deep breathing) is helpful for fear management.
5. Deliberate practice.
Practice your beginning, identify challenging concepts, and practice, practice, practice—out loud. These techniques work, and I use them myself as well as with clients. They are powerful and will prove useful in scenarios other than presenting."

Hope you will enjoy this.

Wednesday, February 23, 2011

Video: Javascript the good parts

Gotten this from the google blog, high recommended from my colleagues on how to write good javascript.



As usual, I will only share the good stuff. Pun not intended.

Saturday, February 19, 2011

Learning iPhone development via iTunes

This link is shared in Facebook by one of my friend and I am quite surprise seriously Stanford is giving this course free of charge. I have yet to listen to it so do feedback to me on the quality of the lessons. If I'm not wrong, MIT also does provide a wide range of courses for free.

IMO, schools should still focus on lessons on improving engineering processes and practices. Application development on specific product come and go and hence it will be more beneficial for graduates to come out of school with the life-long "soft" skills like design pattern, best practises etc rather than going in too technically on a specific product.

Well its just my 2 cents opinion.

90% of the battle

Just to note down a conversation I had with a solution architect in the company. There is one particular portion that strikes me as I always thought that implementation phase might be the longest phase among the SDLC or  software development life cycle. I was surprised that it can be much shorter than what I think.

If the assumption is truly spot on, actually 10% of the time is doing implementation!

How can it be done? Probably the O2C SDLC will fit in perfectly. As programmers from China/India cost only 1/3 of Singapore, we can use 3 times the number of engineers to speed up the process. There are important consideration using this approach and one of them probably is whether the task can be split and run in parallel.

Having a infrastructure that is catered for the similar task also help the project to be on time tremendously. I will make some assumption that my current project should be at least 3-5 years and because of the infra, process has accelerated by 50% and more.

This is probably why the engineers won't get paid well unless the specialization is very niche. And that is what I'm aiming for: to have a balanced soft and hard skill set with my specialization on niche areas. Sounds like I'm asking for the best of both worlds :D

Thursday, February 17, 2011

Moving on (to brunei)

I shall announce that the I have resigned from my job and move on to another company. Well I'm still doing the same job but with lower benefits.

As of now, I am in Brunei as a senior software engineer helping out with the requirements gathering. It is a rather refreshing experience compared to pure engineering job in previous company. I have been meeting up with several clients for the past 2 days and the skills required is quite different and hence I have to adjust myself to a totally different mindset. Like writing good and understandable minutes so that you don't have to rewrite and save the time for other task example sleeping.

Engineering is pure technical skills while requirements gathering is more of a soft skill. What I have learn is that once you are good at technical skills, you should be ready for gaining the domain knowledge for a specific sector. This is where you would value add. Knowing the processes of your client will help in knowing your client requirements beforehand and the obstacles ahead.

Knowing to do your task is one thing but the approach is also important. Requirement gathering is a human task and taking a soft stance towards your customer can help in building a cordial human relationship. As much as you want to get the things done, you also want your customer to be happy. Right?

I also learn about having a process towards gathering requirement is also beneficial. Talk with your customer about their requirements and then generate out a set of questionnaire for them to fill up before meeting up with them helps in reducing the time for requirement gathering.

Longer working hours seems like a norm like right now, just back from work and dinner, I am already at the living room with colleague ready to push on to finish the next task.

Time is short. Ciao

Friday, January 28, 2011

Enumeration improved with Generics

Google is your friend, Wiki is your teacher is very true. I have been reading on the bus ride during the CNY trip and learnt some power concept for OOP in java especially the use of generics. Below is the code I improved on AbstractEnum class which will now be even more flexible than ever.

public abstract class AbstractEnum<INPUT_TYPE>{
    private final INPUT_TYPE k;
    private static int nextOrdinal = 0;
    private final int ordinal = nextOrdinal++;
   
    protected AbstractEnum(INPUT_TYPE k){
      this.k = k;
    }
   
    public INPUT_TYPE getValue(){
      return this.k;
    }
   
    public int getOrdinal(){
      return this.ordinal;
    }
   
    //override equals method   
    public boolean equals(Object o){
        AbstractEnum objE =  (AbstractEnum) o;
        return ( this.ordinal == objE.getOrdinal() );
    }
}

Here's the implementation. Look much cleaner than before isn't it?

public class DayImpl extends AbstractEnum<String>{

    protected DayImpl(String name) {
        super(name);
        // TODO Auto-generated constructor stub
    }
   
    //creating your enum
    public static final DayImpl Mon = new DayImpl("monday");
    public static final DayImpl Tue = new DayImpl("tuesday");
    public static final DayImpl Wed = new DayImpl("wednesday");
    public static final DayImpl Thur = new DayImpl("thursday");
    public static final DayImpl Fri = new DayImpl("friday");
    public static final DayImpl Sat = new DayImpl("saturday");
    public static final DayImpl Sun = new DayImpl("sunday");
}

Sunday, January 23, 2011

Finished Java 2 unleased. Goodies included

I've finally finished the book of almost a thousand page long! It took me close to 30 hours to finish everything. I think a do learn a great deal more as compared to just doing what work has required me. Even though Java might be a dying program, I still think there is a market for Cheapo peeps like me who feel cost might be the determinant of a successful project continuation.

As of now, there are many people complaining to me how Java is going downhill after Oracle bought over it. I do not have a crystal ball so I would rather not comment. Probably I will learn more about it before jumping to next language, which will be dot Net.

I will be writing my own framework, so that I can improve and showcase my stuff! Below is the helper class to do encryption and decryption for a String. Hope you like it!


import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;

public class CipherHelper {
   
    public static final String CIPHER_TYPE = "DES/ECB/PKCS5Padding";
    public static final String KEY_GEN_TYPE = "DES";
   
    public static SecretKey genKey() throws NoSuchAlgorithmException{
        KeyGenerator kg = KeyGenerator.getInstance(KEY_GEN_TYPE);
        return kg.generateKey();
    }
   
    public static byte[] encrypt(String o, SecretKey k) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException{
        Cipher cip = Cipher.getInstance(CIPHER_TYPE);
        cip.init(Cipher.ENCRYPT_MODE, k);
       
        return cip.doFinal(o.getBytes());
    }
   
    public static String decrypt(String s, SecretKey k) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException{
        Cipher cip = Cipher.getInstance(CIPHER_TYPE);
        cip.init(Cipher.DECRYPT_MODE, k);
        byte input[] = cip.doFinal(s.getBytes());
       
        return new String(input);
    }
}

Wednesday, January 19, 2011

Coding configurable software

A summary of what I had learn in writing requirement-changeable software.
  1. Use of properties file
  2. Configuration to be refactored into another class for rendering component input
  3. Spring framework for tier division
  4. Anymore?

Tuesday, January 18, 2011

Programming: how to do it better

2 nice video on how to program better. All in all, I think I got some ideas on how to do better testing. 2 types of testing packages will be created. One for object testing, another packages will be multiple situation testing for the following routine as an example (login, search, read email, delete mail, refresh inbox, search). Probably another for bug fixes?

I've got doubt in formal prove as you may prove within a system, things are bug-free. However, what if, multiple systems do interact and something right on one system might result in fault at the other.  However if I can prove program is bug-free formally, it will be great! But life would probably be very sucky looking back at discrete maths. Noooooo!!!

Wisdom
  1. design code components so they cant be used incorrectly
  2. make good use of compiler features like -wall and -wextra to find "invisible" errors
  3. Use of tools like valgrind to check for memory leaks
  4. Testing
    1. Core concept
      • automated
      • repeatable
      • as comprehensive as possible
      • seperate code and test
      • new test for new feature or bug fixed
    2. Limitations
      • only show the presence of bug
      • buggy test
      • test coverage is never complete
      • oo testing required per object = no of change state x number of state
      • looking deeper into bug to fix the processes
      1. Future
        • better languages
        • type systems (curry-howard isomorphism)
        • theorem prover to show its bug-free. more code for testing then the original code!

    Part 1, 2

    Monday, January 17, 2011

    Concurrency

    Shortcut to avoiding race condition on threading application with read and write operation.
    1. Use Synchronize
    2. Use Volatile
    3. Follow rule 1 and 2

    Saturday, January 1, 2011

    Installing XAMPP with tomcat plugin

    Doing a quick installation of XAMPP on my macbook now. And if you wonder why I'm doing this post, the reason is simplicity. With a single installation you get Apache and MySql up and running in less than 10 mins. Here comes the difficult part. Tomcat is not part of the default installation. Configuration of the ini and conf files is needed to get it running. Trying out if mac will work with windows configuration tutorial.



    Enumeration (improved version)

    With reference to the previous post. I have try to improve the code so that enum will become extensible. The code will be broken down to 2 parts. The abstract version and the implementation

    Abstract enum class

    public abstract class AbstractEnum {
        private final String name;
        private static int nextOrdinal = 0;
        private final int ordinal = nextOrdinal++;
        
        protected AbstractEnum(String name){
          this.name = name; 
        }
        
        public String getName(){
          return this.name;
        }
        public int getOrdinal(){
          return this.ordinal;
        }
        
        //override equals method    
        public boolean equals(Object o){
            AbstractEnum objE =  (AbstractEnum) o;
            return ( this.ordinal == objE.getOrdinal() );
        } 
    }

    The implementation class for Day enum.
    public class DayImpl extends AbstractEnum {
    
        protected DayImpl(String name) {
            super(name);
            // TODO Auto-generated constructor stub
        }
        
        //creating your enum
        public static final DayImpl Mon = new DayImpl("monday");
        public static final DayImpl Tue = new DayImpl("tuesday");
        public static final DayImpl Wed = new DayImpl("wednesday");
        public static final DayImpl Thur = new DayImpl("thursday");
        public static final DayImpl Fri = new DayImpl("friday");
        public static final DayImpl Sat = new DayImpl("saturday");
        public static final DayImpl Sun = new DayImpl("sunday");
    } 

    Design Patterns: Enumeration

    Enumeration is often used when the list of variable is always fixed. For example the days in a single week can be written as:

    public enum Day {
        SUNDAY, MONDAY, TUESDAY, WEDNESDAY, 
        THURSDAY, FRIDAY, SATURDAY 
    }

    However there is often a problem of testing the Enumeration. I have to get back to my codes to know the violations of using default enum. I believe enum cannot exist as a class and hence you will have to replicate enum across the class that is using it. I chance upon the following clever get-around solution using Java object class.

    This is the sample code for Java Enumeration:

    class Day{
    
      private final String name;
      private static int nextOrdinal = 0;
      private final int ordinal = nextOrdinal++;
    
      protected Day(String name){
        this.name = name; 
      }
    
      public String getName(){
        return this.name;
      }
      public int getOrdinal(){
        return this.ordinal;
      }
    
      //creating your enum
      public static final Day Mon = new Day("monday");
      public static final Day Tue = new Day("tuesday");
      public static final Day Wed = new Day("wednesday");
      public static final Day Thur = new Day("thursday");
      public static final Day Fri = new Day("friday");
      public static final Day Sat = new Day("saturday");
      public static final Day Sun = new Day("sunday");
      //override equals method
    
      public boolean equals(Object o){
        Day objE =  (Day) o;
        return ( this.ordinal == objE.getOrdinal() );
      } 
    }
    

    There are things to take note:
    1. The use of protected construction to prevent the instantiation of Day class
    2. Use of final ordinal and static nextOrdinal to issue a unique number for a new Enum. Mon will get ordinal 1, Tue get ordinal 2 and so on....
    3. Use of overridden equals method as a more efficient way to compare object instead of using String

    Hope this helps. Have a nice day ahead!

    ps: I have a improved version of Enumeration

    9986 hours: finishing JSP/Servlet chapter

    As of now, I've completed 10 chapters of J2EE unleashed. Not going through the chapter in order, reading in a mix of what I know that can be make better use in my current project and what I will be interested in especially in the direction of EJB and JMS.

    Just finished the JSP/Servlet chapters, it is quite sad they only went through the custom jsp tag. I am currently looking at some online resources and should be able to apply it in another hour.

    At the same time, I am wondering what are the personal projects I can start doing in order to practice the stuff I read. I shall end this post with a quote.

    “Knowing is not enough, you must apply; willing is not enough, you must do.”

    Counting down: 9989 hours

    I feels great to have a new year resolution that span out over several years. So before the start of the new year, I've already been chipping away part of the 10,000 hours I set out to achieved.

    It definitely does give a sense of having your feet on the solid ground and walking step by step towards your goal. My new year resolution at least for this and next 2 years is to become a accomplished J2EE developer.

    Personally, I feel one of the ways to "upgrade your skills" is the copy what others are good at and apply it and become better than what others are doing as time goes by. This is what the Japanese do best and give them the edge over other countries in the 20th century. This comes to the need for design patterns. Design patterns provide developers to better communicate their ideas across and working with designs that are already recommended for its ability to adapt to changes.

    Over the next few post, I will discuss the several popular design patterns. Below is a Amazon link on Head First Design Pattern book. This is one I really enjoy very much. Better than a story book I would say. Stay tune for my next post!