Feelings on programming dogmata

Started by
34 comments, last by Kylotan 19 years, 10 months ago
quote:Original post by GnuVince


You should look at Smalltalk. It addresses both problems you talk about: everything is held in a single image file and the environment really takes advantage of everything being in one place (and being truly alive).

You should download either Squeak or the Non-Commercial version of VisualWorks Smalltalk (by Cincom).


Looks interesting. Haven''t played with Smalltalk yet...

Ta.

--
Sean Timarco Baggaley
Sean Timarco Baggaley (Est. 1971.)Warning: May contain bollocks.
Advertisement
quote:Original post by Kylotan
You need to consult the parent class to see the template method, not the implementation of the method you''re overriding. And the various overridable methods cannot always be totally independent as they are typically performing mutating operations on an object as if it''s a production line. For example, if one of the earlier methods set the content type to "text/html" then one of the later methods would want to generate HTML output. If the earlier one had set the content type to "text/plain" then the later method would not want to create HTML output. etc.

[edited by - Kylotan on June 1, 2004 10:03:43 AM]
I don''t really understand your example, but I suppose that it is true that on rare occasions it may be necessary to have methods that know how the others work. To tell the truth, though, I find that its rare that I need inheritence. If I was doing something involving CGI, I would create a class (or use one of the many in existence) which handles all the Content-type stuff, POST/GET, environment variable, stdin, parsing stuff, and just use this class to do everything in a non OOP way. What''s the need to inherit the class for each page?

Zorx (a Puzzle Bobble clone)
Discontinuity (an animation system for POV-Ray)
Zorx (a Puzzle Bobble clone)Discontinuity (an animation system for POV-Ray)
quote:Original post by Kylotan
fallenang3l (and clum, to an extent) - The black box concept isn''t all that useful when applied to the template method. Bear in mind that the template method pattern is not so much about ''being object oriented'' as it is about exploiting the polymorphism system to customise parts of a system. You need to be very familiar with the templated algorithm in order to appreciate which functions to override in the subclasses. Naming and understanding individual components wasn''t a problem here, but having program flow split over several files and hidden in the polymorphism implementation was.


Perhaps the template method pattern wasn''t the one to use. The template method has a schizophrenic mandate as it has to accomodate both the client programmer and the writer of the specific algorithms derived from the base. In effect, as you said, it relies on polymorphic behavior so heavily that by calling a method you don''t have a clue what gets called.
What I''d have done is split up the responsibilities into two classes. One class is the specific algorithm (in fact, it not need to be a class, it can be a free function) that a reference to the worker class. The worker class might be an ABC providing just an interface so you can derive more specific workers, but it not need to be. So in your code you see what actual algorithms are invoked and what specific workers you pass in, so it should be clear what happens without delving deep into the implementation details. Not as totally automated, true, but still clear, generic and flexible.
quote:
The moral of this story is that I took it too far. A layer of abstraction buys you flexibility but loses you clarity, and in this case the amount of clarity I lost far exceeded the flexibility I received.


That''s what documentation is for :-p.

I agree with you about the second part, though. It''s the same thing with people who think you can''t mix procedural and oo programming. Sorry, but I''m not encapsulating generic math routines in a class.

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

quote:Original post by Kylotan
I made a choice, but it was the wrong choice. I was designing to solve a problem that I didn''t really have, adding in flexibility and safety that I didn''t yet need. It gave me some potential benefits in return for some definite downsides.

I think that you hit the nail on the head here. What''s wrong is not the design, but that it was applied before it was needed, if it would ever be. So many people get caught up in the power and flexibility of abstraction and polymorphism that they subconsciously perceive future problems or scenarios that will require certain design patterns to overcome. You get so used to thinking about problems in a specific way that some solutions seem naturally correct, and only once you''ve applied them do you get the opportunity to test your "assumptions." I guess this brings us back to the rigid way of thinking, as you say. However, I wouldn''t put anyone at fault for this. Everyone has their own instinctive sense of how design should be approached that was picked up somewhere along their programming career. We find something that suits our fancy and stick with it. It''s not being rigid that''s the problem, it''s being stubborn; actively refusing potentially better solutions or suggestions. In this case, copy-and-paste turned out to be that better solution, but with all the peer pressure surrounding avoiding such a method in addition to what I know about it, I would too refuse such an approach It''s only ironic that something relatively quite low on the "food chain of design" turned out to work better than something relatively high on the chain.

I suppose, when everything is said and done, there is no absolute design solution to any one problem. It''s just human nature for the mind to settle on something, and subconsciously perceive things in a way that suits what we already think rather than change. Especially when we learn new things, we like to try and utilize the most powerful tools for the simplest of problems. For example, I sometimes find myself using differential Calculus to solve algebraic word problems, just because that''s the most recent mathematics I know that can still solve the problem.

But I''ll stop rambling right here.
The price we pay for forgetting that the whole point is to write something that both people and computers understand.

Using OO is like speaking with an enormous vocabulary. You can say things more precisely than you might otherwise, but you can also confuse the hell out of anyone trying to understand.


"Without deviation, progress itself is impossible." -- Frank Zappa
"There is only one everything"

This topic is closed to new replies.

Advertisement