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

Usage does not print required type for positional params in MAIN #4265

Closed
p6rt opened this issue May 26, 2015 · 9 comments
Closed

Usage does not print required type for positional params in MAIN #4265

p6rt opened this issue May 26, 2015 · 9 comments

Comments

@p6rt
Copy link

p6rt commented May 26, 2015

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

Searchable as RT125251$

@p6rt
Copy link
Author

p6rt commented May 26, 2015

From @bbkr

Named params print required types​:

17​:33 bbkr​: r​: sub MAIN (Int :$x!) {...}
17​:33 camelia​: rakudo-{moar,jvm} c2a57e​: OUTPUT«Usage​:␤ /tmp/tmpfile -x=<Int> ␤»

However positional types does not​:

17​:33 bbkr​: r​: sub MAIN (Int $x!) {...}
17​:33 camelia​: rakudo-{moar,jvm} c2a57e​: OUTPUT«Usage​:␤ /tmp/tmpfile <x> ␤»

I think this is bug because type is more important than irrelevant variable name.
Expected output is​: "Usage​:␤ /tmp/tmpfile <Int>"

@p6rt
Copy link
Author

p6rt commented May 26, 2015

From @pmichaud

On Tue May 26 08​:38​:30 2015, bbkr@​post.pl wrote​:

I think this is bug because type is more important than irrelevant
variable name.
Expected output is​: "Usage​:␤ /tmp/tmpfile <Int>"

In this case, the variable name is "irrelevant" primarily because the programmer chose an irrelevant name. A clearer case for the current behavior comes from

  sub MAIN (Int $count!) { ... }

which produces a more useful "Usage​:␤ /tmp/tmpfile <count>" message.

Or consider a grep-like replacement​:

  sub MAIN ($pattern!, @​*files) { ... }

that produces "Usage​:␤ /tmp/tmpfile <pattern> [<files> ...]".

In the original report, an argument can be made that the programmer ought to have made the program more useful by writing

  sub MAIN (Int $integer) { ... }

which outputs "Usage​:␤ /tmp/SJk_VxNAxM <integer>".

I'm inclined to reject this ticket, but will leave it open for further discussion.

Pm

@p6rt
Copy link
Author

p6rt commented May 26, 2015

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

@p6rt
Copy link
Author

p6rt commented May 26, 2015

From @bbkr

In the original report, an argument can be made that the programmer ought to have made the program more useful by writing

sub MAIN (Int $integer) { ... }

What if there are two integer params? MAIN (Int $integer1, Int $integer2) looks bad and subroutine body may be hard to understand.
We already have typed variable and choosing variable name to duplicate type name just to display this information to caller is redundant.

Despite that I found another inconsistency in positional params - anonymous one still display types​:

$ perl6 -e 'sub MAIN (Int, Str) { ... }'
Usage​:
-e '...' <Int> <Str>

Maybe more consistent way of displaying types would be​:
"--age=<Int> --name=<Str>" for named
"<Int>age <Str>name" for positional with variable name
"<Int> <Str>" for anonymous positional
?

@p6rt
Copy link
Author

p6rt commented May 26, 2015

From @bbkr

BTW​: whatever decision for this ticket will be, also there is inconsistency between usage text and how Perl 6 display types​:

$ perl6 -e 'Int.WHAT.say'
(Int)

So it should be displayed as --age=(Int) instead of --age=<Int>.

@p6rt
Copy link
Author

p6rt commented May 27, 2015

From @bbkr

In the original report, an argument can be made that the programmer ought to have made the program more useful by writing

sub MAIN (Int $integer) { ... }

What if there are two integer params? MAIN (Int $integer1, Int $integer2) looks bad and subroutine body may be hard to understand.
We already have typed variable and choosing variable name to duplicate type name just to display this information to caller is redundant.

Despite that I found another inconsistency in positional params - anonymous one still display types​:

$ perl6 -e 'sub MAIN (Int, Str) { ... }'
Usage​:
  -e '...' <Int> <Str>

Maybe more consistent way of displaying types would be "--age=<Int> --name=<Str>" for named and "<Int>age <Str>name" for named positionals and "<Int> <Str>" for anonymous positionals?

On 26 May 2015, at 20​:01, Patrick R. Michaud via RT <perl6-bugs-followup@​perl.org> wrote​:

On Tue May 26 08​:38​:30 2015, bbkr@​post.pl wrote​:

I think this is bug because type is more important than irrelevant
variable name.
Expected output is​: "Usage​:␤ /tmp/tmpfile <Int>"

