Proposal to remove semicolons


(Joao Nunes) #1

Hi,

I submitted a PR with a proposal to remove the swift end of line semicolons.

It was rejected because i didn't discuss it here. So here i'm discussing it :slight_smile:

My proposal is simple: remove the semicolons in the end of lines.
It isn't needed and makes the code ugly.
It must be decided wether to use it or not for every project we start in the coding style.

What do you think?

Jo茫o Nunes

路路路

Sent from my iPhone


(David Owens II) #2

Swift already doesn鈥檛 require semicolons, so I鈥檓 confused.

Are you saying you want to make this invalid?

聽聽聽聽let df = 12
聽聽聽聽let db = 12; // do not allow this line?

And would you disallow constructs like this (single-line, multi-statements)?

聽聽聽聽var x = 10; x = 12

-David

路路路

On Dec 13, 2015, at 6:12 AM, Jo茫o Nunes via swift-evolution <swift-evolution@swift.org> wrote:

Hi,

I submitted a PR with a proposal to remove the swift end of line semicolons.

It was rejected because i didn't discuss it here. So here i'm discussing it :slight_smile:

My proposal is simple: remove the semicolons in the end of lines.
It isn't needed and makes the code ugly.
It must be decided wether to use it or not for every project we start in the coding style.

What do you think?

Jo茫o Nunes

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Austin Zheng) #3

Semicolons are already optional at the end of lines and only required to separate multiple statements on the same line (and for C for loops, but changing the grammar of those or removing them is a different topic.

If your proposal is to make a semicolon at the end of a single line invalid syntax, that's fine with me, although it seems like an unnecessarily small change to the grammar (and something better handled by a linter). If your proposal is to remove the semicolon as a way to separate multiple statements on the single line, then -1.

Austin

路路路

On Dec 13, 2015, at 6:12 AM, Jo茫o Nunes via swift-evolution <swift-evolution@swift.org> wrote:

Hi,

I submitted a PR with a proposal to remove the swift end of line semicolons.

It was rejected because i didn't discuss it here. So here i'm discussing it :slight_smile:

My proposal is simple: remove the semicolons in the end of lines.
It isn't needed and makes the code ugly.
It must be decided wether to use it or not for every project we start in the coding style.

What do you think?

Jo茫o Nunes

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Marc Knaup) #4

You should link to the proposal you've written.

The only instances of semicolons at the end of the line I had in my code in
the last months were placed there by mistake or when converting code from
ObjC.
First thing I do when migrating ObjC code to Swift is to "Find All" -> ";"
-> "Replace With" -> ""

I'm fine with allowing them only in C-style for loops and to separate
multiple statements on the same line, so +1 :slight_smile:
A migration can easily fix all of them at once.

路路路

On Sun, Dec 13, 2015 at 3:12 PM, Jo茫o Nunes <swift-evolution@swift.org> wrote:

Hi,

I submitted a PR with a proposal to remove the swift end of line
semicolons.

It was rejected because i didn't discuss it here. So here i'm discussing
it :slight_smile:

My proposal is simple: remove the semicolons in the end of lines.
It isn't needed and makes the code ugly.
It must be decided wether to use it or not for every project we start in
the coding style.

What do you think?

Jo茫o Nunes

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Chris Wood) #5

A word of warning on this - I鈥檝e just hit a case where an end of line semicolon is actually critical!

If you鈥檙e debugging and need an early exit from a function, you add 鈥渞eturn鈥 somewhere in the middle of the code. But return can take an argument, so the compiler takes the argument from the following line which you think won鈥檛 be executed. Bad things happen, followed by swearing.

So in that particular case, you do in fact need to write:

return;

There may be other edge cases where it鈥檚 necessary to explicitly mark the end of something in the same way.

Chris Wood

路路路

Hi,

I submitted a PR with a proposal to remove the swift end of line semicolons.

It was rejected because i didn't discuss it here. So here i'm discussing it :slight_smile:

My proposal is simple: remove the semicolons in the end of lines.
It isn't needed and makes the code ugly.
It must be decided wether to use it or not for every project we start in the coding style.

What do you think?

Jo茫o Nunes

Sent from my iPhone


(Arthur Ariel Sabintsev) #6

I'm also game for making them invalid syntax.

The only time I've seen `;` in my code is from my old Obj-C habit.

路路路

