Nishith Nand

April 12th, 2012 by Nishith Nand

Python Style – Learning plan

Here is my updated learning plan, incorporating some of the feedback that I received.

Learning plan

1. Write small programs without worrying about style. (CodeEval, Topcoder)
2. When sufficient number (5) of programs has been completed, go through each of them and find the 2 most common variations from PEP8. If no differences are found go to step 5.
3. Write more small programs, keeping in mind the 2 differences identified.
4. Go to step 2.
5. Write a medium sized c program.
6. Translate that to python.
7. Check it for variations from PEP8, if found repeat steps 2 and 3 with medium sized programs, else go to 8.
8. Start an open source project in Python. Check it thoroughly for PEP8 compliant, invite others to do this.

Metrics

Number of differences from PEP8 per 100 lines of coding.
Number of surprises in the code for a python expert.

April 12th, 2012 by Nishith Nand

The Gilded Rose Kata

The problem – Gilded rose kata
Solution 1 – Clean up of the provided code
Solution 2 – Different and much improved approach
Set of tests

Gilded rose kata is a problem of special cases. The problem statement starts with a simple requirement of decreasing the value of an item as its sell by date approaches. It then goes on to introduce a multitude of special cases. The kata in itself is not difficult to solve, what is difficult though is to keep the code readable and extensible. The sample code provided with the kata almost follows the problem statement completely, starting with the simple requirement and then adding a lot of conditionals to handle the special cases. This makes the code hard to understand and the behavior for a single item is broken down and handled at multiple places making it very hard to add new functionality.
In my frist attempt at the problem I tried to reduce the nesting level of the original code and handle an individual item at a single place, so that if the rule for that changed then it would be easy to change it in the code. This was, I think, a fairly decent attempt and the code looked a lot friendlier then the original version. But there were still too many special cases handling conditionals embedded in the code.

For my second attempt at the kata I decided to take a completely different approach. I created individual functions for each of the rules that was applied to the items to handle their attributes on each update. I also added a dictionary which bound each item to the rule that it was tied to. The code is pretty self-explanatory and commented where required. This approach turned out really well and the code is now very easy to understand and very extensible.

Doing the kata more than once was very useful because it made me think of different ways to solve the problem, something that I might not have done other wise. That led to finding a different and much improved solution.

March 26th, 2012 by Nishith Nand

Apprenticeship: Journey for craft improvement

As an effort to improve my craft, I am starting an apprenticeship, as described in the very helpful book “Apprenticeship Patterns” by Hoover and Oshineye.

My current goal is to improve my python coding style. While using python, I tend to write C code with python syntax, instead of using the language features which can make the task easier and my code cleaner.

For me Software Craftsmanship includes the notion of building higher quality products. It includes my ability to identify the correct tool for the job and to apply it to its full merit. I want to get better at utilizing the tools at my disposal to their potential. For this purpose, I have created the following learning plan.

Learning plan

1. Write small programs without worrying about style.
2. When sufficient number (10?) of programs are complete, go through each of them and find the 2 most common variations from PEP8. If no differences are found go to step 5.
3. Write more small programs, keeping in mind the 2 differences identified.
4. Go to step 2.
5. Write a medium-sized c program.
6. Translate that to python.
7. Check it for variations from PEP8, if found repeat steps 2 and 3 with programs of medium size, else go to 8.
8. Start an open source project in Python. Check it thoroughly for PEP8 compliance, invite others to do this.

And my metric to measure my improvement is “the number of differences from PEP8 per 100 lines of code”.

I know that lines of code is generally not a good metric but since this is only for myself, there is no incentive to game the system. So, I think this should work.

February 19th, 2012 by Nishith Nand

Installing wordpress on nearly free speech

Download the wordpress package.

Upload it using sftp.

Create a mysql process.

SSH into the site.

Rename the wp-config-sample.php file to wp-config.php.

Add the database details to the wp-config.php

Mail form powered by Zero Conf Mail