Tuesday, June 22, 2010

Software development principles for an engineering manager,architect and developers

  1. YAGNI - You Aren’t Gonna Need It :
    The YAGNI principle says that do not build something just because it might be needed later. Basically it says that do not build any code/features in the product that are not currently needed. This prevents the team from spending a lot of time planning for some grand, imaginary and unknown future scenarios. This will save time as most likely you do not need it or what you actually need is quite different from what we foresaw. This prevents teams from over engineering something based on what we think we might need later on. It is based on the idea that things will change with time. The principle saves you time twice. First, you don’t spend it now on something that you might don’t need. Second, when you reach the time when you need it, you don’t spend time in rewriting and refactoring but write once and well.By no means YAGNI is against planning and thinking in advance, it only encourages taking stuff into consideration NOW but postponing the implementation to later on
    Ask the YAGNI question

    "What are the chances that You Aren't Gonna Need It?"

  2. KISS - Keep It Simple, Stupid:
    KISS is a principle that states that everything should be done as simple as possible. Applying KISS principle helps teams from over complicating problems. In my experience in the world of software development, developers tend to relieve the boredom of routine jobs by implementing an over complicating solution even when there exists a simple working solution. It feels great and exhilarating to do that until someone else needs to fix, maintain or modify the implementation. I must confess that I myself have done that many a time. One of my mentors once gave me a good analogy that I will not forget...an expert is some one who makes the job at hand look how simple it is and not vice versa. When ever we get back to our own code and start scratching our heads that sure sign that something got complicated than it had to be. Do not use all the fancy OOP, threading, frameworks just because you can.
    It is very simple to Implement the KISS principle. Whenever we come across a solution to a problem ask yourself " is it really the simplest way to do it? "
    Just remember

    "Some of the world's greatest algorithms are always the ones with the fewest lines of code. And when we go through the lines of code, we can easily understand them. The innovator of that algorithm broke down the problem until it was so easy to understand that he/she could implement it.Many great problem solvers were not great coders, but yet they produced great code! "

    For further reading on KISS
    http://people.apache.org/~fhanik/kiss.html

  3. DRY - Don't Repeat Yourself:
    DRY is a principle that encourages to automate/extract tasks/code that we seem to be repeating again and again. DRY is aimed at reducing duplication and having a single point of maintenance. This principle can be applied in also not generalizing an implementation as a framework before we come across the need to repeat it again and again.

  4. Premature optimization:
    Premature optimization is a term coined for the practice of trying to optimize the code to run faster when the code/functionality to be implemented is in a fluid state. Do not forget the well know statement " get it right then make it faster”. Do not get hung up on writing a fast-optimized code before getting the functionality right. The rationale is that it is most likely that the optimization that might be done prematurely might account to less than 3% of the actual bottleneck.The following quote from Donald Knuth in "Structure programming with go to statements" summarizes the problem perfectly

    " Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all-evil. Yet we should not pass up our opportunities in that critical 3%."

  5. Principle of Least effort :
    The principle says that people and even well designed machines stop looking for better solutions once a solution that minimally matches the acceptance criteria is met. Applying the principle helps us to find the most effortless paths to solve problems. It promotes a quick and simple design over elaborate systems designed by committees.

  6. The partew law of 80/20:
    The law in the field of software states that 80% of the user will use only 20% of your features. By understanding the rule and identifying the 20% of the features that 80% of the users use we can concentrate the resources and time on those 20% of the features to produce a better product.

Many senior developers and architects even though well versed with these principles tend to be applying them only when they feel like it and miss the spirit of these principles. As one of my mentor used to say the word is "Resume Driven development" , teams tend to over complicate , try new api's , frameworks and do a lot of wastage disregarding the business goals and objectives. This is the very reason and importance for the management team to be well versed in the field of the development to be able avoid this kind of wastage.

Thursday, May 6, 2010

Best Leadership style

In our lives as a part of work , family, friends we come across leaders with different styles of operations and leadership qualities. Is there a one best leadership style ? ..Not really ..a leadership style in one situation might not go well in other situations. For example a crisis situation calls for a leader who is commanding and pace setting , where as the same leadership in other situations will be construed as a being a bully. Experts in psychology and organizational culture agree that a mix of leadership styles is the approach that gets the best results from the employees. Situational leadership is generally considered as the best way to go...Situational leadership calls for understanding the situation needs and dealing with appropriate style of leadership.
Richard Boyatzi and Daniel Goleman in their book Primal Leadership classify the leadership styles in