On Mon, Dec 14, 2015 at 12:25 PM Austin Zheng via swift-evolution < swift-evolution@swift.org> wrote:

Semicolons are already optional at the end of lines and only required to
separate multiple statements on the same line (and for C for loops, but
changing the grammar of those or removing them is a different topic.

If your proposal is to make a semicolon at the end of a single line
invalid syntax, that's fine with me, although it seems like an
unnecessarily small change to the grammar (and something better handled by
a linter). If your proposal is to remove the semicolon as a way to separate
multiple statements on the single line, then -1.

Austin

> On Dec 13, 2015, at 6:12 AM, Jo茫o Nunes via swift-evolution < > swift-evolution@swift.org> wrote:
>
> Hi,
>
> I submitted a PR with a proposal to remove the swift end of line
semicolons.
>
> It was rejected because i didn't discuss it here. So here i'm discussing
it :slight_smile:
>
> My proposal is simple: remove the semicolons in the end of lines.
> It isn't needed and makes the code ugly.
> It must be decided wether to use it or not for every project we start in
the coding style.
>
> What do you think?
>
> Jo茫o Nunes
>
>
> Sent from my iPhone
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
Best,

Arthur / Sabintsev.com


(Erica Sadun) #7

-1

I think end-of-line semicolons are ugly. I also think the decision to use them or not use them
should be left to individuals and not enforced by the compiler.

In the current implementation a semicolon can be optionally added after any statement and
is proactively used to separate statements on a single line. Changing the language to enforce
what appears to be a style choice is not something I'd support.

The issue with the return needing a semicolon sounds odd to me. I'm curious as to whether
that's something that needs fixing.

-- E

路路路

On Mar 16, 2016, at 9:25 AM, Chris Wood via swift-evolution <swift-evolution@swift.org> wrote:

A word of warning on this - I鈥檝e just hit a case where an end of line semicolon is actually critical!

If you鈥檙e debugging and need an early exit from a function, you add 鈥渞eturn鈥 somewhere in the middle of the code. But return can take an argument, so the compiler takes the argument from the following line which you think won鈥檛 be executed. Bad things happen, followed by swearing.

So in that particular case, you do in fact need to write:

return;

There may be other edge cases where it鈥檚 necessary to explicitly mark the end of something in the same way.

Chris Wood

Hi,

I submitted a PR with a proposal to remove the swift end of line semicolons.

It was rejected because i didn't discuss it here. So here i'm discussing it :slight_smile:

My proposal is simple: remove the semicolons in the end of lines.
It isn't needed and makes the code ugly.
It must be decided wether to use it or not for every project we start in the coding style.

What do you think?

Jo茫o Nunes

Sent from my iPhone

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Erica Sadun) #8

cc'ing the list back in to catch up on this.

-- E

路路路

On Mar 16, 2016, at 10:54 AM, Chris Wood <chris@interealtime.com> wrote:

I really need to remember the 鈥渞eply to all鈥 button for these mailing lists. *Facepalm* :slight_smile:

Chris

On Mar 16, 2016, at 4:25 PM, Chris Wood <chris@interealtime.com> wrote:

I suspect it does (haven鈥檛 tested it), but the chances of there being a function that returns Void and a line of code that returns Void are fairly good (especially in UI code).

Chris

On Mar 16, 2016, at 4:16 PM, Erica Sadun <erica@ericasadun.com> wrote:

Well that makes sense to me honestly unless you think there should be some condition that
a return value should at least start on the same line as the return keyword. Although you'd
think the closure would know if it's -> Void or -> T and parse the return accordingly

-- E

On Mar 16, 2016, at 9:37 AM, Chris Wood <chris@interealtime.com <mailto:chris@interealtime.com>> wrote:

Erica:

The return case is (supposedly) handled as a compiler warning. It does warn that code on following lines will be treated as an argument to the return call normally (it does in a simple test project or playground). Except in the code I鈥檓 working on, it didn鈥檛 warn and happily compiled (and there was much swearing as a result!)

That looks like a compiler bug, and I鈥檝e filed a radar (25192157) already.

Personally I think the compiler warning (when it works) and a trailing semicolon is acceptable in this case (as there may be a time when I want arguments to 鈥榬eturn鈥 on the next line for some obscure reason).

Chris Wood

On Mar 16, 2016, at 3:30 PM, Erica Sadun <erica@ericasadun.com <mailto:erica@ericasadun.com>> wrote:

