Tuesday, 2 September 2014

Why should we not ask about Design patterns in an interview?

There is a famous book "Design Patterns: Elements of Reusable Object-Oriented Software" they have covered a number of classic object-oriented design patterns and also have covered some basic design concepts as well. It's a good book…
But what people in the software industry have done with it is beyond preposterous. It’s not a stop shop to write code this way. It's not a recipe book to be followed slavishly like some kind of paint by number template.
Interviewers always ask if you know design patterns. Job descriptions list "Familiarity with design patterns" as if it is some kind of secret rare knowledge only real programmers know.
Anyone who has been into proper programming over any length of time will accumulate "patterns": things you did in the past that worked, ideas you got from colleagues or from the internet, basically anything that was worth remembering that seemed to be useful. Everyone's experience is different but it makes up the toolbox you use in your daily work. Your approach to solving problems, how you test or debug, how you think about structure and design, your personal process; all sorts of things make up your "pattern". These are the things that you offer to an employer, in whatever shape or form it may be.
Yet people insist on you naming a design pattern in interviews, like it's a secret handshake, or asking a carpenter if they know any kinds of wood. What does it prove? Bloody hell…Nothing.
Programming is not coding by numbers or simply cobbling known patterns together. Today I will write a flyweight pattern and then add some strategy and maybe a proxy which goes well with a nice Chianti and some Fava beans.
Mozart composed music in the style of the period he lived in, he knew what people expected, he understood how to craft excellent music that people would want to listen to, and he definitely knew all the things only bad composers did. He did not write music by filling in blanks in some preconceived template even if the music of the time was highly formulaic: he created music people still listen to today because his patterns were all internalized and he knew how to compose within, and also violate, those formulas without resorting to stringing together simplistic bits of music. He knew all the mundane basics but that didn't drive his compositions.
Programming likewise isn't a bag into which you pour some things you read in a blog. It is an aggregation of your experiences, successes and failures, experiments and deliveries. Like any craft you discover things that work, ideas that have merit, and yes patterns that are worth reusing.
Looking at a set of canned design patterns as something independent and meaningful in all situations isn't craft, it is paint by numbers. It is a tool like anything else. Programming isn't some task that you keep on doing that you’ve mugged up from a book, it’s a continuous learning procedure where every day you make decisions on what to write and how to design or structure the code in a continuous basis. The set of patterns from the book are a useful collection but knowing what they. So stop trying to memorize those patterns!
Given that languages today are often functional or hybrid types, design patterns may be entirely irrelevant for many people. Today having a broader knowledge of how to use these types of languages and being willing to learn how to use them effectively is way more useful than remembering a static set of patterns or as a matter of fact a static set of anything. Programming these days is constantly changing, and we are coming to an age where anything written ten days ago may be partially or even completely pointless today.
So stop asking candidates if they have worked on any design pattern. The answer is always "Singleton"!!!

Tuesday, 15 January 2013

RIP Aaron Swartz.

Swartz took his own life last weekend by hanging himself. But most of the people do not know who Aaron Swartz was. A lot of netizens seemed to be mourning though. From what I've read the poor chap committed suicide because of the fear of a long term prison sentence. All he did was get access to some pay for access site at MIT and made them public. The US government and MIT wanted to show everyone what would happen if you steal. He was facing a life sentence of 35 years in prison. He wanted to make a point that public data should be free and open. Considering the gravity of the situation there was little chance that he would face life imprisonment, but I guess the pressure got to him.

Swartz believed in Open Internet, Open Access, Open Source Code and Open Data. He created some the technology that we even use at the very precise moment. RSS (really simple syndication), many of you might be even reading this through rss feeds. He also co-founded Reddit, many of my mates use that. He was most recently famous for was helping to organize the social media blitz that turned public opinion away from the ill conceived SOPA anti piracy bill last year.

Aaron Swartz, you will truly be missed, as one of the innovative thinkers of this century.

Rest in Peace mate.

Sunday, 16 December 2012

Things I learned from my life experience to be a good programmer

Programming for some people it is really a pain, for some its passion and for others it's just a job. Well my life experience has taught me that programming is a character, yeah!!! your character defines what kind of a programmer you are....

1. Search for Clues
Try to know what you want before you set out to do anything. The web has evolved a lot, there is usually a 99% chance that you might get some kind of advice. Talk to other blokes who have done it. When building something from scratch and you have not done it before it would be quite tough. The end result would look much better if you start with a clue.

2. Sharing is Caring
Open Source is a great thing. I know it looks a bit confusing in the beginning, but give it some time, try to use open source wherever possible. Also try to contribute something to the world of open source. The happiness you get once you have contributed something is well beyond explanation.

3.You never know until you try
Always give other technologies their due respect. The most common debates I've hear is about .Net VS Java. Sometimes other technologies may one day be of more use than you ever imagined. I once had the same experience with mySQL.

4.After cooking, always clean the kitchen
Always try to deliver code that works. Never rely on other programmers or QA's to get the code corrected. Always unit test code. This is the best way to be sure.

5.Don't be Nostalgic
Don't be afraid to replace, rewrite or re-factor code. Sentimental attachment to code will always bring you problems. If it does not work, never hesitate to throw it out of the window. Never ever love your code.

6. Be ready for change
People change, Technology does the same thing too, it changes. Be ready for it. Adapt to new technologies, new ways. Read blogs, articles, get into some tech forums, it helps you to keep your mind fresh. The day you feel programming is nothing but the same wheel turning round and round with different colors, that is the day you should think about switching into management or an entirely different career.

7.Don't be rude
Don't be a bully just because the kid sitting next to you uses Java or .NET or php, try to see what he is doing. You might also have the chance to learn something wonderful from him other than telling him how hilarious and hopeless his language is.

8.Life is not all about programming
Working all the time, will never ever make you productive. Try to get some fun in life, have a couple of beers, coz being stressed out and working all the time will only make matters worse. I have often solved problems by going out for a drive or by watching some TV, or spending sometime with my girlfriend

9.PS When going out in the real world do not forget there are traffic rules to be followed, T.V is meant to be enjoyed and when your girlfriend finishes talking you are supposed to say something back to her ;)

You won't learn if you don't try, everything I learnt is all from my life experience. Always keep and eye out for new Technology and always remember that just like the software you create, you also have a life...

Tuesday, 16 October 2012

Romo is back in Town....

Ever wondered if you could have a robot like the one in WALL·E as a friend, or someone who is there to pick up the TV remote when your lazy to get up. Well the answer is yes and that is not very far away....

Introducing Romo the iPhone powered robot. He's got a cute little face, runs around room and when he sees people he smiles :)   The guys who invented the Romo are based out in Vegas. And just like Vegas Romo has got all the style of Vegas, a streamlined body, a redesigned model from that of the Romo 1.0 and it looks more like a toy than a tool.

Romo can be connected to your iPhone and can be controlled with a smartphone or tablet. We can let Romo run around the room and use the camera as well. The Romo costs $150 if you pledge now and they are looking for quite a lot of money to build and ship these guys.

The best part is that the development  team is planning on building an entirely new app for Romo, adding some kick-ass features like autonomous navigation, facial recognition, and computer vision. They will also add an SDK so programmers and add features to the Romo.

Well there is one thing sure about the future. There are going to be robots and Sci-Fi movies were definitely not lying. Who knows one day robots like Romo will be doing the grocery shopping for us just because it is easier for us and maybe robots can scan the groceries and see which ones are the best. 


Check Romo out on their website at http://romotive.com/meetromo

Tuesday, 9 October 2012

LAMP, is it really that great?

"The truth sat there on the screen, burning a hole into me."

Couple of days ago me and my amigos were celebrating the success of our finished project when one of the guys was telling me that most of the engineers in his company were moving away from the open source platform. The main reasons were the fear of unprecedented bugs, code not being tested properly, and of-course accountability. Well it's not like we have a help-desk number to call if something goes wrong on you Fedora....

These days most of the folks do not actually appreciate the use of good old open-source software, like the LAMP for instance. Well you'll be surprised when you get to know that loads of them have not even heard about LAMP. LAMP stands for Linux OS, Apache Web Server, MySQL and PHP.

It's the development platform that determines the efficiency of the application, the wrong choice of the a platform means the client will not get what they asked for...and that usually does not go well at all. Especially since Cloud computing has come into the market everyone is running behind the cloud, its not like I have anything against cloud computing, but sometimes I feel most of the programmers have lost the flair for sitting down for hours and getting an application running, I remember the times when I used to sit for hours during my time in school trying to start and get the J2EE 1.3 running and the joy when you see the application working, you'd say to yourself "Now I know why Archimedes forgot his clothes"

It’s interesting to note that they were developed individually and at no point during the development of the software did the developers think about creating them for combined use. (Weird huh???) But later it was found that combined together, they offer an unbeatable stack of solutions driven technologies that support application servers.

So what does the components of the LAMP actually do, lets find out...


