Anti-OOP... stupid?
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Feb 14 14:47:03 PST 2012
On Tue, Feb 14, 2012 at 11:00:43PM +0100, Zero wrote:
> Hello!
>
> I've recently started to work with D, and I'll start a "bigger"
> project soon, using it. For a few days I've been thinking about the
> approach I'll take here, and since I don't /have/ to use full OOP in
> D, I was wondering... how crazy is it to not use full OP nowadays?
I do that all the time. I guess that makes me crazy. :)
[...]
> What I want to know from you people... is that stupid? To even think
> about doing something like this? Basically mixing procedural and OOP?
D allows you to program in functional style, OOP, procedural style, or
any combination of them. There is a reason D was designed this way. :)
> I know about the dangers, and disadvantages, but if those don't scare
> one away, would you consider it bad, if someone did this, on a larger
> project?
[...]
OOP has its own share of dangers and disadvantages. Which, sadly, most
people don't talk about very much because they don't have the guts to go
against the current cool trendy bandwagon that everyone's jumping on.
Templates, for one thing, don't fit very well into the OO paradigm (ever
tried a virtual template function?), even though you *can* use it to
enhance an OO-based design. And D's templates are one of the best things
about D, ever.
Of course, many aspects of OO does help with large projects, so it's
usually a good idea to take advantage of that. But that doesn't mean you
*have* to use OO, or that it's "bad" to mix in procedural stuff when it
suits you.
I mean, if you take OO to the extreme, that would require excluding all
those evil procedural constructs like if statements and for loops, and
write everything in terms of invoking object methods... like this
monstrosity:
class MyClass {
void myMethod() {
IntVariable i;
ForLoopFactory.create(
new IntSetter(i.address(), new Number(0)),
new BooleanCondition(
new LessThanComparator(i.address(),
100)),
new IntAdder(&i, 1),
new IfStatement(
new EqualComparator(i.address(),
new Number(42)),
new FunctionCaller(writeln.address(),
new String("Found it!")),
)
).execute();
}
}
which is, of course, completely ridiculous.
The bottom line is, use whatever tools work best for what you need to
do. If OO works well, use it. If procedural code works well, that use
it. If both works well in different cases, then use a mix of both
depending on the circumstances.
Trying to shoehorn everything into an object is stupid.
T
--
Государство делает вид, что платит нам зарплату, а мы делаем вид, что
работаем.
More information about the Digitalmars-d-learn
mailing list