DEV Community

Discussion on: Keep your code dumb

 
mortoray profile image
edA‑qa mort‑ora‑y

Because some people misuse a feature is a bad reason to dislike it. An idiot can just as easily write a function called get_name() that deletes your hard drive.

Thread Thread
 
joelnet profile image
JavaScript Joel

Valid point.

I have been stung by this before, so I definitely hold a bias. I also prefer functional designs over OOP, so there is a lot of OOP that I also dislike.

Thread Thread
 
janjuks profile image
janjuks • Edited

I would argue that obj.set_enabled(true) and obj.enabled = true are semantically the same.

I agree with this, but even more that setters/getters shouldn't be doing any work. I think that Joel didn't name it very good. That 'set' in method name is the part which makes them semantically the same. Maybe it's just me, but naming it obj.enable() would imply that there might be some work to be done and not just setting a value.

That being said, I have written that code myself where private variable would hold some raw data and getter would decode it only once when first needed. This post + just recently read Clean Code by Robert C. Martin reminded me of this ^_^

Thread Thread
 
joelnet profile image
JavaScript Joel

naming it obj.enable() would imply that there might be some work to be done and not just setting a value.

^ This :)