Hacker News new | past | comments | ask | show | jobs | submit login

I wish there was some way that you could configure a C++ compiler to just disable certain features of the language, or enforce good practices.

But that's already what linters/static analyzers are doing? But then, why not integrate those tools directly in a C++ compiler instead?

With cpp2/cppfront, Herb Sutter is already building some sort of a "sane" subset of the C++ language, maybe because you cannot achieve good practices without having a new syntax.

C++ seems to have the same problem of javascript: it has annoying "don't-do-that" use cases, although it seems insanely more complicated to teach good C++ practices.




This is more or less what Sean Baxter was trying to do with https://www.circle-lang.org/.

Of course, this requires buying into a set of tooling and learning a lot of specific idioms. I can't say I've used it, but from reading the docs it seems sound enough.


You can write a compiler plugin that rejects constructs you don't like. Even GCC doesn't immediately lower the more complex (more controversial) C++ constructs. There's an existing system headers mechanism, so it's probably not that hard to skip this kind of feature restrictions for the standard library headers (where the banned constructs might be used to implement something that looks completely different at the surface).


That is what static analysers are for.

The issue is developers that think they are useless tools.


Usefully albeit depressingly, these days you can often get significantly easier buy-in if you call it a linter instead.


Or taken to an extreme, it's not hard to compose clang-queries that find for any arbitrary syntax. You could ban 'int' and pointers in your project if you wanted!


Or the way I like it, configure Sonar to break pull requests when devs ignore the rules that are supposed to be followed.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: