in reply to disadvantages of perl

Structures defaulting to flat lists!

@Arrays and %Hashes act per default as list not as reference which makes many useful things complicated and only some other things easy.

For instance @a=(@b,@c) is not a nested structure but a flattend list, so you better choose $a=[$b,$c].

So if your working with nested structures or your passing structure in and out subroutines you need to switch to references, where you need much more typing, and you loose the "documenting" advantage of sigils.

Especially if you return large arrays out of a sub as a ref to avoid copying, you cant alias them to a normal @array you need a $arr_ref.

e.g. this doesn't work:

my (*arr)= ret_arr_ref(); print @arr

Even if you decide as a consequence to constantly work with references and you enjoy dereferencing with the arrow-operator it's annoying that you can't use the special commands for arrays and hashes directly. You need to put extra dereferencing and often additionally enclosing curlies:

 push @{ $hash_ref->{key_to_arr} }, "elem"

instead of

 push $hash_ref->{key_to_arr}, "elem"

Personally I think this is the biggest obstacle for beginners, a complication where many decide to look for a more intuitive language (in this aspect)!

Cheers Rolf

Replies are listed 'Best First'.
Re^2: disadvantages of perl
by ELISHEVA (Prior) on Jul 03, 2009 at 14:02 UTC

    You seem to be viewing (...) as a data structure. That isn't at all unreasonable, but it is not the only meaning that we commonly give to (...). Perl's definition of (...) is drawn from another part of life: math. A better mental model would be the parenthesis in math statement: (3+4)*(6+10). It is simply a way of grouping things to indicate the order in which you want them processed.

    Merely being an ordered collection doesn't determine how we'll use it. There are many different things one can do with groupings: nest them, concatenate them, visit their members one by one. In Perl which action you want to take on the grouping depends entirely on context. For example, when you use it in a for loop, the for loop processes the elements in order (just as you asked). And when you assign it to an array, Perl adds each element to the array in order, just as you asked. Nesting parenthesis doesn't change the treatment any more than does ((3+4))*((6+10)). The elements still get added in the order you requested.

    I had little trouble grasping Perl's approach to parenthesis because my interest in mathematics and my interest in programming are closely related. Perl's syntax was natural for me. But I fully appreciate that others have come to programming from different directions than I. They are used to giving symbols other meanings than I give them.

    It all comes back to the the vagaries of DWIM (Do What I Mean). As tweetiepooh has pointed out a language's strengths are also its weaknesses. DWIM, or as Larry Wall calls it "The Principle of Least Surprise", is rather subjective:

    ... The question is, whose surprise are you pessimizing? Experts are surprised by different things than beginners. People who are trying to grow small programs into large programs are surprised by different things than people who design their programs large to begin with.

    For instance, I think it's a violation of the Beginner's Principle of Least Surprise to make everything an object. To a beginner, a number is just a number. A string is a string. They may well be objects as far as the computer is concerned, and it's even fine for experts to treat them as objects. But premature OO is a speed bump in the novice's onramp.

    Interview with Larry Wall, Slashdot, Sept, 2002

    In a language where DWIM rules, we need to be very sensitive to the fact that not all of us are thinking the same thing when we get to the word "mean". If you are teaching Perl or helping an organization develop Perl skills it is very important to be sensitive to this issue or else you will end up with confused frustrated programmers for whom Perl definitely does not do what they mean.

    Best, beth

      Hi Beth

      The OP was asking for disadvantages of Perl, and I was giving him a common view. An easy thing is only complicated to achieve, which violates a mantra of Perl.

      In fact this criticism is so widespread that Larry already changed this design in Perl 6 (almost a decade ago): @ and % default to references and the comma operator is changed.

      IMHO that will (sadly) also be the biggest source of confusion for migrating to Perl6.

      To be clear: I like flattened list, just shouldn't be the default.

      Cheers Rolf