Repetition-Driven Development

chromatic on 2007-12-20T01:30:00

Less code is not necessarily more readable (and it's often less maintainable). I much prefer

draw(Rectangle rect, Point point)

over

draw(rect, point)

Notwithstanding the fact that the former enables automatic refactoring and easy browsing while hardly anything can be deduced from the latter.

— a comment by Cedric Beust on his Continuous Tax

Read the examples carefully for a moment. Do you notice anything amusing? I'll give you a hint. How much more maintainable would the first example be with only one simple change?

draw(Rectangle rectangle, Point point)

There. That's much much better better. It almost doesn't need a comment.


Actually...

educated_foo on 2007-12-20T02:46:59

Of course that should really be

drawRectangleAtPoint(Rectangle rectangle, Point point)
"Draw" is such a vague name...

Re:Actually...

lachoy on 2007-12-20T15:14:04

Or:

  rectangle.drawAt( point )

Re:Actually...

chromatic on 2007-12-20T16:41:43

You must be a Perl hacker. The compiler can't enforce and your IDE can't infer anything about rectangle or point. What if someone accidentally passed in a BouncyBall? It's like the end of Watchmen all over again.

Re:Actually...

jjore on 2007-12-23T07:02:06

"Ok?"
^rectangle drawAt: point

Re:Actually...

jjore on 2007-12-23T07:08:51

Just meaning, I get a pretty awesome IDE in Smalltalk but all I can infer about rectangle is that it responds to the draw: method.

Re:Actually...

chromatic on 2007-12-23T18:19:12

Smalltalk had an IDE? It's impossible to write an IDE for a dynamic language! Now Eclipse, that's an IDE.

(Before anyone responds, ask yourself "Hey, why did he mention Eclipse and Smalltalk together?")