[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: succinctness = power




   Date: Sun, 26 May 2002 19:53:50 -0400
   From: Sundar Narasimhan <sundar@ascent.com>
   To: sk@cs.brown.edu
   CC: ll1-discuss@ai.mit.edu
   Subject: Re: succinctness = power
   
      Perhaps their biggest weakness is that their initial
      proponents did not demand linguistic mechanisms that would help
      programmers integrate patterns into programs.
   
      On the other hand, Erich Gamma promised me a beer and an explanation
      for why such a linguistic encapsulation would be a bad idea.  I
      haven't had a chance to collect, but I imagine the argument might be
      that it would inhibit further discovery.  However, I think the Lisp
      experience suggests contrariwise.
   
   Shriram: I'll bite. Could you say more why you believe this?  I've
   always believed that patterns were useful precisely because they were
   NOT wedded to particular language hacks, and consequently more
   powerful in terms of mapping one programmer's mental constructs onto
   another -- especially when it comes to context-sensitive application.

Hm.  There's a very interesting pattern, the "if-then-else"
pattern, that has been used for a long time but got raised
in people's consciousnesses as an important pattern only with
the advent of Structured Programming and its thesis that all
control structure in a procedure could (should?) be expressed
in terms of sequencing, if-then-else, and while-do iteration.

The gist of the pattern is:

  You want to do one of two things S and T depending on the
  value of some boolean predicate P.

  Code pattern:
  
  	evaluate P
  	branch if not(P) to L
  	execute S
  	branch unconditionally to E
     L: execute T
     E:

Now, should we say that this pattern is more useful precisely
because it is not wedded to particular language hacks such as
Scheme's "(IF P S T)" or C's "if (P) S else T" or "P?S:T" ?
On the contrary.  It is good to know the pattern in case you need
to use a low-level language (every compiler writer knows this
pattern and several related ones), but it is also good to have
this extremely commonly used pattern packaged up as an idiom
in most programming languages.  The fact that different languages
express it in syntactically different ways makes it no less useful.

--Guy Steele