Re:What Made OO Be Successful
by colanderman on Sunday January 04, 2015 @12:47PM
(#8835143)
This applies to any language with static types. Or that allows code to be separated in multiple files, for that matter.
In Haskell, I can literally ask the editor to list me all functions that operate on type X. Even in C written with a modicum of coding discipline, 90% of the functions relevant to type X will be defined in X.h, wherein 100% of the functions in X.h are relevant to type X. (And the 10% of functions relevant to type X that aren't in X.h? Well, in Java, they also wouldn't be part of class X anyway.)
I'd be willing to bet that the Point object in any given language is going to have more methods that take it as an argument than methods the class itself has.
A natural way to separate those two types of methods is:
* methods that do something *to* a Point object
* methods that do something *with* a Point object
The former are better to be declared inside the Point object so that they have access to internal state.The latter shouldn't typically access internal state of the Point object.
This separation can help immensely while analyzing a code base.
True. But I still go looking for the "Point" class first. Then I start looking for things which accept "Point" parameters. Big difference from procedural programming languages.
Re:What Made OO Be Successful
by colanderman on Sunday January 04, 2015 @06:30PM
(#8836345)
In C, I look in "point.h" first, then start looking for other things. Not really different.
Ooooh... that's a Point object - no way the AddAccount function does anything relevant with it! In OO you don't even actually need to think that since Point has a limited set of methods.