4 ms·
If you don't count the unsafe sublanguage, Rust, SML, OCaml, Scheme, Java, and Lua all have simpler semantics than C, and that's just off the top of my head. It
by pcwalton 10y ago
If you don't count the unsafe sublanguage, Rust, SML, OCaml, Scheme, Java, and Lua all have simpler semantics than C, and that's just off the top of my head. It's debatable, but I would even argue that Haskell and Swift do. Undefined behavior is really subtle, and there are parts of the spec that compiler developers haven't even come to consensus regarding the meaning of.
- tikhonj 10y agoStandard Haskell (ie Haskell 2010[1]) certainly is. Most of its features are just syntax sugar over a tiny core language with simple (although not 100% formalized) denotational semantics. The language itself isn't very big and it's pretty well-specified. GHC Haskell with all extensions... euh, I don't know. Many extensions are either syntactic sugar or straightforward changes to the base language, sometimes even making it simpler. But I'm not confident about all of them, and I'm not sure how the semantics of some low-level libraries (ie for concurrency) work out. I've written code in essentially just the standard subset and it's a pleasant language—there aren't any extensions that you absolutely must use in real projects. That said, people use lots of them anyhow because most make the language nicer without adding too much complexity. Since the extensions aren't organized in a unified way and have to be split up (since they can generally be enabled or disabled independently), it's hard to figure out how complex they make the semantics of the language as a whole. [1]: https://www.haskell.org/onlinereport/haskell2010/ https://www.haskell.org/onlinereport/haskell2010/
- gajjanag 10y agoI have not implemented a compiler so I can't really judge on that aspect. Isn't it also true that undefined behavior can stem from varying hardware/platform considerations? In particular, leaving some things judiciously undefined allows flexibility in implementations and thus can give good performance across a variety of platforms. Sure, one could force some precise semantics, but that might result in unnecessary "emulation" code on some platforms. So at a programming language level, by having such emulation/fixed behavior, the semantics are simpler. But at a low level, the semantics are more complicated as the machine instructions may differ significantly, thus losing transparency. This is a concern in quite a few resource constrained applications. For a simple example, see http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html http://blog.llvm.org/2011/05/what-every-c-programmer-should-... and the section on oversized shift amounts.