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

Classes aren't outright bad, but I've seen them misused so many times that I knee-jerk cringe when I see the keyword `class` in any programming language; too often have I seen classes misused and misapplied (in my opinion).

If what you're writing is fundamentally a singular self-described action, there's almost certainly no reason to apply thinginess to it. But I see this practice all the time in open-source code, and it describes Java to a tee.

Is the mutation of your data best described as a behavior? If not, then a simpler data structure and functions that act upon that structure may be easier to understand and be more composable in the long run.

And almost never use inheritance, especially if that inheritance chain goes beyond one ancestor.

I almost never use classes these days. If I were writing a game, I imagine that classes would be conceptually helpful in making sense of ideas that manifest as things with behavior in a virtual world. For general programming tasks, I find them largely unhelpful and to be a potential trap.

EDIT: When I said I "almost never" use classes, of course I do work with classes at my job because it would be obnoxious of me to deviate from the collective pattern. With my own personal code, the only time I end up using classes is if I'm forced to (ex. web components).



Django's use of inheritance (with mixins) makes sense to me.

Class based views and that sort of thing is vastly simplified as opposed to building all those views from scratch. One has to spend some time learning what they do though.


> And almost never use inheritance, especially if that inheritance chain goes beyond one ancestor.

With Python's duck typing, I'm not even sure of a case where inheritance is even strictly necessary beyond custom exceptions.


with Raku’s powerful, yet simple, OO you get role composition for code organization and can reserve inheritance to reflect real structure in your data model


I use TypeScript a lot recently, and I've been using class with static methods. No internal states.

It is more of an organizing decision, and I wanted to avoid DI and additional configuration up front. KISS.


in Raku this is called role composition :-)




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: