Tuesday, February 19, 2008

Ruby Chops: Flexible Sort

So I was messing with the comparable module and the <=> method.  I implemented as I would in Java.  Then I played with sort_by and thought that was awesome. Which led me to writing my own method that would allow me to pass in a collection and attributes to be sorted by. The objects in the collection would have to implement my Sortable module. This was more for academic fun and try to keep my mind sharp. If anyone sees a cooler way to do it then please post it here.

Tuesday, February 12, 2008

GeneTree on NBC

The project I'm working on made another news story, this time on NBC.  View Now

Sunday, February 10, 2008

Code Documentation

There are two ways to communicate what your code does: the code itself and using comments.

Self Documenting Code

Source code should be understandable not because it has comments but because of its elegance and clarity – correct use of variable names, good use of whitespace, good separation of logic, and concise readability. Code will be read hundreds of times and written only a few times. So invest quality time into spelling out names such as fn into firstname. Fight the urge to use cryptic variable names.

Code Comments

Code should have comments however an abundance of comments can be just as bad as too few. Comments should explain why something is done. The code itself already shows what it is done. So commenting on what is done is redundant. Do not use commenting as a substitute for good code. Another way to say that is that if you need to comment code due to its unclarity then maybe you need to rewrite the code to be more clear and remove the comment.

I found this article which is about using natural language in your code to make it more readable. http://jamesgolick.com/2008/1/14/taking-style-tips-from-natural-language

Ruby chops: rubyisms

Rubyisms I've accumulated over time: check 'em out.

Ruby chops: module example

UnDRY code

Ruby chops: modules basics

Download Code

Ruby Chops: Class variables and methods

Download Code