←back to thread

155 points samuell | 7 comments | | HN request time: 0.422s | source | bottom
Show context
kjksf ◴[] No.44749375[source]
I think this page describes "what" but not "why" of Carbon.

Carbon exists so that it's possible to migrate a large C++ code base, like Chrome, from C++ to something saner, incrementally.

The most important attribute of Carbon is not the specifics of the syntax but the fact that it's designed to be used in a mixed C++ / Carbon code base and comes with tooling to convert as much of C++ as possible to Carbon.

That's what makes Carbon different from any other language: D, Zig, Nim, Rust etc.

It's not possible to port a millions line C++ code base, like Chrome, to another language so large C++ projects are stuck with objectively pretty bad language and are forced to continue to use C++ even though a better language might exist.

That's why Carbon is designed for incremental adoption in large C++ projects: you can add Carbon code to existing C++ code and incrementally port C++ over to Carbon until only Carbon code exists.

Still a very large investment but at least possible and not dissimilar to refactoring to adopt newer C++ features like e.g. replacing use of std::string with std::string_view.

That's why it's a rational project for Google. Even though it's a large investment, it might pay off if they can write new software in Carbon instead of C++ and refactor old code into Carbon.

replies(14): >>44749770 #>>44750227 #>>44750232 #>>44750657 #>>44751685 #>>44751728 #>>44752039 #>>44752523 #>>44752948 #>>44753844 #>>44754061 #>>44756351 #>>44758133 #>>44758430 #
cb321 ◴[] No.44749770[source]
Not to disagree, but to amplify - FWIW, most of what you say was also the sales pitch for C++ over ANSI C in the early 90s vs. the "pure Java" mentality that shortly followed in the late 90s (with a megaton of Sun Microsystems marketing to re-write almost everything rather than bridge with JNI). People neglect how practical incrementalism can be.

Also, FWIW, it is very ergonomic for Nim to call C (though the reverse is made complex by GC'd types). { I believe similar can be said for other PLangs you mention, but I am not as sure. } It's barely an inconvenience. Parts of Nim's stdlib still use libc and many PLangs do that for at least system calls. You can also just convert C to Nim with the c2nim program, though usually that requires a lot of hand editing afterwards.

Maybe they should write a C++2carbon translator tool? That would speed things up for them. Maybe they already have and I just haven't heard of it? I mean the article does say "some level of source-to-source translation", but I couldn't find details/caveats poking around for a few minutes.

replies(4): >>44750077 #>>44751953 #>>44752008 #>>44753027 #
1. chandlerc1024 ◴[] No.44753027[source]
Source-to-source translation is definitely planned. We've even done some early experiments.

But we need to get the language and interop into good shape to be able to thoroughly test and evaluate the migration.

replies(3): >>44753869 #>>44754585 #>>44754823 #
2. justcuriousab ◴[] No.44753869[source]
Is there a compiler, maybe an online one, for Carbon, or some way to compile and run Carbon code? And if not, what are the plans for that?
replies(1): >>44767982 #
3. cb321 ◴[] No.44754585[source]
I see. So, it's just a slide-ware bullet point right now? It would be helpful to really emphasize a word like "planned" in that bullet. It might have been lifted from some future-sounding/plan-oriented list and now the material makes it seem like it's actually available.
4. justcuriousab ◴[] No.44754823[source]
I am trying to run Carbon in Godbolt.

Printing as in the example from Carbon's Github repository, does not work. 'Print("Test");' gives a complaint about not finding 'Print'.

replies(1): >>44768042 #
5. josh11b ◴[] No.44767982[source]
The nightly release of the Carbon compiler can be used via https://carbon.compiler-explorer.com/ . Note that it is definitely a work in progress, it hasn't even reached our v0.1 goals yet, but a good chunk of important functionality is working.
6. josh11b ◴[] No.44768042[source]
That is correct. Strings and I/O both have a bunch of work to be done. Printing currently requires workarounds like https://godbolt.org/z/MP4164f7s
replies(1): >>44789932 #
7. josh11b ◴[] No.44789932{3}[source]
Array iteration got checked into the prelude so this is now shorter: https://godbolt.org/z/YYheo19ea