Showing posts with label Software Development. Show all posts
Showing posts with label Software Development. Show all posts

Sunday, May 12, 2013

Gambling in Software


I want to tell you about a meeting we had a few days ago. It reminded me of “The Jack Story” (which was part of an old stage routine of Danny Thomas many years ago).

Here’s how it goes:
Traveling salesman gets stuck one night on a lonely country road with a flat tire and no jack. He starts walking toward a gas station about a mile away, and as he walks, he talks to himself. "How much can he charge me for a jack?" he wonders. "Fifty dollar, sounds reasonable. But it's the middle of the night, so maybe there's an after-hours fee. Probably another five dollars. Wait.... He'll probably figure I got no place else to go for the jack. Fifty dollars more."
He goes on walking and thinking, and the price and the anger keep rising. Finally, he gets to the gas station and is greeted cheerfully by the owner: "What can I do for you, sir?" But the salesman will have none of it. "You got the nerve to talk to me, you robber," he says. "You can take your stinkin' jack and shove it..."

The meeting was about a new feature requested by one of our customers. The feature was quite clear and we started talking about how we should implement it. At some point one of the participants claimed that if they need this feature they will surely need another related feature. A third guy immediately followed with: "if this is the case then we should also implement this feature…". This routine continued a few rounds until everybody were convinced that this feature was too big and should be rejected.

It seems that more often than one might think we follow 'The Jack Story" while building software. Fortunately, our story ends well. When we got back to the costumer and explained to him why we must reject the feature he stated that none of our guessing were true and he really only needs the original request. This time we got lucky. No extra work was done and we did not lose any costumers.

But it got me thinking. Did we do something wrong?

Now the typical agile practitioner would argue that we simply should not have added new requests on the original user story. Well...obviously my colleagues and I know this argument. We also know that the costumer often does not fully understand what he really needs. Moreover (perhaps not in this case) any company sometimes needs to be a head of the market instead of following it.
Actually, many times as software engineers we do more then we are explicitly requested (over doing). We enhance existing features. We build our code more generic and powerful than we currently need. We basically gamble on future needs, and I deliberately use the verb 'gamble' and not the verb 'guess' because there is a definite rewords for good bets. Naturally, 'Over Doing' also relates to a person character. Some will choose the 'Over Doing' approach more often than others. But everyone does it at some level.

Usually where ever there is a gamble there are measures and statistics. This must be done in order to track our gamble and measure the profit. This is also the case, for example, in software estimation which in essence also involves gambling. We continuously review our past estimation in order to improve our future ones. But this is not the case with 'Over Doing'. We never mark which of our work is mandatory for now and which is a gamble on a future need. As a direct result, we never come back to check if we were right.

So I answered myself: No, we did not do anything wrong. We should continue to gamble on future needs. But we also must find a way to document and review our gambling. It will enable us to estimate the profit of our gamble and help us improve future ones, avoid over engineering where it is not needed, and insist on generic code where we see future opportunities.

 

Prolog


A key tool for a manager is matrices. We already know that traditional matrices in software engineering often provide little help for a project success. You can read about another matrices we suggested in Effective Unit Testing - Not All Code is Created Equal. In the agile era we are in a quest for finding new matrices. New things to measure which might help us navigate our project to safe shore. This post tries to suggest such alternative metric which might be useful.


Thursday, March 22, 2012

6 things they didn't teach me at the academy - Prepare yourself better for a developer's life

Looking for your first position in the software world? Want to know more about developer's life? Improve your chances of getting hired and blend in better? Most cases you just finished your undergrad studies. The years you spent in the academy are valuable and helpful in many ways, but don’t necessarily prepare you for a developer's life. Now, this post is not about whether undergrad studies are a necessary and sufficient condition for being a good programmer, nor about which university prepares you better, but it is about pointing out what might be overlooked during your study, what can be improved, and how one can have a head start when diving into this exciting world. We present you with 6 essential points that will help you in your upcoming venture:

  • Understanding the structure of a software company. Although this can vary form company to company, in most cases there will be a distinction between Developers, QA's/Testers, Support, Product and IT. Understanding this structure beforehand will help a candidate understand the job description he is interviewing for. A new employee will blend in better, adopt business processes faster and utilize all the companies' capabilities.
  • Development Methodologies. Whether it's Waterfall or Scrum, Agile or not, understanding the different approaches in Development Methodologies can give you a since of how your life will look like as a programmer. It could even help you choose a better suited company.
  • Code Management tools and processes.  
    • You can finish your degree with knowing slim to none about code repository tools such as SVN, GIT, etc, which are used extensively. 
    • Continuous Build as a quality control process.
    • Integration Test as a phase in the development process. 
    • Issue tracking systems such as Trac and Jira used to handle development process as a whole.
  • Coding guidelines. No need to be alarmed if you haven't coded much during your study. However - they say it takes 100 repeats to learn how to bench-press correctly, but if you learn it the wrong way then it takes 10000 to correct yourself. Teach yourself how to write good code from the very start. A great book to get you started is Code Complete, Second Edition.
  • IDE usage.
    • IDE's are great - Don't you think? If you haven't mastered one during your studies - that's a shame. They really make life easier and supply easy access to new technologies.
    • However, on the downside - if you adopted one too fast - you might be baffled when someone will ask you to run something from the command line or mention the word classpath. Be aware that there is a world outside your IDE.
  • Utilizing the power of open source. Let's say you have a great idea for a new project. Most chances are that a large portion of your project's infrastructure is already available as open source. Moreover, choosing the right technology can save you an enormous amount of time. A new developer must understand that open source is a powerful tool that can be leveraged- there is no need to invent the wheel every time.
 As a final note,  and from our point of view, the best tip that we can give a starting developer is joining an open source code initiative. This can certainly introduce him to most of the concepts mentioned above, get him a feel of the software world, and make the difference between him and other job seeking developers.



