Semicolons

Anyone know if they're "unnecessary but allowed", or if I'm going to have syntax errors on like 60% of my lines of code?

Posted Jun 2, 2014, 8:44 PM UTC

35
Fustrate•

Just read this in the language guide:

Unlike many other languages, Swift does not require you to write a semicolon (;) after each statement in your code, although you can do so if you wish. Semicolons are required, however, if you want to write multiple separate statements on a single line.

So yes, you can type semicolons if it's more comfortable to you - Swift won't complain.

5
discohead•

I'm sure it will eventually be considered bad style though.

2
jadengore•

Be careful what you say! JavaScript tools and JSHint niggle you for the semicolon, but a lot of Node applications are forgoing semicolons entirely.

A reverse opinion, but a valid point. These scripting languages don't need semicolons as long as the programmer knows WHEN THEY NEED THEM.

0
discohead•

If Apple doesn't use semicolons in their documentation neither will most developers.

3
fommerjackson•

According to the documentation, you MUST use semicolons when writing separate statements on a single line. Not sure then how it would handle a semicolon on a line with one statement.

2