in reply to Perl6 syntax being too much complex? How we will teach and read that?!

As you point out, perl5 has a complex syntax when compared to many other languages, which makes for a steep learning curve when you start out. but, if you persist long enough to get over the initial hump, the dividends are immense.

As you also point out, for many (most) programming tasks, a program that takes hundreds of lines and days to write in C, C++ or Java, takes only a few lines and a few hours (if that) to write in perl 5.

The question you have to ask yourself is why? Why is perl so productive when compared to those other languages with their simpler syntax?

I've personally thought about this a great deal. The conclusion I have reached is that the reason is totally down to that complex syntax, and more to the point, the design of that syntax. The syntax of nearly every other computer language was designed from the point of view of making it easy to parse. That is to say, easy for the compiler/interpreter to parse. This makes the process of writing the compiler easy for the developers, and means that they can produce great statistics of how many 100s or 1000s of statements they can compile per second. But it also means that each statement is only capable of doing very little work.

That means for any given task, the programmer must construct more statements. More statements means more opportunities to make mistakes. It means longer programs, with the active life of each variable in the program stretching over a greater physical distance within the source. I've read several studies that claim to show that the average human being can hold just 7 concurrent thoughts or ideas in their head at one time. With longer source files, and bigger physical distances between a variables instantiation and it's last use, the room for the programmer to forget a detail or loose sight of the direction of the code grows.

IMO, the power of perl 5 is that it's complex syntax means that each statement does more, and therefore requires less statements. Whilst each individual statement may require more thought to construct correctly, because in many cases, each statement, or closely grouped set of 3 or 4 statements completes an entire, complete part of the overall program, the programmer is able to concentrate on that without needing to scroll back and forth or dive off to lookup the syntax of yet another obscure API. That means that when he has finished or line, or a group of lines, another complete part of the program is finished. And that is the source of perl 5's productivity.

When you learn Perl 5's complex syntax, you are also learning a vast part of what other languages defer to their runtime libraries or API sets. If you never installed or used one CPAN module, you can still write a huge number of useful, productive programs. CPAN is the icing on the cake. Most other languages require their (usually extensive) libraries to be able to do anything useful at all.

The complex syntax, and the careful design that went into it is in large part exactly why perl is so productive. Moreover, when I say careful design, I don't mean "complying with some overarching, elegant master plan of orthogonal purity". I mean careful design in the sense that "Many programs and algorithms call for the programmer to do XYZ, so lets ensure that doing XYZ is not just possible, but as painless and concise as possible".

In other words, Perl 5 was design for the programmer, not the compiler.

If you can accept that the complexity and learning curve involved in getting up to speed with perl 5 is a huge part of why you like using perl 5, then look again at the Apocolypsies, Exogesies and Synopsies that have come out for perl 6 and look at the care that is being taken to ensure that each part of the language, both the completely new stuff, and the revisions and re-working of the old stuff all meld together to produce a syntax that will continue the p5 traditions of letting you do what you need to do, as concisely, and with as little syntax as possible--once you get over the learning curve.

I'm not one for going on faith, nor of accepting something as good, just because someone tells me it is so. There are still areas of p6 that worry me somewhat. But each time I read one of the documents, I try to look at how it would change the way I write code to perform tasks that crop up in many of the programs I write. So far, with the minor exception of the new format stuff which I have barely ever had occasion to use what it replaces, I've seen how what is being proposed would simplify, clarify or otherwise enhance stuff that I currently write in p5. I watch as, one by one, each of the annoyances that crop up regularly when writing p5 code are being addressed.

So, faced with the choice between learning say, Java's "simple syntax" and various (incompatible) and huge libraries, or (re-)learning Perl's complex syntax that is going to allow me to do even more in each statement; write even less lines of overall code; and never have to learn to fight my way through the a huge "Standard Library" before I can write powerful, useful programs; I opt for the latter.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
  • Comment on Re: Perl6 syntax being too much complex? How we will teach and read that?!

