HNHacker News
TopNewBestAskShowJobs

jstimpfle

4,224 karma · joined May 21, 2015

http://jstimpfle.de
submissionscomments
jstimpfle··on Four Months of Zig
That's just a matter of wrapping the allocator if you feel fhat is better approach. Question is, should there always be an allocator around with arr or do you want to split a build phase from an immutable use phase.
jstimpfle··on C for Rust programmers
I find both of these names too long and the colons are noisy. The fact that I can refer to them using different qualifications makes me uneasy. For both we could find better names, e.g. MemoryOrder is already an established term.

I've realized that naming is an art that is difficult to master but makes a huge difference when gotten right. It consists of not just combining names into compounds but also finding new shorter names that are ergonomic and distinguishable. For example, I've replaced the compound "NodeIntersectTest" in my current project with simply "Probe", which is much easier to read and write, easy to distinguish from other terms after learning its meaning once (it is a central concept to my app), and also perfect for log messages and stats where brevity matters a lot.

A two letter prefix for all identifiers in a project or company codebase is a good idea, but I try to avoid hierarchies and finer granularity, and generally to be overspecific, in order to keep things easier to change later.

jstimpfle··on C for Rust programmers
True that integer promotion rules are defined in terms of the machine dependent unsized "real" integer types. That is indeed annoying. I guess I've found ways to cope. Good thing is, those promotions never cast down, they only widen types.

The point of namespaces is exactly to allow less qualified names, to allow spending less energy when creating new names, by having the compiler always add a qualification implicitly. However, that doesn't solve the problem with name collisions when reading or grepping the source code -- it actually makes it much worse. And avoiding those name collisions, i.e. what's in the source literally, what the programmer reads, and what less-than-perfect tools see, is at least as important as avoiding "semantic" name collisions and being able to compile the code.

Namespaces not only encourage many more literal collisions -- now a single name can be available in various shortenings, and even under different aliases, which also makes it hard to tell that two symbols refer to the same thing!

I've found that the only way to get names right is to find a good scheme, to find meaningful good prefixes, suffixes, and abbreviations, and to come up with a system to create new names more mechanically but still keep them as short and readable as possible.

jstimpfle··on C for Rust programmers
True. In C, it's hard to know what's defined where and what dependencies one is even using unknowingly. The only help is to build on multiple platforms from early on, this will reduce the pain of porting to new platforms later.
jstimpfle··on C for Rust programmers
Integer widths are a problem, but hardly the biggest headache (unless it's a decade old preexisting project that was never designed with portability in mind). Fixed width integer types like int32_t have existed for decades. Even Rust has usize which is machine dependent, and pointers as well have to be machine dependent of course.

Much bigger problem is understanding the scope of dependencies. Dependencies can go bad and you need to update. A dependency might not be available on some new platform so you might have to replace with something else on that platform. To make the software portable, good modularity is required. This is to a large extent an aspect of software architecture. Even Rust can't magically make this happen, if you depend on 300 crates that's probably not a great place to be in either if you want to be portable and maintainable.

There is probably a point that C's flat namespace is a major contributor to badly designed software, because people aren't aware of the dependencies they're mixing all the time. Also C encourages transitive includes, leaking implementation details to the user instead of just to the compiler. (But btw. I find C++ and Rust namespace to be unergonomic syntax-wise, and what's needed is not actually namespaces but control over visibility).

jstimpfle··on C for Rust programmers
It's _very_ easy to write C that is impossible to port to other platforms or other compilers. The reason is that more than for most other ecosystems, there are many different implementations with their own implementations and quirks.

It's also easy to write C that won't build on the system it was originally developed on, a few years down the line. But that is true for almost every other language ecosystem. I would say, C makes it _possible_ to write code in such a way that it works on many different platforms and compilers, and/or can continue to work in decades to come with relatively little maintenance.

The latter isn't true for most other ecosystems, because to get anything done in them, you need to rely more on that language and its ecosystem -- specific language features, specific libraries. C isn't a glue code language. It's very good at letting you create your own thing.

To do it well though, requires a lot of care and expertise.

jstimpfle··on Type Safe Generic Data Structures in C (2025)
It couples things and complicates things. Which creates friction against when refactoring a software architecture, making it harder to scale it up.

Fully agree, for locks or other simple begin/end pairs it doesn't create the same kind of architectural damage. But I don't use it even there, because RAII fundamentally doesn't play well with manual cleanup code. It's kind of an all-in game, if you use some RAII there are strong forces (whenever you need to get the "nesting" right) to convert all remaining manual begin/end type code to types that define that functionality out-of-line in the destructor/destructor, leading to fragmentation.

jstimpfle··on Type Safe Generic Data Structures in C (2025)
No need to invent when you already know how it works.

