in reply to Some Insights from a Traveler Between Languages

Your example in Python illustrates one of its major downfalls though. Certainly you can tell what's going on when you see

foo = (1, 2, 3) bar = [1, 2, 3]

What happens after that when you use foo or bar? You have to know what it is, but not only what type of data it has, but how it was created.

This was my biggest stumbling block with Python: I couldn't use the variable names I wanted and I had to remember extra things about the variables I did see. Some people don't like sigils, but I love them. People keep trying to invent them with various notations and styles of variable naming.

The trick to any language is to think like the language and forget anything you think is "reasonable" or "makes sense". Instead of fitting the language into the way that you think, just take the language for the way it is.

For instance, the length() function operates on a scalar and is documented that way. The documentation is very clear on that. It doesn't matter to me what I think it should do as long as I know what it does do. Think like that and all sorts of problems disappear. You might still be offended by some missing symmetry, but life is messy.

As for your list cases, it's not that Perl allows those cases in particular, but that Perl allows these cases:

@array = SCALAR; # promotes to ( SCALAR ); ... SCALAR, SCALAR ... # comma operator in scalar context

Once you have those general expressions, you can put them into larger expressions. It's actually more consistent to keep those because they are extensions of the same rules that allow other things (that you probably don't object to). Once you start adding special cases and exceptions, things get a lot more complicated and a lot harder to explain or remember.

They can't be syntax errors because they follow the rules. They might be candidates for warnings, however (just as an array slice with one element is legal, but generates a warning).

--
brian d foy <brian@stonehenge.com>

Replies are listed 'Best First'.
Re^2: Some Insights from a Traveler Between Languages
by Anonymous Monk on Apr 25, 2005 at 22:04 UTC
    For instance, the length() function operates on a scalar and is documented that way. The documentation is very clear on that. It doesn't matter to me what I think it should do as long as I know what it does do. You're just substituting one form of memory work for another. To maintain python, you have to remember type information: to maintain Perl, you need to embed the counter-intuitive behaviour of length() in your mind, in what purports to be a DWIM language. Both are awkward bits of memory work, in my mind.

      "Counter-intuitive" is a relative term. I've never had a problem with length because I'm not the type to guess at what things do, and if I do guess and get it wrong, I just read the docs. I've never wondered about the "length" of an array because "length" doesn't mean "count" to me. I don't say "what's the length of that bunch of bananas?", just like I don't say "what's the count of this hiking trail?".

      You may think some things are odd, but that doesn't objectively make them odd. Instead of intuiting things, you can usually save the hassle of being wrong by reading the docs.

      --
      brian d foy <brian@stonehenge.com>