Live data from Hacker News

Parsing C++ is literally undecidable (2013)

blog.reverberate.org

101–110 of 146 posts

Re: Parsing C++ is literally undecidable (2013)

#101
post #72
post #66

Earlier quoted context omitted.

In most European universities CS and Engineering are intermingled. Pure CS theory tends to be a maths major.

> In most European universities CS and Engineering are intermingled. Not at the time, when CS didn't even exist in many European universities, or was rudimentary at best.

You will find plenty of degrees already available during the 70's, almost a decade before C++ came to be.

Re: Parsing C++ is literally undecidable (2013)

#102
post #97

Earlier quoted context omitted.

Counterpoint, Rust is actually easier to learn, and take way less time from inception to writing production-ready code.

even the tutorial says that borrowing has a high learning curve

The biggest problem with C++ is that all real life production code is full of memory safety bugs. People usually just live with it. If you want to minimize memory safety issues, C++ becomes even harder than Rust.

Re: Parsing C++ is literally undecidable (2013)

#103
post #27

Earlier quoted context omitted.

The problems with modules is not getting the system right, the module proposal owners are well aware how to do it. The problem was the politcal wars of tons of companies that don't want to let go of their in-house build systems based on translation units just to make use of modules. So the end result is a compromise to make some of those big names happy.

Can you give a specific example of something which was "bent up" from its more appropriate standardization to placate those large companies?

Include headers as modules, aka header units.

Which also brings their macros into scope.

Re: Parsing C++ is literally undecidable (2013)

#104
post #33

Earlier quoted context omitted.

On single developer projects as long as one doesn't stay too much away from them, scale it up to multiple sized distributed teams, add binary libraries, and you end up with double frees, leaks and ownership issues all over the place.

Of course there will always be some issues somewhere. But, ignoring perfect memory safety, the issues are widely overblown, to the extent that I find manually managing memory a lot easier than dealing with GC once a project grows beyond a couple KLOC. It's all about proper planning and code organization. Use pooling, central manager structures, etc. If it can be avoided, then do not allocate and free stuff in a singl…

> You certainly want to (and I'm sure you easily can) contain each ownership management domain wholly in one team.

That doesn't work in enterprise projects with heavy dosis of consulting.

Re: Parsing C++ is literally undecidable (2013)

#105
post #24

Earlier quoted context omitted.

Plenty of GC enabled system languages have proven their value, up to building full stack graphical workstations, so far they just lacked somg big corp political and monetary willingness to push them down the anti-GC devs no matter what. Thanfully with the likes of Swift on iDevices, Java/Kotlin on Android (with an increasingly constrained NDK), COM/UWP über alles + .NET on Windows, ChromeOS + gVisor, Unreal + GCed C+…

Swift's GC is really a lot closer to modern C++ style memory management than the other languages you mentioned. If you use RAII & shared_ptr in C++ you are using the exact same techniques that Swift's "GC" uses.

And as proven by the ixy paper, quite slow versus tracing GCs.

Re: Parsing C++ is literally undecidable (2013)

#106

As someone who had spent quite some time developing C++ refactoring tools, here's the most concise example of the problem: void func() { a d; } If a is a class template, the line in func() declares an instance of type "a ". If a is a global variable, it describes an invocation of the " " operators for 4 different variables. Maintaining a parse tree of this is a massive mess, especially if func() is a template itself…

Thank you, as someone with no C++ background, this example makes the issue at hand much clearer.

Re: Parsing C++ is literally undecidable (2013)

#107
post #91
post #10

Can we design a language (cpp-prime?) that is basically c++ but makes parsing easier? I'm thinking reduce the keyword reuse, use different symbols for multiplication and pointers etc. The code would be easy for c++ developers to read and converting between the two could be automatic. However, we would be able to build tooling for this new language much more easily. It would also compile quicker.

There are been hundreds of attempts using a number of different ideas. The reason for C++ and not those alternatives is there is a lot of C++ code. If most of my code is C++ I don't gain anything from your new language as I spend most of my time maintaining old code. Even if I use your language for new code that means I constantly have to remember if I'm fixing a bug using C++ code rules or the new language rules. So…

I read the suggestion as being about a new syntax for the existing language C++. For that you'd need 'only' a transpiler (and syntax high-lighter in your favorite support tools), quite possibly written in a readily available language, perhaps even C++. That should address your concerns regarding availability on various platforms and optimization. Your other concerns of course stand.

I, for one, find different languages with similar appearance needlessly confusing. I what the experience with different syntaxes for the same language would be.

Re: Parsing C++ is literally undecidable (2013)

#108
post #43

Earlier quoted context omitted.

> I give it about 10 years time, for pure manual memory management to be like Assembly and embedded development. For someone who has spent some time thinking about memory management strategies, manual MM isn't actually that much additional work. By far, most code doesn't allocate or free (and that's a good thing). So MM->GC is hardly like Assembly->Compiler. In Assembly you're constantly allocating and pigeonholing,…

> By far, most code doesn't allocate or free (and that's a good thing). Depends on the code you write. If, like in C++, non-stack memory management is painful, programmers tend to react like you suggest. In pure-by-default languages, you are creating new and destroying old objects all the time. (At least conceptually. A sufficiently smart compiler can eliminate most of that.)

Obviously depends on the use case, but since C++11 there is little to no pain involved in manual non-stack memory management. You clearly express the ownership semantics through things like std::unique_ptr and std::shared_ptr and if those make sense then everything works (minus problems like circular shared_ptr references, which exists in similar forms with GCs).

Re: Parsing C++ is literally undecidable (2013)

#109
post #32

Earlier quoted context omitted.

Rust seems to be the most successful zero-overhead language competitor to C++, though it's far not as mature as C++ yet.

Rust has a high learning curve (borrowing, etc). Rust is a competitor to ADA, not C++. You can certainly ask developers to write things in rust instead, and even progressively rewrite codebase in rust since it's compatible with C++, but a language is about adopters, and ease of learning for beginners and students.

Interesting. I feel like most C++ programmers I meet have a high level of enthusiasm for Rust, as it has C++'s high/low level blend and the safety helps prevent more footguns.

Re: Parsing C++ is literally undecidable (2013)

#110
post #10

Can we design a language (cpp-prime?) that is basically c++ but makes parsing easier? I'm thinking reduce the keyword reuse, use different symbols for multiplication and pointers etc. The code would be easy for c++ developers to read and converting between the two could be automatic. However, we would be able to build tooling for this new language much more easily. It would also compile quicker.

There's not really a need anymore, because LibClang[1] has solved the parsing problem. Historically it was really hard to write tooling (syntax highlighters, static analyzers, scripts to update build dependendencies, etc.) for C++ due to the difficulty of parsing the language. In the past several years, that has completely changed - you just call LibClang to handle the parsing for you, and work with the high-level ab…

You indeed no longer have to do the parsing, but I've been told that even the AST is a beast because the language is so complicated. Corner cases abound. (Note: Have not used libclang myself, but I look at clang ASTs on godbolt from time to time).
Post reply on HN