Rock Star programming : my two cents

I was a little outraged when I red Mikael Grev’s My Top Ten Tips on how to become a Rock Star Programmer a couple of weeks ago when it ended up on reddit. And now that ironmonkey has done his own meaculpa I feel the need to add my little two cents.

Ironmonkey probably has the greatest tip of all, that not only apply to programming : to be the best, learn from the best.
One of the two original tips I was most shocked about was Don’t learn APIs too well. Keeping in mind that his tips were for becoming a rockstart programmer. Someone that, when you look at his code, all you can say is: WOW! How did he thought about it!
Cool code has to be compact, yes… but mostly brilliant and simple. Absurdly simple. People have to be ashamed that they haven’t thought about it before when they see it. That’s rockstar programming. Now how can you end up writing this type of code? You have to know the programming language and api and all libs you’re using by heart, its weakness and strengths. Let’s sum this up with an example in ruby (a rockstart ready language):

Let’s say you’ve just learned ruby, but have been using java for some year and consider yourself a good programmer. The simple problem for my demonstration is this: the second command line argument of a script is the language, if not specified, it has to be English (en). So I’m going to write it first has a new ruby programmer and refactoring it to a more rockstar fashion.

Ok I know ruby syntax, and I know how to do this, simple

if $*.size > 2
  lang = $*[2]
  lang = 'en'

That works… I don’t know the api, but I’ve looked at the docs ’cause I didn’t knew how to retrieve command line arguments ($*).

Now I read some more about ruby, check some code written by cool ppl, put sunglasses on and refactor to the following:

lang = 'en'
lang = $*[2] if $*.size > 2

Ha ah!!! from 5 lines to 2!!! How cool is that???

I read some more code, tear my shirt off, pierce my nose and refactor to the following:

lang = $*[2] || 'en'

What? Isn’t this throwing a IndexOutOfRangeException and those are not boolean expressions!?! (remember, I’m a java programmer) People who don’t know by heart a language or api would assume a great number of things, some are false, some aren’t. My point is that there’s no way I could have guessed that my last line would have worked in ruby if I didn’t knew the language by looking at other people’s code, books and tried it myself. You have to know API and syntax really well.

Other’s tips are also wrong IMHO, but I can’t make a point this clear about them, for now…



Filed under Misc, ruby

5 responses to “Rock Star programming : my two cents

  1. MAC

    Thanks a lot!
    I’ve corrected the first code block, the ‘end’ was missing, which makes it a “super rock star” refactoring.

  2. I am really inspired to read this post which is amazing and so informative. Actually, I love ruby on rails and I want to learn about ruby on rails like most latest developing techniques.

  3. It’s an awesome paragraph in favor of all the internet viewers; they
    will take benefit from it I am sure.

  4. Exceptional post however I was wondering if you could write
    a litte more on this subject? I’d be very thankful if you could elaborate a
    little bit more. Thank you!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s