I could re-type all the essential stuff from std::string that I've ever used myself within 10 minutes, no problem, without looking up external sources, including copy & move semantics and whatnot. But I'm deliberately not doing it. Because I don't like this "invention".

jstimpfle··on Type Safe Generic Data Structures in C (2025)
The projects and people I follow do this all the time. Just like putting a size field near each regular non sentinel terminated array is useful. But if not doing it (maybe linux kernel in many cases), no big deal either, don't sweat the small stuff. String slices are small and rarely perf critical.
jstimpfle··on Type Safe Generic Data Structures in C (2025)
Placing data in .rodata (read only memory) is an actual useful application of const keyword. Not specific to embedded. Arguably there shouldn't have been multiple slightly different meanings of the keyword like that.

I don't know why you are now jumping to setjmp/longjmp, trying to make a point that somehow C is the worst programming languages ever, when all I am trying to argue is for sane programming practices, hinting that more complex features (line especially found in newer languages) are not solutions but part of the complexity problem.

jstimpfle··on Type Safe Generic Data Structures in C (2025)
Yeah... There are libraries like Google Highway but that seems to me like a bulky software abstraction layer even if it is a so-called "zero cost" abstraction. Maybe appropriate in some cases. In my case, I've implemented a couple of lines for AVX2 and AVX512, maybe around 100 lines for the most perf sensitive sections currently, not a big deal. The actual work is in the understanding of the problem and of the phyiscal hardware, and in the software architecture and data layout to even enable vectorized stream processing in the first place. I'm not concerned writing a couple of perf sensitive lines against 2-3 most important concrete vector ISAs. I also fancy adding a GPU backend later (requires D3D12/SM6.0 API level), Highway couldn't help with that.
jstimpfle··on Type Safe Generic Data Structures in C (2025)
> Do you expect some other behavior in such case?

No, just saying this stuff is implicit and thus hard to read. More so the allocation on indexing assignment. and keeping things which shouldn't be mutated const wasn't a problem at all.

> and keeping things which shouldn't be mutated const wasn't a problem at all.

As soon as datastructures become more complicated and more interconnected, it's not clear anymore what const should even mean (issues are similar as with deep vs shallow copies, how do you even draw the lines, where are the objects?).

And the major philosophical flaw in the const vs. non-const distinction is that to make a strict separation you have to move everything mutable into constructor calls (for the most part, not getting more into the weeds of C++). Which is very awkward, it's a real tradeoff you need to be aware of. I realized only after playing these games for a long time what a waste of time it is and how much complexity it creates.

jstimpfle··on Type Safe Generic Data Structures in C (2025)
You must be very experienced to be so judgemental! But maybe ask the many billions of voxels that get tested per second on my multithreaded and SIMD'ed cutting simulation.
jstimpfle··on Type Safe Generic Data Structures in C (2025)
> C++ containers are designed for average demands. If you need something more specific, you can always use an alternative implementation.

As someone who has been programming exclusively in C/C++ for a long time -- the biggest selling point for these languages in 2026 is exactly being suited to doing something specific, not generic.

> Allocations aren't implicit

    std::map<int,int> m;
    m[1] = 42; // implicit alloc
    auto m2 = m; // implicit too

> in C++ it's strictly recommended to mark as const everything in regular user code which shouldn't be mutated.

Theory and practice. Making everything const correct is too painful in practice, often impossible. It's a trap for bean counters that can't focus on getting some actual useful work done. I'm being harsh to my own past self here. Counter question: why include allocation mechanics with some existing data that never gets changed? Why should we have to add much more boilerplate to get the simpler thing?

jstimpfle··on Type Safe Generic Data Structures in C (2025)
Exactly, and a simple usable string type is just a struct MyString { char *buf; size_t len; }; away. Actual magic is in how you use it, where you allocate it, how you integrate allocation and formatting and logging and I/O... i.e. all the things that aren't solved by crufty complex std::string either.
jstimpfle··on Type Safe Generic Data Structures in C (2025)
It's a slow generic data structure with an unintuitive API. You can use it for leetcode or for CRUD. For anything more demanding it's horrifically bloated and bad. std::string too. Whenever you see STL datatypes like even string and map, you have to deal with RAII, implicit allocations, weird operator syntax, unexpected mutation (invalidation) and so on.

(Spporting or even encouraging destructive mutation, and by this I mean not incrementing counters or anything harmless but allowing iterator invalidations and crashes, are also why std::vector is bad in my opinion, these are idiomatic APIs for 90s and 2000s programming, which we should know better to avoid in 2026).

jstimpfle··on C's Flexible Integer Sizes Were Not a Design Mistake
Point is that C isn't tied to POSIX. It's just not. Of course there are apps created on e.g. Linux, those sometimes get ported by relying on standardized "POSIX" platform. But that's not how you have to program, and it isn't a great way to program. And it isn't a sufficient platform to do anything useful.
jstimpfle··on C's Flexible Integer Sizes Were Not a Design Mistake
If id Software is any indication, apparently they wrote their games in C since their inception in 1990 with Commander Keen.
jstimpfle··on C's Flexible Integer Sizes Were Not a Design Mistake
I don't know about you but I need zero POSIX to write C on Windows. Not even much of the (mostly bad) C standard library. I use snprintf for convenience (but I don't have to), and memcpy, that's about it.

And many projects properly abstract their OS layer so they aren't tied to POSIX.

Maybe Unix is tied to C, but C isn't tied to Unix.

jstimpfle··on What Zig felt like, coming from Rust
I don't even have to search. Given the frequency of you repeating the same old tired stories, one is bound to stumble over your comments every other day.
jstimpfle··on What Zig felt like, coming from Rust
There is plenty history of you repeating the same strawmans literally thousands of times. I've just never seen _anyone_ on HN (or elsewhere for that matter) make such claims?
jstimpfle··on What Zig felt like, coming from Rust
You repeating this weird strawman take a million times doesn't make it true. Why don't you finally just put out some genuinely interesting projects demonstrating how everybody was doing it wrong, so people can make up their own mind and finally be convinced. There must be some true magic in those languages and platforms you mention, that should offset the pain of writing in upper case and with super long KEYWORDs everywhere, and to offset the cost of switching to a culture that has way less mindshare and way less of a software ecosystem around it.

FWIW I've actually worked for 6 months on a large old Delphi project. It was some performance work that, as almost always, mainly required getting the language crap out of the way. In the end I got the job done (100x-1000x speedup) but I wouldn't want to switch back to this ecosystem: Licensing costs, weird language warts there too. A slow moving ecosystem. Ultimately, I just need something that does what I tell it to do, reliably and fast, and that doesn't get in the way.

jstimpfle··on Stabilizing Rust's Never Type
For the most part, software does not exist in a vacuum. If there is a serious bug, or much improved feature, in a library you depend on, what do you do? Most likely you'll try to upgrade the library. Same deal for the compiler, it's a huge dependency.

If your project is truly done, by all means ship it on a N64 cartridge. I can't say I don't have sympathy for that attitude. But don't expect this is how the world works today. And don't forget, N64 cartridges weren't built using massive amounts of dependency, so it was easier to confidently declare something "done".

jstimpfle··on Programming is Art
I believe there are many top level chess masters that consider chess an art. Same for programmers, to many of the best, it is an art form or at least a craft that they take very seriously. And many would disagree that programming is solved. "Boring and standard" can be a sign of quality, but it also applies to those code bases that don't solve any interesting problems and just drown in boilerplate, kept alive by dozens or hundreds of programmer drones just working to collect their paychecks.
jstimpfle··on Carbon-aware electricity pricing, measured daily on 38 grids
Good to point out the difference between taxes and other tariffs, but I have a hard time understanding why you have to call what I said "wrong"? What you went to explain in detail is exactly what I alluded to, that also matches the previous posters "electricity [...] taxed into oblivion".

Another point: 3.3% of federal tax income, or 1.7% of all taxes paid by citizens, goes directly into "Klima- und Transformationsfonds" i.e. gets pumped into energy transformation. And the state even pumps more money into that, by means of "Sondervermögen" (taking additional debts). Measured as a percentage of federal state tax income, seems like Germany is pumping more than 7% total into energy transformation. Quite a lot I think, and even if this is not directly a tariff on electricity, it's easy to imagine how this can result in general price inflation.

jstimpfle··on Carbon-aware electricity pricing, measured daily on 38 grids
The prices of so many things have gone down with times due to increased efficiencies. Why not electricity? If solar PV is cheaper than fossils, I would, naive as I am, expect prices to go down.

(I acknowledge fossils have been going up for various reasons, and have become more scarce, and energy demands are rising)

jstimpfle··on Carbon-aware electricity pricing, measured daily on 38 grids
FTR and for the inevitable downvoters, I am not a fan of fossil energy. I am merely a fan of well presented arguments, and downvotes aren't that.
jstimpfle··on Carbon-aware electricity pricing, measured daily on 38 grids
What I am saying is that those spot prices may not represent all of the reneweables' marginal costs. Question is, will the end consumer prices ever go down, and by how much?
jstimpfle··on Carbon-aware electricity pricing, measured daily on 38 grids
I was under the impression that the taxes are going into infrastructure and grants for renewable energies, meaning those energy prices are maybe way higher than advertised. Funny thing is we are constantly being told how cheap reneweables are to produce but apparently there are other costs involved.
jstimpfle··on Carbon-aware electricity pricing, measured daily on 38 grids
Why I said not only... but also.
Page 1 of 34Next →