Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Moving to C++ seems wiser than using a dubious hack like this.


I wrote on reddit[1] about why I prefer this over c++:

> It's not a technical problem, but a social problem. Yes, I would definitely prefer the c++ RAII (and refcounts would be nice too). If you say 'my project is in c++', that sends a certain message to prospective contributors, about what your priorities and ideals are. It can attract certain kinds of contributors and discourage others. Then you have the problem of how to define your subset of c++. It's easy to say 'no exceptions, no RTTI, no STL'. But there are subtler things. As you mention, templates are occasionally useful. But sometimes they're completely superfluous. Do you allow virtual functions? Multiple inheritance? The answer is almost invariably 'maybe'; you have to exercise taste. I can do that by myself, for my own project. But if I want to be able to accept contributions from others, I need a clearer set of contribution guidelines than 'wherever my whimsy takes me', and for such a purpose 'whatever the c compiler accepts' is the best I can do.

> Also, tcc is about 10x faster than gcc and clang, which makes development a joy.

1: https://www.reddit.com/r/programming/comments/f4gb6n/i_made_...


The compiler speed pain is real, and excessive use of templates to do compile time metaprogramming can be intractable, but really it's not the 2000s any more (+) and we should stop pretending that C++ is just C with classes; exceptions, RTTI and STL do actually work now and are portable.

(+) offer not valid on microcontrollers or proprietary C++ compilers


> Then you have the problem of how to define your subset of c++. It's easy to say 'no exceptions, no RTTI, no STL'.

how about you just don't do that like 99% of modern C++ projects and just accept "whatever the C++ compiler accepts".

Remember that "whatever the C compiler accepts" covers most of IOCCC too.


Because the C++ compiler accepts an absolutely insane variety of code styles. I say this as someone who mainly writes C++. If I write my own project, or a project where I only have to work with a small number of people all of whom I know have extensive C++ experience, or a project that is so large that I can afford to consistently rewrite parts, educate contributors and maintain style guides, I choose C++. But anything that doesn't hit these bells, I'd rather use C (or something else). People mixing completely different styles in C++ is a nightmare.


> People mixing completely different styles in C++ is a nightmare.

This is really not my experience. Any decent-sized program will have parts more in a functional style, others in a more OOP one, others in regular-typed Stepanov bliss, others in template or constexpr metaprograms.... and this causes zero issues in practice once people get past their assumptions about what clean code should look like.


I think most large scale projects, or those with special requirements (things like embedded systems) are defining what subset of C++ they are ok with. Here are some examples:

- Chrome: https://chromium-cpp.appspot.com/ - Mozilla: https://developer.mozilla.org/en-US/docs/Mozilla/Using_CXX_i...


Large commercial projects. The problem is the mid sized projects, especially FOSS ones, there isn’t the time needed to curate every pull request and bikeshed. There is also something to be said for having less abstractions, moderately wet code can be easier to follow and fix than needlessly dry code.


Agreed. "Defer" in Go isn't a great idea anyway. It's more what they were forced to, given a GC language without actions at scope exit.

(Callbacks from the garbage collector on deallocation are even worse. That way lies locking problems and "re-animation", a nightmare in Managed C++. One of the cleaner solutions to scope-based cleanup is the "with" clause in Python, which is based on "with" constructs in Common LISP. Only thing I've seen where exceptions in a destructor work right.)


Defer and errdefer in zig are pretty awesome, so I'm not convinced c couldn't use it, but zig has a very different error return model from C, and I tend to disapprove of hacky solutions.


or Rust if you'd rather not touch C++.

C with improvements suffers from uncanny valley. If it's not plain C, then it's weird and non-standard, and C programmers don't want it.

So if you're deviating from pure boring C, then you can just as well switch to another language, and one that doesn't have legacy baggage.


The only improvement C really needs are true constants that don’t rely on macros or enums. How this still isn’t in the language is baffling.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: