Live data from Hacker News

Libvirt: Adoption of GLib library to replace GNULIB and home grown code

berrange.com

41–50 of 66 posts

Re: Libvirt: Adoption of GLib library to replace GNULIB and home grown code

#41

I think that 3/4 of their issues would probably be solved by a well thought use of modern C++. I've seen too many C projects (including some of mine) starting by swearing out C++ for one reason or another and then ending out reimplementing half of it using macros or poorly written hashmap implementations taken from somewhere. Glib2 is one excellent example of how people have been shunning C++ due to its complexity, w…

For long applications you get into he realm of tool chain bugs with C++. C compilers are more reliable.

If you write C-style C++, which parts of libstdc++ can you safely use without exceptions?

Re: Libvirt: Adoption of GLib library to replace GNULIB and home grown code

#42
post #41

I think that 3/4 of their issues would probably be solved by a well thought use of modern C++. I've seen too many C projects (including some of mine) starting by swearing out C++ for one reason or another and then ending out reimplementing half of it using macros or poorly written hashmap implementations taken from somewhere. Glib2 is one excellent example of how people have been shunning C++ due to its complexity, w…

For long applications you get into he realm of tool chain bugs with C++. C compilers are more reliable. If you write C-style C++, which parts of libstdc++ can you safely use without exceptions?

Google writes a lot of C++ code, disables exceptions entirely, and it does not shy away from STL at all.

Re: Libvirt: Adoption of GLib library to replace GNULIB and home grown code

#43

I think that 3/4 of their issues would probably be solved by a well thought use of modern C++. I've seen too many C projects (including some of mine) starting by swearing out C++ for one reason or another and then ending out reimplementing half of it using macros or poorly written hashmap implementations taken from somewhere. Glib2 is one excellent example of how people have been shunning C++ due to its complexity, w…

C++ was already everywhere on desktop computing back in the 90's, with Apple, IBM, Microsoft, BeOS adopting it on their frameworks, and even on the mobile with Symbian.

Then FOSS happened with its manifesto to use C for portability, war on KDE due to licensing gave raise to Gtk and related eco-system, and here we are.

Thankfully I learned C++ on MS-DOS and became enlighted, even with its 640 KB limit it was already so much better than the primitive C, in regards to type safety, generic code and yes RAII was already a thing.

Re: Libvirt: Adoption of GLib library to replace GNULIB and home grown code

#45
post #41

Earlier quoted context omitted.

For long applications you get into he realm of tool chain bugs with C++. C compilers are more reliable. If you write C-style C++, which parts of libstdc++ can you safely use without exceptions?

Google writes a lot of C++ code, disables exceptions entirely, and it does not shy away from STL at all.

Then they don't care about applications being terminated in case of std::bad_alloc and similar.

The crucial applications they use are written by others (like the Linux kernel).

Also, having seen the output of several Googlers, I think their code quality is overrated.

Re: Libvirt: Adoption of GLib library to replace GNULIB and home grown code

#46
post #3

Glib is OK except for the fact that it has a memory cache on top of that of malloc. This prevents tools like asan or valgrind from detecting memory related bugs. It caused my team a lot of grief, to the point that we regretted the choice of using glib in the first place. I am not sure why there is a memory cache in the first place. Malloc may have been slow in the 90s, but these days there is no reason to cache and r…

I don't know anything about this cache you're referring to, but, is it so pervasive within the library that you can't easily do a patch to remove it? Would such a patch be accepted by upstream? If you're opposed to using the environment variable, those would be my next thoughts if you wanted to get back the ability to use valgrind et al.

You only need an environment variable. It is already implemented. They just did not try it.

Re: Libvirt: Adoption of GLib library to replace GNULIB and home grown code

#47
post #39

I think that 3/4 of their issues would probably be solved by a well thought use of modern C++. I've seen too many C projects (including some of mine) starting by swearing out C++ for one reason or another and then ending out reimplementing half of it using macros or poorly written hashmap implementations taken from somewhere. Glib2 is one excellent example of how people have been shunning C++ due to its complexity, w…

Absolutely. It makes perfect sense, and in an ideal world this would be the direction which would benefit many, if not most, projects using C and/or GLib2. Unfortunately, there are far too many people who are wedded to the philosophy that C is perfect for every task, and C++ is the devil. Despite the fact that GLib/GObject are more complex than C++, more error-prone than C++, slower than C++ and make static code anal…

I gateway drug to C++, was Turbo C++ 1.0 for MS-DOS, released in 1990 as per Wikipedia. I got my copy in 1992.

Basically C++ARM as per language standard, on a 386SX running at 20 MHz, 2 MB but 640 KB was more than enough, right? :)

Our high school teacher giving us C classes with Turbo C 2.0 also had it around, so as it were back in those days, I eventually got a copy.

My gateway drug to programming until then were Turbo Pascal 6.0 and TASM, and C++ was in the same ballpark of features and culture for safer systems programming.

Never had any issues using it in such kind of PCs, including with my own bounds checked string and array classes, hardware that most modern MCUs can easily outperform.

Re: Libvirt: Adoption of GLib library to replace GNULIB and home grown code

#48
post #41

I think that 3/4 of their issues would probably be solved by a well thought use of modern C++. I've seen too many C projects (including some of mine) starting by swearing out C++ for one reason or another and then ending out reimplementing half of it using macros or poorly written hashmap implementations taken from somewhere. Glib2 is one excellent example of how people have been shunning C++ due to its complexity, w…

For long applications you get into he realm of tool chain bugs with C++. C compilers are more reliable. If you write C-style C++, which parts of libstdc++ can you safely use without exceptions?

> which parts of libstdc++ can you safely use without exceptions?

Almost all of it, as long as you're happy to abort on memory allocation failure - which, according to the article, libvirt is now willing to do.

In fact for me, that's one of the main questions to ask when deciding between C and C++ for a project. Is it OK to abort on allocation failure? If so, use C++ (without using exceptions). If not, use C.

Re: Libvirt: Adoption of GLib library to replace GNULIB and home grown code

#49

Earlier quoted context omitted.

Google writes a lot of C++ code, disables exceptions entirely, and it does not shy away from STL at all.

Then they don't care about applications being terminated in case of std::bad_alloc and similar. The crucial applications they use are written by others (like the Linux kernel). Also, having seen the output of several Googlers, I think their code quality is overrated.

   auto ptr = new (std::nothrow) ......
   if (ptr != nullptr) {
       //........
   }

Regarding STL, allocators with similar behavior can be provided.

Re: Libvirt: Adoption of GLib library to replace GNULIB and home grown code

#50

I think that 3/4 of their issues would probably be solved by a well thought use of modern C++. I've seen too many C projects (including some of mine) starting by swearing out C++ for one reason or another and then ending out reimplementing half of it using macros or poorly written hashmap implementations taken from somewhere. Glib2 is one excellent example of how people have been shunning C++ due to its complexity, w…

The main practical benefit of C is the simplicity and stability of its ABI.

There are currently 8 different language bindings listed on LibVirt's website. It's not clear to me that this situation would improve by switching to a language as notoriously difficult to interop with as C++.

https://libvirt.org/bindings.html

Post reply on HN