From ccfea3af030160a547988736174ca109e4bd7c07 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sat, 24 Oct 2020 22:12:52 -0600 Subject: move the C comparison to its own file --- index.md | 71 ++++------------------------------------------------------------ vs-c.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 67 deletions(-) create mode 100644 vs-c.md diff --git a/index.md b/index.md index 6093de8..b63a778 100644 --- a/index.md +++ b/index.md @@ -6,73 +6,6 @@ Crowbar is a language that is derived from (and, wherever possible, interoperabl Ideally, a typical C codebase should be straightforward to rewrite in Crowbar, and any atypical C constructions not supported by Crowbar can be left as C. -# Removals - -Some of the footguns and complexity in C come from misfeatures that can simply not be used. - -## Footguns - -### Almost Always The Wrong Thing - -- `goto` -- Octal literals -- Hexadecimal float literals -- Wide characters -- Digraphs -- Prefix `++` and `--` -- Chaining mixed left and right shifts (e.g. `x << 3 >> 2`) -- Chaining relational/equality operators (e.g. `3 < x == 2`) -- Mixed chains of bitwise or logical operators (e.g. `2 & x && 4 ^ y`) -- The comma operator `,` - -### Explicit Beats Implicit - -- `typedef` -- Octal escape sequences -- Using an assignment operator (`=`, `+=`, etc) or (postfix) `++` and `--` as components in a larger expression -- The conditional operator `?:` -- Preprocessor macros (but constants are fine) - -## Needless Complexity - -### Let The Compiler Decide - -- `inline` -- `register` - -### Who Even Cares - -- `restrict` -- `volatile` -- `_Imaginary` - -# Adjustments - -Some C features are footguns by default, so Crowbar ensures that they are only used correctly. - -- Unions are not robust by default. - Crowbar only supports unions when they are [tagged unions](tagged-unions.md). - -C's syntax isn't perfect, but it's usually pretty good. -However, sometimes it just sucks, and in those cases Crowbar makes changes. - -- C's variable declaration syntax is far from intuitive in nontrivial cases (function pointers, pointer-to-`const` vs `const`-pointer, etc). - Crowbar uses [simplified type syntax](types.md) to keep types and variable names distinct. -- `_Bool` is just `bool`, `_Complex` is just `complex` (why drag the preprocessor into it?) -- Adding a `_` to numeric literals as a separator -- All string literals, char literals, etc are UTF-8 - -# Additions - -## Anti-Footguns - -- C is generous with memory in ways that are unreliable by default. - Crowbar adds [memory safety guarantees](safety.md) to make correctness the default behavior. - -## Trivial Room For Improvement - -- Binary literals, prefixed with `0b`/`0B` - # Context - [Rust is not a good C replacement](https://drewdevault.com/2019/03/25/Rust-is-not-a-good-C-replacement.html) @@ -83,6 +16,10 @@ However, sometimes it just sucks, and in those cases Crowbar makes changes. - [Crowbar: Simplifying C's type names](https://www.boringcactus.com/2020/10/13/crowbar-2-simplifying-c-type-names.html) - [Crowbar: Turns out, language development is hard](https://www.boringcactus.com/2020/10/19/crowbar-3-this-is-tough.html) +# Comparison with C + +The [comparison with C](vs-c.md) is an informal overview of the places where Crowbar and C diverge. + # Syntax [Read the Syntax chapter of the spec.](syntax.md) diff --git a/vs-c.md b/vs-c.md new file mode 100644 index 0000000..60d7905 --- /dev/null +++ b/vs-c.md @@ -0,0 +1,68 @@ +What differentiates Crowbar from C? + +# Removals + +Some of the footguns and complexity in C come from misfeatures that can simply not be used. + +## Footguns + +### Almost Always The Wrong Thing + +- `goto` +- Octal literals +- Hexadecimal float literals +- Wide characters +- Digraphs +- Prefix `++` and `--` +- Chaining mixed left and right shifts (e.g. `x << 3 >> 2`) +- Chaining relational/equality operators (e.g. `3 < x == 2`) +- Mixed chains of bitwise or logical operators (e.g. `2 & x && 4 ^ y`) +- The comma operator `,` + +### Explicit Beats Implicit + +- `typedef` +- Octal escape sequences +- Using an assignment operator (`=`, `+=`, etc) or (postfix) `++` and `--` as components in a larger expression +- The conditional operator `?:` +- Preprocessor macros (but constants are fine) + +## Needless Complexity + +### Let The Compiler Decide + +- `inline` +- `register` + +### Who Even Cares + +- `restrict` +- `volatile` +- `_Imaginary` + +# Adjustments + +Some C features are footguns by default, so Crowbar ensures that they are only used correctly. + +- Unions are not robust by default. + Crowbar only supports unions when they are [tagged unions](tagged-unions.md). + +C's syntax isn't perfect, but it's usually pretty good. +However, sometimes it just sucks, and in those cases Crowbar makes changes. + +- C's variable declaration syntax is far from intuitive in nontrivial cases (function pointers, pointer-to-`const` vs `const`-pointer, etc). + Crowbar uses [simplified type syntax](types.md) to keep types and variable names distinct. +- `_Bool` is just `bool`, `_Complex` is just `complex` (why drag the preprocessor into it?) +- Adding a `_` to numeric literals as a separator +- All string literals, char literals, etc are UTF-8 + +# Additions + +## Anti-Footguns + +- C is generous with memory in ways that are unreliable by default. + Crowbar adds [memory safety guarantees](safety.md) to make correctness the default behavior. + +## Trivial Room For Improvement + +- Binary literals, prefixed with `0b`/`0B` -- cgit v1.2.3