http://www.perlmonks.org?node_id=265923


in reply to "Perl Design Patterns"

A design pattern is a way of using components; that's why design patterns are not components of languages.

You might come up with a "language" consisting of mortar and bricks of various sorts. The design patterns would be the various common ways of arranging bricks to achieve various results. For example, when building a freestanding brick wall, you'll see some bricks sideways, to tie two layers together.

Cliches, aka idioms, are standard bits of code, such as open ... or die $! in Perl, or while( (c=getchar()) == 0 ) in C. Design patterns are both more complex and more abstract than these.

One simple design pattern is the use of an object, the iterator to traverse an array or linked list, rather than coding a loop. You could not make an iterator a part of a language in the sense that while loops or exceptions can be. If you have a library of data structures, as Java & C++ do, you can implement iterators as part of that.

--
TTTATCGGTCGTTATATAGATGTTTGCA

Replies are listed 'Best First'.
Re: Re: "Perl Design Patterns"
by tjh (Curate) on Jun 14, 2003 at 18:30 UTC
    And wouldn't the design of the components also fall under the design pattern issue? What type of bricks, for instance?

    Possibly the accepted idioms, either included in the language, or as an external library or a CPAN module, directly or indirectly, force the patterns of their usage on the work?

    The perl.com article discusses the iterator in Java and Perl, resulting in this statement,

    "In Perl any built-in or user defined object which can be walked has a method which returns an ordered list of the items to be walked. To walk the list, simply place it inside the parentheses of a foreach loop. So the Perl version of the above hash key walker is:..."

    "The inclusion of iteration as a core concept represents Perl design at its finest. Instead of providing a clumsy mechanism in non-core code, as Java and C++ (through its standard template library) do, Perl incorporates this pattern into the core of the language." (emphasis mine)

    The iterator is simply an example. I'm not interested in dissecting iterators specifically.

    However, the article led me to think that Perl developers considered the iterator component mentioned important or reasonable enough to more thoroughly integrate it, given their view of the language's mission.

    Maybe it's a pattern-within-pattern-within... question for me, a fractal issue. More global design issues (probably moderated by 'accepted usage' or what becomes idiomatic) containing idiomatic usage of core components, external modules, object usage, etc. Something is Perlish, for instance, and becomes an accepted pattern of usage.

Re: Re: "Perl Design Patterns"
by zby (Vicar) on Jun 16, 2003 at 10:02 UTC
    use of an object, the iterator to traverse an array or linked list, rather than coding a loop - I think you still need a loop to use that iterator, the opposition is artificial.