Is Google really going Carbon neutral?

Is Google really going Carbon neutral?

Okay, keeping the horrible title pun aside, I was intrigued when Chandler Carruth announced Carbon at the recent Cpp North 2022. Not because of the "new programming language" but actually because I wanted to know all about the reasons that led to this creation in the first place. Cpp is my go-to choice for performance and has been ever since my acquaintance with the language. When these people were claiming that there were things that can make this highly performant language even better, it hit my curiosity.

Evolution is necessary, irrespective of the subject. You must constantly try to evolve as a person, your relationships must evolve, and your work must evolve. The same goes with Languages

C evolved to become C++ Java evolved to become Kotlin JavaScript evolved to become my favorite Typescript

But have you ever wondered, that when all these languages JS, Java, and C have their respective associations for standardization and improvements like JS has ECMA which releases new variants every year, then why do we need their evolved specimens? The same even applies to JS frameworks (just saying...enough is enough guys).

6ok4dl.jpg

Then, why did Google create Carbon when C++ 23 is going to come out.

Well, here's why:

Technical debt and getting over it: Backward compatibility is a curse, the more your language is well adopted the harder it becomes for you to introduce fundamental changes in it, now this results in a huge technical debt where sometimes you find yourself in a place where you know a better way of doing a particular thing but because this can break previous versions you are forced to avoid it ( my deepest condolences to those who work at ECMA )

Improved grammar and syntax: So, C++ was first launched in 1985, and the syntax has been followed ever since. Those who code in C++ can relate with me when I say that the syntax can be made a little better, and even I agree with Google on this. After all Print("something"); looks much better than std::cout<<"Something"<<endl;

Local namespace vs Global namespace: Now I haven't had the privilege of working on a large C++ codebase but the idea of having only single namespace globally which every other file has to merge into seems a bit off when scaling is considered. It's fun and simpler to have a modular and exportable codebase.

Public vs Private declaration: Here's where I don't agree with what google did, well from a security point of view I think it's better to have your class members private until explicitly made Public. No wonder C++ we learned in our school and colleges came with the public there by default. But Google thinks the other way, they felt that all the members are better declared public by default and are private until declared explicitly, now they're not wrong but I prefer to be old-school in this ( maybe, I need to evolve :P ).

Interop: One of the best things I liked about Carbon is the 100% Interoperability that it offers, which means you can import any C++ header file directly into Carbon and it would work just fine. TBH, If I were building Carbon myself then this would be the first thing even I'd look into.

struct SomeLibrary{  
  int variableName;
}

Now Carbon Code

import Cpp library "SomeLibrary.h"; 

fn someFunction( someParam ){  
  cppLibrary: lib = Cpp.SomeLibrary; 
  Print(lib.variableName); 
}

Now the magic is when your carbon file compiles into a cpp header and you can use the same in your C++ code.

Now, these are only a few things that I was able to understand, the rest went above my head. Not to sound like a cOntEnt CreaToR but lemme know if you like anything else in the comments below.

Until next time,
Hail Hydra!!

Did you find this article valuable?

Support Kunal Dubey by becoming a sponsor. Any amount is appreciated!