Live data from Hacker News

Carbon’s most exciting feature is its calling convention

foonathan.net

161–170 of 223 posts

Re: Carbon’s most exciting feature is its calling convention

#161

Earlier quoted context omitted.

> you sure have made some very odd comments and I don't know what to make of them Well they’re from practical experience aren’t they.

Well, first you don't seem to understand what 'ambiguity' means in the context of parsing "Nobody writes a parser that has a random decision..." which is weird. It's a very establish meaning here. Then you say "I guess I don't understand why we use languages for writing grammars that let you express ambiguity in the first place" without any suggestions, or even if this is possible, or if it is, whether the resulting…

If you choose to specify your language using a class of grammar which permits ambiguity, then you have to resolve that ambiguity.

If instead you choose to specify your language using a class of grammar which does not permit ambiguity, then you don't have to resolve it because it never existed.

That's the point.

The suggestion is to either specify your language using a formal grammar which does not permit ambiguity, or to specify your language imperatively, using a reference parser.

I've written many parsers, both using parser generators and manually. I'd choose to write one manually. In fact, I'm currently looking at a project at work right now to take a generated parser and to re-write it manually because it's easier to work with.

That's a pretty mainstream opinion amongst professionals in the industry - not sure why you think it's surreal or why it's throwing you.

Re: Carbon’s most exciting feature is its calling convention

#162

Earlier quoted context omitted.

since C++20 you can get around this https://en.cppreference.com/w/cpp/language/attributes/no_uni...

comex mentions this above. It's a nice hack, but it doesn't actually fix the problem I was talking about, you can give this attribute to a data member, which allows you to do the ZST marker type trick that is available in other languages, but you can't apply the attribute (at least, not as documented) to a type itself, those empty tuples are obliged to take up one byte each.

But why not use an empty base class instead? That seems both more idiomatic and simpler. And since C++ supports multiple inheritance, there's no limit to how many empty base classes you could have.

Re: Carbon’s most exciting feature is its calling convention

#163

Earlier quoted context omitted.

Scope-bound resource management, like C++. GC and ARC are for people that need shared ownership, which is pretty much always a bad idea.

So how do you implement multithreading if the above are a bad idea?

Deep copy on passing between threads. Interesting pros and cons to the performance of that vs sharing pointers.

Re: Carbon’s most exciting feature is its calling convention

#164

Earlier quoted context omitted.

It's Google but yes, another instance of Embrace, Extend and Extinguish . I hope this doesn't take off, with my sincere apologies to the ones who have been working hard on this. The last thing the C/C++ ecosystem needs is becoming de facto owned by a private company.

I prefer a fast evolution when necessary to a slow committee process. I don't see any drawbacks, unless your the type that prefers to build consensus before moving forward

I think most people feel today that, if anything, C++ is moving too fast (in terms of standards evolution), so I really don't see who wants an even faster changing C++.

Re: Carbon’s most exciting feature is its calling convention

#165

Calling convention? That's the most exciting feature? It doesn't boost productivity, reduce compile times, offer a larger standard library or create a boost a reasonable language would provide? No thanks google. I've been saying that for years now. You jumped the shark

The author has expertise in C++ and is excited about a C++-like language that addresses the pain point of C++'s calling convention which will _never_ be fixed by the standards committee due to their commitment on backwards compatibility.

This was not an overview of the language, so this comment seems a little uncharitable to the author.

Re: Carbon’s most exciting feature is its calling convention

#166
post #44

I'm sure the ship has sailed on Carbon's naming convention, but darn if that isn't a confusing article-title. It is interesting to contemplate the most-ambiguous and least-comprehensible/googleable name one might be able to give to a piece of software. "the"? "Biden"? "Russia"? "water"? "air"? "dog"? "person"? "!"? "?"? " "?

Is this really an issue? Humans are pretty good at understanding context. You have been lead to the lead-roof by the lead builder.

Re: Carbon’s most exciting feature is its calling convention

#167

Earlier quoted context omitted.

Ok that's about the "parser generator" part. But what about the "formal grammar" part? Do you really want your language to be defined by a particular imperative parser implementation? I'm asking because I do have a practical problem: my team has a hand crafted parser for a language. It should follow a spec written in EBNF. That spec could be ambiguous it's not because an automated tool checks that that EBNF grammar i…

> Do you really want your language to be defined by a particular imperative parser implementation? Yes please. The code defines completely and unambiguously how the language is parsed.

If the code only handled parsing the grammar, I'd be with you, but more than half of a parser deals with what to do with what you just parsed which may be quite different between the various implementations of the grammar

Re: Carbon’s most exciting feature is its calling convention

#168

Earlier quoted context omitted.

Well, first you don't seem to understand what 'ambiguity' means in the context of parsing "Nobody writes a parser that has a random decision..." which is weird. It's a very establish meaning here. Then you say "I guess I don't understand why we use languages for writing grammars that let you express ambiguity in the first place" without any suggestions, or even if this is possible, or if it is, whether the resulting…

If you choose to specify your language using a class of grammar which permits ambiguity, then you have to resolve that ambiguity. If instead you choose to specify your language using a class of grammar which does not permit ambiguity, then you don't have to resolve it because it never existed. That's the point. The suggestion is to either specify your language using a formal grammar which does not permit ambiguity, o…

> If you choose to specify your language using a class of grammar which permits ambiguity, then you have to resolve that ambiguity.

I added an edit after which you may not have seen:

   even context-free grammars have ambiguity, eg. the regexp "aa" is legal but ambiguous for sentence "aaa"
So what grammar can you suggest that's even weaker than context-free (to make expressions of ambiguity impossible) and still useful?

> I'd choose to write one manually

Matter of taste I guess.

Re: Carbon’s most exciting feature is its calling convention

#169

Earlier quoted context omitted.

If you choose to specify your language using a class of grammar which permits ambiguity, then you have to resolve that ambiguity. If instead you choose to specify your language using a class of grammar which does not permit ambiguity, then you don't have to resolve it because it never existed. That's the point. The suggestion is to either specify your language using a formal grammar which does not permit ambiguity, o…

> If you choose to specify your language using a class of grammar which permits ambiguity, then you have to resolve that ambiguity. I added an edit after which you may not have seen: even context-free grammars have ambiguity, eg. the regexp "aa" is legal but ambiguous for sentence "aaa" So what grammar can you suggest that's even weaker than context-free (to make expressions of ambiguity impossible) and still useful?…

> So what grammar can you suggest that's even weaker than context-free (to make expressions of ambiguity impossible) and still useful?

It doesn’t need to be weak. For example use a Parsing Expression Grammar.

Re: Carbon’s most exciting feature is its calling convention

#170
post #120

Earlier quoted context omitted.

No, but that's also not relevant as C++ is ABI stable. I can take any C++ compiler, and I can compile any C++ library, and then I can take some other compiler and compile some other piece of C++ that calls my library, and it will Just Work. I can then go back to my library, and make a bunch of ABI safe changes, just as I would have to do in C, and compile my library again, with yet another compiler. At that point the…

The C++ standard does not define an ABI. > I can take any C++ compiler, and I can compile any C++ library, and then I can take some other compiler and compile some other piece of C++ that calls my library, and it will Just Work. This is most definitely not true. It just happens that clang and gcc are mostly compatible, but MSVC and clang/gcc is not! For example, vtables are implemented differently and therefore virtu…

[edit due to the above edit I just saw: wasn't me, I didn't see what you said as being inherently bad and so deserving of downvoting, otherwise I wouldn't have bothered replying :-/]

That sounds like what you're saying is that gcc or clang fail to conform to the platform ABI, which is a compiler bug. If a compiler wishes to ignore platform ABI, it doesn't make the ABI not a thing.

But if you are comparing ABI compatibility to MSVC, you are comparing the ABI used by the code generated by clang or gcc to what is by definition the windows platform ABI. If the code generated by a compiler targeting a given platform, does not match the ABI used by that platform, the problem is the compiler is generating broken code.

> vtables are implemented differently and therefore virtual method calls can crash

No, vtables are implemented incorrectly by the compiler. If the vtable for a type laid down by gcc or clang crashes when it is passed to a OS function, that means the compiler is broken, as the compiler has decided to ignore the platform ABI. Again, if I write a compiler that chooses to use the wrong ABI when interacting with the host OS, I don't get to claim that it is the language's fault, or the OS, or the ABI. Similarly I don't get compile code for linux that makes windows system calls, and then complain that there isn't a windows ABI.

Here is the thing: The ABI for vtables is specified for every non-trivial platform. The ABI for argument parameter ordering is specified for every platform. The ABI for struct layout and struct padding is specified for every platform.

"thiscall" is the ABI for member functions on windows, it's not some magical non-abi thing, is is by definition _the_ abi. There needs to be a name for it, because documentation at the very least has to be able to distinguish it from "cdecl". Importantly, claiming that it's a sign that C++ doesn't have an ABI, or that ABI isn't stable, is simply incorrect. The fact that it exists as a name we can reference is an indication that the ABI matters enough that it is specified. Claiming it's evidence of a lack of ABI is like claiming the C doesn't have an ABI because gcc has stdcall and cdecl - and thiscall is useful MS choosing it as the ABI for member functions on i386 is a reasonable performance win that gcc chose not to do, in favor of using cdecl everywhere, even if cdecl was a slow choice.

There is generally a pile of sadness when dealing with 32bit C++ as the various platform ABIs came into existence when C++ was new, and so the ABI for it on any given platform just happened to be whatever happened to be used by the first releases of the primary C++ compilers for those platforms. That's also why those ABIs - for windows, linux, macOS, etc - tended to not be super well designed or systematically created. Hence even when trying to match ABIs it was easy to hit edge cases where things went horribly wrong between completely different compilers. However even then, generation to generation of each of those compilers maintained ABI stability with themselves at least. Mercifully in the consumer 64-bit every compiler seems to have essentially gravitated to the itanium ABI, which is an actionably thought our and designed rather than evolved as the language is being invented.

So continuing to claim that there is not an ABI, or that that ABI is not stable, or whatever other claim you wish to make, does not make it become true just because you don't like C++. It also does not become true because you are a fan of a language that doesn't want to provide a stable ABI. The historical problems of gcc vs msvc were a product of how the respective ABIs were developed, but on architectures that are more modern it should not be a problem, and I'm sure that if you find places where the compilers differ from the host OS on a more modern platform the developers are much less likely to ignore the issue vs. i386 where they are stuck with whatever their exact ABI was in the early 90s.

In the end, to be very clear, C++ has an ABI, it is stable - a fact demonstrated by Windows, XNU, QT, etc all existing, and continuing to successfully exist. Technically the c++ standard library demonstrates this as well but given the various implementations of the standard library are now maintained largely by their respective compiler projects, that seems like cheating.

Post reply on HN