4 ms·
OO concepts are occasionally cool and useful. Note the use of the word occasionally. 90+% of the time, when you create an object, what you really want is a str
by time_management 18y ago
OO concepts are occasionally cool and useful. Note the use of the word occasionally.
90+% of the time, when you create an object, what you really want is a struct/record. Most methods should really be static. Most of the power that does come from OO comes from its ability to foster a hierarchical type system in an extensible way.
OO smells like something that was invented to give "business" types the illusion that they can understand code without reading it in detail. "This is 'like a' Chair."
- narag 18y ago90+% of the time, when you create an object, what you really want is a struct/record. I don't. I've been fortunate enough to use a language that doesn't force the "everything's an object" mantra. The two real advantages of OOP (from my POV anyway) are encapsulation (minimal interface) and convenient syntax: the first parameter turns to be a prefix so it resembles human language, a question of usability really.
- silentbicycle 18y agoEncapsulation can also be handled well at the module/package system level, though. (The package system in OCaml has some particularly interesting features.) The latter is a mixed blessing. It's often very convenient, but sometimes there isn't a clear answer which object should be the primary one in a binary operation. (This is particularly troublesome with non-commutative operations.) Lua's syntactic sugar for this ( obj:method(args) vs method(obj, args) ) seems like a good balance; it's explicit that it's just sugar for convenience, but you aren't required to use it.
- narag 18y agoEncapsulation can also be handled well at the module/package system level, though Yes, it's more or less the same, but you can define public and private parts for individual objects. The good part of encapsulation is separating interface from implementation: you can publish a data type without giving access to its innards. sometimes there isn't a clear answer which object should be the primary one in a binary operation I really haven't found it to be a problem in practice.
- silentbicycle 18y agoThe good part of encapsulation is separating interface from implementation: you can publish a data type without giving access to its innards. And you can do that in a good module system, too. Look at OCaml's. (http://caml.inria.fr/pub/docs/manual-ocaml/manual004.html http://caml.inria.fr/pub/docs/manual-ocaml/manual004.html) Also, look at the functors - modules are first class, so you can write functions that take a module and return a (usually more specific or generated) module.