Mon May 26 14:43:19 CEST 2008
This article is about the benefits of programming in a concatenative
language, viewed from the point of programming as iterative
refactoring of a prototype.
Let's say composition and decomposition are the basic tools of any
* build complex, specialized systems out of simple, generic parts
* refactor an evolved complex design to create a toolbox of generic parts
The most difficult step is obviously the latter one.
Decomposition creates interfaces: when a monolithic part is split in
2, there is now a thing connecting them. Good decompositions can be
judged by the complexity of the interfaces they create. You do the
right thing if cutting at some point hides the stuff you want to
forget, but keeps open some sane way of interacting with the rest of
the world. Simple interfaces promote reuse.
In most programming languages, the procedure / function / message is a
basic unit of composition: it can be used to create a black box which
reacts to input and produces output. Decomposition or refactoring in
such languages amounts to the "extract method" pattern: split up a
complex uncontrolled interaction by identifiying primitive operations,
and rewrite the complex interaction as a simpler interaction between
Looking at Martin Fowler's explanation in Refactoring: Improving the
Design of Existing Code:
"You have a code fragment that can be grouped together. Turn the
fragment into a method whose name explains the purpose of the
Important consequences of extracting methods:
* compression and modularity: Code will be smaller because
duplication is removed: share NOW. This reduces local
* promotes reuse: It creates a possibility that code can be shared
by new nodes LATER, possibly outside of the current project.
* documentation: The name annotate the code note with a meaningful
explanation. the better the factorization, the easier it becomes
to give names.
Now, an advantage of concatenative programming languages is that
'extract method' is a simple cut and paste operation: the absence of
names for function parameters disposes of the hurdle of inventing them
when factoring out code. This leads to easier identification of
components, which usually ends up in concatenative code having a very
fine factoring granularity.