×
Login Register an account
Top Submissions Explore Upgoat Search Random Subverse Random Post Colorize! Site Rules Donate
8

Header-only C++ libraries are pretentious faggotry

submitted by SithEmpire to programming 5 monthsNov 18, 2024 22:02:56 ago (+8/-0)     (programming)

All the reasons to go header-only are superficial, as is the counter to the compile time problem with thorough templating of every function. This isn't about minor pros and cons, it's about not breaking stuff.

One of the great things about separate declaration and implementation is exactly that, the latter is totally shielded from impact and from impacting anything else. To argue for header-only is to claim that the implementation does not and will never cause any conflict with anything else ever, which is pretentious bullshit.

Sqlite gets it right - they produce amalgamated source, but it's one header file and one source file. The header looks suspiciously large, but that's only because it's 99% comment text to document it.

Some libraries are designed header-only but have a separated version available or a script to produce that, so they get a pass, at least it's not forced header-only.

Then we have shit like Eigen. Nice actual library, but good god damn have they caught the gay header-only HIV. It's just too much time to hit an unexpected compile error for which the resolution involves editing an included library, in this case just to move implementation out of the headers.

For anyone who needs an analogy, the problem with header-only libraries is the same as the problem with open-plan offices.


17 comments block


[ - ] x0x7 1 point 5 monthsNov 30, 2024 00:38:29 ago (+1/-0)

I'm not a C++ programmer. More of a C programmer, but haven't been significantly in that space for some time.

If I was handed a header only library I'd assume it's because they are lazy.

You could in theory get by with header only when only using it on your own system. Just relabel your .c file as a .h, and you have a library. Now if you are extra lazy you actually ship this out to other people like that.

If you are super extra lazy you don't even own up to your laziness and you tell people there are benefits.

[ - ] MasklessTheGreat 3 points 5 monthsNov 18, 2024 22:13:52 ago (+3/-0)

Bunch of dudes sitting around coding, “I’m so gay, I’m doing header only C++ things.” “OMG!!! Me too! It’s so gay to do header only! I love doing it because I’m gay.”

The fuck outta here.

[ - ] Prairie 1 point 5 monthsNov 19, 2024 06:57:55 ago (+1/-0)

How can you do otherwise with a library of templates? Have compilers gotten smart enough to find the template definition in another file than where it's instantiated?

[ - ] SithEmpire [op] 1 point 5 monthsNov 19, 2024 08:09:48 ago (+1/-0)

Indeed they're not smart enough - wherever conflicting implementations have been moved to a source file, the end of that file needs instantiation lines appended for any specific type parameters the program will be using.

Adding that source file to the build then keeps the linker happy as long as the instantiated types match up.

[ - ] Master_Foo 1 point 5 monthsNov 19, 2024 08:31:53 ago (+1/-0)

See D lang.

[ - ] Prairie 0 points 5 monthsNov 19, 2024 19:50:45 ago (+0/-0)

It's hard to not have seen Bright's endless spamming about it over the years. I got my share in the early 2000s. But the point is that someone writing a library in C++ is bound by C++'s limitations.

[ - ] Master_Foo 1 point 5 monthsNov 19, 2024 20:00:47 ago (+1/-0)

I went to a D conference a few decades back when it happened to be within driving range.
One topic that came up was implementing a new feature, I forget exactly what it was, but doing so would break backwards compatibility with the current D standard.

Everyone there was like "Do it faggot!"

At some point C++ is going to have to stop being C++

[ - ] Prairie 0 points 5 monthsNov 19, 2024 21:40:42 ago (+0/-0)

I can't disagree with that. I liked C++ in the late 1990s. I haven't kept up with the massive additions since then. I don't even think a lot of it is for backwards-compatibility. I can't even bear to look at what it's become. I'm sure it has use in big development efforts, but it seems crippling.

[ - ] Belfuro 1 point 5 monthsNov 19, 2024 01:25:31 ago (+1/-0)

Fun fact, I started modding civ v today.

[ - ] SithEmpire [op] 1 point 5 monthsNov 19, 2024 03:04:24 ago (+1/-0)

Great way to learn, and if it makes something else more based then that's a bonus!

Game industry lefties get so mad when modders mod the gay away. It was not long ago that their "why does it matter?" talking point needed a full lecture video to counter, but now they've trashed their own argument by trying to ban mods which turn pedo flags into USA flags.

[ - ] lord_nougat 1 point 5 monthsNov 18, 2024 22:28:43 ago (+1/-0)

Open plan offices make me want to annihilate.

[ - ] TheNoticing 1 point 5 monthsNov 19, 2024 00:32:34 ago (+1/-0)

Why do you not like open office plans?

[ - ] lord_nougat 0 points 5 monthsNov 19, 2024 00:48:06 ago (+0/-0)

Where did I say I didn't like them?

I just said that they make me want to kill everyone.

[ - ] Trope 1 point 5 monthsNov 18, 2024 22:05:23 ago (+1/-0)

Programming and programmers are so gay.

Having said that, thank you for doing the work no one wants to do or cares about. You are the backbone to the digital age. …not sure if I should be thanking you for that but I’ll bet we share that sentiment. I’ll bet it’s a rough career path shrouded by pretentious corporate sales fluff.

I mean, Plumbers have a shitty profession. But the bullshit programmers deal with isn’t even real yet it exists nonetheless.

[ - ] SithEmpire [op] 0 points 5 monthsNov 18, 2024 22:35:33 ago (+0/-0)

Luckily this has some actual tangible robotics on the output end (hence Eigen to provide a linear algebra platform) - aside from not being entirely hidden in a server and seeming fake, that also frees it from opinions affecting anything!

[ - ] Master_Foo 0 points 5 monthsNov 19, 2024 08:31:17 ago (+0/-0)

Modern compilers for modern languages are smart enough to understand that when you implement something, the implementation IS the declararation.

The only reason C++ needs header files is due to backwards compatibility with itself from 80+ years ago.

See Dlang for a modernized C++.

[ - ] x0x7 0 points 5 monthsNov 30, 2024 00:52:32 ago (+0/-0)

I mostly touch modern languages today, and I do like writing out a function header only once. But there is a reason why implementing a plugin for any modern language involves C or C++. Nobody is backing a python module with nodejs or a nodejs module with python.

Of course performance is a factor, but part of it is the header files, and being able to ship an implementation separately as a resource that many languages can load.

Yes C/C++ have libraries that are very nice to access from other languages. Accessing libcurl or libsqlite3 is great. But other languages besides C have things to offer to other languages. If pandoc wasn't implemented in Haskell every language would be wrapping libpandoc. But they don't, and instead use IPC to make use of that. Why? It's technically infeasible. Why? No headers separate from a binary.