Replies are listed 'Best First'.
Re: Re: Perl6 syntax being too much complex? How we will teach and read that?!
by optimist (Beadle) on Mar 23, 2004 at 00:09 UTC
    Why is perl so productive when compared to those other languages with their simpler syntax?....IMO, the power of perl 5 is that it's complex syntax means that each statement does more, and therefore requires less statements.
    This is a good question, but I have to disagree with the answer. What makes Perl so darn productive is not the syntax, IMHO, but the semantics. LISP (particularly Common Lisp, and the Zetalisp of the lost and lamented LISP Machine) is the only language I've ever worked in that matched Perl5 in terms of expressive power, yet you can't get much further away from LISP syntax than Perl. But semantically, the two langauges have a lot in common:
    • Essentially, weakly typed beyond the scalar/array/hash (LISP: atom/list) distinction.
    • Functions easily take a flexible number of arguments
    • Functions as first-class data objects
    • Both lexically and dynamically scoped variables
    • Built-in, or at least well-understood, operations for manipulating lists of values (e.g., map, the Schwartzian transform, foreach
    • Flexible object-oriented features, including support for true multiple inheritance. And if you don't like what's there, it's easy to build your own.

    These are the qualities (along with numerous others) that make Perl so expressive, so flexible, and, let's face it, so enjoyable to program in. It doesn't matter that we're writing foo(\&subname) or foo(sub { blah; blurfle; }) rather than (foo #'subname) or (foo '(lambda () (blah) (blurfle))). What matters is we didn't have to create a define an interface and create a stupid anonymous class just to pass the function!

    As for the syntax of Perl 6, based on what I've seen a little of it is some general tidying up, more of it adds some useful orthogonality (string/integer/boolean, e.g.), but the bulk of it (junctives, >><<, sub vs method vs multi, etc.) is being introduced to support new semantic power. And that has got me seriously jazzed up.

    In other words, Perl 5 was design for the programmer, not the compiler.

    Amen, brother.

      I think your probably right re: syntax versus semantics. Though perl does have a lot of syntax compared to other languages. And without that large syntax, I don't think it would be possible to have the powerful semantics without hiving much of the native power off into a RTL/Class library as other languages have done.

      I also reached the conclusion that it the rise in complexity of the syntax (p6 -v- p5), as perceived by the OP and many others, is required to allow the further enhancement of the semantics.

      The devil is undoubtably in the detail. Balancing the Huffman principle; with the (natural) calls for orthoganality; with the desire for greater OO-ness; with the extension of the Lisp-ishness; with an overarching desire (and need) to maintain the perlish usability, is a knife-edge balacing trick that reminds me of an old joke about flies sliding down razor-blades, using their ...er...anatomy... as brakes.

      I've recently been forced into re-aquainting myself with C++ (complete with MS' overdefined types and class libraries, hungarian notation and 5 lines per statement example code!), and it is painful. I was never much enamoured with C++ from either the syntactic or semantic level. It took the very simple, elegant syntax of C and 'stuck on' a lot of complicated syntax that barely worked. It also tried to apply braces and a plaster cast to the simplistic C semantics (roll your own:), and resulted in a complexity that made it like using three languages all at the same time--(almost untyped) C, strongly-ish typed, multiple-inheretance OO, and templates. The result is a very powerful, but hugely difficult language to do well.

      Like natural languages, perl needs to evolve. I'm not a latin scholar, but I hear testimony from many that are, that latin is a very elegantly structured language. Which begs the question, why did it die? My conclusion (which has no more authority than that of a casual observer) is that it died because the civilisation that evolved and regulated it died, and it therefore failed to evolve further.

      If perl stayed static and didn't evolve, it too would die. Sure, there would be some hard core enthusiasts that would keep it from dying out completely just as there are with many ancient natural languages, but newer languages would simple overwealm it.

      From my perspective, the only hard part is not being able to use it now, but in nature the only things that have short gestation periods also have short frenetic, lives, so I watch and wait with (tempered) eager antisipation.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail

        I'm pretty certain the fact that Perl has a lot of syntax isn't key to its usefulness. It is key to its readability (when the programmer actually puts effort into expressing himself naturally), but not to usefulness.

        Look at the usefulness of the aforementioned LISP, which doesn't have very bare syntax, but rather really has no syntax (the programmer is basically writing raw parse trees in textual representation). Yet LISP didn't have to syphon all that complexity into class libraries to be useful; it is right there in the core of the language.

        Remember that Perl6 is doing a lot to orthogonize Perl syntax — sometimes adding by adding to it, but not rarely by dropping cases that so far have been special or by integrating multiple special cases in a unifying frame.

        The elegance of C is its minimalism in assumptions — it doesn't do any of your work for you, but it also doesn't prevent you from doing anything. C++'s failure is that it implements the restrictions necessary to implement a higher level world view without offering any higher level constructs to get work done easier. You still have to do as much legwork to get places as in C, but suddenly you're no longer allowed (nay, even able) to walk across the field. You get no car, not even a bike, but you have to stick to the roads now.

        Makeshifts last the longest.

Re: Re: Perl6 syntax being too much complex? How we will teach and read that?!
by McMahon (Chaplain) on Mar 22, 2004 at 21:33 UTC
    I disagree with this stuff:

    "...complex syntax ... which makes for a steep learning curve when you start out..."

    "If you can accept that the complexity and learning curve involved in getting up to speed with perl 5..."

    As a relative newbie, I found that the learning curve for Perl was much less steep than for other languages, because of the effort Perl takes to emulate natural language. You learn any language by making gradually more complex sentences using your dictionary; and by talking with native speakers. Perl makes this process easier than any other language I've encountered.

    So Mr. BrowserUK and I get the same conclusion by radically different paths: Perl 5 was designed for the programmer.

      Yes. I would say that Perl was designed for two different types of programmer. I recommend the article "The Tyranny of Choice" in the April issue of SciAm. It distinguishes "maximizers" from "satisficers". To a satisficer, the learning curve of Perl looks quite shallow because they don't have to learn it all at once. To a maximizer, the learning curve of Perl looks very steep because they do feel that they have to learn it all at once--but that's what makes a maximizer happy, after all.

      I confess that I am a maximizer. I am so obsessively maximizing in my approach to life that I have to strike a careful balance between maximizing and satisficing. And that's good enough for me... :-)