Design Patterns and Programming Language Design
Design and more Design...Patterns and Programming Languages
Mark Dominus has an interesting article about design patterns and programming language design.
In short, the thesis is made that a design pattern reflects a short coming of the programming language, or as the author puts it,”Patterns are signs of weakness in programming languages.” The speculation is what-if design patterns
had been popular in the 1960’s and 1970’s.
An interesting statement by the author is,”...the patterns should be used as signposts to the failures of the programming language. As in all programming, the identification of commonalities should be followed by an abstraction step in which the common parts are merged into a single solution.”
As I have designed a programming language, Mynx, the author’s article and commentary (even though it has a touch of bluster rather than objectivity) pointed out a design facet of programming language design. Namely, what features
become part of the programming language, and what features must be constructed by a developer in the programming language.
To think about the question, a specific, tangible feature of Mynx needs to be
considered in relation to a design pattern.
One feature in a way in Mynx has a corresponding design pattern, static classes and the singleton design pattern.
A singleton in short practice, is a creation design pattern that allows only one instances of an object exist, hence single. Any time the method used to create or get the instance is accessed, it returns the reference/pointer to that single instance.
A Mynx static class is a class that is never instantiated, but always exists -- there is only one version of it, hence static. All class elements are also static, and the only classes that can be inherited are static.
Comparing code for a static class and a default class that implements the singleton design pattern with the same method “doIt” in the class:
The static class is quick and easy to code, whereas the singleton class requires more overhead, the constructor to create an instance, a static attribute for the single instance, and the access method to get the reference to the instance.
At first glance, it would seem that Mark Dominus has something profound...but (and you knew this was coming...) there is one other point to consider.
Making the leap from singleton design pattern is equivalent to static class overlooks the fact that a singleton can have state -- memory, whereas the static class does not, a static class is stateless. The static attributes can retain memory, but the static class and static methods do not.
So does this mean static attribute is equivalent to singleton? No. A singleton uses a static attribute which has state, and the methods are created to control creation and access to the static attribute. So then, why not just use a static attribute? That opens up the can of worms about encapsulation. Violating one object-oriented principle in order to integrate a design pattern into the language is to use a phrase robbing Peter to pay Paul (and vice-versa).
What does it mean? The conclusion is that saying for a design pattern there is a language feature is an over-simplification, and design patterns use features of the object-oriented paradigm like encapsulation, polymorphism, method overloading to create constructs with desirable features. Saying a design pattern is indicative of a weakness in the programming language is to say eliminate all the features of the object-oriented paradigm and provide nothing but design patterns as features of the language. Then it is a question of power in terms of one kind of language creating features in the other. Can an object-oriented language create design patterns (yes) versus can a language of nothing but design patterns create object-oriented features like encapsulation, polymorphism, inheritance...I’d say no without some difficulty.
To use a metaphor, design patterns and object-oriented programming languages are like plastics to chemistry, the laws of chemistry allow plastics which are synthetic materials to be made, but does that mean there’s a flaw in nature because plastics do not naturally occur?
But there is something interesting that design patterns and programming languages can have...but I'll save that for another blog post about a possible future feature of Mynx.
Mark Dominus has an interesting article about design patterns and programming language design.
In short, the thesis is made that a design pattern reflects a short coming of the programming language, or as the author puts it,”Patterns are signs of weakness in programming languages.” The speculation is what-if design patterns
had been popular in the 1960’s and 1970’s.
An interesting statement by the author is,”...the patterns should be used as signposts to the failures of the programming language. As in all programming, the identification of commonalities should be followed by an abstraction step in which the common parts are merged into a single solution.”
As I have designed a programming language, Mynx, the author’s article and commentary (even though it has a touch of bluster rather than objectivity) pointed out a design facet of programming language design. Namely, what features
become part of the programming language, and what features must be constructed by a developer in the programming language.
To think about the question, a specific, tangible feature of Mynx needs to be
considered in relation to a design pattern.
One feature in a way in Mynx has a corresponding design pattern, static classes and the singleton design pattern.
A singleton in short practice, is a creation design pattern that allows only one instances of an object exist, hence single. Any time the method used to create or get the instance is accessed, it returns the reference/pointer to that single instance.
A Mynx static class is a class that is never instantiated, but always exists -- there is only one version of it, hence static. All class elements are also static, and the only classes that can be inherited are static.
Comparing code for a static class and a default class that implements the singleton design pattern with the same method “doIt” in the class:
static class Static is
public singular doIt is
null;
end doIt;
end class;
default class SingletonXXX is
private static XXX single to default;
private construct is to null;
public constant XXX getInstance is
return single;
end getInstance;
public constant doIt is
null;
end doIt;
end class;
The static class is quick and easy to code, whereas the singleton class requires more overhead, the constructor to create an instance, a static attribute for the single instance, and the access method to get the reference to the instance.
At first glance, it would seem that Mark Dominus has something profound...but (and you knew this was coming...) there is one other point to consider.
Making the leap from singleton design pattern is equivalent to static class overlooks the fact that a singleton can have state -- memory, whereas the static class does not, a static class is stateless. The static attributes can retain memory, but the static class and static methods do not.
So does this mean static attribute is equivalent to singleton? No. A singleton uses a static attribute which has state, and the methods are created to control creation and access to the static attribute. So then, why not just use a static attribute? That opens up the can of worms about encapsulation. Violating one object-oriented principle in order to integrate a design pattern into the language is to use a phrase robbing Peter to pay Paul (and vice-versa).
What does it mean? The conclusion is that saying for a design pattern there is a language feature is an over-simplification, and design patterns use features of the object-oriented paradigm like encapsulation, polymorphism, method overloading to create constructs with desirable features. Saying a design pattern is indicative of a weakness in the programming language is to say eliminate all the features of the object-oriented paradigm and provide nothing but design patterns as features of the language. Then it is a question of power in terms of one kind of language creating features in the other. Can an object-oriented language create design patterns (yes) versus can a language of nothing but design patterns create object-oriented features like encapsulation, polymorphism, inheritance...I’d say no without some difficulty.
To use a metaphor, design patterns and object-oriented programming languages are like plastics to chemistry, the laws of chemistry allow plastics which are synthetic materials to be made, but does that mean there’s a flaw in nature because plastics do not naturally occur?
But there is something interesting that design patterns and programming languages can have...but I'll save that for another blog post about a possible future feature of Mynx.

