Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routines sprintf and printf need auto newline capability #5661

Closed
p6rt opened this issue Sep 11, 2016 · 14 comments
Closed

routines sprintf and printf need auto newline capability #5661

p6rt opened this issue Sep 11, 2016 · 14 comments
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented Sep 11, 2016

Migrated from rt.perl.org#129252 (status was 'rejected')

Searchable as RT129252$

@p6rt
Copy link
Author

p6rt commented Sep 11, 2016

From @tbrowder

Both routines need an alias (or adverb) so that a newline is automatically appended to the output. I would like to see something like​:

  sprintfn
  printfn

or

  sprintf-n
  printf-n

or

  sprintf-nl
  printf-nl

@p6rt
Copy link
Author

p6rt commented Sep 11, 2016

From @lizmat

Just curious, but what is wrong with "say fmt()" ?

On 11 Sep 2016, at 22​:48, Tom Browder (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Tom Browder
# Please include the string​: [perl #​129252]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=129252 >

Both routines need an alias (or adverb) so that a newline is automatically appended to the output. I would like to see something like​:

sprintfn
printfn

or

sprintf-n
printf-n

or

sprintf-nl
printf-nl

@p6rt
Copy link
Author

p6rt commented Sep 11, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 11, 2016

From @tbrowder

On Sun, Sep 11, 2016 at 3​:54 PM, Elizabeth Mattijsen <liz@​dijkmat.nl> wrote​:

Just curious, but what is wrong with "say fmt()" ?

Liz, one reason, i'm ashamed to say, is lack of familiarity with fmt()
(too many years of C/C++ and Perl 5, I guess). The printf family I am
very aware of and am trying to get the docs right. It looks like fmt
can almost piggy back on some of it, though.

@p6rt
Copy link
Author

p6rt commented Sep 11, 2016

From @zoffixznet

On Sun Sep 11 13​:48​:04 2016, tbrowder wrote​:

Both routines need an alias (or adverb) so that a newline is
automatically appended to the output. I would like to see something
like​:

sprintfn
printfn

I'd prefer to avoid adding two new subs and two new methods for the sake of saving a single character of typing. Since you're writing the format already sticking a \n into it isn't that difficult.

@p6rt
Copy link
Author

p6rt commented Sep 11, 2016

From @tbrowder

On Sun, Sep 11, 2016 at 5​:08 PM, Zoffix Znet via RT
<perl6-bugs-followup@​perl.org> wrote​:

On Sun Sep 11 13​:48​:04 2016, tbrowder wrote​:

Both routines need an alias (or adverb) so that a newline is
...
I'd prefer to avoid adding two new subs and two new methods for the sake of saving a single character of typing. Since you're writing the format already sticking a \n into it isn't that difficult.

Uh, say "what?" :)

@p6rt
Copy link
Author

p6rt commented Sep 11, 2016

From @zoffixznet

On Sun Sep 11 15​:29​:45 2016, tbrowder wrote​:

Uh, say "what?" :)

I don't think that works as a justification. The put() is used much more frequently than printf(), so it makes sense to have it as a "\n"-adding alternative to print().
But my main point was that with printf() you're writing the format string anyway, so adding a \n into it is easy, as compared to adding one to print()​:

  put self.meow;
  print "{self.meow}\n";
 
Compare to​:

  printfn "%s", self.meow;
  printf "%s\n", self.meow;

You literally save 1 character of typing in a not the most used subroutine, all for the price of 4 extra routines for developers to maintain and document and for users to remember and debug when they miss the `n` at the end of the sub name.

@p6rt
Copy link
Author

p6rt commented Sep 12, 2016

From @tbrowder

On Sunday, September 11, 2016, Zoffix Znet via RT <
perl6-bugs-followup@​perl.org> wrote​:

On Sun Sep 11 15​:29​:45 2016, tbrowder wrote​:

Uh, say "what?" :)

Just a little humour. Someone thought thought it was worth it to not have
to explicitly add the newline on print, and I feel the same way about
printf.

...

I don't think that works as a justification. The put() is used much more

frequently than printf(), so it makes sense to have it as a "\n"-adding
alternative to print().
But my main point was that with printf() you're writing the format string
anyway, so adding a \n into it is easy, as compared to adding one to
print()​:

...

You literally save 1 character of typing in a not the most used
subroutine,

I respectfully disagree, Zoffix. I used printf in Perl 5, to a file, for
many years writing auto-generated documents, and I would have loved to have
the equivalent of println (is that Java?).

In addition, such a function would reduce code line noise quite a bit IMHO.

Anyway, if we ever get printf for an IO​::Handle, I would like to see
something like I suggested.

@p6rt
Copy link
Author

p6rt commented Sep 12, 2016

From @tbrowder

On Sun, Sep 11, 2016 at 6​:49 PM, Zoffix Znet via RT
<perl6-bugs-followup@​perl.org> wrote​:

On Sun Sep 11 15​:29​:45 2016, tbrowder wrote​:

Uh, say "what?" :)

I don't think that works as a justification. The put() is used much more frequently than printf(),
so it makes sense to have it as a "\n"-adding alternative to print().
...
You literally save 1 character of typing in a not the most used subroutine,
all for the price of 4 extra routines for developers to maintain and
document and for users to remember and debug when they miss
the `n` at the end of the sub name.

I would give up the fmt() routine if necessary to avoid extra maintenance.

@p6rt
Copy link
Author

p6rt commented Sep 12, 2016

From @coke

On Sun Sep 11 13​:48​:04 2016, tbrowder wrote​:

Both routines need an alias (or adverb) so that a newline is
automatically appended to the output. I would like to see something
like​:

sprintfn
printfn

or

sprintf-n
printf-n

or

sprintf-nl
printf-nl

-1 from me.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Sep 12, 2016

From @moritz

Hi Tom,

On Sun Sep 11 13​:48​:04 2016, tbrowder wrote​:

Both routines need an alias (or adverb) so that a newline is
automatically appended to the output. I would like to see something
like​:

sprintfn
printfn

or

sprintf-n
printf-n

or

sprintf-nl
printf-nl

I don't like it. Those names don't speak very well for themselves.
On the other hand, adding a \n at the end of the format string doesn't seem to be such a big burden.

If you don't like to reach for your backslash key, say sprintf "..." is also an option.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Sep 12, 2016

@moritz - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Sep 12, 2016
@p6rt
Copy link
Author

p6rt commented Sep 12, 2016

From @tbrowder

On Mon Sep 12 07​:39​:56 2016, moritz wrote​:

If you don't like to reach for your backslash key, say sprintf "..."
is also an option.

Moritz, that's fine for sprintf, but it doesn't help printf if it ever gets to be a method of IO​::Handle.

@p6rt
Copy link
Author

p6rt commented Jan 29, 2017

From @tbrowder

On Sun, Sep 11, 2016 at 3​:54 PM, Elizabeth Mattijsen <liz@​dijkmat.nl> wrote​:

Just curious, but what is wrong with "say fmt()" ?

Liz, one reason, i'm ashamed to say, is lack of familiarity with fmt()
(too many years of C/C++ and Perl 5, I guess). The printf family I am
very aware of and am trying to get the docs right. It looks like fmt
can almost piggy back on some of it, though.

@p6rt p6rt added the RFC Request For Comments label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

1 participant