develooper Front page | perl.perl5.porters | Postings from October 2011

Re: [perl #100190] RFE: fix sprintf to be consistent with printf and be useful!

Thread Previous | Thread Next
From:
Linda Walsh
Date:
October 1, 2011 09:19
Subject:
Re: [perl #100190] RFE: fix sprintf to be consistent with printf and be useful!
Message ID:
4E873D51.5030804@tlinx.org
Eric Brine via RT wrote:
>>    Hmm...  Let's examine this strawman argument are any of these command
>>    that would take a list of scalars that are not written to?
>>
>>    length -- <$> - takes 1 expression
>>
>
> Are you saying array cannot hold one element?

----

    I'm saying that the argument to length is NOT a list.  Therefore an
array
makes no sense.   Where are the people who comment on silliness at this
point?


>>    substr -- <$,$>[,$[,$] --- maybe, but it's not a variable length list
>>
>
> By that logic, neither is sprintf, it's 1 scalar but a variable length
list.

----

    ?!?  sprintf takes a variable length list just like printf does.  The
minimum number of params passed is determined by the 1st.  Such is not
true of
substr, which doesn't take a variable length list, but always takes 2, 3
or 4
params, but no list of 0..[size that machine & perl will allow].  Again your
example doesn't fit the paradigm.


>
>    exit   -- $ -- one expression
>
> Are you saying array cannot hold one element?

----

Are you saying 1 element IS an array?  Are you saying exit can take more
than
one value?

If not, and you pass it an array, which value from the array do you return?
Do you have or consider any logic to your pointless obstructionism?  What is
exit or length supposed to do with an array?  Should length return the
length
of an array?, or the length of the sum of the chars in the array?  Or
just the
length of the 1st or what?   you'd have to change the definition and
function
of length and exit to make either change.

What you are proposing are changes that would require redefining how those
functions work.

What I am proposing clearly makes nor requires change in functional
behavior.


> Yes, so, printf should be like sprintf.
>
> I.e. why not just allow a list?
>
>
> Because sprintf takes a scalar plus a list, and printf takes a handle/block
> plus a scalar plus a list.

You just hit the nail on the head.  They both take a scalar, comma separated
from a list...  indistinguishable from a list.

printf takes an optional, and MOST IMPORTANTLY, a **COMPLETELY ORTHOGONAL**
syntax that cannot be mistaken for being part of a list.



>
> I don't think anyone has put forth an argument as to why sprintf not be
able
> to handle the same list-arguments as printf.
>
> Actually, I did. The purpose of the sprintf prototype is to make it hard to
> accidentally write bad code. Removing the prototype will cause sprintf to
> fail more subtly when used incorrectly.

Make it hard to write bad code (are you a perl hacker?  'sides that's what
prototypes are for! ;-) [preventing!] )  How does it pass bad code?  You CAN
pass an array to it, it just is BAD code -- it certainly doesn't throw an
syntax error -- it allows an array there, which, "___is [almost]^ never
useful__".  (Note: word 'almost' bracketed with ^ to indicate editorial
deletion, as circling it and drawing a line out won't work, and
strike-through
doesn't work in ascii...which seems to be std.bug input format; *idea*:
Maybe
the bug input form could allow wiki-like text markup??.....(*ducking before
someone throws something at me*))





Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About