Jonathan Müller Profile Banner
Jonathan Müller Profile
Jonathan Müller

@foonathan

11,811
Followers
73
Following
220
Media
10,257
Statuses

C++, compilers, and programming languages. Library developer @thinkcell , assistant chair for std::ranges at @isocpp . @foonathan @fosstodon .org

Aachen, Germany
Joined September 2014
Don't wanna be here? Send us removal request.
@foonathan
Jonathan Müller
4 years
"How can I detect which C++ compiler is used?" "Oh, that's easy:" (via )
Tweet media one
31
488
2K
@foonathan
Jonathan Müller
2 years
I'm currently optimizing lexy's JSON parser example. I've now reached a point where it is 12000% faster than all other JSON libraries. The trick is to consider all characters whitespace and skip them...
11
20
460
@foonathan
Jonathan Müller
7 years
"Family name contains invalid characters." - No, my family name does not contain invalid characters by definition. Your program just sucks.
19
229
435
@foonathan
Jonathan Müller
2 years
To countless people in the reddit comment section: No, somebody implementing their own language after they've failed to change an existing one, isn't throwing a tantrum. Programming languages are tools. If they don't work for you, switch. If no alternative exists, invent one.
7
25
416
@foonathan
Jonathan Müller
1 year
C++ optimization in a nutshell: #cpp #cplusplus
Tweet media one
11
17
339
@foonathan
Jonathan Müller
3 years
New blog post: I wrote a compile-time Brainfuck compiler that generates optimized assembly. The best part: I didn't need to do anything, I've tricked clang into doing it for me. Technique: Compile Time Code Generation and Optimization #cpp #cplusplus
Tweet media one
Tweet media two
7
58
276
@foonathan
Jonathan Müller
2 years
I love reddit sometimes.
Tweet media one
6
18
251
@foonathan
Jonathan Müller
3 years
"We have strlen() to get the length of a string, strcpy() to copy a string, and strcmp() to compare a string. How should we call the function to search inside a string?" "Eh, I don't know. str..., str..." "Perfect, thanks!"
Tweet media one
8
31
235
@foonathan
Jonathan Müller
4 years
I have written a new library! lexy: a C++ parser combinator library #cpp #cplusplus
Tweet media one
11
31
227
@foonathan
Jonathan Müller
11 months
The "fun" thing about C++ is that static_cast<decltype((x))>(x) is a no-op, but static_cast<decltype(x)>(x) isn't.
13
19
223
@foonathan
Jonathan Müller
2 years
UB is fun: Credit to u/geekfolk. #cpp #cplusplus
Tweet media one
17
30
192
@foonathan
Jonathan Müller
1 year
My day so far.
Tweet media one
4
10
189
@foonathan
Jonathan Müller
1 year
To improve my personal development experience I will at some point in my life write 1. My own programming language. 2. My own text editor/IDE. 3. My own OS and/or window manager. The question is: in what order?
53
9
184
@foonathan
Jonathan Müller
1 year
Shoutout to MSVC for ignoring [[no_unique_address]] and forcing you to use [[msvc::no_unique_address]] instead. That's exactly the point of standardized attributes.
6
11
180
@foonathan
Jonathan Müller
6 years
Else if? Boring. I present to you: The else switch.
Tweet media one
13
31
166
@foonathan
Jonathan Müller
2 years
I have just released the first non-beta version of lexy. Want to parse anything in C++? Try it out. It has Unicode support, automatic error recovery, and many more features. #cpp #cplusplus
Tweet media one
5
24
157
@foonathan
Jonathan Müller
4 months
You can't debug modern C++ anymore because of all the std:: invoke.
15
2
156
@foonathan
Jonathan Müller
2 years
@vzverovich 1. Strict aliasing violations. 2. Union type punning,. 3. std:vector 4. mmap 5. arbitrary pointer subtraction 6. treating raw memory as objects 7. signed integer overflow 8. function pointer casts And that's just my current project!
5
5
146
@foonathan
Jonathan Müller
1 year
High-speed train to the airport is powered by Microsoft DOS.
Tweet media one
10
10
148
@foonathan
Jonathan Müller
2 years
@jntrnr The `else switch` when you don't have pattern matching:
@foonathan
Jonathan Müller
6 years
Else if? Boring. I present to you: The else switch.
Tweet media one
13
31
166
2
6
140
@foonathan
Jonathan Müller
1 year
How do Java people live with the net/foonathan/tweet/punchline/deeply_nested_folder/structure.java?! Isn't that really annoying to work with?
36
4
141
@foonathan
Jonathan Müller
3 years
I've spent the last half hour looking for the bug in my coroutine related code for my upcoming @ACCUConf talk. Turns out, it was this for loop: for (auto i = 0; i != steps; ++steps)
15
0
139
@foonathan
Jonathan Müller
6 years
Slides and additional resources of my #meetingcpp "Writing Cache-Friendly C++" are now available: #cpp #cplusplus
4
32
138
@foonathan
Jonathan Müller
3 years
r/cpp post about the latest CppCast episode. Title: "Beautiful C++" Contents: 195 comment discussion about Rust. Ah, reddit, never change.
8
4
127
@foonathan
Jonathan Müller
2 years
std::deque seems to be an underrated container: * you can efficiently insert at the front * the elements have pointer stability * reallocation doesn't require copying things around Sure, pure iteration is slower as it's a collection of segmented array - am I missing sth else?
18
4
123
@foonathan
Jonathan Müller
3 years
The lifecycle of a C++ library developer: 1. You implement a feature. 2. You work around bugs in older version of GCC and clang. 3. You work around bugs in the current version of MSVC. 4. You work around MSVC some more. 5. Eh, maybe this works? 6. No? 7. ??? 8. Profit.
7
6
119
@foonathan
Jonathan Müller
1 year
This is a great post: Type systems for memory safety
2
24
113
@foonathan
Jonathan Müller
2 years
The feedback section of @jfbastien P2723 is perfect. #cpp
Tweet media one
2
20
115
@foonathan
Jonathan Müller
2 years
I've just tagged the first (beta) release of lexy, my C++ parser DSL library! It features parse tree generation, automatic error recovery, operator precedence parsing, Unicode support, and much more. #cpp #cplusplus
Tweet media one
1
20
109
@foonathan
Jonathan Müller
2 years
I've asked for ChatGPT's opinion on @jfbastien 's "zero-initialize objects of automatic storage duration" proposal. Are we sure it hasn't been trained on the committee mailing lists?!
Tweet media one
3
7
103
@foonathan
Jonathan Müller
2 years
The C++20 range based algorithms with projections are so much more convenient: std::find_if(vec.begin(), vec.end(), [&](T& elem) { return elem.member == needle; } vs std::ranges::find(vec, needle, &T::member);
4
7
99
@foonathan
Jonathan Müller
3 months
Last committee meeting had an earthquake, this one has a fire alarm. Maybe it's a sign that we should stop working on C++.
4
4
101
@foonathan
Jonathan Müller
6 years
I haven't forgotten that I have a blog: Tutorial: When to Write Which Special Member #cpp #cplusplus
Tweet media one
6
25
95
@foonathan
Jonathan Müller
3 years
I'm using this book underneath my computer monitor to make it higher. Highly recommended!
@clrs4e
Introduction to Algorithms, Fourth Edition
3 years
Dropping on 22 March 2022.
Tweet media one
129
1K
10K
4
7
93
@foonathan
Jonathan Müller
2 years
I'd like to use this opportunity to remind you about my website (for no particular reason): There you'll find a list of my talks and projects, as well as links to e.g. my GitHub account.
Tweet media one
1
5
96
@foonathan
Jonathan Müller
2 years
I'm currently writing a C interpreter, live on YouTube. Join the streams every Tuesday and Thursday at 17:00 CEST/CET. #livecoding #compiler #cpp
3
9
94
@foonathan
Jonathan Müller
1 year
Typo of the day: struct foo { foo& operator==(foo&& other); }; That was a fun segmentation fault.
11
3
91
@foonathan
Jonathan Müller
2 years
Today's debugging session was brought to you by foo(foo&& other) : ptr(std::exchange(ptr, nullptr)) {}
11
3
87
@foonathan
Jonathan Müller
4 years
The things you learn about C from student submissions. This declares a global variable and four functions returning int.
Tweet media one
6
6
83
@foonathan
Jonathan Müller
5 years
Every global variable should be 0. non-existent, or 1. constexpr, which means it's immutable and initialized at compile time, or 2. constinit, which means it's mutable and initialized at compile time. That way, there is no static initialization order fiasco. #cpp #cplusplus
6
16
82
@foonathan
Jonathan Müller
1 year
I've written a new blog post: Should we stop writing functions? (and use lambdas instead) #cpp #cplusplus
11
14
80
@foonathan
Jonathan Müller
2 years
C++ standard library in a nutshell: 1. Standardize a cool algorithm/container. 2. Early implementation is rushed and/or makes a decision that did not age well. 3. Early implementation cannot be changed due to ABI making it unusable. 4. Repeat with the new alternative.
2
9
75
@foonathan
Jonathan Müller
7 months
Twitter in 2024.
Tweet media one
8
1
76
@foonathan
Jonathan Müller
2 years
Pro tip if you want to expose a lot of bugs: change your custom allocator implementation so that it immediately returns memory to the OS instead of caching it. Quick way to get use-after-free errors.
11
4
73
@foonathan
Jonathan Müller
5 years
I recently needed to iterate over a null-terminated string via iterators, but I didn't want to calculate the end iterator up front. Luckily, this is easily done with a sentinel. Tutorial: C++20's Iterator Sentinels #cpp #cplusplus
Tweet media one
3
13
76
@foonathan
Jonathan Müller
2 years
I've been reading "C++ has become a legacy language" a lot recently; I'm curious what you think. Has or will C++ become a legacy language in the near future? Please RT for reach. #cpp #cplusplus #rust #safety
As a C++ user: YES legacy
1220
As a C++ user: NO legacy
2035
As a non-C++ user: YES
1178
As a non-C++ user: NO
760
55
49
75
@foonathan
Jonathan Müller
2 years
TIL: division by -1 on x86 can also raise a division by zero error, which is a bit confusing to look at in the debugger. I also did not want to learn that.
3
3
75
@foonathan
Jonathan Müller
5 months
@beyerstein It's illegal in Germany. If you can create a contract online by clicking a button, you must be able to cancel it online by clicking a button; cancellation must not be more difficult than subscribing.
0
3
73
@foonathan
Jonathan Müller
6 years
Just wrote twenty slack messages explaining the difference between `T t;`, `T t{};`, `T()` and `T{}` (basically**** the first doesn't do zero-initialization, the others might) C++ truly is a language where initialization is a discussion among experts, for experts.
6
6
72
@foonathan
Jonathan Müller
6 years
I published a new project I've been working on for the past two months or so: foonathan/array - an array based container library Featuring: std::vector equivalent with powerful customization for SBO & co, flat sets/maps etc #cpp #cplusplus
3
22
69
@foonathan
Jonathan Müller
2 years
My malloc blog post results in two reactions: If you're coming from a C++ perspective, you see malloc as a low-level API that you only use for absolute performance. Then you agree. If you're coming from C, malloc is your convenient allocator and any change a complication.
5
0
66
@foonathan
Jonathan Müller
5 years
New blog post about naming with a small detour about the C++ object model, because why not. Naming Things: Implementer vs. User Names Thanks to @gregcons @CppCon talk about naming for giving me the proper term for the symptom! #cplusplus #cpp
5
20
69
@foonathan
Jonathan Müller
2 years
I've surpassed 10k followers! When I created this twitter account almost exactly 8 years ago, I had no idea how much it would change my life: it caused me to do open source projects, start a blog, give talks, and I got to meet so so many amazing people. Thank you all.
4
0
67
@foonathan
Jonathan Müller
2 years
@vzverovich Why preparse all possible inputs? It's enough to preparse the inputs of the benchmark.
3
0
64
@foonathan
Jonathan Müller
4 years
A while back, I've started to write comments as full sentences, with punctuations and everything. I've noticed that I am consistently using "we" in the comments. // Check, whether we've reached the end. // We need to handle -1 as well. etc. I sort of like it.
9
2
65
@foonathan
Jonathan Müller
4 years
The nice thing about writing a library that is almost completely templates: you have really high code coverage by default. Functions are only measured if you have a test that instantiates them. If you want 100% code coverage, just delete all tests!
2
2
65
@foonathan
Jonathan Müller
6 years
I've created a couple of docker images for building C++ projects. They're very lightweight and are designed to create fully statically linked executables compatible with any Linux distribution. #cpp #cplusplus #docker
3
19
64
@foonathan
Jonathan Müller
3 years
I wrote a short blog post that might be interesting for the C++ bloggers out there: Tutorial: Interactive code snippets with Hugo and @CompileExplore #cpp #cplusplus
Tweet media one
1
9
62
@foonathan
Jonathan Müller
7 years
How to detect that your introductory C++ lecture is bad, part 42: using namespace std; list<Employee*> employees; void main() { ... }
15
16
61
@foonathan
Jonathan Müller
6 years
Thank you, @google , that's exactly what I meant.
Tweet media one
6
3
59
@foonathan
Jonathan Müller
1 year
@vzverovich Google plans to be Carbon neutral by 2030.
1
1
62
@foonathan
Jonathan Müller
2 years
For me personally, Rust has two advantages over C++: 1. A modern, clean, usable standard library. 2. Only having to support a single compiler frontend. Now that GCC will gain a Rust frontend, the second advantage is gone.
6
1
59
@foonathan
Jonathan Müller
2 years
@jfbastien I've proposed [[uninitialized]] back in 2017:
4
0
61
@foonathan
Jonathan Müller
6 years
Pro tip for custom compile-time error messages: template <typename ... Args> constexpr bool error_with = false; Then: static_assert(error_with<A, B, C>, "A not compatible with B and C"); clang will show: static_assert failed ... 'error_with<int, char, float>' "A not ..."
3
10
58
@foonathan
Jonathan Müller
2 years
The nice thing about C++ is that you can be the first person to use a certain combination of features! Today, unnamed bit fields and has_unique_object_representations. Bonus points for broken operator== on clang. #cpp #cplusplus
Tweet media one
4
7
60
@foonathan
Jonathan Müller
3 years
Pro tip: Don't install a compiler update while currently compiling with that compiler. You'll get really weird error messages.
0
0
56
@foonathan
Jonathan Müller
3 years
@lefticus It depends. Here it is singular, as `Color c` will only ever hold one color. But if your enum is used as flag, one enum variable might hold a combination of flags, so it is plural.
3
0
59
@foonathan
Jonathan Müller
4 years
I'm releasing a new library tomorrow! I've been working on it for the past year or so, going through various designs, trying things out, and now I've finally got something ready to be released. If anyone wants to proofread the tutorial I've just written, let me know.
6
3
56
@foonathan
Jonathan Müller
6 years
std::is_array<std::array<T, 5>> is std::false_type. Because std::array is not an array, obviously. (Yes, I know why it is false)
4
6
56
@foonathan
Jonathan Müller
2 years
There is a big discussion about Linux and Rust's safety, but most seems to focus on an earlier email by Linus. I find this reply more interesting: I think those functions should be unsafe as they can lead to UB, but Linus doesn't seem to care much #rust
Tweet media one
2
7
55
@foonathan
Jonathan Müller
2 years
C++ is a low-level language: instead of the language features you actually want, you have tools to build them. Want customization functions? Build something using friend functions, arcane look up rules and overloading. Want to tweak move behavior? Use this weird reference type.
3
5
55
@foonathan
Jonathan Müller
6 years
Naming is hard, part N of ∞: I didn't implement a feature I had in mind because I didn't know how to name it.
4
1
54
@foonathan
Jonathan Müller
2 years
Tools ranked by how long it takes to fix their error messages, ascending: 0. clang-tidy 1. C compiler 2. C++ compiler (non-template) 3. CMake 4. C++ compiler (template) ... 999. Linker
2
4
55
@foonathan
Jonathan Müller
3 years
WTF was I supposed to do?! Wordle 243 X/6 🟩🟩🟨🟨⬜ 🟩🟩🟩⬜🟩 🟩🟩🟩⬜🟩 🟩🟩🟩⬜🟩 🟩🟩🟩⬜🟩 🟩🟩🟩⬜🟩
17
0
51
@foonathan
Jonathan Müller
3 years
The problems of an open source maintainer: 1. Write code. 2. Test code. 3. Document code. 4. Workaround MSVC. 5. Crash GCC in the process. 6. Spend an afternoon running creduce. 7. ??? (I'm not here yet) 8. Release. Only 1. and 8. is actually fun...
6
1
55
@foonathan
Jonathan Müller
2 years
Carbon has a feature that I've been thinking about for years, and which has a lot of potential, so I've blogged about it: Carbon’s most exciting feature is its calling convention #carbon #CarbonLang
5
14
53
@foonathan
Jonathan Müller
4 months
@djwesallen @matttomic No, there are obviously 9 teams in the top half, 9 in the bottom half, and 2 in the middle half.
1
1
50
@foonathan
Jonathan Müller
11 months
I've written a new blog post: C++ needs undefined behavior, but maybe less #cpp #cplusplus
0
9
53
@foonathan
Jonathan Müller
2 years
Functions should be small. What if you have a big function that does three things in sequence though? If you extract it into three functions step1(); step2(); step3(), this looses information about the potential order. Ping @tvaneerd
49
1
50
@foonathan
Jonathan Müller
6 years
@zygoloid @CppCon template <auto V>constexpr bool i(){return *(__PRETTY_FUNCTION__ + 14) >> 6;} template <class E, size_t ... D>constexpr auto e(index_sequence<D...>){auto r=0;((i<E(D)>() && ++r), ...);return r;} template <typename E> constexpr auto enum_size = e<E>(make_index_sequence<32>{});
3
12
51
@foonathan
Jonathan Müller
1 year
In some compiler messages, you are reminded that C++ doesn't support default-int. While I'm sure this was helpful to include 40 years ago, I'd argue that most people are getting confused by it since they have no idea what default int is. #cpp
5
1
50
@foonathan
Jonathan Müller
2 years
Days since the last compilation error because I forgot a constexpr on a function: 0 Remember, if you don't have a test that calls your constexpr function at compile-time, your function isn't really constexpr!
2
1
51
@foonathan
Jonathan Müller
3 years
Writing documentation is great way to discover bugs and interface inconsistencies. It is also great to go "ah, I should probably do that here" only to discover that you already thought of that, and it's been implemented for ages...
2
5
48
@foonathan
Jonathan Müller
7 years
Hey, I have decided to setup a Patreon. If you like my work, I'd love to get your support. Thank you all for blog post comments, Github stars, issues and PRs and way too many followers!
6
13
50
@foonathan
Jonathan Müller
6 years
Immediately-Invoked Function Expression: struct iife {}; template <typename Func> auto operator+(iife, const Func& f) { return f(); } #define IIFE(T) iife{} + [&]() -> T // x can be const, even though... const auto x = IIFE(int) { ... // complex init here }; cc @gregcons
5
21
50
@foonathan
Jonathan Müller
6 years
In the C++ UG meeting in Aachen last month a string switch based on tries was presented. This inspired me to write a tokenizer based on the same mechanism. The result is a very fast C++14 (compile-time) tokenizer: #cpp #cplusplus
0
11
49
@foonathan
Jonathan Müller
6 years
Exams are over, time for a new blog post: This is the C++ heaviest post of the series where I talk about <=> Mathematics behind Comparison #4 : Three-Way Comparison #cpp #cplusplus
3
15
49
@foonathan
Jonathan Müller
4 years
Schrödinger's directory.
Tweet media one
1
6
47
@foonathan
Jonathan Müller
6 years
I've started a series on my blog: Mathematics behind Comparison #1 : Equality and Equivalence Relations #cpp #cplusplus
0
14
48
@foonathan
Jonathan Müller
6 years
I may have created yet another library... foonathan/tiny: low-level library featuring tombstones, improved bitfields (tiny types) and other tricks to make your types as small as possible. #cpp #cplusplus
2
10
47
@foonathan
Jonathan Müller
7 years
The 3 most complex parts of C++: 1. std::memory_order_consume 2. std::launder 3. variable initialization rules
7
3
46
@foonathan
Jonathan Müller
2 years
I'd normally wouldn't quote tweet to disagree but since this tweet blew up, I feel I need to for visibility. What he's saying here is false and misleading. Circle isn't being censored from the subreddit, the occupation of the mod is irrelevant, and only a single post was removed
@seanbax
Sean Baxter
2 years
Circle is being censored from the C++ reddit. I built a C++ compiler from scratch. I'm documenting my work on extensions that are aimed at keeping it from going extinct. But a mod who works for a commercial vendor is now pulling down posts. This is terrible for free discourse.
Tweet media one
47
79
676
3
6
46
@foonathan
Jonathan Müller
2 years
I'm speaking later today about coroutines in C++ vs Rust at @cpponsea . No Rust knowledge necessary.
3
0
46
@foonathan
Jonathan Müller
6 years
Every C++ class should be exactly one of: * abstract (base class in hierarchy) * polymorphic *and* final (derived class in hierarchy) * non-polymorphic, public dtor (regular class) * non-polymorphic, protected dtor (non-polymorphic base classes) #cpp #cplusplus
8
7
45