Live data from Hacker News

Carbon’s most exciting feature is its calling convention

foonathan.net

211–220 of 223 posts

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

#211

I have to say, and pardon me for saying so, but Carbon seems to be utterly uninteresting to me. They are not solving any interesting problems that shows me that they are creating a modern language. As an example, look at this issue from the mold linker: https://github.com/rui314/mold/issues/584 They are looking at creating an embeddable custom dynamic linker in order to greatly reduce loading times, by fixing locatio…

Carbon solves a very important problem, to realize Google's vision for C++ which they lost trying to make through ISO.

That is all.

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

#212
post #35

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.

In fairness this is as opposed to Go? Swift? Rust? Java? C#? Then C and C++ are defacto controlled by private companies: Google+Apple do pretty much all the clang development, MS does MSVC - if they choose not to implement a feature that’s approved, or implement one that isn’t, that is the de facto standard. You can argue it would require all three to agree on something, but that’s still essentially making WG21 somew…

> Google+Apple do pretty much all the clang development

They don't anymore, that is why clang is lagging in ISO C++20 features, as no one else has taken up their roles.

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

#213

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?

The thread lifetime is also scope-bound, to ensure the thread dies before any object it might be referring to does.

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

#214

Earlier quoted context omitted.

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.

There is no need to copy objects for multiple threads to refer to them.

It's just that there is a single owner, and the other threads have a non-owning view only.

You need strict control on the thread lifetime, which is enforced through the same single ownership system, in order to enforce this.

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

#215
post #207

Earlier quoted context omitted.

What about rust?

As much as I love Rust, it really has a significant impedance mismatch at the low-level with GameDev. Things must be initialized in Rust. Things must have a single identifiable owner. Things really want to be immutable. Sure, you can duck these in Rust with lots of "unsafe". But, if you do that, are you really gaining anything from using Rust?

I agree with you that Rust isn't a perfect match for video game development. Jonathan Blow's Jai is targeting that sort of program, it's not offering Rust's safety promises (Jon is confident this doesn't matter) but it can hardly be less safe than C++.

However, the purpose of unsafe is to mark code that does something which a human needs to check for correctness. We're not saying "This isn't OK" but "The compiler can't check this is OK, so a person needs to do so". If you write C++ today, all of your code is like that. I'd be astonished if more than a tiny proportion of the actual game code in a modern video game needed that treatment in Rust.

For example, Rust's approach to late initialization is std::mem::MaybeUninit, a wrapper type which says to the compiler hey, I am not initialized yet, it's OK to write a T value into me, but you can't read my value until somebody says they're done initializing me. The "say you're done initializing" part is indeed unsafe, but that's a small part of the program. That intern writing a zone preview gadget? They don't need to be writing unsafe initialization code, when they try to access preview_zone.orb_color the compiler tells them this is MaybeUninit and so they can't read it. "Huh, apparently orb_color is MaybeUninit ?" "Oh, just show all the orbs in preview as orange, it'll be fine". You just avoided Undefined Behaviour and possibly a trip to the land of "But it works in debug builds".

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

#216

Earlier quoted context omitted.

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

The thread lifetime is also scope-bound, to ensure the thread dies before any object it might be referring to does.

Sorry, I meant how to guard against race conditions where multiple threads try to write to the same shared memory?

This is clasically done via memory synchronization mechanisms/atomics.

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

#217
post #179

Earlier quoted context omitted.

> How would you define object identity fn main() { let vs = [(), (), (), (), ()]; for v in vs { println!("{:?}", v); } } This loop will five times print "()", because `v` will iterate through all five elements of `vs`. Are this values are identical or they aren't? I don't know, it doesn't matter, isn't it? But I think of them as of different values: they are different members of `vs`.

They are the same value , but with different identities . vs[0], vs[1] etc. are different objects , but they are all initialized with the same value. The difference is kind of irrelevant for a constant object like an empty tuple. But imagine the following program: fn main() { let mut vs = [(1,), (1,), (1,), (1,), (1,)]; vs[0].0=2; for v in vs { println!("{:?}", v); } } Here we can see that identity is in fact importa…

> They are the same value, but with different identities. vs[0], vs[1] etc. are different objects

What allows you to say that they have different identities? They are zero-sized types. Literally zero. `()` is a type and `()` its the only possible value. log(1) = 0 bit. If you look into machine code you will not find anything that you can call an object. The very existence of `()` is a shared dream of a programmer and compiler, and `()` ceased to exist after a compilation.

> But imagine the following program

In this program you are using types of size > 0bit, which allows more than 1 value of that type. But even then I wouldn't bet that they are different objects only because you changed one. If you didn't, it would be completely logical to replace them all with just one value in a memory, while pretending that there are many copies of it.

In this particular case I don't believe rustc would manage to do it even if we drop mutation from the example. And I can't think of a case when it will manage. But I wouldn't bet that such case doesn't exist.

> By the way, note that your example should be completely equivalent to the following C++ program

Hmm... And if we write in C++ something like:

    fn main() {
        let vs = [(), (), (), (), ()];
        for i in vs.iter() {
            println!("{:?} {:?}", v, v as *const ());
        }
    }
Will we get an output like this:

    () 0x7ffdae96bec8
    () 0x7ffdae96bec8
    () 0x7ffdae96bec8
    () 0x7ffdae96bec8
    () 0x7ffdae96bec8
Will all addresses be equal? If they are, then the proposition "C++ also pays a price for insisting not only that objects have addresses, but those addresses are distinct"* is false.

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

#218
post #207

Earlier quoted context omitted.

What about rust?

As much as I love Rust, it really has a significant impedance mismatch at the low-level with GameDev. Things must be initialized in Rust. Things must have a single identifiable owner. Things really want to be immutable. Sure, you can duck these in Rust with lots of "unsafe". But, if you do that, are you really gaining anything from using Rust?

And yet…Bevy exists and has a nice API.

> But, if you do that, are you really gaining anything from using Rust?

In each new release of Bevy, they've found soundness bugs with the borrow checker—seems like they're gaining something.

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

#219

Earlier quoted context omitted.

The thread lifetime is also scope-bound, to ensure the thread dies before any object it might be referring to does.

Sorry, I meant how to guard against race conditions where multiple threads try to write to the same shared memory? This is clasically done via memory synchronization mechanisms/atomics.

I don't understand how this has anything to do with lifetime management, which is what GC/RC/ARC are for.

You do need to synchronize concurrent access to the same object, and it's not just concurrent writes, it's concurrent accesses if at least one of them is a write.

Post reply on HN