Hi --

On Fri, 19 Aug 2005, Kroeger Simon (ext) wrote:

>> According to my experience, it's because Python is just insanely
>> inconsistent in every single way.
>
> examples?
>
> I will start with a ruby one:
>
> $1 to $9
> The contents of successive groups matched in the last successful
> pattern match.
> In "cat" =~/(c|a)(t|z)/, $1 will be set to ``a'' and $2 to ``t''.
> This variable is local to the current scope. {}

I don't think you'd want it any other way.  Imagine if you were using
those variables, and you called another method also did a matching
operation.  Your $1 and friends would be clobbered.

> $0
> The name of the top-level Ruby program being executed.
> Typically this will be the program's filename.
> On some operating systems, assigning to this variable will
> change the name of the process reported (for example)
> by the ps(1) command.
>
> Actually this are two in one. If $1 to $9 are groups, I don't
> think $0 is following the principal of least surprise.

POLS is *so* 2002... :-)  Anyway, it never meant that you didn't have
to learn anything to use Ruby.  You have to learn that $0 is the
filename even though the other /^\$\d+$/ variables aren't.  There: now
you know :-)

> Additionally $1 to $9 aren't global despite the '$'.

That's actually good -- see above.  (Unless you'd like 1,2,3...
themselves to be reassigned the values of your captures...? :-)  If
you don't like $1 etc. you can always use the MatchData object
directly.

My personal slogan for Ruby is:

   The triumph of balance over symmetry

and I guess one could add: the triumph of balance over mechanistic
consistency.  Yes, abc can be a method while def is a keyword and ghi
is a variable.  That's "inconsistent", but it has a positive, rather
than negative, effect on the design of the language and the look of
the code.

Don't you like it better this way?


David

-- 
David A. Black
dblack / wobblini.net