News for hackers. Stuff that matters.
Re:Don’t assume that safety comes for free: a Swift case study by mikeash on Tuesday December 06, 2016 @01:31PM (#13117030)
I'm puzzled by how many people want their programs to just keep on trucking and try their best after something unexpected occurs.

Crashing is not the worst thing your program can do. In fact, I'd argue that it's the second-best thing your program can do, right behind working correctly. Losing data is much worse than crashing, and corrupting data is worse still. Both are strong possibilities once your program's state is something unexpected.

Re:Don’t assume that safety comes for free: a Swift case study by arcticbull on Tuesday December 06, 2016 @01:48PM (#13117167)
I agree and disagree. What the author says is true, if a thoroughly irrelevant part of your program (let's say a drawing routine for UI somewhere) hits an overflow and crashes your app in the middle of taking a payment, or in the middle of surgery -- while that much more critical element continued to work perfectly -- that's not ideal.

Not all parts of your app make sense to fail-fast. By enforcing this behavior even on peripheral parts of your app, you're taking away the decision making ability about what's important and what isn't from the system designer.

I understand that position, though I still think on the whole explicitness is right. Being able to explicitly disable the check when you know what you want is the right balance, whether it's &+ in Swift or (better, imo) .wrapping_add() in Rust.

Re:Don’t assume that safety comes for free: a Swift case study by mikeash on Tuesday December 06, 2016 @02:04PM (#13117307)
Displaying corrupt data in the UI can be just as bad as saving it to disk, if the user actually reads and uses the data you display (and if not, why are you displaying it?).

And since the UI almost certainly shares data with the rest of the program, bugs in the UI can corrupt the underlying data.

Separation of concerns is great, but if you really want different parts of your system to have different reliability constraints, then you need to truly separate them, for example by running them in different processes. Running them in the same process but having some of the code be more lax about state because it's less important is just begging for horrible bugs.

Re:Don’t assume that safety comes for free: a Swift case study by lomnakkus on Tuesday December 06, 2016 @02:15PM (#13117389)
> Separation of concerns is great, but if you really want different parts of your system to have different reliability constraints, then you need to truly separate them, for example by running them in different processes. Running them in the same process but having some of the code be more lax about state because it's less important is just begging for horrible bugs.

Indeed, and you might even want to run them on entirely different and independent systems (connected by some type of network/bus) depending on exactly what bits are critical vs. non-critical.

Re:Don’t assume that safety comes for free: a Swift case study by IgorPartola on Tuesday December 06, 2016 @08:14PM (#13119744)
Why can't it be opt-in instead of opt-out? Or can we have more granular control overall? On an application, module, class, function, and block level? That way my super tight hit loop that I can prove does not overflow gets a 2x speed up, while the rest of the code is safe. Oh and I can always recompile it to be always safe and analyze crashes in the real world, no t just my silly unit tests that amount to 2 + 2 == 4.
Re:Don’t assume that safety comes for free: a Swift case study by stouset on Tuesday December 06, 2016 @10:25PM (#13120212)
Continuing on as a default is dangerous, and has led to hundreds of thousands of security vulnerabilities. Not continuing is inconvenient, but safe.
Re:Don’t assume that safety comes for free: a Swift case study by emodendroket on Tuesday December 06, 2016 @11:08PM (#13120403)
Maybe it's time to bring back VB6 and On Error Resume Next.
Re:Don’t assume that safety comes for free: a Swift case study by flukus on Tuesday December 06, 2016 @11:17PM (#13120423)
It never went away, now it's just "catch (Exception) { }" spread liberally throughout the code base.
Re:Don’t assume that safety comes for free: a Swift case study by vurpo on Wednesday December 07, 2016 @02:15AM (#13121039)
How to fix all errors in Python:

  try:
    #your code goes here
  except:
    pass
Re:Don’t assume that safety comes for free: a Swift case study by emodendroket on Wednesday December 07, 2016 @09:27AM (#13122701)
Well, technically the behavior of that is somewhat different.
Re:Don’t assume that safety comes for free: a Swift case study by fabian2k on Tuesday December 06, 2016 @02:42PM (#13117631)
One issue is that failures are not necessarily contained. An error in a less important area could still corrupt the state of something more important.

The most convincing take on this I've seen is Erlang/Elixir. You generally fail fast there, but each program is composed of many different, isolated processes. No matter how a single process fails, it won't affect any other independent processes. A stopped process only takes down those processes that depend on it, everything else continues. And Supervisors can restart the failed processes from a known good state again.

Re:Don’t assume that safety comes for free: a Swift case study by kibwen on Tuesday December 06, 2016 @07:23PM (#13119478)

  > Being able to explicitly disable the check when you know 
  > what you want is the right balance, whether it's &+ in 
  > Swift or (better, imo) .wrapping_add() in Rust.
To clarify, Rust does disable the overflow check in release mode (and the benchmarks shown in this post are exactly why, to much heated debate), wrapping instead. `.wrapping_add()` in Rust is just what you use in order to guarantee wrapping behavior in debug mode as well (and also to guard against future changes to the language specification, which currently allows implementations to choose to either panic or wrap on overflow). In order to get the behavior of Swift's basic `+` in Rust, you'd use `.checked_add().unwrap()`.
Re:Don’t assume that safety comes for free: a Swift case study by arcticbull on Tuesday December 06, 2016 @08:28PM (#13119803)
Of course, you're right -- which is a behavior I'm even more in favor of, wherein your debug builds fail fast all the time but your release builds don't.
Re:Don’t assume that safety comes for free: a Swift case study by xenadu02 on Tuesday December 06, 2016 @05:43PM (#13118943)
It comes from mistakenly architecting systems as monolithic entities. No one would run a major website serving millions of users on a single piece of hardware. Why do applications stuff everything into a single process? Applications can and should be broken up into multiple pieces. The Web Browser is a great example - run each tab in its own process. Run WebGL in yet another process. Our tools could make this a lot easier.

FTIW Swift may not necessarily need to bring down the entire process anyway. When it gets a concurrency story where the compiler can enforce thread boundaries at compile time it could be paired with separate heaps per thread to allow a single thread to abort without aborting the entire process. That would be ideal for the server case.

Re:Don’t assume that safety comes for free: a Swift case study by ArkyBeagle on Tuesday December 06, 2016 @05:37PM (#13118910)
You ( in the we sense of "you") cannot categorically say which is better.

The decision between "keep on trucking" and crashing is a design choice, and will have to be balanced against other considerations.

Re:Don’t assume that safety comes for free: a Swift case study by mikeash on Tuesday December 06, 2016 @10:29PM (#13120238)
If a language is going to have a default behavior, then it can't be a design choice that balances other considerations, because it has no idea what context it might be used in. The best option then is to default to safety, and allow the programmer to choose other behaviors if they need them.
Re:Don’t assume that safety comes for free: a Swift case study by ArkyBeagle on Wednesday December 07, 2016 @10:55PM (#13128311)
I think it's up to the end developers to decide that the behaviors are. You/I don't know that the best option is to default to "safety" - because we lack the information necessary to make that decision.

And yet again - this is UB because the original writers of the C language knew that the behavior of the hardware would be known to assembly programmers of the time.

Re:Don’t assume that safety comes for free: a Swift case study by mikeash on Thursday December 08, 2016 @09:48AM (#13130569)
You either have to pick a default, or you have to forbid developers from writing a + operation unless they first choose an overflow behavior. I can see arguments for the latter, but it's not a common choice.