|
|
|
|
|
by FuzzyDunlop
5052 days ago
|
|
I'd like you to offer some examples of code that successfully documents its own raison d'ĂȘtre - in a way that a comment couldn't do better - instead of repeating this 'crutch of poor developers' rhetoric. I mean, I can write self documenting code without any comments, and it's perfectly understandable. before_create :auto_increment
def auto_increment
self.count + 1
end
That code fails to tell the programmer why it's in the application logic and not defined in the database schema. What should I do instead, so I can code without crutches? def auto_increment_natural_key
self.count + 1
end
That's not a great deal better, it's still just saying what it does, not why it's there in the first place. def auto_increment_natural_key_because_another_app_relies_on_it
self.count + 1
end
Is that it? |
|
I would argue that in this case, it is far better to just understand the code and then fix it appropriately. A comment would leave you second guessing.
(though, for the purposes of self documenting code, count probably is not a great variable name either)