Monday, February 27, 2012

Junior Developers - Anthropological Review

Junior Developers...You can't live with them and it is illegal to shoot them. Well, except maybe for our North Korean readers. So how the hell can you pass software development knowledge to someone who thinks that Maven is a city in Eastern Europe?

In his book 'Software Development as a Cooperative Game', Alistair Cockburn describes the three levels of learning in Aikido. They are Shu, Ha and Ri which roughly translate into learn, detach and transcend.
  • A worrier in the Shu level learns techniques from his master and copies them. This level is also called ‘Follow the Master’.
  • In the Ha level the worrier learns the strengths and limitations of a technique. He learns other techniques and can now choose which one to use according to his position. 
  • In the last level Ri the worrier creates a blend of techniques he knows, while also inventing new ones.
These three levels of learning exist in any craft, software development included. The Junior is naturally at Shu level in most aspects of software development. Consider Object Oriented Design for example. A Junior will adequately follow the rules he just learned at the CRC Object Oriented Design course. He is the one saying "We should use smaller cards. In the course they told us to use 6 inch cards...”

Let’s consider the communication between two people in different levels. If we deduce it to our world then it is between a Senior and a 'Shu' level worrier/developer. A Junior will always prefer to receive a set of instructions/rules for every task he needs to accomplish.

A Junior joining a software development team has a lot of catching up to do. He doesn't know the product. He doesn't know the business domain. He might not know all the tools and technologies you are using. He definitely has no familiarity with software development idioms such as Dependency Injections, Continues Build, etc. Make sure his assigned tasks are with no more then one unknown domain. Moreover, make sure he understands that one of the task goals is to better understand that unknown domain. Taking a different approach will lead the Junior to the mood of "the world is too complicated to understand", rushing to you with problem descriptions like "That red thing is not talking to the green part of my screen anymore. I tried to restart it but it doesn't help". Remember that a software developer must be inspired to understand what is happening under the hood. Throwing to much complexity at once might generate the exact opposite. 

Embracing new technologies is a good practice – depends when and where. Google-Guice home page describes how using the ‘new’ operator is old-school. In the Git home page they tell you that using a client-server source control is old news - Distributed Source Control is Da - Bomb. When visiting the Scala home page they will convince you that using critical section and ‘synchronize’ is ancient history - STM (software transactional memory) is buzzing. The Junior will believe them all. One day he will call you all excited for a simple dialog application demo. It will be on a Git branch, while all objects will be created using Guice, and instances will only communicate using an inner event bus that uses weird syntax of embedded Scala code... you get the idea. So please don't let a Junior embrace new technologies without your review.

The Junior only recently graduated from the University. He already gain experience in problem solving. In the University solutions are always elegant yet complicated where in the real world most chances the best solution is naive yet simple. Once more he will come to you showing off his latest coding. He was instructed to read some configuration from a database and save it in-memory. You are desperately trying to keep up with his explanation on why he had to use a red-black tree (something about reducing the complexity from O(nlogn) to O(lognlogn)) while also trying  to overcome the sharp pain you suddenly feel in the chest. So stop mumbling "...but there were only 20 rows in that table..." and remember that you must change his approach to the well known "keep it simple".

