[Israel.pm] Gabor's problem with newbies

Gaal Yahas gaal at forum2.org
Sun Dec 28 07:49:39 PST 2008


On Sun, Dec 28, 2008 at 5:10 PM, Jason Elbaum <jason.elbaum at gmail.com> wrote:
> On Sun, Dec 28, 2008 at 3:17 PM, Gaal Yahas <gaal at forum2.org> wrote:
>> Oh, there exist places where list length is useful. Haven't you ever
>> done "1 .. @foo" or "unless @foo == 2"?
>
> Sure it's useful. But it's certainly not intuitive.

Well, I suppose this is what we're disagreeing on. "$num_of_elements =
@array" is by now pretty intuitive to me.

I also remembered now that in Perl 6, that would have to be $num =
@array.elems. And I believe that after getting back to some Perl 6
coding, that'll seem intuitive to me, too. I guess that makes me
unreasonable...

>> I don't really get the "reasonable person" argument. I never met
>> anyone (who didn't know C and) thought to write
>
> Larry legitimized the "reasonable person" argument when he established
> DWIM as a Perl design principle. It implies that the semantics should
> somehow reflect the intent of a typical programmer. I don't think
> array-to-scalar conversion is consistent with DWIM.

I'm just saying, if we don't agree in our respective ideas about a
typical programmer, there's not a lot of further appeal we can make to
the very idea of a typical programmer.

Of course, if you interpret the "I" in DWIM as referring to Larry,
some of this goes away.

> Of course, Larry also argues that languages should not be designed for
> the convenience of newbies. A language is learned once and used many
> times; the initial investment in learning it is amortized over time.
> So I don't think he has much sympathy for complaints that particular
> features confuse beginners.

Good call, IMHO.

> Jason
>
>
>
>> That said, even today I occasionally make mistakes with context, like
>> $match = /..(.....)../ or (shudder) $arg = @_. But personally I just
>> view these as silly slips that I occasionally make, not as language
>> misfeatures. Perl 6 (you knew this was coming) will do away with the
>> second error, since parameter handling is no longer manual. I _don't
>> want_ to do away with list-to-scalar conversion because it's very
>> often useful.
>>
>> Scalar hash conversion is a whole different matter...
>>
>> On Sun, Dec 28, 2008 at 3:00 PM, Jason Elbaum <jason.elbaum at gmail.com> wrote:
>>> If you ask me, this is a bug in the semantics of Perl. Based on the
>>> principle of Do What I Mean, it's entirely unreasonable for a list in
>>> a scalar context to be converted to its length. I can't conceive of
>>> any reasonable person who would consider that to be "what they mean"
>>> when they write $x = @abc - unless, of course, they're already
>>> familiar with Perl's semantics. Not to mention when they write (and
>>> lots of confused beginners do this) $x = ( 'abc' ). And not to mention
>>> the difference between how we take the length of an array, the length
>>> of a string, and the size of a hash.
>>>
>>> This is perhaps the most blatant instance where DWIM differs from Do
>>> What Perl Thinks I Mean. Ideally, it should be deprecated and warned
>>> against, but no doubt there's too much live code to make that
>>> feasible.
>>>
>>> Chag sameach,
>>>
>>> Jason Elbaum
>>>
>>>
>>> On Sun, Dec 28, 2008 at 2:57 PM, Jason Elbaum <jason.elbaum at gmail.com> wrote:
>>>>
>>>> If you ask me, this is a bug in the semantics of Perl. Based on the principle of Do What I Mean, it's entirely unreasonable for a list in a scalar context to be converted to its length. I can't conceive of any reasonable person who would consider that to be "what they mean" when they write $x = @abc - unless, of course, they're already familiar with Perl's semantics. Not to mention when they write (and lots of confused beginners do this) $x = ( 'abc' ). And not to mention the difference between how we take the length of an array, the length of a string, and the size of a hash.
>>>>
>>>> This is perhaps the most blatant instance where DWIM differs from Do What Perl Thinks I Mean. Ideally, it should be deprecated and warned against, but no doubt there's too much live code to make that feasible.
>>>>
>>>> Chag sameach,
>>>>
>>>> Jason Elbaum
>>>>
>>>>
>>>>
>>>>
>>>> On Sun, Dec 28, 2008 at 2:51 PM, Peter Gordon <peter at pg-consultants.com> wrote:
>>>>>
>>>>> I deleted the email, but from what I remember the problem is:
>>>>>
>>>>> @argv = "123456"
>>>>> split("4", at argv)
>>>>>
>>>>> The context forces @argv to a scalar, much like $n = @argv.
>>>>> So the @argv tranlsates to 1.
>>>>>
>>>>>
>>>>> A more convincing example is:
>>>>>
>>>>> @argv = ("123456") x 123
>>>>> split("2", at argv)
>>>>>
>>>>> results in 1,3
>>>>> It is the result of the count of the elements being split.
>>>>>
>>>>> Peter
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Perl mailing list
>>>>> Perl at perl.org.il
>>>>> http://perl.org.il/mailman/listinfo/perl
>>>>
>>> _______________________________________________
>>> Perl mailing list
>>> Perl at perl.org.il
>>> http://perl.org.il/mailman/listinfo/perl
>>>
>>
>>
>>
>> --
>> Gaal Yahas <gaal at forum2.org>
>> http://gaal.livejournal.com/
>> _______________________________________________
>> Perl mailing list
>> Perl at perl.org.il
>> http://perl.org.il/mailman/listinfo/perl
>>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>



-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list