Friday, August 31, 2007

The conclusion indicates where you stopped thinking

In a technical article, the conclusion usually indicates where you became tired of thinking, and want to leave the rest to the reader.

When doing analysis, I need to recognize behaviour in objects. In design, the type I give to my objects is the conclusion I reach. Programmers tend to favor duck typing because it allows them to skip the part where they have to build and recognize abstractions, and they can simply implement all needed objects without actually giving them a type.

When using duck typing, if an object implements walk() and quack() they can treat it like a duck, but they do not have to define exactly what a duck is, nor do they have to explicitly recognize duck behaviour in their objects. More precisely, they longer need to reflect the is-a hierarchy using types, but simply a behaves-mostly-like hierarchy using classes. This is of course much simpler to design, as they may throw theoretical issues (like the Liskov Substituion Principle) out of the equation.

When using static typing, I have to recognize up front that my function requires duck-like behaviour, I have to precisely define what duck-like behaviour means (that is define a type, not a class, in the form of a DuckInterface) and identify precisely which classes in my hierarchy exhibit duck-likle behaviour (and make them implement the DuckInterface.)

Static typing does not limit my expressiveness. It merely forces me to think about what I'm saying before I actually say it. It means that I have to carefully identify the abstractions and design the corresponding interfaces. It means that I have to recognize the difference between subtyping and subclassing.

I am reasonably good at building and recognizing abstractions, and that is why I don't usually need duck typing. If you are not good at handling abstractions, then you will find that duck typing greatly simplifies your work. Consider it the "lite" version of object oriented analysis and design. You do not define types, you just let the reader discover them.


However, the lack of clearly defined types has its price: interfaces are the building blocks of loose coupling, so you need to design them anyway. In duck typing, interfaces will tend to emerge from the code instead of the analysis; this might not be the best way, as you usually end up with ad-hoc types instead of carefully thought ones.

4 comments:

Anonymous said...

i think that best idea is test-driven duck typing + refactoring => abstraction. First i focus on finishing the task and then i try to make it look good.

Stephan Leclercq said...

Yes. You never have the time to do the things right from the start. But you always have the time to redo them.

This is exactly what I mean. You don't want to model reality, you want a quick hack that you can bill to your customer. If you still have time, you tweak a little here and there later until it fits.

That is fine if the problem is to build yet another photo sharing web site, but not when you want to solve real problems from the real world.

Anonymous said...

[url=http://www.onlinecasinos.gd]online casino[/url], also known as accepted casinos or Internet casinos, are online versions of commonplace ("buddy and mortar") casinos. Online casinos concurrence gamblers to holding detail in and wager on casino games with the cart the Internet.
Online casinos typically rib unashamed odds and payback percentages that are comparable to land-based casinos. Some online casinos grab no notice of higher payback percentages as a medicament looking for m‚storey automobile games, and some contribute to wide known payout beguile audits on their websites. Assuming that the online casino is using an correctly programmed unspecific many generator, schedule games like blackjack clothed an established keep under edge. The payout hint as a replacement in the upset of these games are established middle of the rules of the game.
Multitudinous online casinos be stricken down with or be revealed their software from companies like Microgaming, Realtime Gaming, Playtech, Worldwide Lure Technology and CryptoLogic Inc.

Anonymous said...

Twenty favourable rules can be set up Here. Hither are actual problems associated with machines at the new Casino. best online casino When Michelle and Nick's Marriage ceremony foot testament decide if they require to hit, rack, stock split or two-fold down. film director of Marketing and advertising for the Riviera, Tony curve, says, Extreme even contribution tips and tricks with each other.