Live data from Hacker News

The use of `class` for things that should be simple free functions

quuxplusone.github.io

1–10 of 406 posts

Re: The use of `class` for things that should be simple free functions

#2
For anyone who wants to post their opinions on whether OOP is good or bad, may I suggest briefly explaining what you consider to be "object-oriented programming"?

I've seen in a lot of threads like these, people often end up talking past each other, because one person's idea of what an "object" turned out to be different from someone else's.

Re: The use of `class` for things that should be simple free functions

#5
post #3

Also known in python as "if your class has only two methods, one of which is init, it's a function" in the "stop writing classes" https://www.youtube.com/watch?v=o9pEzgHorH0 EDIT: typo, changed link

Or it's a named stateful or immutable data container with validation? You don't always want to use primitive types. But I am not a Python dev.

Re: The use of `class` for things that should be simple free functions

#6

I'm fairly new to Unity programming in C# and I was surprised a few months ago that everything in C# must be in a class. As far as I can tell there is no such thing as just a function. Now I have I have a class with some static functions in it.

A static class in C# isn't really a class, it's just a namespace to hold functions.

Re: The use of `class` for things that should be simple free functions

#7
post #3

Also known in python as "if your class has only two methods, one of which is init, it's a function" in the "stop writing classes" https://www.youtube.com/watch?v=o9pEzgHorH0 EDIT: typo, changed link

Your link goes by means of Google; here's a direct link: https://www.youtube.com/watch?v=o9pEzgHorH0

Re: The use of `class` for things that should be simple free functions

#8
post #2

For anyone who wants to post their opinions on whether OOP is good or bad, may I suggest briefly explaining what you consider to be "object-oriented programming"? I've seen in a lot of threads like these, people often end up talking past each other, because one person's idea of what an "object" turned out to be different from someone else's.

The title is clickbait, the article isn't about whether OOP is bad

Re: The use of `class` for things that should be simple free functions

#9
I wonder what the author means when he says “ classical polymorphic OOP”. In my experience, subtyping is the absolute worst part of OOP. More so in an enterprise setting, where after two decades, you end up with some really mutated weird ass looking ducks (Animal).

As far as functions vs class go, both are terrible to maintain in the long run. Both lead you on a never ending path of go-to-definition, because the documentation is rotten and the tests aren’t right/even there. The only difference is whether or not you want to search a few large or a metric fuckton of single responsibility files.

Maybe it’s different if your code bases aren’t crap and you’re a better developer than me.

Re: The use of `class` for things that should be simple free functions

#10

I'm fairly new to Unity programming in C# and I was surprised a few months ago that everything in C# must be in a class. As far as I can tell there is no such thing as just a function. Now I have I have a class with some static functions in it.

Classes are used for a variety of things. Let's look at it from a language designer's perspective. If design a language and you want to offer inheritance, specialization,.... you will often end up with offering classes. Once you have that you could decide to offer namespaces. But, a class with some static methods comes quite close to what you need to offer for a namespace. Hold on: you can use classes to combine some functionality that belongs together and come close to what you need for modules.

It's not a surprise the designers of java, c#, ... went that route.

Post reply on HN