To be fair, the operating system is not as important as the server, database and language options, because AMP is also an effective combination on other platforms, including Windows. It is, however, more common to use an entirely open source solution, and the support that comes with Linux distributions for easily installable versions is an obvious bonus.

Did You Know that...

Wikipedia uses PHP, MySQL, and Apache HTTPD to provide an online encyclopedia with thousands of entries in multiple languages. All of this is served by Linux servers running the WikiMedia application.

And trust me folks once you have got the flavor of open source software, you'll never revert back. If you are a programmer or a guy who loves to explore all kinds of things and want to know How stuff actually works open source is the road ahead for you. So go ahead, break out from the Mac or the Windows bubble. Explore the world of open-source software, back in the day there were people who were actually willing to risk it all. When we were growing up we never even used to have backups for the code we wrote, and only actual testing (Alpha Testing as it is known) we used to do was ask the junior chaps to take the software for a spin ;) 

Friday, 22 June 2012

How to Create Your Own Website: The Beginner's A-Z Guide

It hits you like a TON of BRICKS! You've got a KILLER idea and you want the entire world to see it. With the idea fresh in your mind you sit down and BANG it's out there and then it sinks into you...."how do I show it to the entire world?"

Well you make your own website: unless all you want is a Facebook fan page.

It's true that these days there are a quite a few websites out there which helps you to make a website!!! But think about it for a second. Did Mark Zuckerberg ask someone else to write facebook for him? or did Larry and Sergey hire someone to make google? NO, well as a matter of fact Hell No.

You have an idea and if you want to make it the way you want it to, there is only one way to do it. Your Way. 

So how do we actually start making a website? Some might tell you to get a domain name, then get a web host, then design the web page using CSS (a pinch of Javascript if required) and finally depending on the complexity you might have to do some server side scripting and your done. Well any idiot with a CS degree knows this...the question is what is the exact way of doing it?

Well there are many ways out there, and I thought of this one particular way which is easy and efficient. 

Introducing Salesforce.com,  well to be honest, if are not into sales or CRM the chances of you hearing about Salesforce is pretty less. Salesforce.com is a software as a service company that distributes business software on a subscription basis. Like all CRM software it captures, records and organises information from the present or prospective customers from different departments of the company. That's pretty much about Salesforce, we on the other hand are interested on how to make a website.

There are some basic things which you need to know about Salesforce before we start making our website. 

The first one is VisualForce: This is where you do your front-end design. Salesforce has got it's own components for VisualForce like buttons, text-boxes, drop-down menus things like that. This would look like HTML, so if you can understand HTML understanding VisualForce should not be that difficult. You can also use HTML or JavaScript or CSS.

The second is Apex: Apex is a language which Salesforce has created. It looks very similar to Java and those who know Java, Apex should be a walk in the park. Apex is used to write classes. Let's say you would like to add some functionality to the pages like query some items from a database and filter it with a set of parameters. Well that is where Apex comes handy, you can create classes and write your business logic in those classes and call those classes in your VisualForce page. You can write all these classes in Eclipse, by either downloading a plugin or download the entire Eclipse is available from Salesforce.

And finally Sites: Another fact about Salesforce is that it is a Software As A Service (SAAS) platform. So everything is on the cloud. Since things are on the cloud, there are a lot of security issues. Once you design your webpages in VisualForce, write your classes in Apex you need to you give the necessary permission through sites. Sites allows you to create your own domain and let the general public see what you've made. But before the public can see what you've made you need to give access to each and every component that you've used in your VisualForce pages.

So shall we crack on with it?

First of all we need to create an account on Salesforce. You can do that by going to http://www.developerforce.com/events/regular/registration.php?d=70130000000EjHb

The registration is fairly simple and after you've finished with the it you can login on https://login.salesforce.com/

Once you've logged in your page would something like this...

Once you see this page, on the top right hand-side of the page you would see your name. Click on your name and go to setup.

After you are in the setup page, on the left hand side you would see something called Develop, click on that and it would expand. Inside that there is an option called Pages. This is the one that would help us create our web-pages. 

Click on the new button and it would take you to a page, it would look something like this.

As you can see I have already entered some data and I have done some coding. In the Label part you can select the name of the web-page.  I have entered "testPage" as the label name and if you look closely I have done some VisualForce coding. Here is the VisualForce code