-1

I think end-of-line semicolons are ugly. I also think the decision to use them or not use them
should be left to individuals and not enforced by the compiler.

In the current implementation a semicolon can be optionally added after any statement and
is proactively used to separate statements on a single line. Changing the language to enforce
what appears to be a style choice is not something I'd support.

The issue with the return needing a semicolon sounds odd to me. I'm curious as to whether
that's something that needs fixing.

-- E

On Mar 16, 2016, at 9:25 AM, Chris Wood via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

A word of warning on this - I鈥檝e just hit a case where an end of line semicolon is actually critical!

If you鈥檙e debugging and need an early exit from a function, you add 鈥渞eturn鈥 somewhere in the middle of the code. But return can take an argument, so the compiler takes the argument from the following line which you think won鈥檛 be executed. Bad things happen, followed by swearing.

So in that particular case, you do in fact need to write:

return;

There may be other edge cases where it鈥檚 necessary to explicitly mark the end of something in the same way.

Chris Wood

Hi,

I submitted a PR with a proposal to remove the swift end of line semicolons.

It was rejected because i didn't discuss it here. So here i'm discussing it :slight_smile:

My proposal is simple: remove the semicolons in the end of lines.
It isn't needed and makes the code ugly.
It must be decided wether to use it or not for every project we start in the coding style.

What do you think?

Jo茫o Nunes

Sent from my iPhone

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution


(Paul Ossenbruggen) #9

+1 I think that let people do whatever they want if i makes them happy when it makes the code less readable is not a good idea. I support the notion that semicolon should not be allowed at end of line. It does nothing to help readability of the code. If it does nothing, it should go. Swift code should be easy to read, and in this case clarity wins. We have to break the semicolon habit :slight_smile:

Perhaps providing a warning fix-it which removes them from the end of all lines in the file. I suspect most cases the only reason people put it there is habit or they are converting old code from another language.

- Paul


(Paul Cantrell) #10

+1 to 鈥渂etter handled by a linter.鈥 As with the 鈥渞equired self.鈥 proposal, this seems better suited to an external style checker than to a language rule.

SwiftLint can already generate warnings and errors that look exactly like compiler errors in Xcode for those who want the seamlessness of a language rule.

If the language provides a construct, there are always unforeseen consequences to not providing it in its full generality, even when good style dictates narrower usage. For example: this proposal might complicate Swift code generation. I know, code generation, who wants that, yuck, right? But there are time when it鈥檚 the right solution, and being able to just concatenate things with terminating semicolons and not have worry about an arbitrary EOL rule would make a generator鈥檚 job easier.

Cheers, P

路路路

On Dec 14, 2015, at 12:04 PM, Arthur Ariel Sabintsev via swift-evolution <swift-evolution@swift.org> wrote:

I'm also game for making them invalid syntax.

The only time I've seen `;` in my code is from my old Obj-C habit.

On Mon, Dec 14, 2015 at 12:25 PM Austin Zheng via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
Semicolons are already optional at the end of lines and only required to separate multiple statements on the same line (and for C for loops, but changing the grammar of those or removing them is a different topic.

If your proposal is to make a semicolon at the end of a single line invalid syntax, that's fine with me, although it seems like an unnecessarily small change to the grammar (and something better handled by a linter). If your proposal is to remove the semicolon as a way to separate multiple statements on the single line, then -1.

Austin

> On Dec 13, 2015, at 6:12 AM, Jo茫o Nunes via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
>
> Hi,
>
> I submitted a PR with a proposal to remove the swift end of line semicolons.
>
> It was rejected because i didn't discuss it here. So here i'm discussing it :slight_smile:
>
> My proposal is simple: remove the semicolons in the end of lines.
> It isn't needed and makes the code ugly.
> It must be decided wether to use it or not for every project we start in the coding style.
>
> What do you think?
>
> Jo茫o Nunes
>
>
> Sent from my iPhone
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org <mailto:swift-evolution@swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution
--
Best,

Arthur / Sabintsev.com
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Chris Wood) #11

Paul

The semicolon is actually needed still to avoid accidental multi-line statements. E.g. these functions behave differently:

func doNothing1() {
break
print(鈥淭his text gets printed鈥)
}
func doNothing2() {
break;
print(鈥淭his text isn鈥檛 printed鈥)
}

