Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I appreciate the author's honesty.

To be perfectly honest myself, the last time I looked at Perl was about 4 years ago, and I despised the experience. I used it for about 10 months because the company I worked at had their entire infrastructure running on it, but it was the worst code I had ever seen, so I quit. If I remember correctly the code that broke the camel's back for me (pun intended) was:

$a = $src[$src];

I've forgotten my Perl syntax so the syntax may be incorrect, but essentially what happened was that the original author had defined two different variables with the name "src", one being a scalar variable and the other being an array, and apparently those have two different namespaces.

So when I looked at the perl tutorial that the author points out, it looked like regular perl to me. However, if the syntax of Perl has changed since 2007, then I'd be willing to give it a shot. Although I've recently started learning Python, and I'm enjoying it, except for the dynamic typing and the GIL... which is a rant for another time.



I had the exact same experience coding Perl in my last company. I found myself, just like Steve Yegge says in his ancient languages blog post, having to memorize all the special edge case rules and idioms of the language just to get anything done. Whenever I got to choose Python, Ruby, or C for a task I felt like I was breathing fresh air again after being stuck in a musty room for a while.

I remember being offered to choose any toolset I wanted for a particular project and finding out that Perl was the only scripting language that had the bindings to the C libraries I needed to use. Naturally, I decided to to do the whole project in straight C instead. :)

The funny thing is, whenever I would code in Perl for a while, I would actually grow acclimated to it. I would start to think to myself, "Hey! I'm finally getting things done. I CAN be productive in this language!" It was only after switching away to another language again that I would re-recognize just how painful Perl really is. This experience actually repeated itself multiple times for me as I moved on and off Perl projects and it helped me learn to sympathize more with others who are perfectly content to code in Perl for a living.

At one point, I had enough and began recording all the weird Perlisms that were wasting my time as I encountered them. My goal was to compile a "95 theses against Perl" document and post it on my manager's door as a joke. Fortunately, I only got into the 40s before my manager offered to let me move to another team where I never had to write a line of Perl again in that job!

It's possible to write good Perl just like it's possible to write good COBOL, and better tutorials would definitely help newcomers to the language do just that. I would rather spend my time writing good code in other languages, however.


