Miles to code

Just another WordPress.com weblog

Traits of a good programmer

with one comment

In his latest blog, Peter Bohm has written a review of Chad Fowler’s “The Passionate Programmer” and has basically summarized a few qualities that a programmer should have. I think that analytical and programming skills apart, it is the amount of “passion” a programmer has that makes him/her a good programmer.

One of Peter’s arguments is about how good programmers never stop to learn. I couldn’t agree more. If there is a one key difference I have seen between good and average programmers, it’s their passion for learning. Good programmers see learning as an investment and spend a lot of time upgrading their skills and improving their knowledge. They read, browse, blog, network, join forums, attend conferences and above all get into the trenches try out new things whenever they can.

Good developers hate bad code. I was reading “Secrets of the Rockstar programmers: riding the IT crest” by Ed Burns. This book is a collection of interviews of some of the “celebrities” from the IT world. One of the traits that sprung up as a common characteristic among most programmers interviewed in the book was their passion for continuously improving the systems they were working on. In the interview with Kohsuke Kawaguchi, the creator of continuous integration tool Hudson, he says that he wrote Hudson because he wasn’t happy with CruiseControl (and other CI tools). Good programmers will feel very uncomfortable on seeing poor code or existing bugs and would want to fix them. They will cringe every time they are forced to put in a tactical solution/bug fix for the benefit of time and will always go back and put a better fix whenever they can.

In my opinion, good programmers are lazy. They hate doing manual tasks and therefore invent creative ways to automate mundane jobs. One of my friends recently spent several hours converting a manual build task into a fully automated one-click build and managed to reduce her effort from several hours per build to almost zero. She was almost delirious with joy on seeing all the time she saved. As Yukihiro Matsumoto, the creator of Ruby once said, “Be lazy. Machines should serve human being. Often programmers serve machines unconsciously. Let machines serve you. Do everything you can to make you lazy”.

I have also often observed that many, if not all, smart programmers are tool junkies. Nothing excites them more than tinkering with new tools, installing new plugins or customizing their development environments. I am not sure if there is a pattern here but the child like pleasure we programmers derive from these activities make our work all the more interesting.

Another interesting characteristic of good developers is that they are not scared to step out of their comfort zones. For example, they share their code with others and welcome feedback. It takes a lot of courage to show your code to the rest of the world. Good programmers work hard to swallow their pride and overcome their fear and shyness of letting other people review their work. For the same reason, they enjoy company of programmers who are smarter than them. This gives them an opportunity to observe and learn from others. Joel Spolsky once said in his podcast, “if you’re not doing a few things where you’re failing a little, you’re probably not trying hard enough. I say if everyone likes you, you probably aren’t doing anything interesting.”

Finally, the one quality that I hold in very high esteem is humility. Good programmers are humble. They don’t mind admitting that they don’t know something. While it is easier said than done, I have seen that the biggest disservice we do to ourselves is by being egoistic and snobbish about our knowledge and programming skills. You end up losing by shutting off other people if you are continuously trying to prove the superiority of your programming skills to others. Smart programmers don’t do that. They know that there is nothing wrong in saying “I don’t know”, nor do they harshly judge another team mate who says that. There is a lot that can be learnt from each other if only we let our guards down and stop being defensive about our skills or lack thereof.

Written by rahulj51

August 31, 2009 at 9:14 am

Posted in General, Skills

Tagged with ,

Main method not supported in scala companion object

leave a comment »

I was working on some practice problems from the Ninety-Nine Scala Problems website when I stumbled across an interesting behavior.

I wrote a dummy class and a main method in its companion object.

package arithmetic {

    class S99Int(val start: Int) {
      import S99Int._

      def hello = println("hello")
    }

    object S99Int {

      def main(args: Array[String]) :Unit = {
          println("hello world")
      }

    }

}

To my surprise, I got a NoSuchMethodError: main from the compiler.

Turns out that this is not supported in Scala (as of now). Companion objects can’t have a main() method. There are some esoteric explanations available on the Scala mailing list for this behavior.

Written by rahulj51

August 14, 2009 at 9:58 am

Posted in Uncategorized

Moving to WordPress

leave a comment »

WordPress has built in code formatting (SyntaxHighlighter) so no more manual formatting of code. My new blog is here

