views:

12979

answers:

36

Why was Google's Chrome browser written almost entirely in C++ and not C# or Java?

+48  A: 

Because writing it in C# or Java would have added a huge dependency without giving them anything in return.

Shog9
Doesn't C++ add a *huge* dependencies as well? Would you be more specific how less of a dependency using C++ bring?
Sung Meister
Jay Bazuzi
From the user's point of view, I'd agree that they add dependencies that C++ doesn't. Most of the target audience just wants to download and run a browser.
MandyK
@Jay: We're not talking about some CRUD data-entry app here. A modern web browser is a huge undertaking, and you don't get to be naive about resource management just because you have garbage collection. Look at one of the dependencies Google *did* take on: WebKit.
Shog9
@Sung: The C++ runtime is quite lean compared to .NET/Java, and widely available. Beyond that, the dependencies added are entirely at the discretion of the developer: Google used WebKit, built a JS engine, and did their own UI abstraction.
Shog9
@Shog9: so by dependencies, you meant in the context of runtime. Thank you.
Sung Meister
@Shog9 - nice little implication that C# is only good for CRUD apps there. The size of the dependency might be part of the issue though I think Google's language policy is probably #1 reason why. C# has a good perf profile. @Jay - well said, sir. @Shog9 - go read http://yosefk.com/c++fqa/ .
kronoz
C++ is an ISO standard available on all machines Google might be interested in. .Net is designed for lock-in, Google didn't want to depend on Microsoft for their future.
Jimmy J
@Jimmy - C# and .net is an ISO standard too, and there are implementations for linux and mac. Oh and note Chrome uses win32 API calls directly all over the place. Hence your statement could be repeated replacing C++ with C# and deleting the last part which is simply incorrect.
kronoz
@kronoz: I use C#. It's great. Etc. But I don't pretend it makes all the bad scary parts of programming magically go away, or even that it makes all things easier. Please note that no one here has yet given a single concrete reason why one might want to use it for writing a *web browser*...
Shog9
I'm not saying C# is the be-all and end-all. I think C# is a nice language to use *in general*, and thus would be good on a web project - let's spin this around - why would C++ be a good choice? There are reasons why you might choose it, however C# isn't automatically a bad idea. That's the point!
kronoz
C# is a fine language, and .NET is a fine platform. I enjoy working with both. But it's a whale of a dependency, which was my point. C++, like it or not, lets you pick and choose your dependencies in a way that .NET does not (Mono allows actual compilation and linking, but that's fairly new).
Shog9
And FWIW, i don't really care what you or anyone else thinks of C++ as a language. I've never been terribly enthused with it myself. It allows you to segregate platform-specific code and to pick and choose which libraries you'll depend on on any given platform - for some apps, that's gold.
Shog9
Finally... Sorry if i offended you with the CRUD comment. My point is, .NET has a lot of good things to offer those writing CRUD and data-entry apps, but once you exclude those, exclude RAD, you're left with a very large framework that doesn't give you anything you can't get piecemeal elsewhere.
Shog9
@kronoz: "ISO" is a Microsoft con game - C# is a standard, .Net certainly isn't and without it C# isn't much use.
Jimmy J
Even if .NET was a ISO standard, that wouldn't solve the availability issue. So far, two implementations exist. One up to date, and one playing catch-up. That is not good enough if they want to be able to port to arbitrary platforms in the future.
jalf
Google already has a huge dependency on Java through Android and more importantly the GWT which most of their offerings are written in
Chris S
GWT compiles down to JavaScript for client code. Android is their own OS, and ships with their own custom Java VM. The Chrome browser can be installed and run by users on machines where they do not have administrative rights, much less control over the OS and installed runtimes - that imposes a rather different set of requirements from those applicable to *shipping an OS*.
Shog9
+23  A: 

Performance.

Java or .NET runtime need to start up and the programs are interpreted by the runtime. This decreases performance.

