Wednesday, March 29, 2006

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...


Anonymous Jeff Atwood said...

An excellent example!

7:21 p.m.  
Blogger MAC said...

Thanks a lot!
I've corrected the first code block, the 'end' was missing, which makes it a "super rock star" refactoring.

11:10 a.m.  
Anonymous Anonymous said...

Custom engagement rings, fine jewelry design, diamonds, colored gemstones and
antique jewelry are among our specialties. Please visit our on-line galleries of fine
jewelry, custom engagement rings and beautiful gemstones.

4:34 a.m.  
Anonymous Anonymous said...

Hello people.Winter good time!
This is best.
Best ski:jay peak ski resort
Best credit secret:pay victorias secret credit card
Best house:real estate in charlotte north carolina
Best forex info:forex training course currency trading
This is cool:punishment enema picture

9:14 a.m.  
Anonymous Anonymous said...

Good-girl-turned-bad Britney Spears has topped an eclectic list of the net’s most popular searches
n the run-up to Christmas. The popstar,who hit the headlines last week for stepping out
“commando” with her new best friend Paris Hilton,has helped revealed exactly what the internet
savvy are looking for from their stars - the thick and the dead.

2:32 a.m.  
Anonymous Anonymous said...

This is all you car.
auto junk yard
aaa auto club
auto truck broker
oreilly auto
auto dealerships

1:05 a.m.  
Anonymous Anonymous said...

Buy Ultram Online

Buy Ultram Online

4:16 a.m.  
Anonymous Anonymous said...

1d003d67cd0ea029 event

4:49 p.m.  
Anonymous Anonymous said...

Classifieds for our community. Buy, sell, trade, date, events... post anything. Adquity Classifieds.

9:49 a.m.  
Anonymous Anonymous said...

Hi all!
[url=]buy soma[/url]
[url=]buy carisoprodol[/url]
[url=]buy ultram[/url]

11:13 a.m.  
Anonymous Anonymous said...


buy Cialis
[url=]buy Cialis[/url]
[url=]Cialis online[/url]
Cialis online
[url=]generic Cialis[/url]
generic Cialis

5:28 a.m.  
Anonymous Anonymous said...

[url=]john mayer[/url]
[url=]carrie underwood[/url]
[url=]robin thicke[/url]
john mayer
carrie underwood
robin thicke

1:47 p.m.  
Anonymous Anonymous said...

[url=]john mayer[/url]
[url=]carrie underwood[/url]
[url=]robin thicke[/url]
john mayer
carrie underwood
robin thicke

6:37 a.m.  
Anonymous Anonymous said...

Valium benzodiazepines
Viagra sildenafil
antidepressant medication
tricyclic antidepressant
arthritis medicine
juvenile arthritis
antibiotic and alcohol
new antidepressant
antibiotic for acne
antibiotic side effects
antidepressant medication
natural antidepressant
arthritis pain relief
high blood pressure symptom
antidepressant drug
pain relief medication
natural pain relief
antidepressant side effects
joint pain relief
high blood pressure treatment
inflammatory arthritis
normal blood pressure range
natural antibiotic
blood pressure reading
pediatric gastroenterology
chronic pain relief
back pain relief
gastroenterology doctor
high blood pressure medicine
sleep insomnia
insomnia sleep disorder
early menopause
menopause relief
Blood Pressure
Muscle Relaxant
Arthritis Rheumatics
Birth Control

7:04 a.m.  
Anonymous Buy Levitra said...

Great article! Thanks.

10:40 a.m.  
Anonymous Phentermine said...

Thanks for interesting article.

4:23 p.m.  
Anonymous Anonymous said...

all usa
viagra tramadol citalopram relpax
Telfast pharmacy
drugs Sirdalud

10:57 a.m.  
Anonymous Anonimous said...

Nice! Nice site! Good resources here. I will bookmark!

5:22 p.m.  
Anonymous Maxwells said...

I see first time your site guys. I like you :)

3:09 a.m.  
Anonymous Anonimous said...

Excellent website. Good work. Very useful. I will bookmark!

6:47 a.m.  
Anonymous Thomas said...

Some Movies You might Like

11:35 a.m.  

Post a Comment

<< Home