Settings

Theme

Can we become better programmers through studying code?

5 points by jakubholynet 13 years ago · 8 comments · 1 min read


To help myself and others understand better the qualities of good code and deficiencies of a bad one, I have started a new blog called Wonders of Code. The question is, is this something that can trully help us improve our understanding and thus skills?<p>The idea is to take a piece of code, point out some noteworthy improvement opportunities - preferably in relation to the general principles of clean code, such as DRY, SRP, readability etc. - and rewrite it in a (presumbely) better way and explain the new qualities.<p>You might want to check out some of the 3+1 code studies already published at WoC to see what I mean: http://wondersofcode.wordpress.com/.<p>I have two questions:<p>1) Is this something worth doing, something that can really help us - and especially the juniors among us - become better programmers faster? 2) Do you have any tips and ideas for how to make it better and more effective?<p>Thank you!

ragatskynet 13 years ago

Looking at other people's code (and I mean more experienced programmers of course) always helped me to learn best-practices, patterns, etc. Also if you does not understand something (why is it there? why is it written that way?) it is very good to ask the guy who wrote it down about his purpose - maybe both of you can learn from these situations.

Also this kind of "learning" is very useful in the future - you can understand other people's code faster or recognize problems by looking at the code.

I think your idea is worth doing and I would encourage you to keep working on it; I am sure I will recommend it to my friends too.

Sealy 13 years ago

I would always encourage any form of education, coding included.

The way I learned how to code was to play with pre-written pieces of code myself.

1. I would say to myself... I want to see if I can write a loop to print out a message.

2. Then I would go and google for the code.

3. Copy and paste it into my own file, and change it to do what I want.

I'm willing to bet that most of the hackers on HN learned how to code this way. That's why we call ourselves hackers right?

I guess this is similar to your approach but in a more controlled environment?

  • jakubholynetOP 13 years ago

    You are right, we all do this. What is missing from this is feedback: how do I know if my design is good enough or what are its pros & cons? (Since often there is no absolute "good".) That is something I am trying to provide: showing two implementations of the same thing, discussing the advantages and disadvantages of each in relation to general coding and design principles. Thus it helps to learn not only how to do a particular task and how somebody else has solved it but also to think critically about design and the ability to relate to design principles. At least that is what I hope :)

    • Sealy 13 years ago

      That's so true, we hackers operate in a world where many different answers can be correct. However we can generally gauge if a solution is better or worse.

      I guess you would need to come up with some sort of metric to measure how much 'better' one solution is over another. A crude example which I've seen is the number of lines. To me that just shows how elegant the code is, but as you know it does not necessarily mean it will execute faster.

bjoerns 13 years ago

hi Jakub, definitely worth doing. In terms of making your blog more efficient, how about putting the code examples side by side (looking at your Python/MongoDB API snippets)? I know it's visually probably a bit harder but I guess it makes pros and cons etc more obvious. Just my two cents...

  • jakubholynetOP 13 years ago

    Thank you, bjoerns! That is actually a good suggestion and modern screens are wide enough for that. I am afraid that Wordpress won't allow me to do that but will explore it.

joelmaat 13 years ago

Of course. I do this all the time. Even a passive perusal of good code makes you better.

w_t_payne 13 years ago

Yes, I think that this is definitely something worth doing.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection