aboutsummaryrefslogtreecommitdiff
path: root/index.md
blob: 4a924068b8f32fb91ab34af2f4dfb5416b1d60b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Crowbar: the good parts of C, with a little bit extra.

**This is entirely a work-in-progress, and should not be relied upon to be stable (or even true) in any way.**

Crowbar is a language that is derived from (and, wherever possible, interoperable with) C, and aims to remove as many [footgun](https://en.wiktionary.org/wiki/footgun)s and as much needless complexity from C as possible while still being familiar to C developers.

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)

# cactus's Blog Posts

- [Crowbar: Defining a good C replacement](https://www.boringcactus.com/2020/09/28/crowbar-1-defining-a-c-replacement.html)
- [Crowbar: Simplifying C's type names](https://www.boringcactus.com/2020/10/13/crowbar-2-simplifying-c-type-names.html)

# Syntax

[Read the Syntax chapter of the spec.](syntax.md)

# Semantics

TODO

[![Creative Commons BY-SA License](https://i.creativecommons.org/l/by-sa/4.0/80x15.png)](http://creativecommons.org/licenses/by-sa/4.0/)