News for hackers. Stuff that matters.
Re:Swift – observations from Rust’s original designer by xixixao on Monday June 02, 2014 @10:31PM (#7837830)
Funny how this just falls out of JS (in CS):

  if concrete = optional
    call concrete
Re:Swift – observations from Rust’s original designer by stormbrew on Monday June 02, 2014 @11:03PM (#7837928)
Pretty much every language to date allows this construct. And it's often considered a bad idea in languages where = is assignment because it's so easy to get it confused with == and accidentally assign to the thing you're trying to compare to, which will usually evaluate to truthy.

The special things about the way it works in Swift are:

- You have to put let in front, thus avoiding the confusion.

- If the RHS is optional it unwraps the option for the success branch, but the variable is not available in any other scope, thus ensuring safe use.

In JS, C, CS, Ruby, etc. you're not really doing anything useful if you assign a value to another name just for one branch of an if statement. In Swift you are.

Re:Swift – observations from Rust’s original designer by tveita on Tuesday June 03, 2014 @08:21AM (#7839643)
That's a bad idea if "optional" is a number, a boolean or a string.