6 ms·
I have to say, strictly as an uninformed outsider, this bit of nastiness is just pushing Go, Rust and even Swift higher on my priorities list. I don't think I'
by hinkley 11y ago
I have to say, strictly as an uninformed outsider, this bit of nastiness is just pushing Go, Rust and even Swift higher on my priorities list.
I don't think I'm the only one.
- ktRolster 11y agoWell then, don't look too deeply at the nastiness in Go, Rust, and Swift.
- dsfuoi 11y agoCan you elaborate? Hopefully they don't have straight UB do they?
- ktRolster 11y agoHopefully they don't have straight UB do they? Yes, most languages do, unless they are formally defined (ML is formally defined, but most other languages are not. In this book http://www.amazon.com/Masterminds-Programming-Conversations-Creators-Languages/dp/0596515170 http://www.amazon.com/Masterminds-Programming-Conversations-... several of the language creators say that fully defining the language formally is not worth the effort).
- zokier 11y agoWell, Rust for example does not have a formal well-defined behavior to start with, so its kinda fuzzy about UB too. And of course `unsafe` is another story altogether.
- mastax 11y agoCan you elaborate? The rust docs [1] seem to disagree: Unlike C, Undefined Behavior is pretty limited in scope in Rust. All the core language cares about is preventing the following things: - Dereferencing null or dangling pointers - Reading uninitialized memory - Breaking the pointer aliasing rules - Producing invalid primitive values: - dangling/null references - a bool that isn't 0 or 1 - an undefined enum discriminant - a char outside the ranges [0x0, 0xD7FF] and [0xE000, 0x10FFFF] - A non-utf8 str - Unwinding into another language - Causing a data race And all of those things require `unsafe`, so safe rust cannot do any of them (barring compiler or unsafe library or OS bugs). Edit: And I must admit I don't know much about language theory or formal definition, but there is also a self-described formal grammar [2]. [1]: https://doc.rust-lang.org/nomicon/races.html https://doc.rust-lang.org/nomicon/races.html [2]: https://doc.rust-lang.org/grammar.html https://doc.rust-lang.org/grammar.html
- ArkyBeagle 11y agoI think the best way to approach this question is the see CAR Tony Hoare's "Billion Dollar Mistake" talk. A fellow stands up at the end and says, in detail, something that can be summarized as "it's all golden until you invoke the I/O monad."
- marcosdumay 11y agoWhat do those languages return when you calculate MAX_INT + 1?
- steveklabnik 11y agoIn Rust: let x = std::u32::MAX + 1; This line will generate a warning upon build, and in a debug build, will panic. In a release build, it will overflow.
- drewcrawford 11y agoIn Swift: let a = Int.max + 1 Produces a compile error as the overflow is within Swift's conception of a "literal expression". If we step out to a case where the overflow is not trivially a literal expression: func foo(a: Int) -> Int { return Int.max + a } foo(1) This causes a runtime assertion failure in optimized or unoptimized builds. There is a (rarely-used) "Ounchecked" optimization level for which this program produces UB.
- ArkyBeagle 11y agoI'd say that staying an uninformed outsider is an excellent choice.
- hinkley 11y agoThe list of things I wanted to learn in my life is halfway to the horizon now. I'm good.
- PeCaN 11y agoYou might want to check out Ada, D, and OCaml too. Ada is as safe as Rust and lower-level but very fast and very mature. It gets a bit of a bad rap for being ugly, but after a couple hours the Pascal-ish syntax is not any uglier than C. The type system is much less expressive than Rust's, however, which makes a lot of things more awkward. What you lose in conciseness you make up for in performance and readability. Ada does require you to be extremely explicit about everything, which many people do not like. Still, if you're looking for a language around the abstraction level of C but safe and easily auditable, Ada is a quite well-designed language. D is basically C++25. There's still some undefined behavior, but you hit it much less often. Also it has excellent metaprogramming support. It is not as safe as Rust, but a little safer than C++. Overall it's a very pleasant language if you're a C programmer and want something higher-level. OCaml also has a syntax that many people find unpleasant at first. Personally I got over that pretty fast and now fine ML syntaxes beautiful. OCaml is essentially garbage-collected Rust with prettier syntax. It has predictable performance (in the sense of being fairly easy to predict what the compiler will generate—the GC will make actual runtime performance a little unpredictable, but isn't bad; probably because OCaml programs tend to involve much less GC pressure than Java or C#). I don't think Go should be lumped in with those languages though. It is not very safe (it has a terrible error-handling mechanism and doesn't isolate unsafe code particularly well), it has a large runtime and slow generated code, it offers piss-poor abstractions, etc. If Go becomes the next popular systems language, language design will be set back another 30 years.
- steveklabnik 11y agoHow is Ada lower-level than Rust? I don't really know Ada. I'm also interested in the performance comparison, we're usually neck and neck with C and C++ already.
- alricb 11y agoIt's pretty low level: you can specify the layout of a record in detail, for instance: http://www.ada-auth.org/standards/12rm/html/RM-13-5-1.html http://www.ada-auth.org/standards/12rm/html/RM-13-5-1.html It also has support for hardware interrupts and real time programming.
- coldnose 11y agoYou may want to check out hypertalk, algol, prolog, and simula 67 too.