Live data from Hacker News

TOML for Modern C++

marzer.github.io

31–40 of 48 posts

Re: TOML for Modern C++

#31
post #7

> C++17 > Works with or without exceptions Is anyone using C++17 features with exceptions disabled? I thought the “no exceptions” people were generally only using C++ as C-with-classes?

In my experience, few people use exceptions in systems-style code like database engines, while still using every feature of the latest versions of C++. You can essentially use all of C++17 without them if you wish, and many people do. Definitely not C-with-classes style code.

Re: TOML for Modern C++

#32
post #9

Earlier quoted context omitted.

Ouch. Seems like an unsolvable limitation at this point. Nice catch.

C++20 introduces “modules” which are an attempt at alleviating the problem of headers. Support, though, is lacking in major compilers’ master branch. GCC supports it if you build a certain branch from source though.

Some really prompt bugfixing on C++ committee's part. "We have a broken compilation process that leads to humongous build times and namespace pollution! Oh, OK, let's wait another 20 years to fix it".

I guess C++ coders deserve the std::'s their language gives them.

Re: TOML for Modern C++

#33
post #6
post #2

I don't get why C++ programmers like to keep the namespace prefixes around. I'd just add lots of "using ..." statements and make my code more readable. What's the chance of conflicts anyway when you are already dealing with a tiny fraction of the code in the current file?

You could do that in .cpp files, but it's objectively bad to do so in the header files due to namespace pollution. And now you have an inconsistency between headers and .cpp files..

Why do header files even exist and why do sane languages work without them? Oh, I forgot, you cannot question The Holy Warts of Stroustrup. It's just C++. Leave all hopes of developer productivity at the door.

Re: TOML for Modern C++

#34
I'm a bit surprised by this snippet from the "Traversing and manipulating data" example:

  for (auto& elem : *arr) {
      // visitation helps deal with the polymorphic nature of TOML data
      elem.visit([=](auto&& el) noexcept
      {
          if constexpr (toml::is_number)
              (*el)++;
          else if constexpr (toml::is_string)
              el = "five"sv;
      });
  }
I thought constexpr would work at compile time but how can the compile here inside a loop "know" when this labmda will encounter an int or a string ?

Re: TOML for Modern C++

#35

Earlier quoted context omitted.

Yes, plenty, including Google. If anything exceptions are declining in popularity, due to non-obvious and non-local effects. Exceptions are an uber-goto, that can jump outside entire functions. Some people still like that, but very disciplined code bases (of which there are a lot in C++) tend to avoid them. At the very least, utility libraries like this one tend to err on the side of most compatible: header only, no…

> Exceptions are an uber-goto, that can jump outside entire functions. Some people still like that, but very disciplined code bases (of which there are a lot in C++) tend to avoid them. I've never heard discipline as a reason to be exceptionless, its always been performance related (specifically performance predictability).

I have. That's why languages always end up trying to add checked exceptions and then give up because it is too much of a pain in the arse.

For C++ see https://en.cppreference.com/w/cpp/language/except_spec and note that it has been removed from C++. Features are only very rarely removed from C++!

Re: TOML for Modern C++

#36
post #7

> C++17 > Works with or without exceptions Is anyone using C++17 features with exceptions disabled? I thought the “no exceptions” people were generally only using C++ as C-with-classes?

All of Google's codebase, including Chromium, is OO C++ without exceptions. https://google.github.io/styleguide/cppguide.html#Exceptions

Let's insist on

> On their face, the benefits of using exceptions outweigh the costs, especially in new projects. However, for existing code, the introduction of exceptions has implications on all dependent code. If exceptions can be propagated beyond a new project, it also becomes problematic to integrate the new project into existing exception-free code. Because most existing C++ code at Google is not prepared to deal with exceptions, it is comparatively difficult to adopt new code that generates exceptions.

Also let's note that there are more new C++ projects being created today that at any previous point in time.

Propagating the -fno-exceptions meme is harmful to the whole community.

Re: TOML for Modern C++

#37
post #27

Earlier quoted context omitted.

The standard library uses exceptions, but in ways that are avoidable. Not using exceptions does necessitate avoiding the `new` operator, or allowing your program to terminate on OOM. [1] https://stackoverflow.com/questions/37700365/if-youre-in-the... [2] https://news.ycombinator.com/item?id=13354027

Many of the large C++ projects I've been on are exceptionless, but do throw an OOM exception which is caught at a very high level. That's usually the point where a crashdump is taken and some other forensics are gathered; a decent strategy is to freeze threads (if you can), release some reserve memory and try to gather evidence. Doesn't always work . . .

Some "exceptionless" projects actually disable exceptions entirely via compiler flag.

Re: TOML for Modern C++

#38
post #7

> C++17 > Works with or without exceptions Is anyone using C++17 features with exceptions disabled? I thought the “no exceptions” people were generally only using C++ as C-with-classes?

According to a recent talk from Herb Stutter (https://www.youtube.com/watch?v=ARYP83yNAWk), as many as 20% of users fully ban exceptions and an additional 30% ban them partially.

Even code doesn't actually reach the throwing paths, exceptions and RTTI induce a huge binary size overhead that is simply not acceptable if you have binary size constraints.

Re: TOML for Modern C++

#39
Hm, it looks like it is using things like std::vector and streams, etc.

So it does actually require exceptions and RTTI/still forces linkage against throwing functions, etc.

Re: TOML for Modern C++

#40
post #39

Hm, it looks like it is using things like std::vector and streams, etc. So it does actually require exceptions and RTTI/still forces linkage against throwing functions, etc.

Sure, if you want to be pedantic: it works without them when paired with standard implementations that can work without them
Post reply on HN