>In good OO programming, we don’t make class hierarchies in order to satisfy our inner Linnaeus. This correctly identifies one of the worst problems with how people construct OO programs when they get out of college. They are infected with the idiotic desire to make neat taxonomies. They don't know why. They can't even explain the rules that make one taxonomy good and another one bad. They just feel some immense pres…
> 3. Often you want to use the default protocol implementation with some changes. Instead of re-implementing the rest of the protocol, it's highly convenient to be able to specify only the differences. > #3 is the core reason why inheritance was developed. No, absolutely not. As sibling comments say, composition is sufficient for that. I can only see exactly one reason why inheritance is necessary: to allow superclas…
Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
91–100 of 113 posts
Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
#92Earlier quoted context omitted.
> It's odd he makes these complaints, because the comment he's responding has this caveat: > > unless they are talking about writing a clone of The Sims or something Although I formatted it as a quote, I wasn't quoting or responding to somebody else in that part. That part about the Sims was part of the somewhat flippant principle I was proposing. The litany about ducks was just to explain the reasons for it. It wasn…
Even though I disagree with it, I think it was still a valuable point. And everyone should deliver a litany about ducks at some point in their life.
Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
#93>In good OO programming, we don’t make class hierarchies in order to satisfy our inner Linnaeus. This correctly identifies one of the worst problems with how people construct OO programs when they get out of college. They are infected with the idiotic desire to make neat taxonomies. They don't know why. They can't even explain the rules that make one taxonomy good and another one bad. They just feel some immense pres…
We make class hierarchies in order to simplify the code
In fact, much of the abstractions of programming were invented for this reason, and it's unfortunate that a lot of courses don't really teach the why. They tend to start off on the right track with something like "use a loop to repeat a sequence of operations X times", but then get caught up in preaching about abstraction with functions when it's far more intuitive and sensical to approach it from the perspective of "repeat a sequence of operations, with perhaps some small differences in parameters". For the same reason, I think OOP should be taught only after basic arrays (grouping homogenous data together), structures (grouping heterogenous data together) and functions, since OOP is really just another level of organisation that can --- not must, unlike what a lot of people seem to believe --- be applied to code once it becomes complex enough.
The dogmatic attitude towards OOP and treating it like a goal leads to ridiculous explosions in complexity for even the simplest of applications; what can be done by someone who hasn't been indoctrinated in a few lines of code can turn into hundreds of lines instantiating dozens of objects. "Design patterns" helps to amplify that too.
Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
#94Earlier quoted context omitted.
> 3. Often you want to use the default protocol implementation with some changes. Instead of re-implementing the rest of the protocol, it's highly convenient to be able to specify only the differences. > #3 is the core reason why inheritance was developed. No, absolutely not. As sibling comments say, composition is sufficient for that. I can only see exactly one reason why inheritance is necessary: to allow superclas…
Firstly, late binding is orthogonal to inheritance. It simply means that methods are looked up based on runtime information, rather than determined at compile time. You can have late binding in a language with no inheritance or classes at all. Secondly, OO composition does not solve the problem I described in #3. If object X has 9 methods I want to reuse in object Y, making X a component of Y still requires me to re-…
That is also not universal. In Ruby, for instance, one can write:
class Y
def method_missing(m, *args, &block)
@x.send(m, *args, &block)
end
endRe: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
#95Earlier quoted context omitted.
Firstly, late binding is orthogonal to inheritance. It simply means that methods are looked up based on runtime information, rather than determined at compile time. You can have late binding in a language with no inheritance or classes at all. Secondly, OO composition does not solve the problem I described in #3. If object X has 9 methods I want to reuse in object Y, making X a component of Y still requires me to re-…
> If object X has 9 methods I want to reuse in object Y, making X a component of Y still requires me to re-implement those 9 methods in Y, even if they are just pass-throughs. That is also not universal. In Ruby, for instance, one can write: class Y def method_missing(m, *args, &block) @x.send(m, *args, &block) end end
Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
#96Earlier quoted context omitted.
> If object X has 9 methods I want to reuse in object Y, making X a component of Y still requires me to re-implement those 9 methods in Y, even if they are just pass-throughs. That is also not universal. In Ruby, for instance, one can write: class Y def method_missing(m, *args, &block) @x.send(m, *args, &block) end end
I don't think you have to squint very hard to see that as an implementation of inheritance.
Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
#97Earlier quoted context omitted.
> 3. Often you want to use the default protocol implementation with some changes. Instead of re-implementing the rest of the protocol, it's highly convenient to be able to specify only the differences. > #3 is the core reason why inheritance was developed. No, absolutely not. As sibling comments say, composition is sufficient for that. I can only see exactly one reason why inheritance is necessary: to allow superclas…
Firstly, late binding is orthogonal to inheritance. It simply means that methods are looked up based on runtime information, rather than determined at compile time. You can have late binding in a language with no inheritance or classes at all. Secondly, OO composition does not solve the problem I described in #3. If object X has 9 methods I want to reuse in object Y, making X a component of Y still requires me to re-…
In Java, or C++, or Python, how can we allow superclass methods to call methods on a subclass (a form of late binding) without inheritance? I don't think it's possible. So unless I am much mistaken (and please correct me if I am wrong), inheritance is convenient for reducing boilerplate but necessary for late binding (in many languages).
Have I made a mistake in my analysis somewhere?
Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
#98Earlier quoted context omitted.
Do any functional languages support partial evaluation using named parameters? That would solve the parameter ordering complaint. As for higher order functions you would write a function that does the 90% and accepts a function parameter for the other 10%.
> As for higher order functions you would write a function that does the 90% and accepts a function parameter for the other 10%. Surely you see how this doesn't scale, right? You would need to first write your code, then abstract every single piece of it as a call to a function passed in parameters. Now your function is accepting five different functions in parameters, and calls them. This is a terrible and impossibl…
Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
#99Earlier quoted context omitted.
Not sure what you mean, exactly. Could you sketch a simple example with some types and typeclasses?
This is how it would be done in Java: class Parent { public void first() {}; public void second() {}; public void third() {}; } class Child extends Parent { @Override public void third() {}; //change implementation of third function, reusing the first two. }
data Numberable = Numberable {
first :: IO ()
,second :: IO ()
,third :: IO ()
}
parent = Numberable {first = return (), second = return (), third = return ()}
child = parent { third = print 'third' }
And if you wanted to DI into a function: data Env = { numberable :: Numberable }
doStuff :: (MonadIO m, MonadReader Env m) => Int -> Int -> m ()
doStuff num1 num2 = do
myNumberable Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
#100>In good OO programming, we don’t make class hierarchies in order to satisfy our inner Linnaeus. This correctly identifies one of the worst problems with how people construct OO programs when they get out of college. They are infected with the idiotic desire to make neat taxonomies. They don't know why. They can't even explain the rules that make one taxonomy good and another one bad. They just feel some immense pres…
Well said. And #3 is also an area where Functional Programming falls completely flat. There is simply no easy way in any FP language that I know to capture such a simple mechanism as: "Reuse 90% of this piece of code but alter just this 10%". Specialization is a very, very powerful aspect of OOP, one that's extremely easy to explain and which comes in handy to model a surprisingly wide variety of problems.