Comment by elric

4 days ago

Not being able to have top level functions is a feature, not a bug.

You can declare static methods on interfaces in Java, which means you could call things like Users.create("Foobar") if you wanted to.

Not everything can be associated to a single entity. Many operations work on two or more entities where none of them are the "master". Otherwise you end up with "coordinators".

Users.create(...) is the easy case. Try transfer_permissions(user1, user2, entity) while retaining transactionality and the ability of either user to cancel the transfer.

  • Permissions.transfer(x, y, z)

    I'm not sure why having a global function by the same would make this any easier or harder to implement. But it would pollute the global namespace with highly specific operations.

It is not a feature. Every programming language since has decided this was a mistake.

  • Can you provide an example of that?

    • Here is an example of a 2006 rant that qualifies: https://steve-yegge.blogspot.com/2006/03/execution-in-kingdo...

      OO conflates many different aspects that are often orthogonal but have been conflated together opportunistically rather than by sound rigor. Clearly most languages allow for functions outside classes. It's clearly the case today especially with FP gaining momentum, but it's also clear back then when Java and the JVM were created. I think smalltalk was the only other language that had this limitation.

      Like others in this thread, I can only recommend the big OOPS video: https://youtu.be/wo84LFzx5nI