It's finally done -- "Embracing Modern C++ Safely" now has an official release date! 🎉
Get the digital version of the book on 23 December 2021. Available NOW for PRE-ORDER (see below).
Please re-tweet! :)
#cpp
#programming
#coding
#cplusplus
@Pearson
I needed to help my students visualize struct layout and padding bytes, so I created a C++20 pretty printer (see picture).
Available below, use/improve it as you like!
#cpp
#cpp20
#metaprogramming
#reflection
The C developer brain cannot comprehend this 🤯
Modern C++'s compile-time safety and readability, with negligible compile-time and zero run-time overhead.
Literally cannot compile a program with bugs 😏
RT and tag your favorite C developer or anti-C++ apologist!
#cpp
#gamedev
Every time someone paints compile-time safety as "hand-holding" and "weakness" I die inside.
Programming languages are tools meant to make our lives easier and help us achieve our goals.
Tools are NOT a vessel to demonstrate one's "strength" or "power".
#cpp
#rust
#rustlang
@seanbax
With great power comes great responsibility.
There is a memory-safe path in C++. The tools are all there but C++ doesn’t hold your hand. You need to learn how to write safe code. If you do you’re rewarded with an incredibly efficient and capable result.
BTW, before anyone asks -- I am not implying that all C developers are like this with the caption of my tweet.
I am merely stating the fact that the person in question was developing in C.
Following the heated discussions regarding
#cpp
and
#gamedev
that revolved around one of my latest tweets, I wrote an article telling their story, sharing my thoughts on common misconceptions, and providing a list of features everyone should use. Enjoy!
C is just syntactic sugar for assembly language, which is the reason it’s so good. It requires great skill but gives full control.
Someone who codes in C doesn’t want their hand held with compiler warnings. Obfuscation is designed in.
If you cannot explain these concepts to another programmer, then you are not a C++ Developer
- `std::launder`
- Integral promotion rules
- `[[carries_dependency]]`
- Partial template ordering rules
- `std::memory_order::consume`
- Type aliasing rules
- Pseudo-destructors
My unpopular
#cpp
opinion: the next major compiler releases should implicitly turn on `-Wall`, `-Wextra`, and `-Wpedantic` by default, and introduce a `-Wno-default-warnings` flag for backwards compatibility.
I mostly share your sentiment, but the sad truth is that Rust's metaprogramming is years behind C++'s.
Macros are not a substitute for type-level metaprogramming and compile-time evaluation.
#cpp
#rust
It's amazing how quickly Rust's core team completely demolished any possibility of having half-decent metaprogramming for potentially years. It's still better than C++, but that's a low bar, and I was hoping Rust could get a little higher than... this.
"I have a small gripe with filesystem's API so I'm going to shit on the entire committee's experience and volunteer work while ignoring all the good things about Modern C++ for easy echo chamber Twitter likes."
The more I use modern C++ features the more I wonder if the people designing that stuff actually ever did some real programming. Instead of keeping things simple and straight forward everything feels like badly designed joke.
"fixing c++ with epochs"
My new probably controversial article on how we could fix and improve
#cpp
following on
#rustlang
's footsteps.
@isocpp
@rustlang
Constructive feedback is greatly appreciated, even if it starts with "you're wrong!" :)
@freikev
@blelbach
I admit I was harsh, but I don't think I was disrespectful.
One reason why I was harsh was his history in the industry: "Worked at Oculus, Valve, RAD, Muckyfoot, 3Dlabs, now back at Intel. Blade2, Larrabee, TF2, VR".
It's inexcusable to waste 3 day with that experience.
@supahvee1234
@cmuratori
I think it would be VERY educational if you chose a case of "maintainable" code you think it's better, and
@cmuratori
presented his version. Initially, I'm personally prone to agree with Casey
C is a horrible language because who even thought "typedef struct { ... } my_struct_t" is a good syntax?
That's why you always go for C++. If you do actual C then you're either memeing or just dumb.
I like this new feature, but I feel like the syntax is way too implicit. It will be unfamiliar to most developers! How about:
std::same_as<int> auto n = 42;
?
Cope. In practice:
- No destructors/RAII -> mental overhead, can be catastrophic in case of mistakes
- Poor abstraction/encapsulation -> higher chance of safety issues or mistakes
- No templates -> abuse of token macros or code duplication
Zero reason to use C instead of C++.
People don't understand that C's limited feature set is GOOD, and not something you grow out of:
• Syntax doesn't hide expensive/complex operations
• Focus on coding and not language trivia
• Compiles fast
No other mainstream language understands this.
TIL that the
#JavaScript
world has a prolific
@npmjs
contributor of over 1420 one-liner packages:
@jonschlinkert
.
One of these gems is `is-valid-path`, which simply includes `is-invalid-path`, and prepends a `!` to its result. Used by almost 9k projects.
@nilansaha
I wasn't 100% serious. But the thought of even more shallow AI-generated spam (replies, advertisements, influencer bullshit) I have to sift through to actually find worthwhile content makes me feel sad.
This kind of UI should be illegal. I always end up typing too fast and the textbox focus switch can't keep up.
Use a single textbox. If you want to make the required number of digits obvious, put some underlines in the textbox.
Duh, of course there's an easier way. Why would you write the if-else chain by hand? Just generate it via
#cpp
template metaprogramming. 🙄
Look at that beautiful assembly!
Now that Unity is dying, does anyone know of a C++-based code-first modular game engine that is not too heavyweight?
Something between SFML and Unreal Engine would be cool.
Godot seems nice but it doesn't support C++ that well.
#cpp
#gamedev
@cmuratori
's "Clean Code, Horrible Performance" post does as much damage to the industry as blindly applying the OOP rules he criticizes. The entire post is a strawman.
In many domains, run-time performance is not a priority. Delivery, velocity, and teamwork are.
#cpp
#gamedev
Dear
#gamedev
community: I hear your concerns about poor debug performance with modern
#cpp
.
I am trying to improve the situation by making standard library implementers aware:
-
-
Please consider contributing to the above issues.
The more I use
#cpp
packs and fold expressions, the more I wish they were available at run-time. They are a very elegant and convenient way of expressing some operations. (
@seanbax
had the right idea!)
As an example, here's primitive generation of a texture atlas for Quake VR.
A sample of my book, "Embracing Modern C++ Safely", is now available on
@InformIT
:
Contents:
- Forewords by Shawn Edwards and Andrei Alexandrescu (
@incomputable
)
- `override`
- `[[deprecated]]`
- `extern template`
- `inline namespace`
- Index
Enjoy!
LEWG decided to forward my `function_ref` proposal (P0792) to LWG with unanimous consent! Really happy about this, maybe I'll add something useful to the Standard Library...
#cpp
#cppjax
As much as I love
#cpp
and genuinely enjoy using/teaching it, most people defending its future or criticizing Rust are clutching at straws.
Evolving C++ is beneficial for existing codebases, but we can do much better for new ones.
I'd rather invest in
@rustlang
than C++ 2.
Speaking of languages, it's time to halt starting any new projects in C/C++ and use Rust for those scenarios where a non-GC language is required. For the sake of security and reliability. the industry should declare those languages as deprecated.
@template_rex
I could have definitely delivered the same advice in a nicer form. I will do better next time. Still, I believe the reaction was disproportionate. Very disproportionate.
Here's an header-only library for 2018 startups that fits in a single tweet:
template <typename T>
using blockchain = std::list<T>;
template <typename T>
using flat_blockchain = std::vector<T>;
Basic ~50 LOC reflection-based AoS to SoA transformation POC with Modern
#cpp
and
@Boost_Libraries
PFR.
Allows to change storage policy at compile-time without touching neither gameplay logic code nor component struct definitions.
#gamedev
#ecs
If I had a nickel for every time I shared this screenshot I would have already bribed the Standard Committee to remove `std::bind` from the Standard Library
Since a few people have asked, I was supposed and really looking forward to being at
@meetingcpp
, but unfortunately I got in a car accident on the highway on the way to the airport, due to a mechanical malfunction.
I am OK, despite severe pain. Here's what happened:
Rare Jason bad take 😔
5 minutes is an unreasonably long time for most projects.
Fortunately, C++ build times can be very fast with good practices and tooling 👇👇
#cpp
#gamedev
#accu
Me: Do you have long compile times?
Students: yeah
Me: how long is long
Students: a full clean build can be 5 minutes!
Me: ok... Moving on to the next topic...
I presented epochs (, similar to
@rustlang
's Editions) in EWGI and SG15 (Tooling) at the
@isocpp
Belfast Meeting 2019 (
#cppbfs
).
There was strong encouragement to keep working on this proposal! I will present a new revision in Prague.
It actually happened... I encountered a
#cpp
codebase that used 'concept' as an identifier and was forced to rename all usages to migrate to C++20.
Backwards compatibility? Lies!
You’re a great engineer if you know the definition of:
- pseudodestructor
- ODR-used
- ill-formed NDR
- dependency-ordered before
- pointer-interconvertible
- multi-pass guarantee
- phase synchronization point
- vacuous initialization
What else would you add?
#cpp
#gatekeeping
You're less likely to debug something from `<algorithm>` compared to an error-prone manually written loop. Algorithms are templates (inlined), so link times are unaffected. `accumulate` autovectorizes just as well as a loop. Only valid concern is compile time.
Don't spread FUD.
@kinjalkishor
Debug performance. Debugging. Compile times. Link times. Inability to reason about performance. Inability to use SIMD. Inability to reason about overflow, order or operations or anything else really. Lots.
Clang 15 has been released, and...
> Improved -O0 code generation for calls to std::move, std::forward, std::move_if_noexcept, std::addressof, and std::as_const. These are now treated as compiler builtins [...].
Thanks!
From:
#cpp
#clang
#llvm
#gamedev
One of the luxuries of being outside of the game development industry is the lack of toxic, close-minded, and jealous coworkers.
I still love gamedev as a hobby, but I cannot recommend it as a real job to any young developers.
These are many examples of people like Balazs :(
@Manu343726
@scaipgec
@supahvee1234
From seeing Vittorio's code, I assume, in his line of work, the enormous budget wasted on the project allow kids to experiment with stupid c++porn, instead of solving actual fucking problems ;)
Awesome news from
@Boost_Libraries
:
"Boost library authors and maintainers are free to drop support for old C++ standards in their libraries, at any time."
I expect this new policy to bring better compilation times and smaller libraries. 👍
#cpp
How I spent my morning: writing a short paper to convince
@godotengine
maintainers to not reject my PR on the basis that I refused to rely on transitive includes when explicitly asked to do so.
Yup.
#cpp
#gamedev
My paper on
#cpp
epochs has been released as part of the 2019-10 pre-Belfast mailing:
(This is basically
@rustlang
's Editions for C++.)
The rest of the mailing is available here:
@isocpp
Fast compilation times are important.
I've done a lot of work to improve them on
@sfmldev
, and I'm pleased to say that a full rebuild of SFML 3.x, including tests and examples, takes on average ~6s on my system.
I will be speaking about this at
@ACCUConf
:)
Currently investigating an issue with Boost coroutines for a customer:
The repro .cpp file I got has 56 lines only, but includes <boost/asio.hpp> among other things. That file takes more than 19 seconds to compile on my machine.
The same machine compiles *all* of Live++ in <10s.
#cpp
pet peeve, this shouldn't be your only API:
std::vector<std::byte> read_file(const std::filesystem::path& p)
This should:
void append_file_into(std::vector<std::byte>&, const std::filesystem::path&);
Former can be defined in terms of latter, allows vector reuse.
Inspired by
@krisjusiak
's latest tweet, here's my attempt at visually explaining his implementation of `nth_pack_element` -- hope this helps!
#cpp
It's a particularly cool snippet because it doesn't require any recursion :)
Encapsulation of data behind functions is probably the single biggest performance destroyer of modern programming practices out there.
Invert the relationship. Expose data publicly in global memory. Use them as your interfaces instead of functions. One stage of a pipeline writes
Yes, the `reinterpret_cast` is definitely less evil than the `static_cast`...🙄/s
Code for readability and maintainability, not to save a few keystrokes.
C++ version is also more greppable and *discourages* frequent casting - that's good!
#gamedev
#cpp
@supahvee1234
@richgel999
@RealBisqwit
Your weights are obviously different, but as you seem to make money explaining people the intricate details of Modern C++, it seems you are incentivized to make it more complex in the long run ;)
My second
#cpp
video course, "Type-Safe Interfaces with Modern C++", was recently published on
@PacktPub
!
I cover `std::variant`, `std::optional`, and ownership in the context of public APIs. I also show how to implement pattern matching!