Hacker News new | past | comments | ask | show | jobs | submit login

My problem with object oriented programming it's not the object part, it's the oriented part. In object oriented programming, there is, usually, no trade-off. It's objects all the way down.

The problem is that not many things actually need to be an object. But when something needs to be one, there is no distinction. No way to tell whether somebody made a thing an object, because it makes sense or just because that's the only way he could make it. So you have all those User/DateFormatter/Encoding objects for no reason, but language limitation. And then, on top of that, when you want an actual object, something that does its thing, have internal state and an interface to communicate (not a method call), you are on your own.




Not necessarily: C#, for example, has a lot of FP like moments. Its not particularly relevant how are those internally implemented.


Not op, but I think you missed his / her point.

Let's take static void main as example. It's a series of operation called at the beginning (at least during my era), does not need to be in a class. The very reason we put it on class (let's say) Start, feels like language limitation.

The same with class Math, such as Math.floor and Math.ceil. Is Math a class or is it more suitable as a namespace? Since no object instantiated from Math is required (and maybe the same with static class).

However I don't think OOP is bad or limited language, beside the static void main part.


> The same with class Math, such as Math.floor and Math.ceil.

I still want to group them somehow and this "somehow" better have name "Math" so other people would see what it is.

Why are people so attached to name "class". Call it "namespace with state capabilities" if you're annoyed by "class" so much. Or just use namespaces like in C#. You still want namespaces, that's the point.

And speaking about your example. More often than not, we've got quite a bit of functionality attached to program startup and I'd rather have it focused in one single module "Start"/"Application"/"Runner" whatever you want to call it but I want it to be _focused_ and easily searchable, not floating in a see of function.

And by the way, same argument can be made about functions, why do I have to create "main()" at all, why not just start writing instructions like in bash script or python?


> Why are people so attached to name "class". Call it "namespace with state capabilities" if you're annoyed by "class" so much.

The central, first-class “namespace with state capabilities” in OOP is an object. A class is a namespace with state capabilities that may (or may not, because pure static classes are a thing) be an object factory, may or may not be an object or first class entity, and, probably, if the language has static types, is also a type.

And all of that is also true of objects, except the last, and objects are always first class in OOP. So, aside from static typing, classes are superfluous, unless they are just a name for objects with certain common feature.


There are now Top level statements in C# 9.

- https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tut...

> Top-level statements enable you to avoid the extra ceremony required by placing your program's entry point in a static method in a class.


Yes. Records in Java are another example. But that only fuels my suspicion, that oriented part is the problem.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: