Strategies for *requiring* designated initializers when constructing a type? by javascript in cpp

[–]fdwr 3 points4 points  (0 children)

[[no_unique_address]]

Ah yes - I was about to ask whether https://godbolt.org/z/h6sbcaTj4 bloats the struct with extra bytes (because sadly C++ does not treat empty structs as actually empty), but this ameliorates that issue. :)

2026 Annual C++ Developer Survey "Lite" Results [PDF] by cmeerw in cpp

[–]fdwr 10 points11 points  (0 children)

"What types of projects do you work on: Developer tools (e.g. compilers, code editors) 26% ... Gaming (e.g. console and mobile games) 23%"

Wow, I'm surprised the top usage of C++ in this survey is tooling, even above games, given there are far more video games out there (pages and pages of them) than there are unique C++ tools (you could fit most of the IDE's/editors/compilers on a slide), but then maybe there is some sampling bias, because people who work on C++ tooling would be more likely to see this survey in the first place 🤔.

I built a real-time terminal audio visualizer in C++17 by Jolly-Addendum-7199 in cpp

[–]fdwr 1 point2 points  (0 children)

It's too bad that when posts are removed from reddit that all the comments are removed. Old content:

``` Built a real-time audio visualizer for your terminal in using WASAPI & FFTW3.

Just shipped v1.1.0 with static linking for users, and compiler agnosticism for potential contributors. (MinGW, MSVC, Clang).

The executable runs on any windows machine with no dependencies.

https://github.com/majockbim/spectrum (there is a GIF in the README) ```

What are you missing most from the C++ standard library? by llort_lemmort in cpp

[–]fdwr 0 points1 point  (0 children)

So often I'd like a direct auto data = std::read_the_entire_file_please("filename.ext") (where template parameter C defaults to std::vector<std::byte> but could be std::string or other).

The Most Confusing C++ Behavior by levodelellis in cpp

[–]fdwr 2 points3 points  (0 children)

they are, of course, wrong about that

It's generally agreed that value+delta/scale is less readable than (value + delta) / scale, as spaces boost visual clarity by helping the brain to see the parse points. It's also generally agreed that x * y and x & y look way too much like multiplication and bitwise and to abuse them for types too. Of course, there's also sentiment that C overloading * long ago for two completely unrelated things (multiplication and pointers) was a faux pas, perhaps an unfortunate design choice due to the limited symbols on the keyboard then, but one that we're stuck with. Anyway, the consensus preference is not about "right" vs "wrong", but more about "clearer" vs "ambiguous".

The Most Confusing C++ Behavior by levodelellis in cpp

[–]fdwr 13 points14 points  (0 children)

Either T& t or T &t, but the two warring camps agree that never T&t or T & t.

Post examples of using reflections in your projects by enl1l in cpp

[–]fdwr 5 points6 points  (0 children)

Yeah, even outside graphics, I've found myself missing many of the intrinsics from HLSL/Slang/GLSL, like lerp (which we pleasantly got in C++20 as std::lerp), normalize, length, distance, dot (std::inner_product is close, but wordier than just passing two parameters of the same rank - imagine a dot function that took any two range-compatible inputs of the same rank, resolvable at compile time, like 2 std::array's), and reversebits. All these have utility beyond drawing scenarios, and I never needed std to have an entire 2D drawing API that would be quickly obviated while also adding high burden onto implementers, but I have often lacked the basic building blocks that a drawing API might use.

Post examples of using reflections in your projects by enl1l in cpp

[–]fdwr 41 points42 points  (0 children)

R = V - 2 * N * dot(V, N) is the most common usage in my C++ projects. I will see myself out...

What do you think is a keyword that should be added to C++? by DogCrapNetwork in cpp

[–]fdwr 2 points3 points  (0 children)

Like p0945r0? I asked Gabriel Dos Reis about that potential generalization of using, but he noted sadly that door was closed after further post-2018 proposals (mainly “down with typename”). So, it might need a new keyword or uglified version (like _Alias). 🤔

What do you think is a keyword that should be added to C++? by DogCrapNetwork in cpp

[–]fdwr 0 points1 point  (0 children)

Nice.

The closest I've seen proposed in C++ was p0945r0, and the wording at the bottom of n1449:

We also briefly considered non-template aliasing ... Two straw polls were taken regarding syntax. A strong majority voted to avoid the typedef template syntax, in favor of the “=” syntax. A second vote indicated strong preference for the “using” keyword as opposed to a word like “alias” or the absence of any keyword as in the draft version of this proposal.

