From: sjdevnull on
On Feb 2, 5:01 pm, Jonathan Gardner <jgard...(a)jonathangardner.net>
wrote:
> On Feb 1, 6:36 pm, John Bokma <j...(a)castleamber.com> wrote:
>
>
>
>
>
> > Jonathan Gardner <jgard...(a)jonathangardner.net> writes:
> > > One of the bad things with languages like perl
>
> > FYI: the language is called Perl, the program that executes a Perl
> > program is called perl.
>
> > > without parentheses is that getting a function ref is not obvious. You
> > > need even more syntax to do so. In perl:
>
> > >  foo();       # Call 'foo' with no args.
> > >  $bar = foo;  # Call 'foo; with no args, assign to '$bar'
> > >  $bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar'
> > >               # By the way, this '&' is not the bitwise-and '&'!!!!
>
> > It should be $bar = \&foo
> > Your example actually calls foo...
>
> I rest my case. I've been programming perl professionally since 2000,
> and I still make stupid, newbie mistakes like that.
>
> > > One is simple, consistent, and easy to explain. The other one requires
> > > the introduction of advanced syntax and an entirely new syntax to make
> > > function calls with references.
>
> > The syntax follows that of referencing and dereferencing:
>
> > $bar = \@array;       # bar contains now a reference to array
> > $bar->[ 0 ];          # first element of array referenced by bar
> > $bar = \%hash;        # bar contains now a reference to a hash
> > $bar->{ key };        # value associated with key of hash ref. by bar
> > $bar = \&foo;         # bar contains now a reference to a sub
> > $bar->( 45 );         # call sub ref. by bar with 45 as an argument
>
> > Consistent: yes. New syntax? No.
>
> Except for the following symbols and combinations, which are entirely
> new and different from the $@% that you have to know just to use
> arrays and hashes.
>
> \@, ->[ ]
> \%, ->{ }
> \&, ->( )
>
> By the way:
> * How do you do a hashslice on a hashref?
> * How do you invoke reference to a hash that contains a reference to
> an array that contains a reference to a function?
>
> Compare with Python's syntax.
>
> # The only way to assign
> a = b

>>> locals().__setitem__('a', 'b')
>>> print a
b

> # The only way to call a function
> b(...)

>>> def b(a):
.... print a*2
>>> apply(b, (3,))
6

> # The only way to access a hash or array or string or tuple
> b[...]

>>> b={}
>>> b[1] = 'a'
>>> print b.__getitem__(1)
a


From: bartc on
Jonathan Gardner wrote:
> On Feb 2, 7:23 am, "bartc" <ba...(a)freeuk.com> wrote:
>> Jonathan Gardner wrote:
>>> One of the bad things with languages like perl and Ruby that call
>>> without parentheses is that getting a function ref is not obvious.
>>> You need even more syntax to do so. In perl:
>>
>>> foo(); # Call 'foo' with no args.
....
>> If you get rid of the syntax specific to Perl, then having to
>> explicitly obtain a function reference, or to dereference the
>> result, is not such a big deal:
>>
>> foo # Call 'foo' with no args.
>> bar = foo # Call 'foo; with no args, assign to 'bar'
>> bar = &foo # Don't call 'foo', but assign a pointer to it to 'bar'
>> bar^ # Call whatever 'bar' is pointing at with no args
>>
>> (Here I use ^ instead of -> to dereference.) Compared with Python,
>> it saves 3 lots of (), but needs & and ^ added. Still a net saving.
>>
>
> On one shoulder, a demon taunts the programmer: "Ohmygosh, you can
> save three keystrokes if you introduce an entirely new syntax with odd
> squiggles that make no pronounceable sound in the English language!
> Perhaps one day, you can program APL in Python!"
....
> Thankfully, Guido has banished that demon from the realm of Python a
> long time ago.

You mean & (bitwise AND in Python) and ^ (bitwise XOR in Python)?

:-)

--
Bartc


From: John Bokma on
Jonathan Gardner <jgardner(a)jonathangardner.net> writes:

> I can explain, in an hour, every single feature of the Python language
> to an experienced programmer, all the way up to metaclasses,

Either you're a hell of a talker, or I am far, far away from being an
experienced programmer. It's advocacy like this, IMO, that keeps people
away from a language, because you can't feel nothing but a failure after
a statement like this.