.

Written by rahulj51

July 30, 2009 at 10:04 am

Posted in Uncategorized

Scala by example – Sorting

leave a comment »

Here’s an attempt at learning Scala using some basic algorithms. I do realize that these examples look and “feel” like Java and do not use the full power of Scala’s more expressive syntax or its functional approach. This is just my humble attempt at learning a new language.

I use the scala plugin for Netbeans 6.7.

Bubble Sort

package sorts

class Sort {

    def bubblesort(lst : Array[Int]) : Array[Int] =
    {
        val list : Array[Int] = new Array[Int](lst.length)
        Array.copy(lst, 0, list, 0, lst.length)
        var swapped : boolean = false
        do
        {
            swapped = false
            for (i <- 0 to (list.length - 2))
            {
                if (list(i) > list(i+1))
                {
                    swapWithNext(i, list)
                    swapped = true
                }
            }
        } while (swapped)

        return list
    }

    def swapWithNext(i : Int, list:Array[Int]) : Unit =
    {
        val temp = list(i)
        list(i) = list(i+1)
        list(i+1) = temp
    }

Selection Sort


    def selectionsort(lst : Array[Int]) : Array[Int] =
    {
        val list : Array[Int] = new Array[Int](lst.length)
        Array.copy(lst, 0, list, 0, lst.length)

        for (i <- 0 until (list.length -1))
        {
            var min = i
            //find min
            for(j <- (i+1) until list.length)
            {
                if (list(j) < list(min))
                  min = j
            }

            //swap ith number with that at min position
            if (i != min)
            {
                val swap = list(i);
                list(i) = list(min);
                list(min) = swap;
            }
        }
        return list
    }

Insertion Sort


    def insertionsort(lst : Array[Int]) : Array[Int] =
    {
        val list : Array[Int] = new Array[Int](lst.length)
        Array.copy(lst, 0, list, 0, lst.length)

        list.foreach(a => print(a + ","))
        println()
        for (i <- 1 to list.length - 1)
        {
            //pick arbit minimum value
            val value = list(i)

            //iterate through the rest of the "sorted" array
            var j = i-1
            while (j >= 0 && list(j) > value)
            {
                list(j+1) = list(j)
                j = j-1
            }
            //replace
            list(j+1) = value
            list.foreach(a => print(a + ","))
            println()
        }
        return list
    }

Quick Sort


    def quicksort(lst : Array[Int]) : Array[Int] =
    {
        var list = lst.elements.toList

        list = quicksortBasic(list);
        return list.toArray

    }

    private def quicksortBasic(list: List[Int]): List[Int] =
    {
        var less:List[Int] = List()
        var greater:List[Int] = List()
        if (list.length <= 1)
            return list

        val index = list.length / 2;
        val pivot = list(index)

        for (i <- 0 to (list.length -1))
        {
            if (list(i) < pivot)
              less += list(i)
            else if (list(i) > pivot)
              greater += list(i)
        }

        return (quicksortBasic(less) + pivot ++ quicksortBasic(greater))
    }

}

Here’s the Main object that calls the sort methods

object Main {

    /**
     * @param args the command line arguments
     */
    def main(args: Array[String]) :Unit = {
        val list = new Array[Int](5)
        list(0) = 10
        list(1) = 5
        list(2) = 25
        list(3) = 0
        list(4) = 22

        println("bubble")
        new Sort().bubblesort(list).foreach(println);

        println("selection")
        new Sort().selectionsort(list).foreach(println);

        println("insertion")
        new Sort().insertionsort(list).foreach(println);

        println("quicksort")
        new Sort().quicksort(list).foreach(println);

        println("end")

    }

}

I’ll revisit these examples and make them more “scala” like in some time.

Written by rahulj51

July 30, 2009 at 7:53 am

Posted in algorithm, scala

Hello world!

leave a comment »

Moving from BlogSpot to WordPress for its advanced formatting features. In a few days, I’ll move all my blog posts from here to this place.

Written by rahulj51

July 30, 2009 at 7:19 am

Posted in Uncategorized

Random thoughts

leave a comment »


Slack

Reading a book called Slack by Tom DeMarco.

Very large text files processing

If you are dealing with very large text files, i.e. more than 500MB in size, here are a few tips that might help

  1. On windows, use Textpad for viewing/editing files. It handles large files very well. Alternatively you can use unix utilities or cygwin if you are working on windows.
  2. Java doesn’t handle large files very well. Consider using Perl or unix shell script. You will be amazed at the performance gains.
  3. If you need to save this to a database, consider a direct bulk copy using your database’s load utility e.g. sqlldr (oracle) or bcp(sybase, ms-sql).

Procrastinators logic: Cleaning your apartment is O(1) complexity

N being the number of days since you last cleaned your apartment, for small N, the time taken, t, to clean your apartment will not vary much over N.

This makes apartment cleaning an O(1) complexity algorithm.

.

Written by rahulj51

July 18, 2009 at 9:05 am

Posted in Uncategorized

Netbeans 6.7 is released. I am still not happy with "Go To File".

leave a comment »

Netbeans 6.7 is released.

Despite “Improved search” as one of the features of the new release, the “Go To File” feature (Alt+Shift+O) is still as slow as the previous version. This is a bummer as I use this feature most often. In Netbeans, file search is either very slow or throws a <No Files Found > even when the file exists.

Compare this with “Open Resource” (Ctrl + R) feature in Eclipse. Works like a charm and gives you a filtered list of all matching resources even before you’ve finished typing.

——–

Written by rahulj51

July 1, 2009 at 4:34 am

Posted in Uncategorized

Are you testing your units ?

leave a comment »

Read a brilliant and very apt article on Functional testing by Tim Sutherland. The article makes a case of why functional testing is more important than unit testing in some applications specially those that do not have complex algorithms or APIs in the code.

The application I work on at my workplace is a case in point. It’s a highly data centric, legacy, ETL application written in Java. Most of the code does not have any complex business logic that requires testing at a unit level. In fact it is the integration of the tiny java components and how they collaborate during run time that contributes to the complexity of the application. In the last 2 years that I have worked on this code, I have seen very few cases where a bug could have been caught during unit testing. Typically, most defects occur due to unexpected or bad data.

In such cases, I strongly agree with the author of the above post that a small, carefully written set of functional tests is more useful than unit tests. We can run these tests nightly as part of continuous integration and also for smoke testing during every release.

I do think, however, that at the unit level, a test driven approach might still be useful. So when I am writing, let’s say, a DAO, I can write a few integration tests first for testing the DAO. Even in such cases, hard core unit testing (with mocking etc.) does not yield much benefits. These tests could be reused later for low level integration testing of individual components. But they need not be run regularly as part of the continuous integration process to save time.

————–

Written by rahulj51

July 1, 2009 at 4:02 am

Posted in Uncategorized

Why isn’t my unix sort working?

leave a comment »

Gaah.Today I ran into a strange problem while running the ’sort’ command on Unix. On running this command with the following input,

AECS
@ADS
@AED

I was getting

@ADS
AECS
@AED

as the output. I was expecting the output to be

@ADS
@AED
AECS

It was as if the ‘@’ character in my input data was completely being ignored. This caused a long running data load process to fail due to wrong data as I was using sort and merge logic to eliminate duplicates and merge data from multiple files.

On seraching the internet, I found that the ’sort’ command depends on locale to decide the ordering of characters. you can check the default locale by using the ‘locale’ command.

The solution to fix the above sort is to set LC_ALL to “C” before calling sort. “C” stands for collation locale.

> export LC_ALL=C
> cat inputdata sort -s -T .

Turns out that there are some other comands that depend on locale. Read more on this subject here.

———–

Written by rahulj51

June 22, 2009 at 8:44 am

Posted in Uncategorized

Ruby on Rails

leave a comment »

I attended a 2 day course on RoR during the Good Friday weekend. It was a beginners course.

RoR has a lot of “magic” moments when you just click a few buttons and ‘viola’, it spews out a shiny new web application for you. Nothing hard core though as the “scaffolding” as it is called is only good for the very basic CRUD web apps.

On the other hand, I found very little information available on the net that could explain what was happening under the hoods. It is possible that I did not look in the right places, though.

I am now practicing the concepts by creating a simple effort tracking web application in my free time.

Written by rahulj51

May 15, 2009 at 10:15 am

Posted in Uncategorized