4 ms·
> Why would I want to write a class/object when all i need is print "Hello World". There is a huge gap between what OO could/was meant to be and how it is seen
by klibertp 12y ago
> Why would I want to write a class/object when all i need is print "Hello World".
There is a huge gap between what OO could/was meant to be and how it is seen nowadays. I prefer thinking of OO as it's implemented in Smalltalk or Io instead of in C++ or Java.
To be more specific, in Smalltalk your hello world would look like this:
Transcript show: 'Hello world'
and in Io:
"Hello world" println
No class/object declaration in sight, right?
And then this:
> The root problem seems to be trying to do eveything the OO way when all you need is a function
is a wrong question altogether - there is nothing stopping you from writing a function in OO (other than broken and dumbed down implementations in major languages, that is). In Smalltalk:
my_func := [ 'Look, I'm a function!' ].
"There's this slightly unusual way of calling the function though:"
my_func value. "returns 'Look, I'm a function!'"
similarly in Io:
my_func := block( "Look, I'm a function!" )
my_func call # same as above
So, to make my point clear: there is NOTHING in OOP itself which REQUIRES verbosity and over-abstraction. On the contrary: going "full OO" makes it easier to write short, readable, to-the-point code. It also makes it easy to use FP patterns should you want it.
What you're arguing against are the currently popular implementations of OO, which are just bad. And before I forget: Erlang (and I program in it quite a bit) is one of the best Object Oriented languages I worked with.
- colomon 12y agoAgreed, but note that C++ doesn't require you to ever declare a class or an object. That's a Java thing you're complaining about.
- klibertp 12y agoC++ is equally "bad" in this regard - it doesn't force you to write classes, but when you don't you're using underlying primitives which are not first class objects. In both Smalltalk and Io the expressions I gave as examples produced real objects (BlockClosure and Block instances, respectively), while in C++ this: void my_func(){ std::cout << "I'm a function"; } produces a simple pointer. Of course, this is how it should be - it follows from C++ design goals and totally makes sense for a number of reasons; however, from the perspective of OOP, this makes C++ less "pure OO" than mentioned languages (and many others).
- mikkom 12y agoI'm not sure if you are trolling or not but erlang is not an object oriented language. Joe Armstrong said it quite clearly in the article where his quote was taken > As Erlang became popular we were often asked “Is Erlang OO” - well, of course the true answer was “No of course not” - but we didn’t to say this out loud - so we invented a serious of ingenious ways of answering the question that were designed to give the impression that Erlang was (sort of) OO (If you waved your hands a lot) but not really (If you listened to what we actually said, and read the small print carefully). http://harmful.cat-v.org/software/OO_programming/why_oo_sucks http://harmful.cat-v.org/software/OO_programming/why_oo_suck...
- klibertp 12y agoI'm not trolling; of course whether Erlang is OOP depends on a definition of OOP you consider "real". If you think of OOP as Java-style programming, then of course, Erlang has very little in common with it. On the other hand, if you go back to what Alan Kay had in mind when he invented OO, namely objects as "black boxes, similar to computers in miniature" and "message passing as the only way of doing something" then Erlang is very, very much OO. Its processes are objects, and sending (asynchronous!) messages is built into the language. Then you get encapsulation, data hiding and interfaces with module exports and behaviours. That doesn't stop Erlang from being FP, too. Really, there are many different paradigms and many implementations of each one, it benefits no one to only consider one particular implementation as representative for a whole paradigm. Footnote: Alan Kay post on a similar topic: http://lists.squeakfoundation.org/pipermail/squeak-dev/1998-October/017019.html http://lists.squeakfoundation.org/pipermail/squeak-dev/1998-...
- slowmovintarget 12y agoTo paraphrase Robert Downey Jr., 'Never go "full OOP."' I think the bigger problem has been decades of education that start with decomposing domain objects into OOP class hierarchies by common attributes. Animal, Dog, English Bulldog, Herman. Now we have significantly better ways of teaching OOP: - favor composition over inheritance - decompose and group behaviors - Liskov substitution principle Sadly we're dealing with mainstream languages that are barely OO like Java (which I've done 99% of my work in for the last thirteen years). But even if Eiffel had somehow taken off and stood in Java's place... Nope... can't finish that sentence. It couldn't have. OO was originally created as a way to cleanly allocate memory on the heap. That's a fairly well solved problem now. The best parts of OO aside from heap allocation are encapsulation and polymorphic dispatch (two sides of the same coin). Closures and functions as fundamental units of decomposition handle that fairly well, especially when you couple that with type inferencing. I'm not arguing that OO is bad. I'm arguing that it's no longer anywhere near as useful as it used to be, even when it was implemented and used properly.
- klibertp 12y ago> OO was originally created as a way to cleanly allocate memory on the heap. That's the first time I hear something like this. Any source for this?
- slowmovintarget 12y agoI can't find the reference now, but it was part of a history I'd read about the creation of Simula 67. Given that the summaries you read on Wikipedia about it describe Simula 67 as a fulfillment of the need to create a better process description abstraction, I may simply be wrong.
- fenollp 12y agoQuick side question on this piece of Smalltalk: my_func := [ 'Look, I'm a function!' ]. How does the string parsing work here? I like it a lot edit: welp, this [1] makes it sound like 'Look, I'm a function!' is a typo and should in fact be 'Look, I''m a function!' (Note the double simple quote `I''m`) But the idea to not need to escape single quotes when surrounded by something else than whitespace is interesting. [1] https://gist.github.com/sin3141592/602700#file-smalltalk-grammar-L53 https://gist.github.com/sin3141592/602700#file-smalltalk-gra...
- klibertp 12y agoOMG, yeah, my bad - I tested the code with some other string in Pharo and then changed it when pasting it here. I should have known better and tested the exact code I was going to post :)