v icon indicating copy to clipboard operation
v copied to clipboard

Allow to omit commas in multiline function signature block

Open dadooda opened this issue 1 year ago • 5 comments

Describe the feature

It's cool that Vlang lets us omit the comma when using multiline syntax in array enumeration and function calls. Like this:

// (1) ✅
greet('Mr.', 'Joe')

// (2) ✅
greet(
  'Mr.'
  'Joe'
)

At the same time, it's not yet possible to omit the comma in greet() definition (signature):

// (3) ✅
fn greet(salutation string, name string) {
  println('Hey, ${salutation} ${name}!')
}

// (4) ❌
fn greet(
  salutation string
  name string
) {
  println('Hey, ${salutation} ${name}!')
}

I'd propose example (4) above to be made possible.

Use Case

Comma omission in multiline enumerations looks good, feels good. And it's partially supported already. Let's make it consistently available in all parts of the language.

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

Version used

V 0.4.7 7baff15

Environment details (OS name and version, etc.)

Ubuntu 18 under WSL.

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

dadooda avatar Aug 10 '24 12:08 dadooda

V seems to allow greet('Mr.' 'Joe') as well. I think that should actually be an error. It is working in V because V still sees it as 2 separate strings, but it shouldn't work, as there really should be a , separator between the parameters, whether they are on the same line or not.

For example, this works, too, and it looks really odd...

fn greet(i1 int, i2 int) {
  println('${i1} ${i2}')
}

greet(17 23)

JalonSolov avatar Aug 10 '24 12:08 JalonSolov

For example, this works, too, and it looks really odd...

Oh yes, it does… The parser definitely needs some reinforcement…

dadooda avatar Aug 10 '24 12:08 dadooda

Good find, will fix.

I like no comma when there're newlines, that's why I implemented this way back:

arr := [
'foo'
'bar'
]

Many people are against this, and vfmt was changed to insert a ,.

I still think a comma shouldn't be needed here. Just like ; Looks cleaner this way.

medvednikov avatar Aug 10 '24 13:08 medvednikov

As long as it's documented that either newline or comma works. But then what about OP's comment about function declarations? Shouldn't they work the same way, then?

As long as it doesn't work on same line without the comma.

JalonSolov avatar Aug 10 '24 14:08 JalonSolov

Just adding an opinion. Agree with the line of thinking that it should be consistent. So in reference to the examples that dadooda gave, if example 2 is allowed, then arguably so should example 4. Otherwise, don't allow both 2 and 4, and force the comma.

Many people are against this, and vfmt was changed to insert a ,.

Possibly the fear is people doing strange things or mistakes, like multiple blank lines in between. Thus the comma to make sure.

Wajinn avatar Aug 26 '24 07:08 Wajinn