5 ms·
Well, another option would be to use a C++ compiler, which supports templates, but limit the use of classes through a coding convention standard.
by self_awareness 11mo ago
Well, another option would be to use a C++ compiler, which supports templates, but limit the use of classes through a coding convention standard.
- lelanthran 11mo ago> Well, another option would be to use a C++ compiler, which supports templates, but limit the use of classes through a coding convention standard. When the other option is "ask the developers to practice discipline", an option that doesn't require that looks awfully attractive. That being said, I'm not a fan of the described method either. Maybe the article could have shown a few more uses of this from the caller perspective.
- krupan 11mo ago"ask the developers to practice discipline" is a baseline requirement for coding in C
- pjmlp 11mo agoUnfortunately the majority has failed to attend the temple classes on such practices.
- lelanthran 11mo ago> "ask the developers to practice discipline" is a baseline requirement for coding in C Sure, but since there's 10x more opaque footguns in C+++, there is much less discipline needed than when coding in C++. The footguns in C are basically signed-integer over/underflows and memory errors. The footguns in C++ include all the footguns in C, and then add a ton more around object construction type, object destruction types, unexpected sharing of values due to silent and unexpected assignments, etc. Just the bit on file-scope/global-scope initialisation alone can bite even experienced developers who are adding a new nonlocally-scoped instance of a new class.
- Loudergood 11mo agoIf only.
- EPWN3D 11mo agoAnd it hasn't worked in practice. C unfortunately does not have a very big pit of success -- it's way too hard to do the right thing and way too easy to do the wrong thing. The solution to this doesn't have to be "rewrite everything in Rust", but it does mean that you need to provide safe, easy implementations for commonly-screwed-up patterns. Then you're not asking people to be perfect C programmers; you're just asking them to use tools that are easier than doing the wrong thing.
- krupan 11mo agoNot sure why this is down voted when the whole point of TFA is to torture the C language into doing something it can't really do. I guess there's an unspoken assumption in TFA that you are stuck using C and absolutely cannot use a different language, not even C++?
- relling 11mo agoThis looks far less tortured to my eye than C++. I think a lot of us have this self-imposed rule, for whatever reason, that we absolutely will not use C++.
- pjmlp 11mo agoC folks rather reproduce badly C++ than acknowledge its Typescript like improvements over C.
- lelanthran 11mo ago> C folks rather reproduce badly C++ than acknowledge its Typescript like improvements over C This is a rather crude misrepresentation; most C programmers who need a higher level of abstraction than C reach for Java, C# or Go over C++. IOW, acknowledging that C++ has improvements over C still does not make the extra C++ footguns worth switching over. When you gloss over the additional footguns, it looks like you're taking it personally when C programmers don't want to deal with those additional footguns. After all, we don't choose languages based on which one offers the most freedom to blow your leg off, we tend to choose languages based on which ones have the most restrictions against blowing your leg off. If your only criteria is "Where can I get the most features", then sure, C++ looks good. If your criteria is "Where are the fewest footguns", then C++ is at the bottom of the list.
- pjmlp 11mo agoNah, it is called life experience meeting those kind of persons since the 1990's, starting on BBS forums. My criteria is being as safe as Modula-2 and Object Pascal, as bare minimum. C++ offers the tools, whereas WG14 has made it clear they don't even bother, including turning down Dennis Ritchie proposal for fat pointers.
- lelanthran 11mo ago>> looks like you're taking it personally > it is called life experience meeting those kind of persons Looks like you are confirming that you are taking it personally. I don't understand why, though. You cannot imagine a programmer that wants fewer footguns?
- pjmlp 11mo agoYes, when careless programmers are responsible for critical infrastructure systems, and rather take a YOLO attitude to systems programming.
- flashgordon 11mo agoActually this was my first instinct too. Just limit what you use c++ for and write c code with templates and be done with it. The problems I am guessing start when you are tempted into using the rest of the features one by one. You have generics. Well next let's get inheritance in. Now a bit of operator overloading. Then dealing with all kinds of smart pointers...
- eptcyka 11mo agoWhat would be the detrimental effect of using smart pointers?
- flashgordon 11mo agoOh i didnt mean that smart pointers were bad or detriemental. Or even that any of the other gazzilion features of C++ were bad (or detrimental) on their own. Just that C++ has sooo many features that i dont think there is any one in the world who knows who any one feature X interacts with feature Y so your ability to reason about what you have written in C++ is significantly lowered. If you can say I will only use features A, X an Z of C++ and some how enforce it then you are mitigating a lot of the risk. IIRC Carbon (Google's new lang to migrate their code off C++) came about because they themselves used C++ in a very bounded way (I recall a lot of the templates they created for their use of C++ actually resembled how Go code looked like and may have been one of the reasons for creating Go). But I am not sure how many mere mortals have that kind of tooling and discipline to limit themselves?
- 1718627440 11mo agoUnclear, not explicit ownership.
- hawk_ 11mo agoIs there a way to pass compiler switches to disable specific C++ features? Or other static analysis tools that break the build upon using prohibited features?
- fweimer 11mo agoNo two development groups agree on the desired features, so it would have to be a custom compiler plugin. You could start with a Perl script that looks at the output of “clang++ -Xclang -ast-dump” and verifies that only permitted AST nodes are present in files that are part of the project sources.
- hawk_ 11mo agoFor sure no two groups want the same subset but is there no "standard way" to opt in / out in the ecosystem? It's strange that there are large orgs like Google enforcing style guidelines but manual code reviews are required to enforce it. (or may be my understanding of that's enforced is wrong)
- pjmlp 11mo agoYes, via static analysis tools it is possible. As usual with additional tooling, there must exist some willingness to adopt them.
- 1718627440 11mo agoThere is -fno-rtti, -fno-exceptions, -Wmultiple-inheritance, -Wvirtual-inheritance, -Wnamespaces, -Wsuggest-final-types, -Wsuggest-final-methods, -Wsuggest-override, -Wtemplates, -Woverloaded-virtual, -Weffc++, -fpermissive, -fno-operator-names and probably many more. The warnings can be turned into errors, e.g. -Werror=namespaces.
- EPWN3D 11mo agoIt never seems to work out that way though. C++ is just too large a language, and it gets bigger with each revision. The minute you hire a senior/principal engineer who loves C++, they'll make the case to enable "just this one" feature, and before you know it, you've got a sprawling C++ code base, not a "C with a light dusting of C++" code base.