1. THE COMMANDING LEADER
Style: Gives clear directions and expects compliance.
Best used: In times of crisis, to kick-start a turnaround, and in dealing with "problem employees" who don't respond to other methods.
Most likely to say: "Do as I tel! you!"
2. THE PACE-SETTING LEADER
Style: Sets goals and expects them to be achieved.
Best used: For getting results from a motivated and competent team.
Most likely to say: "Go for itl"
3. THE VISIONARY LEADER
Style: Moves people towards a shared vision.
Best used: When a new strategic direction is needed.
Most likely to say: "Come with me."
4.THE COACHING LEADER
Style: Develops peopie for the future.
Best used: To help employees improve performance and develop long-term strengths.
Most likely to say: "Try this."
5.THE AFFILIATIVE LEADER
Style: Creates harmony and builds emotional bonds based on loyalty and trust.
Best used: To heal rifts in a team or to motivate people during stressful periods.
Most likely to say: "People come first."
6.THE DEMOCRATIC LEADER
Style: Forges consensus through participation.
Best used: To build "buy-in" and encourage Input.
Most likely to say: "What do you think?"

So what differentiates a leader from a great leader? It is the wisdom to decide on the best leadership style to employ in a given situation that differentiates a good leader from a great leader.




Tuesday, March 16, 2010

Access to ApplicationContext in Spring based Web applications

Recently in a Spring WS application , i had to get access to the Spring ApplicationContext and it turns out that it is not so well documented. Spring ApplicationContext can be created either by using
ClassPathXmlApplicationContext:
ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml", "applicationContext-part2.xml"})

WebApplicationContext:

If we have access to the servletContext 

WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

In a web/Spring WS app, if we do not have access to the servletContext and if we would to like use the existing ApplicationContext , the following approach might be the way to go:


Create a class ApplicationContextContainer that implements ApplicaionContextAware and have it be defined as a
bean in Spring context xml file.

import org.springframework.beans.BeansException;

import org.springframework.context.ApplicationContext;

import org.springframework.context.ApplicationContextAware;

public class ApplicationContextContainer implements ApplicationContextAware {

private ApplicationContext appContext; 


@Override 

public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {

 this.appContext = applicationContext; 

} 
 

public ApplicationContext getAppContext(){

 return appContext; 

} 

}
Create a bean definition for the above class in the spring context file

 <bean id="applicationContextProvider"  class="com.test.ApplicationContextProvider"/>



And by injecting the bean applicationContextProvider, the spring ApplicationContext is accessible in the rest of the application.


Sunday, January 3, 2010

Asynchronous Messaging Architecure as an Integration Solution

Fundamental challenges of integration solutions include most of the fallacies of distributed application
1. The network is reliable
2. Latency is zero
3. Bandwidth is infinite
4. The network is secure
5. Topology doesn't change
6. There is one administrator
7. Transport cost is zero
8. The network is homogeneous

We can summarize the major challenges of integration solutions into to the following
  • Networks are unreliable
  • Networks are slow
  • Any two applications are different
  • Change is inevitable
When we are trying to integrate two Apps A and B ,there are 4 main approaches to do this and overcome the above mentioned challenges
  1. File Transfer : One application writes a file and another application reads from the file. The applications will need to agree on filename,location and format
  2. Shared Database: Multiple applications share the same database schema, the integration happens through the database.
  3. Remote Procedure Invocation/ Web services: One application exposes one sort of functionality that can be accessed remotely by other application as remote procedure. This could as well be a web service. Communication occurs in real time and synchronously.
  4. Messaging: One application publishes a message to a common message channel. Apps need to agree upon message channel and format. Communication is asynchronous.
The issues with approaches in 1,2,3 include
  • Apps are tightly coupled.
  • Apps A and B need to scaled together
  • If A needs high availability then even B needs to made highly available.
  • The model of communication involves the applications to be polling for the availability of the data from the other application.
Messaging is more immediate than file transfer, better encapsulated than a shared database and more reliable than a web service/RPI.Advantages of going with the messaging approach include:
  • Apps involved in integration (A,B) are loosely coupled .
  • Apps can be scaled independently of each other
  • Apps can functionally be available independent of each other. App A can be up and functional even when B is down. App A will queue up the data that is required by B , When B is up it start consuming the events from A.
  • Apps do not have to be build to support peak load as the asynchronous messaging allows the processing to be spread out over time. Asynchronous dampens the load.
  • Throttling Ability.
  • Reliable Communication - reliable and guaranteed delivery
  • Platform/Language agnostic integration
Asynchronous Messaging Architectures have in turn have its own challenges.
  1. It is a complex programming model. Asynchronous messaging requires developers to work with an event driven programming model.
  2. Message sequence issues - Message channels guarantee message delivery but they do not guarantee when message will be delivered. Might require some logic to re-sequence the events at the consuming end if IN ORDER Delivery is a required SLA.
  3. Synchronous Scenarios- There might be scenarios where synchronous is required for better user experience. Intelligent workaround schemes might be required to support it.
  4. Performance-- Messaging is best suited to keep the system in sync after the initial data replication. Messaging is not suited from the performance aspect to be used as mechanism to replicate data.
  5. Limited platform support. This methodology is not yet mainstream and the support and best practices are in limited availability.
  6. Vendor Lock-in: Messaging brokers used might result in a vendor-lockin problem. But as along as we stick to to the standards like JMS and stay away from using the broker specific features most of the vendor lock problems can be mitigated.