Thursday, February 24, 2011

Vision, Team, Leadership and Business

For the last few days Nitesh and myself were discussing team building, work, processes, leadership, business and everything in between. As a full time team leader and an entrepreneur at heart these topics play in my mind every once a while. What does it take to deliver a quality product? How do you ask people to buy your vision? Do you keep everyone monitored or let them be free and come up with solutions for the problems?

Well in our case it is a mixed bag of so many things. Leadership, I believe, is always by example. My being a full time 24x7 product leader should ideally help everyone else in the team. And it is more than just my work that counts, it is also the guidance. A good leader is a cushion too. You can fall back on the leader when all else fails. But what drives the leader? Vision. And staying focused to it is of utmost importance. A vision has to be set out as achievable deadlines. Then the team chases them and finishes each milestone.

But what keeps the team together and motivated? Good processes. Freedom is necessary but to repeatedly provide outcome that takes a business towards more growth needs some base rules in place. The most important of them is discipline. To be on time, to understand the value of the work and to make sure my part gets completed. To understand I am part of a whole and my not completing my responsibilities makes the whole look like a fool. Thus respect for oneself, for the work and the team is also necessary. After that I believe it is the spirit which drives you into crazy hours. The wish to do something worth remembering is what makes you focus at work. At the end of the day we are all incentive oriented. And incentives are great motivation.

Will each member of the team prove as equal? No, that is just not possible. But everyone should believe in the vision, everyone should work towards it. Yes bad days here are there are OK. Although losing track of those milestones could be fatal. And that is where you need a minimum control. It is difficult to monitor brilliant minds but we should also understand that brilliant minds sway a lot too. So someone should be looking at the progress meter every once a while. Just remind the team that things are going slow, and things will move. And yes make favorites. To cheer those who are performing brilliantly gives others something to work harder for. And keep small personal goals which if achieved are rewarded. Like being earliest at office should have a bonus.

Even with all these there are no guarantees in a business (or life). Only when all good points come together do we have empires growing out of them, empires than shine bright. If that is your goal then work hard, because there are no short cuts.

Monday, February 21, 2011

Kolkata's date with Bloggers, Feb 20, 2011

Feb 20, 2011 was a fun filled day for many bloggers of Kolkata. Probably for the first time here we had two back to back blogging events organized separately in two separate venues. The day for us started at about 12AM with the IndiBlogger's meet, which was carrying the Akshaya Patra Foundation's message across to bloggers in Kolkata and around.

The Akshaya Patra Foundation is a non profit organization which provides mid day meals to students in schools. Its program is the largest of its kind in the world by a non profit organization. Akshaya Patra Foundation wants to spread its message across the world through online media: citizen journalism and word of mouth. Its cause is to solve one of th fundamental issues of our country, the battle of education with hunger. Students from very poor financial background can not continue education since they are more hungry for bread than books. What mid meal programs do is reverse the effects of poverty a little bit by providing healthy, tasty food to children who attend school. This message is very strong and the effort is one which can shape India's future.

With the help of bloggers from around the nation Akshaya Patra Foundation can attract more people (donors or volunteers) to its cause. The IndiBloggers meet gave a chance to all kinds of bloggers to meet and discuss on social, technical and general issues. Networking and launch was of course a part of this. Overall a great meet which ended around 5 PM with a band performance.

Right after IndiBlogger meet we head straight to Salt Lake Stadium grounds where Kolkata Blogger's Meet was to start from 6PM. People had already gathered by the time we reached and introductions rounds were just about to start. The crowd here too was filled with enthusiastic bloggers who were eager to show off their blog and learn from others. We had a few prominent bloggers take the stage and talk on what it meant for them to blog. The variety of bloggers including Android fan boys to poets and everyone in between.

Kolkata Bloggers' Meet had some speakers on the important point of monetizing a blog so people can take blogging as a career option. There were discussions on SEO and content quality of a blog too. Overall a great take back and of course nothing beats the networking in a city which waits a while to get an event. But it seems recently that events are catching up in Kolkata. I am really optimistic about this all and would like to hint there is a plan for a monthly meet for IT professionals which will have design, content and technology tracks. Hurrah for us!

Saturday, February 19, 2011

Buzzwords: Cloud, Mobile, Social

The list of the hottest buzzwords in the industry would certainly include Cloud, Mobile and Social. The impact they each of these have is immense, and when combined they practically are changing our lives. In early days of the web applications (even dynamic websites) the notion of cloud based computing was not as popular as it is now. People had to predict their infrastructure requirements and allocate large budgets upfront for hardware and networking. This meant considerable amounts of funding money (for startups) going into silicon chips and their families. In the last half a decade that has changed dramatically. Scaling applications without budgeting upfront is not just possible, but is being done everyday by so many.

