DEV Community

Classes Suck

Dimitri Merejkowsky on November 09, 2019

Introduction A long time ago I received a lecture about the usage of databases and software design. More specifically, how to translate ...
Collapse
 
xowap profile image
Rémy 🤖

Classes are definitely not real-world objects, that's just how bad teachers teach it.

If you code in C you'll notice that you often end up working on a given struct/handler/pointer for various operations. Classes are syntactic sugar so self gets passed to all your methods automatically.

And then you have interfaces, which build upon the way classes are exposed to make abstraction of implementation details and let you create abstractions easily.

Sooooo, I'm not sure what's your point. Should main() not be a method from a useless class? Definitely. Are classes bad? I don't know, how bad are knives, pillows or airplanes?

Collapse
 
dmerejkowsky profile image
Dimitri Merejkowsky • Edited

Classes are definitely not real-world objects, that's just how bad teachers teach it.

Totally agree. But why? Surely there must be a reason why they tell us that, right?

I'm not sure what's your point.

That's because I'm not finished :) I wanted to have a cool cliffhanger in the middle of a two-part series instead of one big boring article. I hope you can forgive me.

Collapse
 
dmerejkowsky profile image
Dimitri Merejkowsky

Part two was just published, we can continue the discussion there if you want :)

Collapse
 
johannesjo profile image
Johannes Millan • Edited

Thank you for the article. I'm having trouble to follow your train of thought here though. I prefer functional programming over class based approaches myself but from this article it's not really clear to my why classes suck. Because they nudge you towards overcomplicated solutions? Maybe you can flesh this out a little more?

Collapse
 
dmerejkowsky profile image
Dimitri Merejkowsky • Edited

it's not really clear to me why classes suck

Yeah, I went for click-bait here. I'm just pointing out that there's something weird going on with classes, software design, and the real world. It seems we can use classes to represent real-world objects, but it also seems doing so sometimes backfires.

they nudge you towards overcomplicated solutions?

They definitely do that too. For more, see the Stop Writing Classes video. But I'm not talking about complexity here, I'm talking about links between code and the real world.

Maybe you can flesh this out a little more?

Well, there will be a part two soon and I hope it will make things easier to understand.

Collapse
 
dmerejkowsky profile image
Dimitri Merejkowsky

Here's part two if you want to check it out.