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 = $* else lang = 'en' end
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 = $* 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 = $* || '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…