Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's a fairly effective rule of thumb: classes--or more accurately objects--are a way to cleanly encapsulate state. If you rely on a mutating state, you probably want an object/class. If not, a function is often better.

Now you can bundle related functions together in a structure, but this structure is morally a module, not an object, let alone a class. Some languages will force you to encode those modules as classes / prototypes / singletons, but that's just a design pattern to circumvent a limitation of the language.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: