The stupid question is the question not asked | |
PerlMonks |
patterns, language and syntaxby stefp (Vicar) |
on Aug 20, 2001 at 20:33 UTC ( [id://106262]=perlmeditation: print w/replies, xml ) | Need Help?? |
This was originally an anwer to Tilly on
Any interesting philosophy of programming articles to recommend?,
but it has grown into a full fledged meditation. The Open Source communauty (and the Free Sotware one for the purists) insists to much on code because that is the thing that is compiled to working code and is licenced. But the notion of a common culture is as much important because it is the ultimate enabler; and social and technical structures that host porters, mongers and monks are necessary ecosystems, We must learn the conceptual software building blocks and have a common language to talk about them. For example, I am amazed how many programmers don't know the concept of iterators. This culture evolution goes toward increased abstraction. For example, it starts close to the hardware with goto, then the syntax of languages captures the notion of loop, then the idea of a state capturing the iteration and so on. Design Patterns, Elements of Reusable Object Oriented Software ISBN 0-201-63361-2 is about such patterns, but usually of higher level. The examples are in C++ 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. The most important long term programming activity is indeed to identify patterns and capture them in the syntax of languages and libraries. They don't have to be as high a level as in "Design patterns".
Indeed, one of the reasons of the success of Perl is its ability to
capture the essence of patterns, but lower levels ones, maps (aka
hashes), arrays and operation on them. Compare that with the approach
of C++ which must resort to a standard library and templates. In Perl
you do: grep { whatever } keys %a while in C++ you must
explicitely create iterator objects. Languages like C++ have instead focused directly on capturing higher patterns but not necessarily well established ones. As a result C++ imposes on you a certain view of Object Orientation. On the other hand, Larry seems to indefinitively deferring the support of higher patterns inside the language. But, as a result it is up to the communauty to select the best higher patterns. For example, he forces us to use the lowly @_ to pass parameters. But eventually with perl5, we discover we can pass references to hashes that is a richer mechanism than positional parameters. Eventually damian (?) comes in the upcoming perl6 with the pair concept that makes things even more powerful. Good support of low-level patterns foster the creation and selection of good high patterns. Early specialization can lead to evolutionnary dead-ends. Some books like Mastering Algorithms with Perl" or <a href=|http://www1.fatbrain.com/asp/BookInfo/BookInfo.asp?theisbn=1565922433&from=MDZ411">the Perl Cookbook are invaluable to explain how to map patterns in the perl syntax. To finish on patterns, one must be careful to understand the spirit of a pattern and not to be stuck by the letter of it. Writing print "hello world" is equivalent of declaring a Main class with a main method printing "hello world\n" using some System.print() method. Like natural languages, Perl encourages ellipsis, that is dropping altogether unformative or redundant material. One thing is to identify patterns, an altogether different issue is to find how to express them (or here not explicely express them). This is not because a complex pattern captures a simpler one that we must be forced to used the complex pattern. Nevertheless it is good to identify the simple pattern as a particular case of a richer one because someday it will indeed be good to evolve it to the richer pattern. As a result of expressivness, like natural languages, Perl is hightly irregular and hard to learn, but it is the cost of real expressiveness. I am not surprised that Perl comes from someone who insists on its linguistic background. A mathematical or engineering scientific background is not enough to design a expressive language. So unlike what is said by Molière who jokes about Jourdain who discovers he is speaking in prose, it is useful to introduce words and concepts if they can help us to better grasp the "world". But there is indeed, a fine line between mere "echolalie" and a structured discourse. So it is probably good to joke about pedant teachers and their victims.
thanks to Hofmator for giving me the links to the books. I did not doctored them, so I hope he will get credit from FatBrain :)
-- stefp
Back to
Meditations
|
|