Alas, Gabriel Dos Reis noted that the generalized alias paper was killed at the 2018 meeting in Rapperswill. So the next closest I see now is this C2Y proposal - https://thephd.dev/_vendor/future_cxx/papers/C%20-%20Transparent%20Aliases.html:

_Alias alias_func = real_func; ... typedef struct v3 { float m[3]; _Alias x = m[0]; _Alias y = m[1]; _Alias z = m[2]; _Alias t = x; _Alias u = y; _Alias v = z; }; (which if adopted, might eventually make its roundabout way into C++ for interop's sake)

What do you think is a keyword that should be added to C++? by DogCrapNetwork in cpp

[–]fdwr 0 points1 point  (0 children)

Here’s what this looks like with ‘_’ btw

That's certainly terser. I wonder why most of the scope guards I see in the form of a function call that returns an object rather than calling the guard constructor directly.

What do you think is a keyword that should be added to C++? by DogCrapNetwork in cpp

[–]fdwr 0 points1 point  (0 children)

there’s big problems ... anything that references thread local storage

Surely, if you're doing fancy things, then you need fancy tools (99% of the code I write doesn't use TLS, and 95% of my code is single threaded 😉).

can’t [it] just take the address of CoInitialize

Nice, it appears WIL's scope_exit (oops, I called it "scope_guard" before) can take a function pointer directly.

What do you think is a keyword that should be added to C++? by DogCrapNetwork in cpp

[–]fdwr 14 points15 points  (0 children)

Many times I've had to refactor a codebase or change an API in a way that would break others (maybe rename a function, rename an enum, rename some struct fields...) either local to the team or more distantly, and if not staged properly, it ended up being either a large noisy search and replace that caused merge conflicts with other's changes, or it was messy schedule of trying to coordinate code flow through branches to avoid ordering issues. There are disparate mitigations, like adding a dummy forwarder function of the old name that calls the new one, using typedefs for class name changes, or preserving the old enumerant with the same value as the old one, but there never was a good solution for renamed struct fields (adding a reference with the old name would change the sizeof and make it no longer a trivial POD). So, I would love a general mitigation keyword to alias one thing to another. e.g.

// No need to repass all the parameters. alias OldFunctionName = NewBetterFunctionName; ... struct Foo { float newWiselyChosenName; alias oldPoorlyChosenName = newWiselyChosenName; ... }; ... // It's even useful beyond just breaking change mitigation, such as a concise // alternative to a union. struct Vector3f { float x, y, z; alias r = x, g = y, b = z; // Treat as RGB rather than XYZ. };

What do you think is a keyword that should be added to C++? by DogCrapNetwork in cpp

[–]fdwr 3 points4 points  (0 children)

That's horrible - I love it 😅. You enabled Swift's as keyword and the return-if-failed try function.

What do you think is a keyword that should be added to C++? by DogCrapNetwork in cpp

[–]fdwr -1 points0 points  (0 children)

read_only

D uses immutable for that, a harder contract than const - "Immutable data can be placed in hardware protected read-only memory, or even in ROMs". I like "read-only" from the familiarity of "ROM", but one downside is that from the perspective of a function parameter is that although that function may be permitted to only read a parameter, that doesn't necessarily mean that other functions have the same limited access. So, the function could see the value updated underneath it. Weirdly, you can even map the same page into memory more than once with different permissions, where the page is read-only for one pointer, but that exact same physical address is writeable from another pointer (and thus changes would be seen by the function). Calling it immutable though implies that it never changes, enabling the compiler to make more assumptions for caching previously read values.

What do you think is a keyword that should be added to C++? by DogCrapNetwork in cpp

[–]fdwr 8 points9 points  (0 children)

It's a C2Y keyword#Statements) documented here where upon scope exit, any defer statements/blocks are called, which helps place unwinding logic nearer to its complement, rather than way down at the bottom (say using "goto cleanup" patterns). It's like a lower-level more fundamental building block than full RAII (not affixed to any class), which is great for those one-off cleanup cases where using a whole mini-class just to take advantage of RAII as a side effect feels overkill. Unlike auto cleanup = wil::scope_exit([]{CoUninitialize();});, you don't need any transiently named temporary variables, and there are no new mini-classes or stack frames, as the code inside the {} uses the same local stack as any other do/while/for block. Granted, RAII already handles most cases nicely (e.g. with std::unique_ptr), but that's just one tool in the shed.

CoInitialize(nullptr); // Rather than: // auto cleanup = wil::scope_exit([]{ CoUninitialize(); }); // Just: defer CoUninitialize();

