News for hackers. Stuff that matters.
Re:Is Apple Using Swift? by stormbrew on Monday January 18, 2016 @04:11PM (#10926977)
I don't think it's trying to be syntactically better than C++. It's an improvement in semantics. Once you unwrap an optional with "if let", it cannot cause an access violation.

You seem to be insisting on using ! and then blaming the language for letting you shoot your foot off with it...

Re:Is Apple Using Swift? by billconan on Monday January 18, 2016 @04:28PM (#10927100)
Sorry, I don't get it.

the example you gave is like the following c++ code:

XXX *object = null;

if ((object = anotherpointer) != NULL)

{ ... }

The point is, ! is only useful, when it can detect null pointers during compiling time. but it doesn't.

the way ! is used, as suggested by your example, is also doable in C++, it is just a habit thing.

in c++, with good habit, you won't have problem. in Swift with bad habit, you will have the same problem.

then what good is !,

Re:Is Apple Using Swift? by stormbrew on Monday January 18, 2016 @06:20PM (#10927744)
No, you don't seem to be getting what I'm saying. I'm saying don't use !, and showing you how to avoid using it in a common pattern. Using 'if let' instead of ! does give you compile time verification of correctness.

! is there for the small number of cases where that's not possible. And it makes it much more obvious where you've got a potential problem, because the '!' is a literal code smell. You can't really do that with c++.

Re:Is Apple Using Swift? by yoz-y on Tuesday January 19, 2016 @07:55AM (#10930366)
Ever since the guard statement was introduced I think you should never, ever use the ! as operator. It still has some sense when using as a type, for example for IBOutlets.