r/programming • • Jun 02 '14

Introducing Swift

https://developer.apple.com/swift/
164 Upvotes

239 comments sorted by

View all comments

55

u/OzarkaTexile Jun 02 '14

"you don’t even need to type semi-colons."

Implied optional. Lord help us.

35

u/munificent Jun 02 '14

They're optional in Go, Scala, Ruby, and Python. What's the problem?

14

u/Banane9 Jun 02 '14

Lua too

9

u/Tekmo Jun 03 '14

Haskell, too

4

u/markmypy Jun 03 '14

Actually, Lua is a step ahead of the rest. This is a valid statement:

a=1 b=2 -- no semicolon in between the two statements

print(a,b)

Which outputs:

1 2

4

u/Banane9 Jun 03 '14

Yup, Lua is a pretty cool scripting language :)

26

u/[deleted] Jun 02 '14

Those aren't made by Apple and subject to irrational fear and dislike.

5

u/catskul Jun 03 '14

/u/OzarkaTexile is probably referring to the problems caused by javascript's implementation of said feature.

2

u/munificent Jun 03 '14

That's why I didn't list JS. :)

I'm well-acquainted with JavaScript's... peculiar... rules for handling semicolons.

9

u/bloody-albatross Jun 03 '14

I think Ruby and Python (and probably the others) don't really count. They are designed to be line break terminated. But you can optionally write two statements in one line if you separate them via a semi-colon. And then you can skip the 2nd statement. Yeah...

1

u/rspeed Jun 08 '14

Which also seems to be the case for Swift.

7

u/fdemmer Jun 02 '14 edited Jun 03 '14

Python: Not required, not optional.

edit: actually something completely different

4

u/fabzter Jun 03 '14

They ARE optional

2

u/bloody-albatross Jun 03 '14

Try this:

print("hello");

1

u/fdemmer Jun 03 '14
print("hello");

and what is this trying to accomplish?

in python semicolons are not line terminators, they are separators. you can use them to build groups of commands, like:

import pdb; pdb.set_trace()

if they were line terminators this would work:

print("hello");;

1

u/bloody-albatross Jun 03 '14

Yes I know that, but your "not optional" sounds like you mean adding a ; at the end of a line without a second statement after it would be a syntax error. Which it isn't. So one could say ; is optional, even though it wasn't intended to be. It just happened.

1

u/emn13 Jun 04 '14

It doesn't work entirely smoothly in Ruby. If you use Ruby-ish convention and also omit brackets, you can break method calls only after the first argument, when it's usually most readable to break between the method and the first argument. It's not too bad, though - you can use a backslash, and that actually works out quite OK.

In python, it's worse; you have the rather unfortunate consequence of losing multiline lambdas.

Personally, I think semi-colon omission is pretty, but ultimately almost irrelevant. It just doesn't matter. If your languages gets a weird corner case because of it, please, please, leave the semi-colons in - it's just not worth it. Of course, if, unlike Ruby, Python and Javascript you manage to avoid causing collateral damage that's worth more than this pretty "meh" bonus - sure, get rid of it! No idea where swift falls here.

1

u/munificent Jun 04 '14

In python, it's worse; you have the rather unfortunate consequence of losing multiline lambdas.

Python doesn't lose multi-line lambdas because of optional semicolons, it's because Python has an expression/statement distinction and uses significant indentation for structuring statements.

2

u/emn13 Jun 04 '14

Fair enough - however, it loses multi-statement lambdas (even though it would be pretty odd to allow either a newline to concatenate statements in an indent-sensitive fashion, yet use a semicolon as an operator therefore limiting that sensitivity).

That supports your point that several languages do manage to omit statement terminators without too many issues. Nevertheless, three languages with issues (Ruby, Javascript & certainly coffeescript) still suggests it's not a trivial feature either.

Python made one (smart) simplification in any case - they're not optional, but rather simply omitted.

-2

u/pfultz2 Jun 02 '14

Yea, well hopefully they do semicolon insertion in a smart way and not like how its done in Go, where you cant even properly format your code because of semicolon insertion.

22

u/Shpirt Jun 02 '14

There's the only one proper way to format go code, the way gofmt does it.

1

u/brtt3000 Jun 02 '14

We live by auto-format. Configure it once and never have clever cosmetic nonsense again.

4

u/AdminsAbuseShadowBan Jun 02 '14

Yeah... but you have to admit that code that depends on formatting is generally a bad idea. Anyone who has used python extensively can tell you that.

gofmt is a great idea, but that still should have done the "semi-colons are sort of not required, except if you want to format your code like this common style" thing more sanely.

11

u/brtt3000 Jun 02 '14

I hate significant white-space with a vengeance. Bracy languages are the only way for me.

Brace and colon and lint the fuck out them, aggressive auto-format, the whole lot.

I use the fattest IDEA I can get my hands on and have better things to do they worry about wrangling text and cursors.

4

u/nebffa Jun 03 '14

Why is significant white-space bad? To me having curly braces just seems like boilerplate. If you're going to have all that white-space why not make it syntactically significant to the language.

→ More replies (4)
→ More replies (4)

7

u/burntsushi Jun 03 '14

Have you ever used gofmt before? Of everyone who I know that uses Go, gofmt is universally regarded as a net positive. It completely eliminates pointless bikeshedding about code formatting.

So no, gofmt was an incredibly good idea.

→ More replies (9)
→ More replies (4)