Carbon (programming language)
Logo on Carbon's GitHub organization | |
Family | C |
---|---|
Designed by | |
Typing discipline | Static, nominative, partly inferred |
Implementation language | C++ |
License | Apache-2.0-with-LLVM-Exception |
Filename extensions | .carbon |
Website | github |
Influenced by | |
C++, Rust, Swift[citation needed] |
Carbon is an experimental programming language designed for interoperability with C++.[1] The project is open-source and was started at Google. Google engineer Chandler Carruth first introduced Carbon at the CppNorth conference in Toronto in July 2022. He stated that Carbon was created to be a C++ successor.[2][3][4] The language is expected to have an experimental MVP version 0.1 in 2025 and a production-ready version 1.0 after 2027.[5]
The language intends to fix several perceived shortcomings of C++[6] but otherwise provides a similar feature set. The main goals of the language are readability and "bi-directional interoperability" (which allows the user to include C++ code in the Carbon file), as opposed to using a new language like Rust, that, while being influenced by C++, is not two-way compatible with C++ programs. Changes to the language will be decided by the Carbon leads.[7][8][9][10]
Carbon's documents, design, implementation, and related tools are hosted on GitHub under the Apache-2.0 license with LLVM Exceptions.[11]
Example
The following shows how a program might be written in Carbon and C++:[12]
Carbon | C++ |
---|---|
package Geometry api; import Math; class Circle { var r: f32; } fn PrintTotalArea(circles: Slice(Circle)) { var area: f32 = 0; for (c: Circle in circles) { area += Math.Pi * c.r * c.r; } Print("Total area: {0}", area); } fn Main() -> i32 { // A dynamically sized array, like `std::vector`. var circles: Array(Circle) = ({.r = 1.0}, {.r = 2.0}); // Implicitly converts `Array` to `Slice`. PrintTotalArea(circles); return 0; } |
#include <math.h> #include <iostream> #include <span> #include <vector> struct Circle { float r; }; void PrintTotalArea(std::span<Circle> circles) { float area = 0; for (const Circle& c : circles) { area += M_PI * c.r * c.r; } std::cout << "Total area: " << area << "\n"; } auto main(int argc, char** argv) -> int { std::vector<Circle> circles = {{1.0}, {2.0}}; // Implicitly converts `vector` to `span`. PrintTotalArea(circles); return 0; } |
See also
References
- ↑ "README". https://github.com/carbon-language/carbon-lang/blob/trunk/README.md. Retrieved 2023-09-06. ""It is designed around interoperability with C++ as well as large-scale adoption and migration for existing C++ codebases and developers.""
- ↑ "Scheduled events for Tuesday, July 19, 09:00 - 10:30". CppNorth, The Canadian C++ Conference, July 17–20, 2022. CppNorth. https://cppnorth2022.sched.com/event/140f8/keynote-chandler-carruth-nulbscience-experiment-timenulb?linkback=grid.
- ↑ "Carbon Language: An experimental successor to C++ - Chandler Carruth - CppNorth 2022". CppNorth. 2022-07-22. https://www.youtube.com/watch?v=omrY53kbVoA.
- ↑ Bradshaw, Kyle (19 July 2022). "Carbon, a new programming language from Google, aims to be C++ successor". 9to5Google. https://9to5google.com/2022/07/19/carbon-programming-language-google-cpp/.
- ↑ Carbon Language: Roadmap, carbon-language, 2024-01-11, https://github.com/carbon-language/carbon-lang/blob/trunk/docs/project/roadmap.md, retrieved 2024-01-18
- ↑ "Difficulties improving C++". carbon-language/carbon-lang repo. Google. 2022-07-21. https://github.com/carbon-language/carbon-lang/blob/b62b7464a4f99f9101edbe3ea5b76d6cb2cdbc9b/docs/project/difficulties_improving_cpp.md.
- ↑ Carruth, Chandler; Ross-Perkins, Jon; Riley, Matthew; Hummert, Sidney (23 July 2022). "Evolution and governance". carbon-language/carbon-lang repo. Google. https://github.com/carbon-language/carbon-lang/blob/trunk/docs/project/evolution.md.
- ↑ Illidge, Myles (21 July 2022). "Google’s Carbon programming language aims to replace C++". MyBroadband. https://mybroadband.co.za/news/software/453410-googles-carbon-programming-language-aims-to-replace-c.html.
- ↑ Jackson, Joab (20 July 2022). "Google Launches Carbon, an Experimental Replacement for C++". The New Stack. https://thenewstack.io/google-launches-carbon-an-experimental-replacement-for-c/.
- ↑ Mustafa, Onsa (20 July 2022). "Carbon, A New Programming Language from Google As A C++ Successor". PhoneWorld. https://www.phoneworld.com.pk/carbon-a-new-programming-language-from-google-as-a-c-successor/.
- ↑ "carbon-lang/LICENSE". 2020-06-16. https://github.com/carbon-language/carbon-lang/blob/31df852738aea520a1a1800259120bc10ce7a005/LICENSE.
- ↑ "carbon-lang/docs/images/snippets.md at trunk · carbon-language/carbon-lang" (in en). https://github.com/carbon-language/carbon-lang/blob/trunk/docs/images/snippets.md.
External links
Original source: https://en.wikipedia.org/wiki/Carbon (programming language).
Read more |