News for hackers. Stuff that matters.
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by ddtaylor on Saturday February 21, 2026 @04:22PM (#47104915)
Thank you for sharing. The only thing I don't understand why this is a header only implementation with a macro that goes in a C++ file.

    #define CANVAS_ITY_IMPLEMENTATION
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by erwincoumans on Saturday February 21, 2026 @05:36PM (#47105600)
It is common for header-only libraries: you need to include this header in one c++ using the macro for linking (don't use that macro in other c++ files to avoid duplicate symbols). In C++, you can declare a function as many times as you want, but you can only define it (write the actual body) once in the entire project.
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by ddtaylor on Saturday February 21, 2026 @06:08PM (#47105938)
I understand that part, but I don't see why do this instead of basic Makefile or CMake setup. It seems like more work than a regular linker at that point. For what purpose?
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by elteto on Saturday February 21, 2026 @06:18PM (#47106061)
Because not everyone is using Makefiles or CMake.

A true header-only library should be build-system agnostic and this is one way to do that.

We can argue about build systems for C++ all day long and never come to an agreement. With this approach this piece of code can be used anywhere.

Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by pjmlp on Sunday February 22, 2026 @01:30AM (#47108766)
We can also argue C++ is not a scripting language, which is what is approach is all about.

When C and C++ were the main programming languages during the 1990's, and commercial compilers abounded strangely we could manage handling all those build systems approaches.

Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by elteto on Sunday February 22, 2026 @02:05PM (#47113670)
I think you are romanticizing the past. I’m pretty sure integration of third party C or C++ code sucked as much back then if not more. You just didn’t have as much of those dependencies because open source was in its infancy and the number of available libraries was much smaller too.
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by socalgal2 on Saturday February 21, 2026 @04:31PM (#47105017)
that's a common pattern in C++ land because there is no standard way to use libraries in C++

https://github.com/p-ranav/awesome-hpp

Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by pjmlp on Sunday February 22, 2026 @01:31AM (#47108771)
It is a common pattern among those that don't want to learn build systems, which isn't exactly the same.
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by socalgal2 on Sunday February 22, 2026 @02:40AM (#47109109)
In my experience. I've run into the issue quite often. You find some library, it has its own build system (meaning not the one you're using). It has special rules etc... Integrating into your build system is time consuming and frustrating. Compiler errors from includes, linker errors, etc..

None of that happens with a single file C++ library.

Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by pjmlp on Sunday February 22, 2026 @03:11AM (#47109274)
Yeah, and?

There isn't a single build system without issues, other than siloed languages without language standards.

Header libraries only started to be a thing when scripting generation educated in Python and Ruby during the 2010's turned into compiled languages.

Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by tw061023 on Thursday February 26, 2026 @02:05PM (#47170556)
That's... definitely a way to describe Sean Barrett, whose excellent libraries popularized this style.
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by capisce on Sunday February 22, 2026 @02:01AM (#47108908)
Or among those who want to support any build system
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by pjmlp on Sunday February 22, 2026 @03:09AM (#47109265)
We managed during the last 20 years just fine.
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by chris37879 on Sunday February 22, 2026 @09:32AM (#47111313)
And what build system do you recommend the entire ecosystem support? Well, I choose (arbitrarily different and incompatible one to prove a point). Do you see the problem?
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by pjmlp on Sunday February 22, 2026 @09:44AM (#47111399)
I see a learning problem, because there is hardly a programming language in widespread use using a single one.

And if you're going to point out Go or Rust, it kind of works as long, nothing else is used, and they don't need to interact with platform SDKs.

Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by CyberDildonics on Sunday February 22, 2026 @10:53AM (#47111985)
Everything is easier with single file headers. This idea that a build system and single header libraries are mutually exclusive is silly.

You can take multiple single file libraries and put them into one compilation unit. Then you have minimal files and minimal compilation units. Compilation is faster, everything is simpler.

Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by pjmlp on Sunday February 22, 2026 @12:48PM (#47113009)
What is silly is pretending everything is a scripting language.
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by CyberDildonics on Sunday February 22, 2026 @01:32PM (#47113431)
I don't know what that is supposed to mean and I don't think it means anything.

I'm talking about real pragmatic benefits and you're making some vague hand wavy judgement without any tangible explanation.

Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by on_the_train on Sunday February 22, 2026 @12:42PM (#47112947)
I wrote a mildly popular header only library with exactly this pattern once. Then there came a guy adding cmake. I didn't really know it back then so I didn't stop him. The downloads went to literally zero lol. Cmake is an extremely vocal minority.
Re:Canvas_ity: A tiny, single-header <canvas>-like 2D raster... by pjmlp on Sunday February 22, 2026 @12:49PM (#47113026)
Who said anything about cmake specifically?