Consistency (was: Re: Python vs Ruby!)

(Kroeger Simon (ext)) #1

Hi David!

From: David A. Black [mailto:dblack@wobblini.net]
Hi --

>> 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.

Ok, that wasn't about bashing ruby (I'm not that silly trying this on a
ruby ML :)) it was in response to 'Python is just insanely inconsistent
in every single way' and I think Python isn't more or less inconsistent
than ruby (or perl, ehm, perhaps less)

Besides that. Yes I would like it another way, I don't like side
effects.
I don't want $1 to become global, but what the heck is this anyway?
But than, it doesn't bother me that much, I would never name one of my
globals (if I use one) $1, so I can safely ignore them.

> $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... :slight_smile: 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 :slight_smile:

What does bother me here is that there seems to be no other way than
using this ugly construct. (Did I miss something?)

> 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...? :slight_smile: If
you don't like $1 etc. you can always use the MatchData object
directly.

Yep, again, this was only on inconsistency. No 'good' or 'bad'.
Talking about good and bad I would definitaly go with the MatchData
object.

My personal slogan for Ruby is:

   The triumph of balance over symmetry

and this worked quite well.

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.

I was looking at Io this day (it was mentioned here multiple times)
and from what I did see, this is realy consistent - and not ugly in
any way.

Don't you like it better this way?

I like ruby, realy. I can live with the quirks, but I don't think they
make a better language.

David

--
David A. Black
dblack@wobblini.net

regards

Simon

···

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

(David A. Black) #2

Hi --

···

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

From: David A. Black [mailto:dblack@wobblini.net]

$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... :slight_smile: 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 :slight_smile:

What does bother me here is that there seems to be no other way than
using this ugly construct. (Did I miss something?)

Which one do you mean -- $0 or the $1 to $n ones? You can use
$PROGRAM_NAME instead of $0, and MatchData#captures for $1 to $n.
(Note: it doesn't stop at $9 :slight_smile:

David

--
David A. Black
dblack@wobblini.net