So here's the thing, Larry Wall is not only a programmer, he is a linguist. That's reflected in the myriad of ways that one can write something in Perl, reflected in the common refrain at YAPCs the world over, "TMTOWTDI" (There's More Than One Way To Do It). But because of the flexibility Larry designed into the language, there's also "more than one way to do it" ...wrong (ok, not "wrong", but so complicated and whacky that Joe programmer 10 years from now wouldn't have a clue about). But this very flexibility gives Perl a unique beauty.

I don't think it's the language's fault that poor code exists to teach people the way to Perl zen. It's more that scripting languages themselves lend to one-offs and poor code writing, especially in the days of early Perl, when people were giddy to get their hands on something that wasn't as ugly as "sh". We need better programmers who are not "too busy to write good code" as well as better material.


This line of reasoning is old and tired. Natural language is a bad enough way to communicate with people, it's a ridiculous way to communicate with machines which take everything literally and treat everything implied to mean "crash in amusing and unforeseeable ways".

One of perl's big "natural language" claims is that things mean something different in different context. I think there are several movies based on what can happen when two people have a conversation but have a context mismatch.


> Natural language is a bad enough way to communicate with people

If it was bad, it wouldn't have become the way to communicate with people in every culture on the planet. Don't forget "natural language" can include body language, as well as words, grammar, idioms, stresses, pause, and intonations.

> there are several movies based on what can happen when two people have a conversation but have a context mismatch

Matching context using protocols such as small talk before a main topic of conversation is also part of natural language. Many of us who work on computers don't learn these other aspects of natural language very well, and tend to project this limited command of natural language onto computer languages.


>If it was bad, it wouldn't have become the way to communicate with people in every culture on the planet.

We have nothing better, but it is not the only way we communicate. Mathmatics made a whole other language to communicate with because spoken language wasn't effective enough.

Further, natural language is useful among people because we can work out meanings, fill in implicit statements closely enough, have experience on what certain phrases mean and so on. Even with every tool we have, we often still get it wrong. So if it takes so much intelligence to be able to communicate with written language, why would anyone imagine it a good idea to expect computers to be able to do this too? A computer must explicitly be told what to do in every situation. Typically when we need to go into that level of detail with people we don't use natural language either. We generally demonstrate what must be done (e.g. youtube tutorials which often don't even have sound, etc.).

>Many of us who work on computers don't learn these other aspects of natural language very well, and tend to project this limited command of natural language onto computer languages.

Is that a rock thrown at me? I don't think I have a problem here. I'm just realistic about what language is good at. Natural language's value is that it can be very concise when everyone has the same context as you. With a computer this is never the case.


>If it was bad, it wouldn't have become the way to communicate with people in every culture on the planet.

That's because the vast majority of social situations are very tolerant of misunderstandings and have lots of redundancy/repetition to ensure that communication occurs successfully.

In cases where misunderstandings can be significant, we turn to more formal modes of communication. Scientific literature, technical manuals, and legal documents are all more stilted than regular prose for the simple reason that they need to clearly and unambiguously communicate their contents. Reader enjoyment is a secondary consideration.

Programming languages need to be even clearer than legal or technical documents, because they're being read by a machine rather than another person. As such, I see ambiguity in programming languages as even more of a sin than ambiguity in contracts and scientific papers.


I'm not saying it's good or bad, all I'm saying is that it was Larry's choice when developing the language.

Here's a great example of C++ meaning different things in different contexts. How about this:

    int *& p;
    *&p;


One is a declaration, one is an expression. And, believe me, I taught C++ for a while and this already causes a lot of confusion.


Seriously?! Someone downvoted this statement? It was completely factually true. People do indeed get confused by the difference between declarations and expressions. That's why some languages don't like to have that distinction.

With things like this I would like to advocate that Perl be treated as politics: something that's just not appropriate for HN. The thing is, when ever perl comes up some of us point out why we don't use it anymore but perl fans get seriously emotional about perl and start downvoting things they disagree with (much more so than ordinarily happens). I really suspect that if it weren't for the downvote limit some perl fan would have gone through and downvoted all my posts by now.


If you want to see sensitive, there are other language communities you should troll instead...


Huh,

The problem is not whether Perl or C++ is bad. All languages have their own use cases. When their use cases go away, nobody feels the need to use the language. That's the golden rule for any language/tool that exists out there.

Perl, C++ and even lisp even over a half a century are still alive out there because there are use cases that those languages serve very well. And a majority of the people feel compelled to use them. The reason why people troll is they feel they can convince others not to use the language they hate.

C++ has a lot of problems, but compared to the other languages advantages it offers are many and it doesn't quite really have good competitors in those areas. We can go and talk about various other languages that you can compare with C++. But language itself is nothing. The surrounding ecosystem, libraries, books, help, availability of programmers, the total weight of the community with their combined wisdom over the years. In all those parameters, syntactical problems of a language count for very little things in the real world. There are more than sufficient real world scenarios out there where C++ has done the job exceedingly well.

I have myself maintained large C++ applications. And have faced many problem like what others have mentioned before. But given our efficiency requirements, Java wouldn't last for an hour in our production environments. And given all the conditions I mentioned, there isn't really a clear alternative apart from C++. And I'm sure vast majority of the C++ project have the same reasons to use C++.

Perl has its own niche. I don't really have time to write 100 line of Java/Python code with piles of exceptions of handling code just to read a file. I don't have time or the patience to deal with alien integration of Regular expression that Python offers. Python has other problems, It never evolved as a rapid scripting language, I still can't consider using python as a prototyping language. It has a little posh gloss to it. Python has nothing even remotely closer to CPAN. Compared to Perl, Python is no where in syntactical flexibility. Perl's documentation is just awesome, support for newbies is too good. And they seem to fixing all the problems in the new language Perl 6. I use scripting for rapid tasks which need urgent attentions. Some of that gets converted to production work. If that rapid aspect is missing I don't really consider that language a scripting language. And serious scripting language will have to provide means of easily modifying data of all kinds text especially. And also provide seamless integration with the Operating system.

Python never provided me all this. Its never could become my primary scripting language.

But I appreciate Python's other use cases. It has some awesome frameworks. And it has a very easy verbose syntax. And I'm sure it has plenty of use cases for people around.

Now just because you like Python, don't go on endlessly trolling Perl. This has a been going for a decade now and is getting a little boring. Both language have their use cases and are likely to be there for a real long time. Whether you like it or not.

As Bjarne Stroustrup mentions in his "The C++ programming lanaguage" - You must learn C++ not for a new syntax to do old things, but to build better systems.


I don't use Python, Ruby or any other scripting language unless someone pays me to. I was simply responding to inaccurate or tautological statements thrown around in this thread.


Huh?

I commented on a bad troll that wrote 10++% of all comments and made sweeping personal attacks.

I assume you wanted to comment on the same comment as me? :-)


:)

Yes, I think by mistake I hit the wrong reply button.


Do you still have that list? I think it could be very useful to someone who has to dive into a legacy Perl codebase.


Two excellent books I can recommend for someone working with legacy Perl:

Perl Medic (Peter J. Scott) - http://amzn.com/0201795264 Effective Perl Programming (Joseph N. Hall, Joshua A. McAdams, brian d foy) - http://amzn.com/0321496949

