http://qs1969.pair.com?node_id=991584

Sam Huges has posted the writeup Teaching Perl to his homepage. This talks about his experiences and opinions on how perl should be taught to people who come out fresh from a university having learnt about Java and not much experience. I believe the writeup presents an interesting and unique viewpoint so it's a must-read for experienced Perlers.

Replies are listed 'Best First'.
Re: Teaching Perl
by Tux (Canon) on Sep 04, 2012 at 10:58 UTC

    I do hope his printed material is better readable than his blog. Of course it most is about taste, but I had to add some style changes before being able to read that without being ultimately annoyed by the layout and chosen fonts.

    <style type="text/css"> body { font-family: DejaVu Sans; } pre, code, tt, kbd { font-family: DejaVu Sans Mono; } .wrapper { max-width: 80%; } p { text-align: justify; } </style>

    added to head did it for me. YMMV.

    I have to (not really voluntary) do a lot of Java lately, and though I do not really dislike the language as such, I really hate the need of an IDE to be able to cooperate with others when using things like maven and jIndent.

    What bothers me about Java is the way some (basic) classes are set up with missing functionality (but still about 20 methods I'd never use). What I *love* about Perl - compared to Java - it autovivivication. Building a short-living cashing construct in Perl is maybe about 4 lines. In Java it is likely to be 4 files of 100 lines each.

    Development in Perl is way faster, and with some constructs being extremely long in Java, I sincerely doubt if what people applaud in Java as being maintainable and scalable holds in all/most cases.

    All and all it is a nice read. I agree with quite a few points he makes, but (TIMTOWTDI) of course also not to all. Like e.g nested data structures difficult in Perl? I don't think so. Personally I see it way more easy in Perl than in Java. Autovivivication and pack/unpack are powertools missing in Java.


    Enjoy, Have FUN! H.Merijn

      IMO nested data structures are always difficult, but Perl adds more difficulty early on. The only easy data structure you can pass around is the flat list, or some scalars in front of a flat list. Creating a complex data structure is "just some syntax", but accessing data in it requires learning about references and dereferencing.

      Python for example makes accessing complex data structures easier, because it does not flatten argument lists. There is the nasty surprise later on, when you realize that you need the equivalent of Storable::dclone, because in Python just like in Perl, all complex elements of hashes and arrays are still references. But you don't need to know that just to pass parameters more complex than a list to a function, and retrieve them in that function.

        Personally, I just pass around a reference to the complex data structure. And to keep it all dead simple, I declare the complex data structure as a reference to start with. That way there are no extra copies being made passing around the data structure is exactly the same as using it, and I don't fall out of practice with dereferencing.

        It is indeed a bit of a climb, but once you get around to figuring out references, everything becomes easier :)