The lowering of upfront costs for startups and the means to handle traffic on shoestring budgets are really empowering entrepreneurs across the spectrum of applications. Large on-demand platform providers like Amazon, Google, Microsoft, Salesforce are leveling the playing field for funded and bootstrapped companies from the technology platform perspective. You can write a data intensive application and actually demo it to a prospective client or launch it publicly without raising much capital.

Mobiles are getting smarter by the quarter (month maybe?). The most recent ones like Motorola Atrix and Samsung Galaxy S II are comparable to Intel Atom based mini laptops from hardware perspective. And on top of it mobiles like Atrix allow you to dock the deice with keyboard, mouse and monitor for a desktop experience. Or take a laptop shell and dock the Atrix for a laptop usage. Same will come out of Samsung and other handset makers very soon. Our working environment thus really shrinks into our pocket. Take your work with you in your pocket, plug into your office keyboard, mouse, monitor and work there. This is again a game changer in the industry.

The last point, social is something which most of us understand better. Being social is a basic human quality. Word of mouth has always worked with us. Now on the web, content that is share-worthy becomes famous. People who are domain experts are becoming our online help-desks. Even corporates are reaching out through social media to the wide audience. But social is yet to touch a few sectors which it should. Like banking, which is still a number based industry. Banking could move to a more social form, where transactions are noted against people, not numbers. Even in its current forms if you join cloud, mobile and social, you immediately get a glimpse of a future that is driven by applications which cater more to "me" and "us"; and are available wherever we need them. The browser is the window to the world. And the browser is mobile, more customized and richer than ever.

Thursday, February 17, 2011

Good code, great code

When you do software development (or any other work for that matter), getting to the first 60% is comparatively easier than the rest 40%. The initial 60% work usual is bulk work, broad plans, overviews from 3000 feet high and all. But the more you cross that mark of broad planning and go into the details, work becomes art. The first lot is almost always science. The last part is true craftsmanship. This is something that any team must consider when they work on projects of any size where quality matters. Of course if you can pass your project with just coarse details then do not even bother to read this blog.

I have myself been programming with web languages (mainly PHP) for the last 7 years at least. Before that I had C, C++ in school and college. And even before that BASIC in lower classes in school. And it all started with LOGO when I was just 6 years old perhaps. Yes these many years and it still takes time to think through a large project. The initial outline comes within the first 30 seconds. But as I go deeper into the details, the architecture shifts. It is not always performance that you need to take care of. Code maintenance is also a big headache. You do not want to be stuck with code which is difficult to hand over to team members. That is basically dead code.

Also the modern stack of code for the web has changed dramatically. It has become a habit to think in terms of APIs. This enables loosely coupled architecture which is probably the best thing about the web itself. When designing web software though one thing I had to learn the hard way is that UI is most important. I have always thought of it, but still failed many times to stick to that rule. Slowly we have almost got to that point though and soon it will be better. But it is very essential to understand usability in user facing software. Code comes later.

A good software product is made of many components. Raw lines of code are just a part of it, very important ones though. But a very efficient data crunching tool will fail if it allows only XML files to be imported. People may have Excels, CSVs and what not. So it is most important to understand the audience. All these go in that ultimate great piece of code. In the end a product is also the packaging, the color, the logo, the manual that comes with it right? Same for software.

So from the next time you start a project by coding, think. Do the above points apply to it? If so try avoiding mistakes noted here. Go make some new mistakes :P

Wednesday, February 16, 2011

Free web hosting with Amazon Web Services (AWS)

I have deliberately titled this blog post such that it gets more hits when people search one of the most common issues related to hosting: free web hosting :D. Of course Amazon does not provide just free hosting, its much more that than. But the general blogger, community leader, shop owner or similar is still more interested in hosting a WordPress, Drupal, Joomla or some e-commerce application. Let me explain a bit what Amazon Web Services is all about and what this free deal means.

Amazon Web Services is a collection of products offered by Amazon (yes the original book seller on the web) which allows users to avail compute power, storage, database, content delivery and other stuff with no up front commitment. You pay for what you use. These allow you to have your application hosted on Amazon infrastructure whenever you need. You do not need to buy resources in advance since Amazon gives you access to them when needed and charges you only for what you use. Lets take WordPress as an application. It runs on PHP, uses MySQL for storage. You may also need normal disk storage if you upload audio/video content or file attachments. What Amazon gives you is building blocks. You have EC2 for running WordPress. It behaves like a complete machine which you can log in to. You buy bandwidth on a per use basis. So basically you install PHP, MySQL and necessary stuff and then throw in WordPress and hurrah! Your own blog on Amazon's servers!

Now you may be interested in hosting your blog (WordPress) or content management system (Drupal, Joomla), custom website (on PHP/Python/Ruby, MySQL etc.) or e-commerce application (Magento, Ubercart). What we are going to do is get to use Amazon's products and run our website on them for free. How free? Well Amazon is giving a free tier to every new customer till about end of this year (2011). Go and sign up for the free tier; you may also read through their product details.

