This document discusses design pattern automation and the use of pattern-aware compilers. It provides a history of programming languages and patterns, defines design pattern automation as using tools to optimize productivity in implementing software based on patterns. It discusses how pattern-oriented software development involves implementing patterns at multiple levels of abstraction. It also addresses myths around why patterns cannot be automated and argues that emerging design and agile methodologies allow patterns to naturally emerge from iterative design processes. An example of applying automation to the Reader-Writer pattern through code generation and verification is also provided.
6. @gfraiteur
1. A history of programming
languages and patterns
2. Defining Design Pattern Automation
3. Pattern-Oriented Software Development
4. Tools for Design Pattern Automation
5. Agile Methodologies and Patterns
6. A last example
7. Q&A
8. Summary
Section
11. @gfraiteur
Simula (1967)
• Classes as
abstraction mechanism
• Virtual procedures
• Object references
• Coroutines
Begin
Class Glyph;
Virtual: Procedure print Is Procedure print;
Begin
End;
Glyph Class Char (c);
Character c;
Begin
Procedure print;
OutChar(c);
End;
Glyph Class Line (elements);
Ref (Glyph) Array elements;
Begin
Procedure print;
Begin
Integer i;
For i:= 1 Step 1 Until UpperBound (elements, 1) Do
elements (i).print;
OutImage;
End;
End;
Ref (Glyph) rg;
Ref (Glyph) Array rgs (1 : 4);
! Main program;
rgs (1):- New Char ('A');
rgs (2):- New Char ('b');
rgs (3):- New Char ('b');
rgs (4):- New Char ('a');
rg:- New Line (rgs);
rg.print;
End;
13. @gfraiteurHolašovice, Czech Republic
How is it possible that any simple farmer could make a
house, a thousand times more beautiful than all the
struggling architects of the last fifty years could do?
Christopher Alexander
in The Timeless Way of Building, 1977
Pattern Thinking (1977)
18. @gfraiteur
Patterns as
WISDOM
in canonical form
• Name
• Also Known As
• Problem
• Context
• Forces
• Example
• Solution
• Structure and Dynamics
• Implementation
• Example Resolved
• Known Uses
• Variants
• Consequences
• Relationships
• Name
• Also Known As
• Problem
• Context
• Forces
• Example
• Solution
• Structure and Dynamics
• Implementation
• Example Resolved
• Known Uses
• Variants
• Consequences
• Relationships
• Name
• Also Known As
• Problem
• Context
• Forces
• Example
• Solution
• Structure and Dynamics
• Implementation
• Example Resolved
• Known Uses
• Variants
• Consequences
• Relationships
• Name
• Also Known As
• Problem
• Context
• Forces
• Example
• Solution
• Description
• Example Resolved
• Known Uses
• Variants
• Consequences
• Relationships
22. @gfraiteur
Cost of low abstraction
• Boilerplate code
• More bugs
• Code review
• Changing the pattern implementation
23. @gfraiteur
1. A history of programming languages and patterns
2. Defining Design Pattern
Automation
3. Pattern-Oriented Software Development
4. Tools for Design Pattern Automation
5. Agile Methodologies and Patterns
6. A last example
7. Q&A
8. Summary
Section
24. @gfraiteur
Pattern Automation
Automation
is the use of
machines, control systems
and information technologies
to optimize productivity in
the production of goods and
delivery of services.
Wikipedia
Design Pattern Automation
is the use of tools to optimize
productivity in the
implementation of software
based on patterns.
34. @gfraiteur
1. A history of programming languages and patterns
2. Defining Design Pattern Automation
3.Pattern-Oriented Software
Development
4. Tools for Design Pattern Automation
5. Agile Methodologies and Patterns
6. A last example
7. Q&A
8. Summary
Section
35. @gfraiteur
they are way too complex general abstract
You can’t automate patterns because…
MYTH 4
36. @gfraiteur
a normal part of any engineering process
Making abstract things concrete is
TRUTH 4
ConcreteAbstract
Automatable
Non-
Automatable
37. @gfraiteur
Pattern-Oriented
Implementation Process
Architecture
Pattern
• Defines Subsystems
Design Pattern
• Define Components
• General problem
• Language-
independent
Implementation
Pattern
• Defines source
artefacts
• Language-specific
• Framework-specific
• Application-specific
• Implementation
guidelines
Source code
• Executable
High Abstraction Zero Abstraction
40. @gfraiteur
• Analyze property-field
dependencies
• Modify all non-const
methods
• Whenever a relevant
field has changed
• When invariants are
valid (after all changes
in the object have been
done)
Example: Observer Pattern
When? How?
3. Application-Specific Pattern (C#)
43. @gfraiteur
1. A history of programming languages and patterns
2. Defining Design Pattern Automation
3. Pattern-Oriented Software Development
4.Tools for Design Pattern
Automation
5. Agile Methodologies and Patterns
6. A last example
7. Q&A
8. Summary
Section
52. @gfraiteur
Example:
Poorman’s Singleton
• Static validation rules:
• Static private readonly field named
‘singleton’, whose type is the current type.
• Static public method GetInstance() whose return
type is the current type, returns field ‘singleton’.
• Class constructors are private.
54. @gfraiteur
• Limitations
• Inadequate UI and
error reporting
• Limited reflection
API
• Alternatives
• FxCop
• PostSharp
Architecture
Framework
Architecture Unit Tests
55. @gfraiteur
1. A history of programming languages and patterns
2. Defining Design Pattern Automation
3. Pattern-Oriented Software Development
4. Tools for Design Pattern Automation
5. Agile Methodologies
and Patterns
6. A last example
7. Q&A
8. Summary
Section
64. @gfraiteur
Example of application-specific pattern:
Business Rule Pattern
• For any class derived from BusinessRule:
• Name ends with “BusinessRule”
• No public constructor
• Has nested class named “Factory”
• Has parameterless public constructor
• Annotated with
[Export(typeof(IBusinessRuleFactory))]
65. @gfraiteur
1. A history of programming languages and patterns
2. Defining Design Pattern Automation
3. Pattern-Oriented Software Development
4. Tools for Design Pattern Automation
5. Agile Methodologies and Patterns
6. A last example
7. Q&A
8. Summary
Section
66. @gfraiteur
Example:
Reader-Writer Synchronized Object
• Code Generation
• Introduce interface IReaderWriterSynchronized
• [ReaderLock], [WriterLock] executes the method with
the right locking level
• Code Verification
• All fields must be private
• Cannot access field without proper lock
First I would like to thank you all for being present here today. I appreciate the time you are spending here. Imagine the total opportunity cost of this couple of hours we will be spending here together – if we all billed our standard rate. Obviously, I would like to serve you during that time. And I don’t only want to serve you, but the larger community too. Today, I would like to serve by planting a seed. An idea that can grow or perish, depending on you. But if we allow the seed to grow, together, we are going to improve the software development industry. We are going to make it easier to build good software. Make it easier to build good software. This idea is to change the way we think about design patterns.
Good morning! My name is Gael Fraiteur. You may think I have a weird accent and even think I am French, but actually I was grown in Belgium and have lived in Czech Republic for the last 12 years.(it’s wonderful being here in the US. Appreciate you take time outside of working hours to improve your skills and the profession. Not everybody does that and there’re many(?) here in the US. I’ll like to thank you guys for being what you are and doing what you do).When I was 15, that was 20 years ago, my English teacher came to me and asked whether I would be skilled enough to manage students’ test results and generate school reports. I said yes, although today I know I was not, and spent the largest part of the summer coding a client-server application in PowerBuilder – an amazing development environment. I have been coding for 4 years at that time, several hours per day, but my previous programs were mere “hacking”. So from a technical point of view, I was prepared. What was really new for me was to build a technology for real users, not for IT specialists. My first version was basically a set of table editors based on the relational database model. With time, I understood that the user interface of a technology should be as close as possible to the way users think and work, and not close to the platform it is built on (a relational database).Nine years ago I started another project: PostSharp. It was a small aspect-oriented framework for Microsoft .NET. It was not the first AOP framework, but I was very fortunate that the community let the seed grow and it became the most popular. The reason of this success, I think, is that I applied the lesson learned years before: the user interface of a technology should be as close as possible to the way users think and work. But this time, the user interface was PostSharp’s public API.The same principle applies to the design of programming languages. And I believe that today, if we want to get programming languages closer to the way human think, we need to look in the direction of patterns. I would like to communicate this vision to you in this talk.
Three years ago, PostSharp outgrew my capacity to maintain it as a free open-source project and, out of necessity, became a commercial product. In an industry dominated by open source and big platform vendors, to make a living from development tools is extraordinarily difficult. We at PostSharp Technologies have been fortunate enough to succeed in this endeavor. We are grateful for the trust we receive from our customers – from the one-man shop to the largest corporations.This remark should also serve as a disclaimer that this talk shall undoubted be biased by my very source of revenues.However, my commitment to you in this talk is to share the vision which motivates us day after day. This vision is much larger than our product itself, and you can implement it with other tools, perhaps less appropriate – and, hopefully we will be able to spark an idea that will influence the design of future language and compilers.
Programming for the UNIVAC FAC-TRONIC system, 1935 by Remington Rand inchttp://bitsavers.informatik.uni-stuttgart.de/pdf/univac/univac1/UNIVAC_Programming_Jan53.pdf
http://www.flickr.com/photos/62405357@N03/8519808328To bridge the gap between the way human think and how machine work.Both humans and machines have limitations.At the beginning there was assembly language and punch cards, then symbolic memory and procedural languages.
In his book “the timeless way of building”, Christopher Alexander asks the question:How is it possible that any simple farmer could make a house, a thousand times more beautiful than all the struggling architects of the last fifty years could do?Answer:Shared knowledge, and the knowledge was in the languageIncremental process, centuries of experienceVernacular architecture (folk architecture)http://whc.unesco.org/en/list/861http://www.holasovice.eu/fotogalerie-1/holasovice/
What is a pattern?RepetitionResolution of forcesSelf-sustainingCommonality / variability -> All humans are equal but some are more equal than othershttp://www.flickr.com/photos/docman/1516309490http://en.wikipedia.org/wiki/Pando_(tree)Pando (Latin for "I spread"), also known as The Trembling Giant,[1][2] is a clonal colony of a single male quaking aspen (Populustremuloides) determined to be a single living organism by identical genetic markers[3] and one massive underground root system. The plant is estimated to weigh collectively 6,000,000 kg (6,600 short tons),[4] making it the heaviest known organism.[5] The root system of Pando, at an estimated 80,000 years old, is among the oldest known living organisms.[6]Pando is located in the Fishlake National Forest, near Fish Lake at the western edge of the Colorado Plateau in South-central Utah.
http://www.basiccarpentrytechniques.com/Carpentry%20for%20Boys/Carpentry%20For%20Boys1.htmlCARPENTRY FOR BOYSWITH 250 ORIGINAL ILLUSTRATIONSBy J. S. ZERBE, M.E.Copyright, 1914, byTHE NEW YORK BOOK COMPANY
There are still some patterns in objects that we are not able to represent in a programming language
Before as after the industrial revolution, talent is the rare commodity. We want talented people to have a maximal output.The industrial revolution is not just about technology, this is also a revolution in social organization, through division of labor, specialization of professions, specialized schools, … There are no fewer skills involved in industrial shoes production – there are actually much more. But the production process makes better use of these skills.
Better technology triggers better output per worker.Our parentsWhat is going to be the contribution of our generation to the software industry? How is it going to become more of an industry and less of an art, to achieve the same productivity enhancements that are required to meet increasing demand?'Increase the speed of agricultural mechanisation, to struggle for the modernization of agriculture. Printno. 8027.6288.
http://www.flickr.com/photos/abstractstv/4358678510Abstract means much variability and little commonality
http://en.wikipedia.org/wiki/Observer_pattern
http://www.flickr.com/photos/liz/8712469709Caïn by Henri Vidal, Tuileries Garden, Paris, 1896
As a result of the iterative development process, you are already creating reusable designs = design patterns
In his book “the timeless way of building”, Christopher Alexander asks the question:Why was an 19th century farmer, without formal education, able to build a house a thousand times more beautiful that anything that was build in the 20th century by formally-educated architects? Where people lived happier?Answer:Shared knowledge, and the knowledge was in the languageIncremental process, centuries of experienceVernacular architecture (folk architecture)TODO: Add a quote from Alexanderhttp://whc.unesco.org/en/list/861http://www.holasovice.eu/fotogalerie-1/holasovice/
I believe that it should become fundamentally easier to write good software.Look at the way we work today. We are working at a ridiculously low level of abstraction. We are implementing change notification and change tracking manually, are struggling with locks to cope with multithreading, relying on code reviews to ensure design compliance. Programming is so complex that companies can’t find enough qualified people to make it. Underqualified people write crap and there seems nothing to do about that.Our society runs on software. Our daily life is ruled by hundreds of millions of lines of code, from our mobile devices to transportation to tax collection. How do we build increasingly complex systems if the technology itself does not make it increasingly simpler? I believe that programming languages should make it fundamentally easier to write good software.And I think we should look in the direction of patterns. Patterns are fundamental to the way humans think. We learn pattern recognition is the first months of our existence. Patterns are intrinsic to the very way we perceive the nature. Regularity and variety only make sense if we have this notion of patterns. Patterns, concepts, objects, are same thing. Object orientation was a first step to make programming language closer to the structure of human cognition. But why stopping there? We need programming languages that are able to represent more complex patterns than what we now say “objects”.There are two principal ideas in this talk. The first idea is that the implementation of design patterns can be automated, and actually is already being automated, if we look at some features of the C# language. Working with design patterns means that the source code is built against a model that is of higher abstraction than the machine on which it runs. Smarter compilers can validate the source code against this model and generate instructions to map higher abstraction to lower abstraction. The second idea is that design patterns don’t live in books but in software, and that discovering and designing good patterns is a natural part of an agile development process -- because to learn is to identify patterns. So, there is a great chain of being, where the industry benefits individual projects and projects contribute back to the industry.With PostSharp, we are proud to contribute to this effort.Thank you.