Re: Teaching Perl
by Jenda (Abbot) on Sep 05, 2012 at 07:12 UTC

    I think he misses THE biggest obstacle. All these youngsters had been told for years that they are being taught the end of all languages, the one and only language they are ever gonna need ... and now, two weeks into their work life they are forced to learn another language and next to nothing they learned holds. You are hurting their pride.

    "There's the fact that Perl is interpreted, not compiled." ... erm ... especially compared to Java, compiled to some intermediate code and then interpreted and/or Just In Time compiled to actual machine code, this statement really causes a chuckle.

    "the fact that in Perl execution just starts at the top of the page, not in public static void main(String[] args)." And the absolutely pointless boilerplate required by Java doesn't end there.

    "You use $var[0] to get information out of an array called @var, which is different from a scalar called $var." Yeah, a huge deal. The sigil is not part of the variable name, but rather specifies what is it you want to obtain. "I want the 0-th scalar from variable named 'var'." How long does it take to explain that? Two minutes? Show them slices and ask them to write equivalent code in Java!

    "Perl has no boolean data type" - Perl has no integer or float or string data type either. It has scalar, array and hash and when it comes to scalar the values get converted between strings, numbers and booleans as needed.

    "You can't put a list inside another list." How do you put a list inside another list in Java? Exactly? Speaking about literals, yeah, in Perl you can't write @foo = ( (1,2,3), (4,5,6));, you have to use @foo = ([1,2,3], [4,5,6]); well ... as far as I can tell in Java, if you wanted an array of array you'd end up with something like Int[][] foo = new Int[][]{ new Int[]{1,2,3}, new Int[]{4,5,6} };, but yeah, Perl is complicated. Now imagine you dared to want an ArrayList of ArrayLists. Yes, you have to explain that they have to store references in arrays and hashes. In Java you have to explain the difference between value and reference types. How much time did they spend on that?

    "Creating elementary nested data structures is difficult, as is getting information out of them." I'd really love to see an explanation of this nonsense. With comparison to Java pretty please!

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

      I think he misses THE biggest obstacle. All these youngsters had been told for years that they are being taught the end of all languages, the one and only language they are ever gonna need ... and now, two weeks into their work life they are forced to learn another language and next to nothing they learned holds. You are hurting their pride. [Jenda's reply]

      I think that's exactly what Sam says in the article.

      Right out of the gate, there's an unavoidable culture shock which comes from learning Java and then learning Perl.

      […]

      It's like being a child: When you're at the very beginning of your life, and you've seen very little of the world of software engineering, the few things that you have seen fill your whole mind up and heavily colour all of your future experiences.

      There's even the fact that - shockingly - Java isn't the number one all-purpose solution to all conceivable problems.

Re: Teaching Perl
by Anonymous Monk on Sep 04, 2012 at 11:17 UTC

    I believe the writeup presents an interesting and unique viewpoint so it's a must-read for experienced Perlers.

    Meh, I think not so much unique :) Maybe be because I've hung around places like this long enough, but seem straight forward common wisdom, though there are some funny commentary ( TheDailyWTF kind of funny )

    Regarding the astonishment, I would think regular unversity english/maths/physics portion of the curriculum would have cured these students of the one true way notion :)

    I've found "evolution and hysterical raisins" works as a panacea answer for astonishment :)

    Also funny, mentions " omitting return calls " practice that should "never be used" but then praises perls positive side, map/grep/sort as incredibly powerful, but you can't use return with those :)

    Andd the overall message good, know your audience, know where your students are coming from, know your enemy, and teach them the good idioms :)

    These materials touch upon some of these things discussed, and I've been waiting for an opportunity to share :)

    http://perl-tutorial.org/, http://learnpythonthehardway.org/, Learning Perl the Hard Way, Why I Am Not A Java Programmer, What Perl Programmers Should Know About Java, Are there any Java texts assuming the user has a perl BG?

      Maybe it's just a viewpoint unfamiliar to me because I've been teaching young (first year or second year) mathematician students, who had not learnt Java and definitely don't have the same background about programming as the people Sam is teaching do.

Re: Teaching Perl
by Tanktalus (Canon) on Sep 06, 2012 at 19:54 UTC

    My favourite bit:

    What I'd like to be able do in practice is teach one canonical Way To Do It, and leave the more advanced syntax for an advanced session, or for newcomers to discover in their own time.
    and then, two paragraphs later:
    Perl also has many simple little things like the unless and until keywords, which are self-explanatory and make life much easier, and the short statement if condition and statement foreach list formations.
    So, he wants one way to do everything, then turns around and compliments syntactical sugar added to the language that simply provides alternate ways of doing things.

    I'm sorry, but I have a hard time taking someone seriously when they cry for consistency ... inconsistently.

    Mind you, I've taught a handful of people perl (not 50, more like fewer than 10) and never encountered any of the concerns he brings up. Then again, I bring up things like TMTOWTDI as a feature instead of as a wart of the language, and so those I talk to start to treat it as such. (I also point out that despite being more than one way to do things, that doesn't make all ways equal - which one is best may depend on what you're doing, etc.)

      Also note that unless and until are "naturally" for people with a native English tongue, but they can be very confusing for those who are not. I actually know TWO people that specifically asked me NOT to use unless in code they have to read/maintain as they have a hard time to understand what it does.

      OTOH, I have added unless as a keyword to my C-files as '#define unless(c) if (!(c))', as I do like it :)


      Enjoy, Have FUN! H.Merijn

      I think that's consistent. He would like to do one thing, but can't, because perl simply does not allow that.