In this case, the variable name is "irrelevant" primarily because the programmer chose an irrelevant name. A clearer case for the current behavior comes from

sub MAIN (Int $count!) { ... }

which produces a more useful "Usage​:␤ /tmp/tmpfile <count>" message.

Or consider a grep-like replacement​:

sub MAIN ($pattern!, @​*files) { ... }

that produces "Usage​:␤ /tmp/tmpfile <pattern> [<files> ...]".

In the original report, an argument can be made that the programmer ought to have made the program more useful by writing

sub MAIN (Int $integer) { ... }

which outputs "Usage​:␤ /tmp/SJk_VxNAxM <integer>".

I'm inclined to reject this ticket, but will leave it open for further discussion.

Pm

@p6rt
Copy link
Author

p6rt commented Sep 30, 2017

From @sjn

I think this bug can be closed.

Here's my reasoning. For me, a major point with the auto-generated usage text is that it helps the developer of the program see the importance of picking good variable names. If a dev chooses to name them $integer1 and $integer2 (which are obviously horrible variable names because they tell nothing about what they will be used for), then the generated usage text *should* looks stupid. Garbage in, garbage out.

In the same way, if the name of the variable doesn't give an indication of the type (e.g. $age is a number), then the error is still with the developer and not the language.

This is a non-issue, and the ticket should be closed. :)

- Salve (who is looking through all tickets related to MAIN)

Wed, 27 May 2015 06​:11​:13 -0700 skrev bbkr@​post.pl​:

In the original report, an argument can be made that the programmer
ought to have made the program more useful by writing

sub MAIN (Int $integer) { ... }

What if there are two integer params? MAIN (Int $integer1, Int
$integer2) looks bad and subroutine body may be hard to understand.
We already have typed variable and choosing variable name to duplicate
type name just to display this information to caller is redundant.

Despite that I found another inconsistency in positional params -
anonymous one still display types​:

$ perl6 -e 'sub MAIN (Int, Str) { ... }'
Usage​:
-e '...' <Int> <Str>

Maybe more consistent way of displaying types would be "--age=<Int>
--name=<Str>" for named and "<Int>age <Str>name" for named positionals
and "<Int> <Str>" for anonymous positionals?

On 26 May 2015, at 20​:01, Patrick R. Michaud via RT <perl6-bugs-
followup@​perl.org> wrote​:

On Tue May 26 08​:38​:30 2015, bbkr@​post.pl wrote​:

I think this is bug because type is more important than irrelevant
variable name.
Expected output is​: "Usage​:␤ /tmp/tmpfile <Int>"

In this case, the variable name is "irrelevant" primarily because the
programmer chose an irrelevant name. A clearer case for the current
behavior comes from

sub MAIN (Int $count!) { ... }

which produces a more useful "Usage​:␤ /tmp/tmpfile <count>"
message.

Or consider a grep-like replacement​:

sub MAIN ($pattern!, @​*files) { ... }

that produces "Usage​:␤ /tmp/tmpfile <pattern> [<files> ...]".

In the original report, an argument can be made that the programmer
ought to have made the program more useful by writing

sub MAIN (Int $integer) { ... }

which outputs "Usage​:␤ /tmp/SJk_VxNAxM <integer>".

I'm inclined to reject this ticket, but will leave it open for
further discussion.

Pm

@p6rt
Copy link
Author

p6rt commented Dec 14, 2017

From @zoffixznet

On Sat, 30 Sep 2017 12​:45​:09 -0700, sjn-perlbug@​pvv.org wrote​:

I think this bug can be closed.

Agreed. Rejecting.

I see little reason to muddy up the Usage even more with type information,
where you're mostly limited to Int/Str types anyway, and variable name
helps know which to use.

The type info is helpful with named args, because without types present,
it'd be harder to know whether they are Bool flags.

also there is
inconsistency between usage text and how Perl 6 display types​:

$ perl6 -e 'Int.WHAT.say'
(Int)

So it should be displayed as --age=(Int) instead of --age=<Int>.

Don't see much consistency relevance between USAGE and the behaviour of the
.gist method on type objects. Personally, I use `Int.^name.say` to display
types...

I found another inconsistency in positional params -
anonymous one still display types​:

Seems reasonable to me. Lacking a variable name, there's little else
to display in its place.

Cheers,
ZZ

@p6rt p6rt closed this as completed Dec 14, 2017
@p6rt
Copy link
Author

p6rt commented Dec 14, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant