Live data from Hacker News

JavaScript Getters/Setters Considered Harmful

labs.transloc.com

11–14 of 14 posts

Re: JavaScript Getters/Setters Considered Harmful

#11
post #5
post #3

JavaScript Getters/Setters Considered Slow "considered harmful" is link bait

"Considered harmful" considered harmful?

No I don't think so. Considered harmful should mean a serious reason why the aforementioned is a bad thing. "Considered harmful" is just being grossly misapplied as unmerited linkbait, but it's still quite beneficial when occasion calls for it.

Re: JavaScript Getters/Setters Considered Harmful

#12
post #5
post #3

JavaScript Getters/Setters Considered Slow "considered harmful" is link bait

"Considered harmful" considered harmful?

In this context it is. There may be some serious implications when saying that x or y pattern in language z is considered harmful.

In Java accessors are almost mandatory if you intend for your object's properties to be publicly available (even the IDEs imply it, by automatically creating them for you). Whereas in languages such as Python and JavaScript, the implementation of this "pattern" makes them optional. You don't have to use accessors if you don't need them right now, since you can always go back and create them later without affecting client libraries.

What the article shows is that, surprisingly, JavaScript's native feature to do this is actually slower than the Java way (what the author called old-fashioned). Is this really a reason to revert to a clumsier pattern because we're optimizing for speed?

Saying that it's "harmful" might get many newbie JavaScript programmers run to start peppering their code with getter and setter Java-style. What happens later when the different scripting engines fix the bottleneck.

Post reply on HN