Niyaz
C# is not interpreted, it's JIT compiled, gives it a chance at beating native C++ programs, since it can optimize for the exact CPU. Many .NET programs have fantastic performance. (Maybe Java, too; not my area of expertise).
Jay Bazuzi
Niyaz is right about start-up time though. The initialization time to load up the .NET dependencies, support assemblies and cache them all is high. Once that is done, the execution time of .NET is usually on par with unmanaged code, but there is a startup cost.
Rex M
Browsers in general already have a slow start-up. I doubt using a framework would slow this down considerably.
Konrad Rudolph
I tend to open my browser once a day. I'd be glad to have 3 more seconds for JVM or CLR startup, if there are no more security flaws caused by buffer overruns and the like which you don't tend to get in managed languages.
Daniel Schneller
Languages don't shield you from security flaws.
Edouard A.
"Java or .net is ...interpreted by the runtime" -- and C++ code is interpreted by the C++ compiler. Both are (in general) interpreted into native optimized executable code before being executed (though, perhaps it's a matter of degree...)
Aaron
Konrad... to the contrary, using a managed language would make it MUCH worse. The reason that managed languages have a large start up time is they need to load libraries and start JIT compiling code. This would put an additional burden on browser startup.
shsmurfy
"if there are no more security flaws caused by buffer overruns and the like which you don't tend to get in managed languages." Funny, so unmanaged languages automatically give you buffer overruns huh? And all this time I thought it was poor programming...
GMan
@GMan yes, overflows are everywhere. Even in OpenSSH with their 5 levels of revision comitees, some slip in. It is inevitable even for the best
Eric
Though in all honesty, if Google went the Java/.NET path, they probably would have made a service/daemon to keep an instance running in memory at all times. Only the first launch would be slow
mcjabberz
+9  A: 

Because C++ is much faster than either of those languages and they didn't want such a huge dependency. The browser is designed for users more than anything and a lot of people still don't know how to download Java. There is also the guess that they have more programmers who are more exceptional in C++ than in C# or Java. I personally would have wrote it in Clojure :p.

Rayne
Aside from startup costs, c++ being faster is no longer true. For the majority of typical computational activities, JIT-ed CIL bytecode in modern runtimes is comparable to unmanaged c++.
Rex M
I don't believe I deserved a downvote for this when technically I am right.
Rayne
Actually, Java is one of Google's official languages (along with Python and C++), so I'm sure they have plenty of competent Java programmers!
John McCollum
@Rex M, Do you mean runtimes written in C++? I love how people dismiss startup times. I have written many utilities that completely do their work in less time then the .NET startup times.
bruceatk
I didn't know that John McCollum :)
Rayne
+26  A: 

Because C++ is a fast and very popular language?

qpingu
Its popularity is as much momentum as anything else. RE: fast, I know my C# programs end up at least as fast, given comparable time spent programming, because I'm done with shippable features in a fraction of the time; the remaining time can go to optimizing.
Jay Bazuzi
I don't think i would trust a Project manager who chooses a language for the reason of language being *popular*.
Sung Meister
1800 INFORMATION
@Sung - A popular language means that you will likely be able to find programmers able to support it in the future. The ready availability of a large pool of talent is a very important consideration when deciding on a language.
oxbow_lakes
C++ is th eonly language of choice for people who care about code quality and freedom to express their designs. C# might seem cool to a newbie but it soon runs out of steam and degenerates into massive verbosity when you run into the barriers inherent in the language.
Jimmy J
if MS is not using C# for their browser, Office or ever calculator in Vista why would Google use it?
Nazgob
@Nazgb: +1 to your comment
Vulcan Eager
@Nazgb, perfect dogfood argument :D
workmad3
Nazgob hit it on the head.
Max Lybbert
People don't give enough weight to "popular". The more people that are familiar with a language, the more that actually use it, translates in to "able to find more people to work on it in the future". Nothing against JAVA or C#, I actually like C#. They may someday finds themselves as popular as C++
Jim C
+12  A: 

Google employs OS-like features in its browser. Like process isolation in its tabs, one tab won't crash other tabs, even the plugins are on separate process. If you'll develop something on that level, C++ could give you the most hooks on OS

Michael Buen
I don't believe you. There's nothing about C# that would make doing that harder. (Probably Java, too, but I don't know Java well.)
Jay Bazuzi
Ok then, you code the next killer browser in C#. Hey I love C# too
Michael Buen
@Jay: Correct me if I'm wrong, but if you built a browser in C# and designed it to run each tab in a separate process, would you not lose most of the benefit of the .NET environment? Or can the .NET VM span multiple OS processes?
j_random_hacker
Michael, you are wrong on this score. The process isolation they employ on tabs is a Windows OS feature (not OS-like, as you implied). They are using a variant of a process known as a "job". If you open Process Explorer, you'll see what I am talking about.
AngryHacker
Adobe PDF viewer in one tab will freeze or crash Chrome. I've done it :-(
Andy Dent
@AngryHacker: indeed, what you say is what i'm also trying to convey. I just didn't go that further(i.e. Explaining the OS's process management through task manager). See? hasen j could understood what i said. I should have put double quotes on OS-like, if that triggers your pedantry. Why angry?
Michael Buen
@Andy Dent: In principle that shouldn't be. But since the "OS-like" features it implemented is just a hook on Windows feature(which AngryHacker too is well aware of), Windows is at fault there. The jury is out until we see its Linux and Mac version.
Michael Buen
The "one process per tab" rule has an exception for plugins, which can crash the whole app.
Max Lybbert
Why Angry? I am not. The domain name was available and I thought it was pretty cool to make my home there.
AngryHacker
It a similar level of difficulty in C++, C#, and Java [not equal, but similar in respect to the other tasks in the languages]. My thought is that they are using the MVC pattern to sperate the controller and model out to an individual process and keeping the [seperated (as intended)] view as what you see. This design would cause the individual processes to be a server and the viewer to be a client.
monksy
+123  A: 

Google Chrome is based on the open-source Webkit rendering engine (also used by Safari), and that is written in C++.

Thilo
This is the only compelling answer so far.
Jay Bazuzi
yep, i agree. it's because of webkit i think. also crossplatform: they want to port it to linux too they say.
Johannes Schaub - litb
The question remains, why did they choose webkit instead of something written in C# or java!
hasen j
Because there is no such thing as a fast, complete, and standard-compliant rendering engine written in C# or Java.
oefe
It is also coming for OS/X as per http://googlemac.blogspot.com/2008/09/platforms-and-priorities.html
Andy Dent
WebKit is written by the Safari team, so while it is technically also "used by Safari" that's not quite fair in spirit :D
olliej
Eh. They based the core on KHTML anyway.
Bernard
yeah, they borrowed the code from the KDE team -.-
Johannes Schaub - litb
As a curiosity, rumours say that WebKit is going to be added to Java7 too.
Esko
Interop with native code is pretty seamless in C#, though not so in Java. But the rendering engine alone is probably not really a reason.
Joey
I'm not sure I still understand why Chrome should be written in C++ simply because it uses Webkit which is C++-based. Safari (Mac), for instance, is an Cocoa app written largely in Objective-C (although the Webkit code is still C++)
Nocturne
@Debajit: Objective-C is still a lot closer to C++ than either Java or C# are. Anyone who's had to work with the .NET MSHTML wrappers knows that the extra level of indirection just adds pain.
Shog9
@hasen j: Because writing an HTML layout engine from scratch is no trivial task. WebKit-the-layout-engine was good enough, it's just that its Javascript engine wasn't
mcjabberz
+13  A: 

Chrome was designed for speed from the start!

The high performance of chrome was not a side effect, it's one of the main focuses of chrome. Otherwise, what would it offer over other popular browsers? (and why would anyone switch to it from, say, firefox?)

UPDATE

Chrome is intended to serve as a platform for web applications; this is why performance is key!

And, if you think about it, having chrome itself run inside another platform (e.g. .NET) is not very effective.

hasen j
Chrome was designed with WebKit, enabling speed ;-) Look at the new Safari 4 beta... blazingly fast, same rendering engine.
Jilles
I switched from firefox to chrome for my daily browsing, exactly for the speed reason (I still use FireFox for development (FireBug!))
Pim Jager
I switched to it for a while but returned to firefox! I've gotten used to all my favorite addons
hasen j
I could do without my add-ons, but I cannot do without incremental search.
Ed Swangren
AFAIK both Chrome and Firefox have incremental search.
Rene Saarsoo
yes, chrome has incremental search
hasen j
+85  A: 

Google has a list of approved languages (Javascript, Python, Java, C and C++ I believe). C# is not on that list, so it was never a candidate.

I can only guess that Java's bad reputation for user apps didn't help it. Eclipse famously had to write its own GUI classes to get an acceptable look, and as a user of Eclipse I have to say that performance still leaves a lot to be desired; especially when compared to similar programs (Komodo and Visual Studio).

Additionally, Chrome has a novel design that each tab runs in its own process (although plugins run in the main process, so crashing Acrobat or Flash brings down all PDFs or Flash animations). Operating systems have certain hooks to do this, and they are accessible from C. In a Java-fied Chrome, Google would have had to call those APIs through JNI, which seems like the long way 'round.

Max Lybbert
Eclipse is a wonderful program, but brings my slower machines to their knees. Not saying this has anything to do with Java, per se, just an observation.
Bernard
Besides from the initial startup time (about 30 seonds - I use MyEclipse 6.6) I don't have any performance issues with Eclipse. I just wish they could work on the startup as much as Visual Studio has. VS 2008 has a minimal startup time now of about 10 seconds on my system.
bruceatk
@bruceatk: Do you measure the startup time using your stopwatch or is there a way to measure it?
Ahmed Said
Visual Studio 2008 runs slower than eclipse on my machine
Edison Gustavo Muenz
they also use ruby in SketchUp
fnieto
I have to agree with Edison. VS2008 drags my machine to its knees sometimes, where I never have a problem with Eclipse.
JasCav
+12  A: 

As far as I understand it Google actually only permit their staff to program in either C++, Java or Python as a matter of policy.

I think the comments about performance are off the mark - yes Chrome is all about performance, however it is possible to write highly performant .NET applications, .NET is a JIT'd environment rather than interpreted, and tests have frequently demonstrated its performance capabilities. I am not sure about Java as I know little about it.

It's well known that C++ a horribly painful language to program in (see C++ FQA - yes, it is Frequently Questioned Answers), not to mention that memory management of highly multithreaded applications is well known to be a significantly difficult task.

In terms of using Webkit, the functionality provided by .NET for unmanaged interoperability would make it possible to do so regardless.

There are, however, some legitimate reasons not to choose C# for the project:-

  • Who's going to maintain it? - Google's core language competencies, tools, and infrastructure revolve around C++, Java and Python.
  • Though C# has a great performance profile, there sometimes are issues with startup time (the CLR runtime kicking in). This can be mitigated somewhat, but still exists to one degree or another.
  • Portability - though Mono provides portability for .NET applications, it may be easier for Google to port Chrome in native code due to its reliance on specific bare metal GUI APIs.
  • Wanting/requiring access to bare metal - chrome interacts with the win32 API directly in order to achieve its UI; this would be made far more difficult in .NET.
  • Wanting more convenient access to 3rd-party libraries - e.g. WebKit. 3rd-party libraries written in C/C++ are more easily accessible from unmanaged code with less interoperability issues. Since Chrome relies rather heavily on these it makes sense to write Chrome in the same language.

Note: Removed inflammatory references to C++ - for the sake of staying on-topic!!

kronoz
mono exists on mac.
Bernard
Aha! Edit time... thanks.
kronoz
EXcept the C++ FQA is wrong in nearly every respect. It completely ignores all C++ developments of the last ten years, eg. Nobody does manual memory management in C++ any more (which eliminates about half the FQA's ranting at a stroke).
Jimmy J
Jimmy, C++ sucks!
hasen j
@Jimmy - are you talking about smart pointers? That abstraction leaks nice and quick. C++0x is not yet available, nor is Chrome programmed in it. I sincerely doubt what you say about the last 10 years is correct.To me C++'s biggest problem is that it is un-parseable - has that changed? The syntax?
kronoz
@Jimmy - ...because I sincerely doubt that it has. As that would break most C++ programs already out there. C++ does not incorporate a GC, so precisely how do you avoid manual memory management?Frankly Jimmy I call B.S. on your comment.
kronoz
Memory management isn't that big a problem. It's just that you can't ignore it, other than that it's not a big deal. C++ has minimal runtime dependencies and will always be faster than C#. How can you guys expect google to use c# or Java, which force monster runtime requirements.
bruceatk
@kronoz, unparseable?? It can be just as readable as any other language. It's easy to write unreadable and cryptic Java or C#. Let me qualify my comments by the fact that I am currently programming in C# and Java. C++ for Chrome is the only language that makes sense to me.
bruceatk
@bruceatk - unparseable = can't be parsed by a /compiler/ *easily*. I was using that a figure of speech really, more accurately it has an undecidable grammar - http://yosefk.com/c++fqa/defective.html#defect-2 for a good discussion.
kronoz
I'm not saying C++ is an insane choice, only that you can argue for C# in this role and saying C# is slow or tied in to Windows is too easy and simply not necessarily accurate.
kronoz
If done in C# it would be tied to a runtime requirement that would be unacceptable for an application like this.
bruceatk
Wow, i wish i'd read this answer first. @kronoz, you have a serious chip on your shoulder WRT C++, and this was exactly why i thought the question should have been closed. FWIW: there's a lot more to resource management than memory. Try to forget about Dispose while you're knocking smart pointers...
Shog9
Well this question is inevitably going to bring up language hang-ups! I don't have a chip on my shoulder about C++, I just think it sucks *and for good reason*, which the FQA site covers nicely. Not just a 'language x suxz0rzz!!' thing.
kronoz
@kronoz: very little of that site you keep linking to is actually relevant to this discussion. I assume you like it because it dumps on C++, but that doesn't mean you can just link to it whenever you want to question the use of C++ and assume your argument is complete.
Shog9
It is *entirely* relevant, it discusses why you might not want to use C++ for a large, important software project. Chrome is huge. It doesn't 'dump' on C++, it makes arguments against it which are fairly indisputable. In any case I made several points about the question, the C++/C# thing = aside.
kronoz
Talking about arguments being complete, C# giving them *nothing* in return?! Are you crazy? Huge reliable libraries, decent clean language that actually compiles in reasonable time periods, automatic memory management with an extremely effective GC, portability, *real* type safety etc. etc...sheesh.
kronoz
@kronoz: Are you saying smart pointers are impossible without C++0x? I've got millions of lines of C++ code which can prove you wrong. You can come over and grep my C++ code for the word "delete" and there's about 10 results (and they're all in pointer/container classes). The FQA is pure FUD.
Jimmy J
@kronos: [quote]"...why you might not want to use C++ for a large, important software project."[endquote] ... Funny how most of the really large, really important programs in this world actually ARE written in C++. How on earth do they manage it?
Jimmy J
@Jimmy to be honest the undecidable grammar issue is enough for me to want to avoid it.Yes a lot of big projects are written in it, but then again a lot of big projects are written in COBOL (surely you saw that one coming)!I'm not saying all C++ programmers suck or some-such. Don't get me wrong.
kronoz
@Jimmy of course I'm not saying smart pointers are impossible without 0x, obviously they are. It's just they're a leaky abstraction in C++ as-is.Are you saying C++ has somehow patched up the issues raised on FQA? How is it FUD?
kronoz
@kronoz: again, whether or not you like C++ as a language is utterly irrelevant. Lots of Python fans at Google, but they didn't choose Python for Chrome. As for compile time... On large C++ *or* C# projects, your build system has a greater effect. The fastest compiler is the one that doesn't run.
Shog9
@Shog9 - Wow this is turning into a right furore here! Of course it's irrelevant whether *I* like the language; there are other issues such as how easy it is to use native libraries, etc. as I raised in my answer.My point is that C++ isn't somehow an ideal language, and wasn't *necessary*.Peace?!
kronoz
@Shog9 - when I say not necessary, I mean they didn't absolutely have to use that language, or it was so far ahead of any other choice as to be moot. Obviously Python genuinely does have perf issues, so wouldn't be a good choice and I hear Java isn't particularly fast + poor interop. So C++ it was.
kronoz
@kronoz: "How is it FUD?" - because it's written purely to bash C++, it ignores STL and smart pointers (ie. the keystones of C++), uses C code for most of the examples, etc, etc. ie. It's a lie.
Jimmy J
That was my point: there's nothing about any of the languages being discussed that would make it a clear win. C++ has the lowest baseline dependency cost (once compiled and linked, nothing but system libraries), which i hold makes it the better choice; of course, no one but the Chrome team can say.
Shog9
OK, a question: What does the C# garbage collector do when you allocate enough objects to cause memory paging? What does all the continuous scanning of the heap by the garbage collector do to your performance? Garbage collectors aren't all pretty pixies and unicorns. C# has showstopping problems...
Jimmy J
@Jimmy J: the .NET garbage collectors are fairly fast; at least to where performance for naive usage isn't much worse than for, say, a naive, malloc/new-heavy program. Not that a web browser could afford to be naive about resource allocation.
Shog9
BTW: kronos, you should have a look at the V8 API. Quite a pretty interface i say, makes excellent use of modern C++ features. May not change your mind about the language, but should at least cure you of the "smart pointers BAAD" notion.
Shog9
@Shog9: "the .NET garbage collectors are fairly fast;" yes, of course. C# is fine so long as you don't stray outside its limitations.
Jimmy J
@Shog9: "Not that a web browser could afford to be naive about resource allocation." ... This is the point. Once you hit the limitations of "automatic" C# the amount of work and verbosity involved suddenly becomes more work than writing it in C++ would be.
Jimmy J
@kronoz "C++ isn't somehow an ideal language" ... No of course not, but the C++ FQA is so far wide of the real problems that it's laughable. That didn't stop you putting two separate links to it in your post though, did it?
Jimmy J
@Jimmy J: Right. I have no doubt that a competent programmer could write a HTML DOM in C# that would be as or more efficient than the (C++) reference-counting implementation used by MSHTML; once you try to tune that though, there's no magic bullet: C# or C++, you've gotta manage memory manually.
Shog9
WOAH! To be honest, once we're talking the nuts and bolts of a browser, I have to admit ignorance and say that I simply don't have the expertise to say. I am basing a great deal on the FQA, and though I know C++, my knowledge is not extensive, so I can't tell if the FQA is always correct.
kronoz
Incidentally I am not saying I would never program in C++, it seems a large chunk of the actually interesting programming jobs out there use it so I may very well end up learning it more extensively at some point in my career...
kronoz
"I am basing a great deal on the FQA." If I was you I'd delete that link from my browser bookmarks. It's not worth the electrons used to transmit it.
Jimmy J
@Jimmy - well I guess I need to take a closer look at the language at some point. Personally I can't see how he can be wrong about the grammar issue, and that alone is enough to make it a bad language in my mind - e.g. horrible error messages + long builds. :-)
kronoz
"Long builds" is very dependent on how well you organize your header files. If you're constantly editing the main header file then yes, you'll do a lot of compiling. Google for "pimpl idiom" for one good way to avoid this.
Jimmy J
+1 for Who's going to maintain it? - Google's core language competencies, tools, and infrastructure revolve around C++, Java and Python.
David Waters
I have written a lot of code in C++ and I have never found it a painful activity. In fact, I think C++ is the language I like most, mainly because its power and flexibility.
Eduardo León
+5  A: 

My take is portability. I has to run on Windows, Linux and Mac. I guess they could, in theory, have used .NET or Java for that (eg via Mono for C#), but as someone else pointed out, a BIG selling point is the WebKit framework, which is (I think) C or C++, so no point in porting it to Java or .NET. Otherwise, they have to write a whole new rendering engine, and WebKit is very, very good.

For those saying it's performance: yes, and no. Managed languages (Java, C#) are nearly as quick as C++ in a lot of cases, especially if you use something like WPF for screen drawing. It's all JITed to machine code anyway.

That said, I guess there will be a lot of Objective-C in the Mac version, especially in the UI management code, so the language may depend on platform. Hell, I just want it for my mac. :)

Nic Wise
JITing takes time. Monstrous runtimes take time (and memory). When comparing speed between two languages you can't compare the speed of an API that they both would use. Compare real work done entirely within the language. Performance of C# is good and so is Java. Neither are as good as C++.
bruceatk
yes, they do, tho I just bought 4GB of RAM for £50 for my macbook. Seriously. You might want to check the stats, tho - last time I looked, once code is JITed, the difference between C++ and Java or .NET was very very little. Not that it matters.... maintainability is WAY more important in my opinion
Nic Wise
The point is "Once JITted" - Chrome may be "almost an OS", but booting your browser takes that one step too far. It should just start and run. (Obviously it's OK to JIT uncommon stuff like printing)
MSalters
Chrome is in no way "almost an OS". It's a browser, an app. With a task manager. It aint no OS. And I'm guessing you may have the wrong meaning of JIT... I'm referring to Just In Time compilation, ala Java or .NET.
Nic Wise
+13  A: 

Kronos is picking up on .NET as having a 'great performance profile'.

This is pipe-dreams. It has dreadful performance penalty in execution, cache invalidation, footprint, dependencies, memory management is overhyped and most apps still leak sufficiently enough not to run decently on anything but latest hardware.

The C++ FAQ he is picking on is a disgruntled guy who deals with hardware and has missed the boat. Just read the style he blogs in and all will be clear.

As for 'on par' performance, anything of any decent complexity outperforms C# by an order of magnitude. I work as a performance engineer for over 30 years now and you can take that for granted as all those VMs and JITers generate appauling cache invalidation and hugely suboptimal code. All for a gain of not dealing with memory, which is pretty sad.

rama-jka toti
Unfortunately, you're essentially right.
Konrad Rudolph
+1. They only look at performance after all the setup work is done and then running in very specific profiles. After that, the best they can come up with is that it's as fast as C++ is by default. The real world has many more factors and they never take those into consideration.
bruceatk
+1 same experience with C#/.NET, ostrich programming at its finest.
Anders K.
Except .net is running the site you're typing on now. Try responding to the FQA's points rather than getting ad hominem... why is there this enormously violent reaction to criticism of C++?! Please provide some evidence for your claims. Seems like you're making assumptions my friend.
kronoz
Using .NET to run a web site is different from using to run a browser: the slowness of the network makes the CPU usage of the server fairly irrelevant, and if you need more CPU you can add extra servers. A browser has a different requirements, so it is not unreasonable to prefer different platform.
pdc
The FQA has a whole lot of points, mostly misguided or wrong in my quick look. Unlike the author, I'm not obsessive enough to go through a long document and refute every point. I have no objection to criticism of C++, I've done some myself, but the FQA is garbage.
David Thornley
+1 A programmer who can't manage his memory isn't a programmer in first place.
Eduardo León
Kronoz, I know you don't know C++ 20% because of the way you pick your references and cricise it. I was part of the 1998 COOL testers.I do C# for over 10 years(16 if you want to take Java, and 25 if you include SmallTalk).You # zealots missed the point while Anders is teaching you to be big-headed.
rama-jka toti
+1  A: 

For 'great performance profile' check out what a managed app does to your machine, something like VS.NET (and don't forget it is due to partial .NET adoption, if it was full-on you'd need a cray to boot it, just like Singularity which won't boot btw).

Silverlight and WPF are another few examples of great performance killers, eating CPUs.

VMs are written in C++, and by reading that Kronos pointer FAQ and believing in it, by definition you wouldn't have a Java or CLR VM available today, yesterday or ever.

Arrogance comes from simplifiers in managed land really..

rama-jka toti
Woah dude! I find VS.NET performs well. Paint.NET is a well-known .net app, though it is obviously a small application compared to some. I find WPF and Silverlight perform well, and ASP.NET performs excellently also.Yes the VMs are written in C++, that doesn't mean C++ is a good language.
kronoz
A lot of the applications we rely on every day are written in COBOL, does that mean it's a good language?...!Anyway, look, let's focus on the guy's question not which programming language is the best, duuude!
kronoz
One last thing, Kronos: What are those COBOL applications you just mentioned? You say everyone uses it?
Vulcan Eager
+2  A: 

Performance wise. as you could see, Chrome is super light-weight, its RAM size used is smaller than Mozilla.

bgreen1989
+4  A: 

They do have top notch C++ engineers so they wanted to take advantage of it. Are there any popular browsers done in C#? I guess not so it would be hard to build a team with experience in both C# and browsers. And perhaps most important thing. C# is MS technology -> if MS is not using C# to write even calculator in Vista or their MS Office why their competitor would do that?

Nazgob
+27  A: 

Since Chrome is based on WebKit which is programmed in C++ (and whose codebase actually pre-dates .NET) the question doesn't pose itself here.

However, the question is very interesting in general: would a language such as C# or Java be well-suited to develop a web browser? In fact, a lot of the code could be written quite naturally in .NET: the HTML parsing engine. Due to its memory usage patterns, this code would be much easier than comparable C++ code and could even perform similarly (the GC in .NET deals well with this kind of memory allocation patterns; C++ in itself doesn't).

However, there still remains the problem of how much the JIT could optimize such code in the real world. While performance surpassing C++ is theoretically possible, it's really rare. In my experience, Majka is right to cite a speed advantage of one order of magnitude for C++ (depending, of course, on the particular application). It would be very interesting to see how HTML parsing would fare. I've already mentioned that the memory access pattern here is in favour of .NET. Another point scored for .NET is the text encoding issue which is hard and inefficient in C++. (see Rico Mariani vs. Raymond Chen).

As for the actual rendering of the pages on screen, I'm prepared to bet that C++ easily outperforms .NET considerably. The same, with some reservations, counts for the JavaScript interpreter. I believe that the simplicity of .NET is simply not enough to beat the adaptability of C++ in this regard.

Also, there are of course cross-platform issues to consider. Although I think that .NET runs quite natively on Unix platforms using Mono, this still partly disqualifies OS X and many other more exotic platforms where installing Mono isn't that trivial.

I can't speak authoritatively but I've got the impression that Java would perform even worse than .NET in some domains.

Konrad Rudolph
+6  A: 

Step back a second here. The C++ FAQ from that link shows you that the author would probably have a heart-attack reading the argument here.

He is going lower level than C++ into C, missing many features and getting lost in ranting. Just imagine what a perf hit for a tab and a button that goes to 12MB in managed would do to his thinking of C# and CLR (btw, it is nonsense to point out to a FAQ that would make CLR and C# look even more ridicolous in overhead than anything else on the planet apart from similar penalty Java VM).

If you just allocate 10,000, not uncommon, DOM nodes you would pay 2x overhead just in managed references overhead alone. So, put very, very simply, CLR doesn't scale or perform for anything but typical Rico Mariani trivial tests. Look at any decent size app and give it a good load and you'll see it scales just as poor as other historical mass-market solutions from MS/Sun. New solutions are no different apart from being more capable with threading and reworked Java with value types.

Do you own perf and sure go ahead if you think you can write a better browser, game, OS, IDE, VM, media editing app, audio and sequencing, image processing etc etc app.

VMs are known to deal extremely poor with large datasets. They grind to a halt basically. But for trivial samples, sure they are on par as it doesn't matter, doh!

VMs have been overhyped as they are easy to sell and train every Joe on the street and enflate his head that engineering is as simple as using a framework (largely due to MS blogging influence and leading to poorer and poorer software out there). But hey, you get useless candy and plenty of productivity to be proud about and be like everyone else.

That is why you pick a language for the task at hand. And you better know it 99% before you criticise it, or in right context. As we know, 99% of C# users know all other languages 100%, and make bloated software by default (they have no choice, MS and Sun make it for them).

rama-jka toti
I'd like to see proof of your claims. In fact, allocating 10,000 not uncommon objects would seem like an obvious case for some easily-implemented caching schema (just look at string interning). Why shouldn't .NET be able to do this?
Konrad Rudolph
Let's see what .Net does whan I allocate a million objects and the garbage collector starts scanning all of them over and over, causing massive pagefile thrashing.... Ooops!
Jimmy J
I don't know what you do Jimmy but I can easily create that many objects in .NET.
Konrad Rudolph
@Jimmy J - go read how the garbage collection actually works before making ignorant assertions. I Richter's work, eg: http://www.theserverside.net/news/thread.tss?thread_id=36413
Andy Dent
Yes, I think perhaps you guys should go read Rico's Mariani's blog for a while. He tends to think .net performs quite well. http://blogs.msdn.com/ricom/ @Reoa you reference him later but conclude the opposite, hm...
kronoz
Strange. Having spent many years (OK, decades) working on very large systems in the public sector, I've been responsible for .NET apps that were caparable to mainframe OLTP and batch services in terms of responsiveness and throughput. Perhaps it helps if you know what you're doing?
Steve Morgan
I didn't see any references in those links to performance while hitting swap. In my experience Java people would trot out the hoary old "RAM is cheap, buy more" platitude, and I see the same from C# devs now. With C or C++ swap perf *can* be as bad as with GC, but it doesn't have to be.
Zan Lynx
Gee, you obviously still chase pipe-dreams. Ask yourself what you are running in fact? A C++ VM, a poorly coded VM in C++, that's all.What young and inepxerienced devs never see is that you are bootstrapped by C++ in all and many ways you still have to connect to.
rama-jka toti
Rico admitted he lost it, but then again Rico is just like Scott Gu. Started off with ASP and VB and what not. Man, we made OS-es when MS didn't even have one to boot with.
rama-jka toti
Anyway, why don't you guys use a C# written CLR or C# browser or C# Office or C# SQLServer then? Go on and install Singularity and then we can talk how well it worksMost of you never did a mpl::vector yet you qualify to criticise something you never saw or your language is still not capable of?
rama-jka toti
Anders mass-market VB + Delphi-speak.. (C#)
rama-jka toti
I completely disagree with bulk processing and having a VM. It depends on your design. With C++ you can get away with loading nearly everything in memory because it has a smaller imprint per data item. However, with a larger imprint you must be aware of ways to mitigate the effect of the larger imprint. (Use caching mechs, partial loading of data, managed systems (db server)) IMO: VMs encourage good habits. They aren't the quickest thing on the block, but an emphasis on a strong design and optimization later will yield the best and quickest results in the long run.
monksy
+4  A: 

Because back then when the WebKit development was started C# didn't exist (as a matter of fact it still doesn't really exist in the Mac platform as of today despite Mono), Java had inferior performance and it was not the default programming language for Mac or Linux.

The codebase was KDE html engine in C++ and that's why it is not in Objective-C.

OscarRyz
+2  A: 

I don't think the arguments "close to the system", "webkit" and so on apply. You can very well wrap this around and call that from C# and Java.

Let's turn the question around. Why shouldn't Chrome be written in C++?

Edouard A.
+4  A: 

Because its main "selling" point over the competition (Mozilla, IE) is performance. Kinda tough to compete on speed using Java or .NET. Second reason is portability: .NET means Windows only and Java means dependence on a runtime that may not be available on the client. Keep in mind that Web Browsers are seen as a commodity these day that have to run on everyone's grandma's computer with no installation hassle whatsoever. A browser with dependencies is dead in the water.

AZ
It's not at all hard to compete on speed using a modern JIT compiler. Memory usage is a different issue, though.
Michael Borgwardt
+40  A: 

Chrome does a LOT of low-level hacking. Check out this article for some details, but the idea is, they pulled a lot of very slick magic to make stuff like the sandbox work, and Java simply does not get them close enough to the OS. The drastic UI changes probably wouldn't work in Java, either.

C++ gives them access to all sorts of low-level and operating system APIs which Java abstracts. I suspect that there were several requirements just like the sandbox, that effectively made their decision between C and C++.

(I consider C# a non-option; it's the least portable of the three you suggested, and I doubt Google wants to rewrite their code for a mac/linux version.)

ojrac
Eff that, just run it in wine. It'll be awesome.
ojrac
Dude, they cannot just use a legally dubious (due to MS patents), unsupported third party environment like Mono. Also, don't call people "Dude", except if you are under 24.
foljs
If you check out the article, it turns out they do some even more legally-dubious stuff: the source code essentially admits to reverse-engineering some Vista API calls around data execution prevention.
ojrac
Lol. Google doesn't even like C#/.NET!
mcjabberz
No doubt Google would have used C# if their business model allowed it. Technically C#/Mono would clearly have been the best choice, but it would have been politically infeasible because they compete so heavily with Microsoft. Just the news that they used C# in a major product woud be bad for their position.
Ray Burns
+1  A: 

C++ was designed primarily so that the author and his friends would not have to program in assembler, C, or various modern high-level languages. Its main purpose is to make writing good programs easier and more pleasant for the individual programmer.
— B. Stroustrup (D&E, p. 106)

lsalamon
+10  A: 

A browser is a style of application that needs to be slick, fast and easy to distribute.

Java's cross-platform capabilities give it limited support for slick GUIs and you also have a distribution issue with the Java virtual machine. Also, Java is generally a bad choice for fast-performing, native applications. How many of them are there out there?

C# WPF could have been a choice but the ordeal of managing and distributing the .NET runtime on every machine running Google Chrome would have been an instant showstopper. A good example of the installation overhead difference between a C# application and a C++ native application is the difference between something like Nokia's Come with Music which downloads the entire .NET 3.0 runtime (~60MB on XP machines) and Spotify which is 2.4MB all told.

The Browser market is difficult now that one of them comes bundled with Windows! So if you give the user a 60MB download of some framework that they haven't heard about and don't care about and it could be the difference between mass-adoption and failure.

Also, I gather that they had a certain amount of code reuse (in the rendering area) with their C++ option.

Duncan Edwards
I doubt that they would have use AWT or Swing. Probably some native JNI-based binding more along the lines of SWT.
mcjabberz
+8  A: 
  1. speed
  2. portability (yes, even over Java as the JVM introduces a dependency -- see #3)
  3. fewer dependencies
Jen
+1 for speed> I love Chrome as it feels so light, can you imagine if it was written in Java, it would be like walking through drying cement.
johnc
+2  A: 

Performance

Jeff
+2  A: 

Unless I am wrong, Chrome is based on many librairies for which .NET wrappers simply do not exist.

Instead of creating wrappers, they chose to go with C++, so they would get performance boost and a faster development.

Creating wrappers for all the C/C++ libraries they use would have required a lot of time / tests.

Martin
:D Good one. That was hilarious.
Vulcan Eager
Performance boost? Yes. Faster development? No.
mcjabberz
+3  A: 

I guess only someone from Google could answer this, but web browsers are really system applications, and system software is written with C or C++, not C#/Java. All other major web browsers are written with C++ as well.

Nemanja Trifunovic
What's a system application? Where is the magical border that makes a web browser system software and VS or Eclipse *not* system software?
Konrad Rudolph
I agree it is a somewhat gray area. For instance, Stroustrup defines system applications as: "applications with a significant systems programmingcomponent; often with resource constraints". See the paragraph 7 of this paper: http://www.research.att.com/~bs/hopl-almost-final.pdf
Nemanja Trifunovic
+1  A: 

A benefit from writing it in C++ over C# is that they can as they plan to release versions for other platforms other than Windows. While it's possible to do this with .NET too it would have meant people would have to install the mono runtime which is not a very common thing on non Windows computers. Similarly writing it in Java would have created the dependency to the Java runtime, which would have been a better option. But it's not a very good idea to write something like a browser for a virtual machine because of startup times and performance, if they want to compete with firefox and other good browsers.

The other reason is the choice of rendering engines. Because they are using webkit which is written in C++ it's an obvious choice.

Vasil
+2  A: 

Applications that was written in C++ can run without the need/dependency of any underlying VM. This will be easier for end-users because they don't need to install .NET framework/JRE first. Also, it will provide better performance and better reliability.

natch3z
+1  A: 

The control, power and speed C++ provides can only be matched (surpassed ?) by C itself and not Java or C#. If you know exactly what you're about and after and do not need guidance from structures like the GC then you'd obviously go for as much control, power and speed as you can get. That's exactly what the Chrome team is doing I believe. Another possible reason is the one-thread-per-tab principle (concurrency of sorts) they've employed in chrome. To run such a system would need a lot of resources and access to these resources is crucial. Thus a language that doesn't hustle much to get to these resources ie. fast and close to the underlining machine architecture, would be the best bet to implement such a system in. Thats where C++ comes in.

gogole
+131  A: 

There are a number of reasons, which can be broadly classified as business reasons and technical reasons.

Lets start with the business reasons.

  1. C# is an open, public standard (ECMA-334) but .Net is not. Note that .NET Framework which is not covered by the ECMA/ISO standard, includes Windows Forms, ADO.NET, and ASP.NET. Patents that Microsoft holds in these areas may deter non-Microsoft implementations of the full framework. Would you develop a product based on a platform your competitor controls, especially when the product you are developing challenges the same competitor's product?

  2. Suppose you want to develop a new browser and you have a fairly decent operating budget. What people would you want to recruit? Clearly someone with browser development experience. You would try to get the best of the Mozilla/Firefox folk, maybe steal some from IE. Guess what these guys have been developing in. C++.

Now for the technical reasons.

  1. There is no Java/C# counterpart for WebKit. At least not with the same maturity.

  2. They want to leverage their V8 engine. Look into this, this is killer stuff.

  3. The following is a list of all that they are potentially using (this is from Chromium so may not exactly acurate). Can you find mature, Java/C# counterparts for them?

    bsdiff, bspatch, bzip2, dtoa, hunspell, ICU, JSCRE, libjpeg, libpng, libxml, libxslt, LZMA SDK, modp_b64, Mozilla interface to Java Plugin APIs, npapi, nspr, nss, Pthreads for win32, sqlite, tlslite, V8 assembler, WebKit, WTL, zlib

  4. No matter what people say sometimes the ability to operate close to the machine and have a fine grained control over memory matters. This is such a case.

  5. Can you name one significant desktop application done in Java/C#. Eclipse. What else? Maybe this is possible but don't you want to play it safe? Develop in a language that has been really battle tested in this regard.

Nikhil
Isn't the V8 argument upside down? If they had decided to write the browser in C#, surely they'd have written V8 in C# as well. It seems unlikely that they wrote V8 *first*, before they had a product to plug it into. Similar for #3, a lot of these wouldn't be needed if they'd used another language.
jalf
I don't agree with no. 5th. SQL Developer, Netbeans, IntelliJ, SIP Communicator and can find many more. Not saying its more than C++, of course.
Adeel Ansari
Um... "battle tested"??? There's plenty of major apps that use .NET, here's a couple: SQL Server, SharePoint
Chris Pietschmann
@Chris -- desktop apps. No one questions Java/C# on the server
Eugene Talagrand
SQL Developer, NetBeans and IntelliJ are all programming environments. Not desktop applications. They are also not very refined as end user applications --as programmers we endure a lot of bad GUI mojo.SQL Server is not written in .NET managed code.
foljs
Both SQL Server and SharePoint are C++ Apps by the way, they just happen to support .net for some stuff thanks to COM. This includes some Management Tools, the Web Front end in SharePoint and additional functions in SQL Server.
Michael Stum
I thought a lot of open office wrote in java.
Antony Delaney
Paint .NET is written all in .NET. I'd consider that a major desktop app. I still argue that you're better off with C++ for a desktop app though...
Dan Herbert
Nikhil, It isn't Windows, but I count Banshee, F-Spot and Gnome-Do as big desktop apps written ontop of dotNet.Also C# does a quite good job in interop with native code.
Dykam
Visual Studio 2010 is fairly major and has a lot of C# code, plus the entire Expression suite?
280Z28
Eclpise is the only large desktop app written in Java I can come to think about.
Viktor Sehr
IntelliJ IDEA is written in Java and most certainly runs on the desktop in Window, Linux and OSX. The purpose of the app doesn't negate that the fact that is is a very responsive application written in Java.
fuzzy lollipop
"C# is an open, public standard (ECMA-334) but .Net is not." Actually the CLR (the runtime) is a public standard, and there is at least one actively developed open source implementation: Mono.
Daniel Earwicker
See the Banshee open source alternative to iTunes - widely used on Linux, written in C# (doesn't even have a Windows version!)
Daniel Earwicker
+7  A: 

For almost the same reasons that surgeons use scalpels and not chainsaws.

Vulcan Eager
+4  A: 

Leveraging Existing Software

Chrome leverages the open source WebKet rendering engine, which is written in C++.

Speed

Speed is a primary design goal of Chrome. C# and Java can be made to be very fast, but at the margins that Chrome is working at they can't be made as fast as C++ code.

Multi-Platform Compatability

Chrome is meant to be available on many platforms: Linux, Mac, etc, not just Windows. While Mono is a viable option for C# on linux, it adds significant complexities and trade-offs. Java is an option but the promise of "write once, run anywhere" has been largely unfulfilled. Multi-platform development using C++ is a known quantity with many successful examples (Mozilla, Apache, Photoshop, etc.)

Wedge
+1  A: 
paperhorse
+1  A: 

Portability and performance are definitely one of the many reasons. I think Java would have been great except that you're now relying on the Java VM which is a punch in the face when you compare such a product to FireFox or IE which are standalone products. I've worked with companies that stay away from anything from Microsoft. To them it's an unnecessary dependency. Using .NET framework may not be extensible enough for what you're doing. You may want to roll out your own algorithms and logic instead of using built-in features. This is especially important for such product as a web browser which competes with giants such as FireFox, Opera, Internet Explorer and etc. You have to make it fast. You have to make it efficient. Otherwise you labor will go to waste as you're not going to be able to compete. This is why having your own framework is a better thing since it allows you to make it as good as you want it w/o getting stuck with what you have to use.

Sergey
A: 

I imagine they made a trade-off of short-term benefits such as performance over long-term benefits like maintainability. C++ might be faster now than C#/Java code, but as hardware advances speed will be less relevent a benefit. It creates a terrible situation for security in that they are effectively snubbing the billions in IS work done to protect the .NET/Java Platforms from exploits. There is no way they can keep up. We might effectively be embracing the next ActiveX browser security hole by embracing Chrome.

Nissan Fan
A: 

anybody here tried Opera as a web browser? i'd consider it a major Java app and it works on every computer i own. works on phones too, btw. also, Open Office anyone? that's a big Java app. being able to write once and run everywhere is my primary motivation for using Java. everywhere meaning: every desktop, every server and every handset. in my career i have never worked for a company that prioritized performance over portability of code.

vitaminD
OpenOffice may use Java for a lot of functions, but the vast majority of it is still C++.
Steve Rowe