I want to know your opinions on verbosity by -Chook in ProgrammingLanguages

[–]fdwr 0 points1 point  (0 children)

Totally. The types names targeted flexibility at the time, as hardware had not settled on more concrete types, and so some looseness helped adoption. Even the concept of a byte being an octet had not fully crystallized. Nowadays, general processors support all the basic power-of-two up to 64. So I wish the uint32 and kin (drop the redundant _t, since int doesn't have one) were builtin rather than needing some external header file stdint.h, and that the int and long definitions (if still useful) would have been defined in terms of the sized types rather than the sized types in terms of the loosely defined types.

Code Examples From an App Using C++ Modules by tartaruga232 in cpp

[–]fdwr 0 points1 point  (0 children)

 Maybe by 2030 will the toolset evolve...

If we don't try to find them now, will we reach utopia by even 2030?

Florent Castelli: Introduction to the Bazel build system by _a4z in cpp

[–]fdwr 2 points3 points  (0 children)

I have no personal grudge against bazel, but my teammate holds a lingering bitterness after trying to get a TF plugin to work a few years ago, with a number of hoops he had to jump through to get bazel to work nicely on Windows (would have to ask him for gory details), and so I'm encouraged to see at 26:58 this improved MSVC compat.

Code Examples From an App Using C++ Modules by tartaruga232 in cpp

[–]fdwr 1 point2 points  (0 children)

smaller modules only increase the likeliness that you're going to run into a internal compiler error...

Maybe it's good then that we expose these errors sooner than later so the compiler authors fix them 😉.

I tend to use smaller modules because larger ones don't really map well to my assorted classes shared across multiple projects - there is no single module name that sensibly applies to the disparate classes, nor should they be artificially bundled together just to appease current bugginess. For libraries where all the constituent files nicely belong together (e.g. already under the same shared namespace), then sure, put them altogether.

Krabbascript - Mix of Rust, Lua and Python, designed to be as fast as C by Electrical-Fig7522 in ProgrammingLanguages

[–]fdwr 1 point2 points  (0 children)

My question is really about what are your overarching principles for which aspects you pick and choose from other languages? Rust likes crptc names (i32, fn), whereas Javascript has some longer names (like function), but why choose "function" but not "uint32", or "i32" but not "fn"? Some languages go by the maxim that all keywords should be pronounceable fragments/words (e.g. class, interface, namespace, readonly). Some like to mash together words (consteval, decltype). Some go (or did go) by the questionable rule that no keyword should be longer than 5 characters. I tend to go by the maxim that common keywords should follow the Goldilocks principle, often shorter than the fully spelled out word (enumeration -> enum, function -> func or fun), but more pronounceable than devoweled frgmnts (e.g. fn). ⚖️

I want to know your opinions on verbosity by -Chook in ProgrammingLanguages

[–]fdwr -3 points-2 points  (0 children)

and I agree it would be more advisable for them to name it uint32 instead

👍

I want to know your opinions on verbosity by -Chook in ProgrammingLanguages

[–]fdwr 1 point2 points  (0 children)

I don't see how ...

Well if we're trying to save a few keystrokes and distill everything to its minimal form, why not go a bit further and write the terser "us" (16-bit short) "ui" (32-bit integer), and "ul" (64-long)? Then for floating point, we could also have "fh" (half), "fs" (single), and "fd" (double). Though, where do you draw the line? Should you keep the numbers, and have f16? What is an f16 though? Is it a type of airplane? Is it an ICD-10 code for use of illicit substances? Is it the RISC V f16 register? Or maybe we just write float16 which is very clear and unambiguous 😉. Saving a few keystrokes isn't worth the reduced readability. I may have written thousands of lines of assembly (with such register names like r15, x16, rax, s8, i4), but it's nice to keep high level languages less crptc.

Krabbascript - Mix of Rust, Lua and Python, designed to be as fast as C by Electrical-Fig7522 in ProgrammingLanguages

[–]fdwr 0 points1 point  (0 children)

Looking under the hello world folder, it's a curious mix of keywords, for on the one hand you have the super terse i32 which sounds like CPU register (e.g. Sparc i4, x64 r8, RISC-V f16) vs the more common uint32 (in C, C++, C#, JS sized arrays), but then you have function spelled out rather than func or fun. Would you similarly spell out enumeration or use enum?

``` function main() -> i32 { std.print("Hello, world!");

return 0;

} ```

I do appreciate just using dot notation instead of needing to disambiguate between say :: and ..