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]
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 = $*[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...

21 Comments:

Anonymous Jeff Atwood said...

An excellent example!

7:21 PM  
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 AM  
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 AM  
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 AM  
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 AM  
Anonymous Anonymous said...

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

1:05 AM  
Anonymous Anonymous said...

Buy Ultram Online

http://www1.fccj.edu/wlara/jaxsearch/_kbas/000001eb.htm

Buy Ultram Online

4:16 AM  
Anonymous Anonymous said...

1d003d67cd0ea029 event

4:49 PM  
Anonymous Anonymous said...

http://www.adquity.com

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

http://www.adquity.com

9:49 AM  
Anonymous Anonymous said...

Hi all!
[url=http://www.shrunkurl.com?id=13253#soma]buy soma[/url]
[url=http://urlbounce.com/go/fO5lU#carisoprodol]buy carisoprodol[/url]
[url=http://rubyurl.com/E38#ultram]buy ultram[/url]

11:13 AM  
Anonymous Anonymous said...

Hello

-____________________________
Cialis
[url=http://www.spbgu.ru/blog26877#1]Cialis[/url]
-____________________________
buy Cialis
[url=http://www.spbgu.ru/blog26877#2]buy Cialis[/url]
```````````````````````````````````````````````````
[url=http://www.spbgu.ru/blog26877#3]Cialis online[/url]
Cialis online
-____________________________
[url=http://www.spbgu.ru/blog26877#4]generic Cialis[/url]
generic Cialis

5:28 AM  
Anonymous Anonymous said...

[url=http://ericbachmann.portmerch.com/stores/schemes/dingbats/color/images/john-mayer.html#1]john mayer[/url]
[url=http://ericbachmann.portmerch.com/stores/schemes/dingbats/color/images/carrie-underwood.html#2]carrie underwood[/url]
[url=http://ericbachmann.portmerch.com/stores/schemes/dingbats/color/images/robin-thicke.html#3]robin thicke[/url]
john mayer
carrie underwood
robin thicke

1:47 PM  
Anonymous Anonymous said...

[url=http://ericbachmann.portmerch.com/stores/schemes/dingbats/color/images/john-mayer.html#1]john mayer[/url]
[url=http://ericbachmann.portmerch.com/stores/schemes/dingbats/color/images/carrie-underwood.html#2]carrie underwood[/url]
[url=http://ericbachmann.portmerch.com/stores/schemes/dingbats/color/images/robin-thicke.html#3]robin thicke[/url]
john mayer
carrie underwood
robin thicke

6:37 AM  
Anonymous Anonymous said...

Valium benzodiazepines
Verapamil
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
rosiglitazone
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
Contraceptive
Arthritis Rheumatics
Birth Control

7:04 AM  
Anonymous Buy Levitra said...

Great article! Thanks.

10:40 AM  
Anonymous Phentermine said...

Thanks for interesting article.

4:23 PM  
Anonymous Anonymous said...

all usa
viagra tramadol citalopram relpax
Telfast pharmacy
drugs Sirdalud
Regenon

10:57 AM  
Anonymous Anonimous said...

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

5:22 PM  
Anonymous Maxwells said...

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

3:09 AM  
Anonymous Anonimous said...

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

6:47 AM  
Anonymous Thomas said...

Some Movies You might Like

11:35 AM  

Post a Comment

<< Home