Besides those, having a good reference to the language is also essential. For example, I keep Perl In a Nutshell close by, even though I almost always just search http://perldoc.perl.org/ when I need that info.


I wish I had kept it, but I can't seem to find it in the set of files I kept from that job. It would have been fun to make a blog post out of it.


Googling for "things I hate about Perl" turns up a number of articles -- often written by folks who like Perl 5 but who also are happy to admit to its issues.


Yeah, the sigils indicate a sort of namespace (@ for array, $ for scalar, & for function), but that breaks down because when dereferencing an array, the @ becomes $. I have a fair amount of experience with Perl and I still had to read your explanation to remember how that could be valid.

In the company I worked for that used Perl extensively, there were coding standards. In fact, you don't even need that, you just need to remind everyone that cleverness is not a goal in writing maintainable software, even if cleverness is what Perl's best at.


They weren't originally intended to provide namespacing, as far as I know. They were there to make the compiler's life easier.

The reason that an array subscript is "$foo[0]" is because the $ sigil means "HEY COMPILER, the expression here is going to evaluate to some scalar".

@foo is the entire list and the compiler treats it as a list type; $foo[0] is an element of the list and needs storage/behavior of a scalar. Same thing for hashes: %bar is the whole hash; $bar{quux} is an element and must be treated by the compiler as a scalar.

The programmer must remember that square braces mean array subscript and curly braces mean hash lookup.

So basically, this is a compiler optimization implemented by having the programmer provide hints to the compiler. It's overhead that probably isn't needed in the modern age, but we're effectively stuck with it. It wouldn't be so bad if they hadn't made the second (and IMO worse) decision:

You can reuse symbols across contexts. The way this works is that the compiler maintains a symbol table where each symbol has a slot available for each of the types (scalar $, array @, hash %, subroutine &). This was originally the way to emulate pass-by-reference: you'd write a subroutine that assigned its arguments into typeglobs (* foo — think of it as a wildcard for all things named foo that behaves as a magic scalar with the contents of foo's symbol table entry) and then pulled them back out as the types it wanted:

  local(*foo) = @_;
  foreach $bar (@foo) {
    do_something($bar);
  }
This amounts to telling the compiler "I want to alias the name foo in all contexts to my argument, and then go look at what's stored in the array at that name" and is a poor man's pass-by-reference.

Perl 5 has a real reference system that completely obviates the need for this, except for the case of monkey-patching a subroutine, where you still say:

  local *Package::quux = sub { ... }"
What's left is an unfortunate case where things like the GP mentioned ($bar = $foo[$foo]) are possible, and people who think they're being clever will do these things. Like the parent said, this is not a good thing to do.


"So basically, this is a compiler optimization implemented by having the programmer provide hints to the compiler."

I'm not entirely sure that's correct. I think Larry Wall (being a linguist originally) designed it that way because he thought that using context-sensitive sigils was more like regular speech where leading words indicate the number, i.e. 'a cup' vs. 'some cups'...


> Larry Wall (being a linguist originally)

Having taken a class on linguistics, I have to say basing a computer language on it is a horrible idea.

Human languages are far more complex and verbose than is required for talking to computers. Consider that it takes years to master a spoken language. A computer language should be much easier to pick up once you already know how to use an existing language. Computer languages should attempt to reduce complexity and verbosity where possible.

Example: I picked up lua in a week. (javascript and ruby experience helped a lot) I'm not an expert by any means but I'm capable of writing usable applications. I doubt a person could pick up a new human language in a week.


Human languages are far more complex and verbose than is required for talking to computers.

This is mostly a quibble, but human languages are not more verbose than computer languages, generally. I can generally rely on you to allocate all the variables and present the result in a context-aware way when I ask you, "What is 3 + 5?" I'd generally have to allocate variables and tell the computer where to put the result if I were to ask it the same question.

What was, and still is, sort of magical about Perl is the degree to which it is aware of context and can use it to sort out meaning. If anything, the chief complaints against Perl, which stems from its similarity to natural languages (!), is its terseness and expressive power, these complaints being that it's indistinguishable from line noise and is a write-only language.


Honestly, Perl is really anything but a write-only language. Consider this:

https://github.com/schwern/AAAAAAA/blob/aaaaaa/aaa/AAAAAAAAA...

It should be unparsable, but most people who have some Perl knowledge find they can actually read and understand this.


I appreciate the depth of your response; the original reasoning makes sense, and as Python 3 tells us, it is very hard to get people to use your new version if you break enough old code.