Confused about how these stuff enable to host your website? Well I will agree it is not as simple as buying a hosting account from a web hosting company. Amazon gives you lower level platform on which you can build your own application. But no need to worry, you can look at services like JumpBox who provide you easy starting points and ready to start machine images for most popular software. They are even supporting the free AWS tier with ready to lunch solution for WordPress, Drupal, MediaWiki and Joomla.

Tuesday, February 15, 2011

Templates with Mustache in JavaScript and PHP

For a long time I have used PHP as the template language with nothing else on top of it. No template engines ever. This was all fine till the point that we wanted a full AJAX UI in and also support basic view in non JavaScript mode. We also wanted to also change to a template structure which is more graphic designer or HTML developer friendly where only knowledge of HTML/CSS is needed. Thus we needed a logic-less no-frills template engine which has support in JavaScript and PHP at the minimum.

After searching a little we came across Mustache, a logic-less template engine with support in many more languages than we needed. But we were certainly happy to see support in Python and Scala, just in case... Well a brief look at the readme in JavaScript version and PHP version will tell you the story: it is damn simple.

Mustache supports Number, String, Array or Object like data structures as its data source (view). It can also check for Boolean and function returns. Well that is more than sufficient for our needs. The major benefit was not that though. If you continue using any PHP based template system which you may end up having some PHP logic stuff somewhere in your templates after a while. This happened to us and we hated it. Our design team obviously wants to keep templates to themselves and thus the need to move to very clean templates.

Now how do we deal with PHP and JavaScript versions? We make one file per module in our system. So say discuss.html for templates related to discuss (Gab) system. Similarly user.html and usermanage.html and so on. Each file contains multiple individual templates which correspond to the sub-feature being requested. These are separated by HTML comments. The files are read in by a PHP code and provided as PHP array of strings to the PHP rendering engine or as JSON array of strings to the JavaScript rendering engine. This rendering engine is not Mustache, its a layer on top of it, which collects templates and data (view in Mustache language) and then send them for rendering.

The major difference between the PHP and JavaScript version of rendering is the way the layout is built. In the case of PHP, every sub-template is parsed, every inch of data prepared and then actual Mustache rendering starts. All this is synchronous. Smaller parts are fed to larger ones as strings, and so on. So we use View Partials in Mustache. But in the case of JavaScript rendering it is a different world. We only render outer portions first. For partials we render them later and modify DOM to insert them back to the page once the partials are rendered. So this allows us to have partials request their own data in totally asynchronous manner which is what we wanted.

We are still in process of developing this whole system. Of course we threw away hundreds of lines of old code to put this new system in place. And much of utility has shifted to JavaScript mode only. Also the back-end now behaves more like an API which just server JSON/PHP arrays.

Monday, February 14, 2011

A simple clean good looking pagination

We are re-writing few base codes in and one of things re-written is the pagination logic. We needed something very simple, good looking, yet works.

The logic boiled down to having 9 slots in total for the pagination labels. First and last ones were fixed at page number 1 and n. They were labelled "First" and "Last" too. Then we chose to keep 5 slots around the current page. So if page 8 was selected, then the labels (and corresponding pages) were 4, 5, 6, 7, 8. This allows users to browse nearby pages. The rest two slots we simply divide equally on both ends. We fill the gaps between the segments with '...' which links to nothing (FALSE here).

If the current page was near the start or end then we simply print 5 slots in that end and put the rest remaining 2 slots at the other end.

If the total number of pages is 9 or less then of course no use of all this logic, simply print them serially.

Well that's it! Here is the code, we build an array of the pagination slots.
  if($num_of_pages > 9) {
    $pagination_slots = $num_of_pages > 9 ? 9 : $num_of_pages;
    $selected_slots = array();
    if($page > 3 && $page < ($num_of_pages - 3))
      $selected_slots = array_merge(array(2, '...'), range($page - 2, $page + 2), array('...', $num_of_pages - 1));
    elseif($page < 4)
      $selected_slots = array_merge(range(2, 6), array('...', $num_of_pages - 2, $num_of_pages - 1));
    elseif($page > $num_of_pages - 3)
      $selected_slots = array_merge(array(2, 3, '...'), range($num_of_pages - 5, $num_of_pages - 1));
    $pagination = array();
    $pagination[] = array('url' => '?page=1', 'title' => _('First'));
    if(count($selected_slots) > 7) {
      foreach($selected_slots as $s) {
        if($s == '...')
          $pagination[] = array('url' => FALSE, 'title' => $s);
          $pagination[] = array('url' => '?page=' . $s, 'title' => $s);
    $pagination[] = array('url' => '?page=' . $num_of_pages, 'title' => _('Last'));
  } else {
    $pagination[] = array('url' => '?page=1', 'title' => _('First'));
    for($i = 2; $i < $num_of_pages; $i++) {
      $pagination[] = array('url' => '?page=' . $i, 'title' => $i);
    $pagination[] = array('url' => '?page=' . $num_of_pages, 'title' => _('Last'));