Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: patterns, language and syntax

by clemburg (Curate)
on Aug 20, 2001 at 21:10 UTC ( [id://106275]=note: print w/replies, xml ) Need Help??


in reply to patterns, language and syntax

Most books are about languages (and how to use them) and algorithms. This one is original because it focuses instead on higher object oriented patterns not captured directly by syntax of current languages (but can nevertheless be expressed in them). It names these patterns and describes them, giving a common vocabulary to programmers.

You might be interested in Design Patterns in Dynamic Programming by Peter Norvig.

This presentation shows how to express common Design Patterns in Common Lisp.

It classifies Design Patterns into three levels:

  • Invisible: So much a part of language that you don’t notice (e.g. when class replaced all uses of struct in C++, no more “Encapsulated Class” pattern)
  • Informal: Design pattern in prose; refer to by name, but must be implemented from scratch for each use
  • Formal: Implement pattern itself within the language -Instantiate/call it for each use - Usually implemented with macros

And concludes:

16 of 23 patterns are either invisible or simpler, due to:

  • First-class types (6): Abstract-Factory, Flyweight, Factory-Method, State, Proxy, Chain-Of-Responsibility
  • First-class functions (4): Command, Strategy, Template-Method, Visitor
  • Macros (2): Interpreter, Iterator
  • Method Combination (2): Mediator, Observer
  • Multimethods (1): Builder
  • Modules (1): Facade

This matches my personal observation that after learning programming in Scheme and Common Lisp, I often find the standard object-oriented languages like C++ and Java to be clumsy and lacking abstraction features (no functions as first-class objects (no closures, no functions as return values), no access to continuations (call-with-current-continuation (call/cc)), no macros, just to name the most important ones). Patterns like "Strategy" or the common C++ "Functor" idiom simply look like an indicator of poor language design when viewed from the perspective of a language with first-class functions.

The paper continues with an interesting historical observation:

Long ago, subroutine call was just a pattern

  • Involves two parts: call and definition
    load R1, x       SQRT: 
    load R0, *+2     ...
    branch SQRT      branch @R0
    
  • Nowadays, made formal by the language
    sqrt(x);         function sqrt(x) ...
    

So yes, indeed, the real task is to put all these Design Pattern stories into code. If the languages we use do not support this, we should change them to do so.

Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://106275]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-28 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found