--
John Bokma j3b

Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
From: John Bokma on
Jonathan Gardner <jgardner(a)jonathangardner.net> writes:

> On Feb 1, 6:36 pm, John Bokma <j...(a)castleamber.com> wrote:

[..]

>> It should be $bar = \&foo
>> Your example actually calls foo...
>
> I rest my case. I've been programming perl professionally since 2000,
> and I still make stupid, newbie mistakes like that.

Uhm, in another post you wrote that you could explain Python in an hour
to an experienced programmer and you *still* make mistakes like that in
Perl!?

By the way, the language is called Perl. If you write "I've been
programming perl" in a Perl related group some people might read it as
that you've been working on the internals of the perl executable (in C)

>> > One is simple, consistent, and easy to explain. The other one requires
>> > the introduction of advanced syntax and an entirely new syntax to make
>> > function calls with references.
>>
>> The syntax follows that of referencing and dereferencing:
>>
>> $bar = \@array;       # bar contains now a reference to array
>> $bar->[ 0 ];          # first element of array referenced by bar
>> $bar = \%hash;        # bar contains now a reference to a hash
>> $bar->{ key };        # value associated with key of hash ref. by bar
>> $bar = \&foo;         # bar contains now a reference to a sub
>> $bar->( 45 );         # call sub ref. by bar with 45 as an argument
>>
>> Consistent: yes. New syntax? No.
>>
>
> Except for the following symbols and combinations, which are entirely
> new and different from the $@% that you have to know just to use
> arrays and hashes.
>
> \@, ->[ ]

@array, one item: $array[ 1 ];
$arrayref, one item: $arrayref->[ 1 ];

> \%, ->{ }

%hash, one item: $hash{ key };
hence: $hashref, one item: $hash->{ key }

> \&, ->( )

should now be clear ;-)

You *should* have no problem with that if you have been
programming professionally Perl since 2000 IMNSHO. Otherwise print my
post or copy it on a post-it note ;-).

Remember that all this was added to Perl in version 5. So it had to be
added in a way that wouldn't break Perl 4. Perl is, in my experience
quite good in backwards compatibility. Quite some Perl modules on CPAN
work from 5.00x-5.10 and most likely will work without trouble in 5.12.

> By the way:
> * How do you do a hashslice on a hashref?

I will reply like it's a genuine question, and not like "Oh, look, how
silly Perl works". I don't care about that much. I do like Perl and am
starting to like Python.

@$hashref{ 'key1', 'key2', 'key3' };

> * How do you invoke reference to a hash that contains a reference to
> an array that contains a reference to a function?

I guess you mean:

$hashref->{ key }[ index ]( arguments );

The long version is:

$hashref->{ key }->[ index ]->( arguments );

[ Python advocacy snipped]

> I'd rather think of the task at hand than what each of the funky
> symbols on my keyboard mean.

Then just quit programming Perl ;-) Perl has always come naturally to
me, no idea why. Recently I said to a close friend:

Python is like my desk, which I prefer to keep clean and neat.
Perl is like my livingroom, which I prefer to keep clean and neat to
some extend, but some mess is allowed. For example, the cat can be
there. Toys of my daughter are allowed to be all over the place. A
pleasant mess, but not too much.

I won't repeat what I said about PHP ;-).

--
John Bokma j3b

Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
From: Steven D'Aprano on
On Tue, 02 Feb 2010 23:11:49 -0600, John Bokma wrote:

> Jonathan Gardner <jgardner(a)jonathangardner.net> writes:
>
>> I can explain, in an hour, every single feature of the Python language
>> to an experienced programmer, all the way up to metaclasses,
>
> Either you're a hell of a talker, or I am far, far away from being an
> experienced programmer. It's advocacy like this, IMO, that keeps people
> away from a language, because you can't feel nothing but a failure after
> a statement like this.

Surely you're exaggerating?

Without making any aspersions towards Jonathan either way, the Internet
is full of both blowhards and geniuses. Anyone who lets the off-the-cup
claims of either ruin their self-confidence is unlikely to be thinking
about learning Python, they're probably sitting alone in a dark room
staring as the walls close in.

Either that or on MySpace.



--
Steven