Until odd cases like this can be avoided, I think semicolons are still (though very rarely) necessary.

Chris

路路路

On Mar 17, 2016, at 3:25 PM, Paul Ossenbruggen <possen@gmail.com> wrote:

+1 I think that let people do whatever they want if i makes them happy when it makes the code less readable is not a good idea. I support the notion that semicolon should not be allowed at end of line. It does nothing to help readability of the code. If it does nothing, it should go. Swift code should be easy to read, and in this case clarity wins. We have to break the semicolon habit :slight_smile:

Perhaps providing a warning fix-it which removes them from the end of all lines in the file. I suspect most cases the only reason people put it there is habit or they are converting old code from another language.

- Paul


(Chris Wood) #12

Sorry, that was a terrible example which doesn鈥檛 work (typing code into an email at this point in the afternoon isn鈥檛 a good idea it seems!)

I made a simple example project to show the issue. Two methods in the view controller, different behaviour depending on the trailing semicolon:

http://interealtime.com/misc/Semicolon.zip

This scenario would be 鈥榳rong鈥 in general code, but is pretty common during debugging - and that trailing semicolon is actually necessary in this case (I hit this for real yesterday).

Chris

路路路

On Mar 17, 2016, at 3:44 PM, Chris Wood <chris@interealtime.com> wrote:

Paul

The semicolon is actually needed still to avoid accidental multi-line statements. E.g. these functions behave differently:

func doNothing1() {
break
print(鈥淭his text gets printed鈥)
}
func doNothing2() {
break;
print(鈥淭his text isn鈥檛 printed鈥)
}

Until odd cases like this can be avoided, I think semicolons are still (though very rarely) necessary.

Chris

On Mar 17, 2016, at 3:25 PM, Paul Ossenbruggen <possen@gmail.com> wrote:

+1 I think that let people do whatever they want if i makes them happy when it makes the code less readable is not a good idea. I support the notion that semicolon should not be allowed at end of line. It does nothing to help readability of the code. If it does nothing, it should go. Swift code should be easy to read, and in this case clarity wins. We have to break the semicolon habit :slight_smile:

Perhaps providing a warning fix-it which removes them from the end of all lines in the file. I suspect most cases the only reason people put it there is habit or they are converting old code from another language.

- Paul


(Paul Ossenbruggen) #13

This seems like unexpected behavior and if the user intended it to return a value, it should be moved to the return line. The compiler is smart enough to warn about it and the warning goes away when you move the line up. If there is an issue where they need something that spans multiple lines putting it parenthesis would allow that.

聽聽@IBAction func makeRed() {
聽聽聽聽return
self.view.backgroundColor = UIColor.redColor()
聽聽}

路路路

On Mar 17, 2016, at 9:12 AM, Chris Wood <chris@interealtime.com> wrote:

Sorry, that was a terrible example which doesn鈥檛 work (typing code into an email at this point in the afternoon isn鈥檛 a good idea it seems!)

I made a simple example project to show the issue. Two methods in the view controller, different behaviour depending on the trailing semicolon:

http://interealtime.com/misc/Semicolon.zip

This scenario would be 鈥榳rong鈥 in general code, but is pretty common during debugging - and that trailing semicolon is actually necessary in this case (I hit this for real yesterday).

Chris

On Mar 17, 2016, at 3:44 PM, Chris Wood <chris@interealtime.com> wrote:

Paul

The semicolon is actually needed still to avoid accidental multi-line statements. E.g. these functions behave differently:

func doNothing1() {
聽聽聽聽break
聽聽聽聽print(鈥淭his text gets printed鈥)
}
func doNothing2() {
聽聽聽聽break;
聽聽聽聽print(鈥淭his text isn鈥檛 printed鈥)
}

Until odd cases like this can be avoided, I think semicolons are still (though very rarely) necessary.

Chris

On Mar 17, 2016, at 3:25 PM, Paul Ossenbruggen <possen@gmail.com> wrote:

+1 I think that let people do whatever they want if i makes them happy when it makes the code less readable is not a good idea. I support the notion that semicolon should not be allowed at end of line. It does nothing to help readability of the code. If it does nothing, it should go. Swift code should be easy to read, and in this case clarity wins. We have to break the semicolon habit :slight_smile:

Perhaps providing a warning fix-it which removes them from the end of all lines in the file. I suspect most cases the only reason people put it there is habit or they are converting old code from another language.

- Paul