Stating the above, we cant ignore the benefits of Juniors. Their ability to adopt new technologies, highly motivated and hard working (usually they don't have 3 mouths to feed...)



Sunday, January 22, 2012

The Wizard Design Pattern

We all love wizards.... (Software wizards I mean). We are always happy to jump on those ''Next" buttons like we were dancing the funky chicken on our… well you get the point. So today we bring you your beloved wizard into your coding experience. Let's jump right into an example.
Say you want to design a ConservativePerson class.
   1: import java.util.List; 
   2: class ConservativePerson{ 
   3:  
   4:  
   5:     private boolean isVirgin; 
   6:     private boolean isMarried; 
   7:     private List<String> children; 
   8:  
   9:     ConservativePerson(boolean virgin, boolean married, List<String> children) { 
  10:         this.isVirgin = virgin; 
  11:         this.isMarried = married; 
  12:         this.children = children; 
  13:     } 
  14:  
  15:     public boolean isVirgin() { 
  16:         return isVirgin; 
  17:     } 
  18:     public boolean isMarried() { 
  19:         return isMarried; 
  20:     } 
  21:  
  22:     public List<String> getChildren() { 
  23:         return children; 
  24:     } 
  25: } 

As such it has some constrains.

  • He must be married before he can be... well, not a virgin.
  • He can't be a virgin before he can have children (as far as we know).

In the old days, which is basically all days until today..., you would probably define all kinds of modifiers methods for this class which will throw an exception in case of invariant invalidation such as NotMarriedException and VirginException. Not anymore.

Today we will do it by using the Wizard Design Pattern. We use a fluent interface style and utilize the power of a modern IDE to create a wizard-like feeling when building a ConservativePerson object. We know, we know, stop talking and show us the code... but before we will present the wizard code we will show you it usage so you will get a grasp of what we are talking about...


   1: public class Main { 
   2:     public static void main(String[] args) { 
   3:         ConservativePersonWizardBuilder wizard = new ConservativePersonWizardBuilder(); 
   4:         ConservativePerson singlePerson = wizard. 
   5:                 createConservativePerson(). 
   6:                 whichIsSingle(). 
   7:                 getObject(); 
   8:         ConservativePerson familyManPerson = wizard. 
   9:                 createConservativePerson(). 
  10:                 whichIsMarried(). 
  11:                 andNotVirgin(). 
  12:                 andHasChildNamed("Noa"). 
  13:                 anotherChildNamed("Guy"). 
  14:                 lastChildName("Alon"). 
  15:                 getObject(); 
  16:     } 
  17:  
  18: } 

Now, it may look just like an ordinarily fluent interface, but the cool thing here is that a method is available for calling only if the current object state allows it. This means you will not be able to call the method andNotVirgin if you haven't called the method whichIsMarried.
See the following set of screen shots:

1

and after we state he is married we can:

2

Here is the wizard code. I urge you to copy/paste it to your IDE and give it a try by building an object with it.

   1: import java.util.ArrayList; 
   2: import java.util.List; 
   3:  
   4: public class ConservativePersonWizardBuilder { 
   5:     private boolean isVirgin; 
   6:     private boolean isMarried; 
   7:     private List<String> children = new ArrayList<String>(); 
   8:     
   9:     public SetMarriedStep createConservativePerson(){ 
  10:         return new SetMarriedStep(); 
  11:     } 
  12:  
  13:     class SetMarriedStep { 
  14:         public SetVirginStep whichIsMarried(){ 
  15:             isMarried = true; 
  16:             return new SetVirginStep(); 
  17:         } 
  18:  
  19:         public FinalStep whichIsSingle(){ 
  20:             isMarried = false; 
  21:             return new FinalStep(); 
  22:         } 
  23:     } 
  24:  
  25:     class SetVirginStep { 
  26:         public AddChildrenStep andNotVirgin(){ 
  27:             isVirgin = false; 
  28:             return new AddChildrenStep(); 
  29:         } 
  30:         public FinalStep butStillAVirgin(){ 
  31:             isVirgin = true; 
  32:             return new FinalStep(); 
  33:         } 
  34:     } 
  35:  
  36:     class FinalStep { 
  37:         public ConservativePerson getObject(){ 
  38:             return new ConservativePerson(isVirgin, isMarried, children); 
  39:         } 
  40:     } 
  41:  
  42:     class AddChildrenStep { 
  43:         public AddChildrenStep andHasChildNamed(String childName) { 
  44:             children.add(childName); 
  45:             return new AddChildrenStep(); 
  46:         } 
  47:         public AddChildrenStep anotherChildNamed(String childName) { 
  48:             children.add(childName); 
  49:             return new AddChildrenStep(); 
  50:         } 
  51:         public FinalStep lastChildName(String childName){ 
  52:             children.add(childName); 
  53:             return new FinalStep(); 
  54:         } 
  55:     } 
  56: } 

As you can see the wizard consists of several steps. Each step is represented by a dedicated inner class. Each step reveals the legal available operations by its methods. Each method will then return a new step according to the change it has made. This way an attempt to create an illegal object will be detected at compile time instead of runtime.

This pattern is actually being used in our production code. One example that comes to mind is the MediaJob class. This class describes a manipulation on some media files. In order to submit a job to the system, one has to create a MediaJob object. The problem is that this object has many parameters that could be assigned with contradicting values that create an illegal object state. By using the Wizard pattern, one can easily build a legal job without the need to know the entire (and complicated…) set of constrains.

That is all for now. Hope you'll give it a try..... We plan to write a more formal description of it (GOF style) in the near future.