<apex:page sidebar="false" showHeader="true" standardController="TestDatabase__c" extensions="MyPageController">

    <apex:pageBlock title="Personal Details">
        <apex:form >
            <apex:pageBlockSection collapsible="true" columns="2" title="Name">
                <apex:inputField value="{!TestDatabase__c.firstName__c}" label="First Name"/>
                <apex:inputField value="{!TestDatabase__c.lastName__c}" label="Last Name"/>
            <apex:pageBlockSection collapsible="true" columns="2" title="Address">
                <apex:inputTextarea value="{!TestDatabase__c.address__c}" label="Address"/>
            <apex:pageBlockSection collapsible="true" columns="2" title="Contact Information">
                <apex:inputField value="{!TestDatabase__c.emailID__c}" label="Email ID"/>
                <apex:inputField value="{!TestDatabase__c.Phone_Number__c}" label="Phone number"/>
            <apex:commandButton action="{!pageSave}" value="Submit"/>

As a rule of thumb, all the VisualForce code should be done inside the apex tag which is <apex:page> </apex:page>. I have not removed the default Salesforce template, if I were to do that, I would have to use Cascading Style Sheet for formatting. Now the standard controller is like the database in Salesforce. I have created a database, which are called Objects. Now in this scenario I have created a custom object and also used and extension.

Extensions are used when you want to add some more functionality. In the above code I have added an extension as well. The extension name is the class name.

Now let us dismantle this line of code 


The inputField is an HTML input element. It's just like an InputField in Java or .NET. The next part value="{!TestDatabase__c.lastName__c}".  TestDatabase__c is the object's name, while lastName__c is the Custom field which have created inside TestDatabase__c. And the last part which says label is simply a label duh!!!

I do admit it's a little bit confusing in the beginning but give it a couple of days and it's fairly simple. The important fact is that you need to be comfortable with the interface.

Now moving on I did mention that I used an extension for some added functionality. It is to basically do a page redirection when I click on the save button. Here is the code for that

public with sharing class MyPageController 
 private ApexPages.StandardController controller;
    public MyPageController(ApexPages.StandardController controller) 

 public PageReference pageSave()
  PageReference ref=Page.saveConformation;
  return ref;
All I am doing here is a simple page redirection which on saving would take you to another page which says, Thank You For Registering. SaveConformation is the name of the page.

Now we have the webpage finished and have a small class. All that is remaining is we have to go to Sites, and provide access to our pages. First we would have to create a domain in sites which is unique, after that add the two web-pages and you have your website ready to be served.

This is the sample website which I created http://personaldetails-developer-edition.na9.force.com/

There are loads of things which can be explored in Salesforce, hope this not very small article would give you some help in creating your next idea :)

Tuesday, 5 June 2012

Multithreading is like juggling grenades!

Writing multithreading code is like juggling grenades; when it works it works like a charm, otherwise it's your worst nightmare.

Couple of hours ago I was working on a multithreaded application in Java,  I was immersed in lots of threads and applications. So when you are interacting with say 500 "things" per second and when something goes wrong all the grenades do explode synchronously, that is when you'd catch yourself wishing "Only if Java had shown me a little bit of mercy."

An all time popular question about multithreading is "What are the major problems you expect while implementing multithreading?" Well if someone has read about multithreading their answer would be "I would try to avoid deadlocks" that is when the your average guy screams at the top of his voice and says "You idiot...deadlocks are easy, trying to protect shared data is the most important thing to do" but only the experienced (Saddy) do know that trying to avoid doing nothing is the most important thing.

Still not buying it??? Ok lets start with the inexperienced guy who said to avoid deadlocks. Deadlocks can generally be avoided if you are disciplined. The average guy who might have done some thread coding maybe in Swing, well locking shared variables is not the hardest thing to do. Now coming to Saddy's answer - "Why is doing nothing the worst of things?" When coming to a complex high speed system the first and the second would be the basic requirement without slowing down the system. So you might imagine what's the big deal if a couple of threads waited in the background while waiting for resources. Well if there is one thing experience has taught me is that Threads are always greedy.

Imagine a very large server has - let's say 2000 threads waiting for something to happen...What would happen if Amazon is processing millions of searches daily and half of their server's capacity is spent on waiting for something to happen (WTF), that is money and power going down the drain. The company would need twice the amount of hardware (forgetting the fact that the CFO having a cardiac arrest) for poor thread coding.

Multithreaded coding is a complex task and implementing multithreading in a complex environment is even more complicated. Sometimes a lot of negative answers do lead to a positive solution, remember for a positive: you will always need two negatives. It's not easy and it's not quick and don't mind the project manager; tell him you are waiting for the pièce de resistance of multithreading.

Then again multithreading is like juggling grenades.

PS: The only guarantee about software development is that the spec always changes.