Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

The Clark

macrumors 6502a
Original poster
Dec 11, 2013
999
2,822
Canada
I've done a little bit of research and different people have different opinions. I come from a programming background and it feels very unnatural to not include a semi-colon at the end of a statement. I would prefer to write a semi-colon but is that seen as bad practice? Does it have any effect on the performance or efficiency?

Do you guys (and gals) include semi-colons?

Thanks.
 
I'm not familiar with Swift, but in other languages, you should include a semicolon if a lack of one sometime means something different, as in JavaScript.

In JavaScript, it'll attempt to automatically join consecutive lines if you don't have a semicolon. It'll only add in a semicolon if implicitly joining the lines together would result in invalid syntax. This can result in really weird and hard to track bugs, so in JavaScript, you should always end lines in semicolons, even though they're supposedly optional in the language.

In Python, if you don't end a line in a semicolon, one will be added automatically. So in Python, semicolons are completely pointless and the best practice is to never use them. They're just meaningless clutter in Python.

So with Swift, you need to find out whether the presence of a semicolon ever changes how things are interpreted or not. If it never impacts it, then the best practice is to leave them off. If it sometimes impacts it, then the best practice is to always use them.

There is no language where mixing semicolons and non-semicolons is a good practice.
 
I've done a little bit of research and different people have different opinions. I come from a programming background and it feels very unnatural to not include a semi-colon at the end of a statement. I would prefer to write a semi-colon but is that seen as bad practice? Does it have any effect on the performance or efficiency?

Do you guys (and gals) include semi-colons?

Thanks.
Do not include a semi colon. This helps my brain separate the languages. Including a semi colon has absolutely no effect on performance or efficiency. You could ask the same about coding using K&R. I absolutely hate looking over code from someone that chooses NOT to include brackets for single line functions, just because they can, but that is me.

Swift convention is no semicolons.
 
Do not include a semi colon. This helps my brain separate the languages. Including a semi colon has absolutely no effect on performance or efficiency. You could ask the same about coding using K&R. I absolutely hate looking over code from someone that chooses NOT to include brackets for single line functions, just because they can, but that is me.

Swift convention is no semicolons.

Okay thank you. If it's convention I'll follow it.
 
Okay thank you. If it's convention I'll follow it.

Unless you're working as part of a team with well-defined code layout conventions, the person with the greatest need to read and understand your code is you. If you find semicolons helpful or comforting, include them. They won't have the slightest effect on the operation or efficiency of the program, and stripping them out, should the need arise, is trivial.

If the worst thing a "language lawyer" can say about your code is that you've used unnecessary semicolons or deviated from the One True Brace Style then you're comfortably ahead of the game.

Remember the words of Sir Terry Pratchett: rules are there to make you think before you break them.

Only danger is that the Swift designers seem determined to expunge all trace of C nostalgia from Swift, so once they've dumped the '++ & --' operators and the 'for(;;)' loop (planned for Swift 3) it wouldn't be surprising if they come for the semicolons next (since the 'for' loop was the thing that needed them).
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.