This seems unfair to Python 3. The Python community, including the developers of Python 3, have not been encouraging people to migrate to Python 3. In fact, it was never in their roadmap for people to migrate immediately. The common wisdom has always been 'When starting a new project from scratch, if all the libraries you need are ported, and you won't need backwards compatibility down the road, then use Python 3. Otherwise, use Python 2.x'.

It's quite difficult to get people to use your new version when you actively tell them that it's probably not a good idea right now.


Perl is really powerful, and with power comes responsibility. Reference handling is an area that needs great care, as you can easily make subtle mistakes. Coding standards are important in a code base, often there are many ways to accomplish the same thing. Usually some forms are cleaner than others and can be enforced. An example regarding dereferencing:

  use v5.10;
  use strict;
  use warnings;
  
  my $ref = ['one', 2, 3];
  say $ref;
  
  foreach (@{$ref}) {
  	say;
  }

  # These are the same. The first form is much cleaner.
  # It also makes more sense semanticaly
  say @{$ref}->[0];
  say @{$ref}[0];
  say $ref->[0];


You're proving your own point about the subtlety of reference handling and the important of coding standards in Perl. Was that intentional?

    say @{$ref}->[0];
This raises a deprecation warning for me.

    say @{$ref}[0];
This is technically correct, as the leading sigil "@" indicates you are returning an array, but since you're only returning one element in that array, this should probably be "${$ref}[0]" which returns a scalar only.

    say $ref->[0];  
This the only form which I would consider correct or "clean".

This example proves nothing about Perl's power, though. The fact that difficult and fiddly reference handling shenanigans are necessary to handle something as trivial as nested arrays and hashes shows quite the opposite.


Absolutely! Running the code under Strawberry (5.12.3) produces no warnings and "works" as one would expect. Can it be any easier to shoot yourself in the foot? Regardless, Perl has a special place in my heart.


... since you're only returning one element in that array, this should probably be "${$ref}[0]" which returns a scalar only.

It's perfectly fine to use the array sigil, in which case it's a one-element list instead of a scalar. That's useful sometimes.


>Perl is really powerful,

Compared to what? C? In what way is it more powerful than Ruby, Python, Ocaml, Haskell, etc.?

There are things perl has over e.g. python (lambdas) but there are at least as many things those languages have over perl (e.g. python generators built in) and all of those languages are easier to use. Look at the code you wrote there! I assume "use v5.10" is actually a forward compatibility declaration instead of a backward one, right? Really embarrassing if so.


It's the equivalent of "use feature qw(switch say state)". "use feature" allows "new syntactic constructs, or new semantic meanings to older constructs" to be enabled in the current scope.

http://search.cpan.org/~flora/perl/lib/feature.pm


When Larry left for Perl 6 everyone figured that would be it for Perl 5 and then a few years later when Perl 6 kept not being viable for more than toy use the p5p was forced to figure out ways of extending Perl 5 without breaking old code. That was one of the ideas. This is what is more current planning in that regard:

http://www.youtube.com/watch?v=yJss-l2XuV8


Some years ago, Damien Conway spoke about changing sigils going away in Perl 6... whenever that comes out... perhaps 2030.


Perl6 already is out - there's a Tetris-implementation using GTK for Niecza, a Perl6 implementation on Mono/.NET. The implementations are not feature-complete, but if that's your sole criterion, then neither C nor C++ are out yet.

The most feature-complete implementation - Rakudo on Parrot - is not production-ready, though, and currently somewhat stalled due to low bus factor: The object-system refactor (which made things like natively-typed attributes possible) introduced a lot of regressions, and the regex engine in particular is not yet fixed as the lead-developer was hit by real-life issues.


The implementations are not feature-complete, but if that's your sole criterion, then neither C nor C++ are out yet.

That's a little disingenuous. I'm a Perl fan and I'd like to use Perl 6 practically, but the fact that someone wrote a Tetris clone in one of multiple incomplete implementations of Perl 6 doesn't mean that Perl 6 is actually useful for much.


That's a little disingenuous.

Not really. It just shows that feature-completeness may be a good metric when comparing implementations of the same language, but not so much when comparing them to implementations of a different language.

the fact that someone wrote a Tetris clone in one of multiple incomplete implementations of Perl 6 doesn't mean that Perl 6 is actually useful for much

The fact that there's a Tetris-clone in Perl6 indeed doesn't mean much. However, the fact that it uses GTK is an example of CLR interop, which opens up a whole new level of practical applicability.


Perl 6 changes this syntax to @src[$src], effectively admitting that the way sigils worked through Perl 5 was a failed experiment.


Also, $a is a global variable within the current package, which means that if you don't have to declare it, even if strict is turned on.


$a and $b are special due to their use in sort functions. This is a wart that predates "my".

Newer languages have warts, too, you just don't know what they are, yet.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: