Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sincerely, from the bottom of my heart: It doesn't matter

I have some familiarity with some of the systems described (and with other systems that use C++). Let me put it this way:

- Large enterprise projects are bad

- Large enterprise projects in C++ are very bad. It's like giving razor blades to a kindergarten group for a whole afternoon. I wish I was kidding

- "Done in C++" is not as important as the capabilities of the platform targeted

C++ is good, and very powerful. And I have a million reasons not to use it unless absolutely necessary.

If you want to use it I'll give you 3 tips:

- Focus on STL and maybe Boost (use it sparringly and wisely! don't overdo it)

- Avoid inheritance hell

- Don't go crazy with Templates, in fact don't even use them (except for what's in STL already)



> Don't go crazy with Templates, in fact don't even use them (except for what's in STL already)

What's wrong with templates? This is the most powerful feature of C++ allowing for Generic programming, Polymorphism and metaprogramming. The latter is of course clunky considering C++ syntax, but overall templates are great. And STL is the best thing that happened to the C-like family of the languages.


The problem is that, as expected in a strongly typed language, you can't do real Generic programming, even with templates. Or even adding another inheritance level (which makes some things easier)

Because type 'fixing' (that is, knowing what you need) happens at compile type, for example, duck typing ("even with" dynamic_cast - yes, dynamic_cast works at run-time, but you're limited in what kind of objects - by your inheritance hierarchy - can be present at the time you're doing the dynamic_cast)

You end up having to specify the type, you don't have a 'Generic' type. And you may have to deal with dynamic_cast

And read again, I'm not against STL, they 'get' templates.

Edit: confusing explanation


> You end up having to specify the type, you don't have a 'Generic' type. And you may have to deal with dynamic_cast

Do you really need one? Because then you really are dealing with run time polymorphism, whereas templates are all about compile time.

I recommend checking D programming language out. It has very powerful templates with a nicer syntax than C++ and a lot of other things aiding metaprogramming. Moreover with Ranges you get an implementation of ideas laid out in STL but with a better syntax and matching the power of what is in proper functional languages.


Qt is capable of lazy typing in C++ using QObject and QVariant, though it also adds its own meta-object compiler on top of the C++ compiler.


Which is really no different than using GObject and GValue from GLib / Gnome world. (Even using a meta-object GOB compiler :))


... or using a union with an enum in plain C:

  struct data {
    void *data;
    size_t length;
  };

  union value {
    char *zstr;
    int intgr;
    float flt;
    struct data *data;
  };

  enum type {
    STRING,
    INTEGER,
    FLOATING,
    DATA,
  };


So what language would you recommend writing Windows in? Firefox/Chrome? LLVM?

What are your reasons for recommending said language over C++?


Firefox and Chrome are both actually written substantially in JavaScript. It's possible that they could get away with JavaScript + C rather than JavaScript + C++ (conjecture here). In this world more stuff is implemented JavaScript perhaps.

There is the saying that any sufficiently large program contains a buggy and ill-specified version of Common Lisp... I would rephrase that as any sufficiently large program needing to contain its own extension language and programming language. JavaScript is filling that role for the browser, and I expect there to be a language in the future that does it better.

There won't be anything that replaces C (or C++). Go can't do it. But there will be something that works better with C and C++ for big performance-intensive applications. Lua is close. The reason I would prefer C is that C++ has a very hostile interface for another programming language to interface with.

I wish Python were there, but it's C API isn't really up to the task, especially with regard to concurrency (which e.g. Firefox and Chrome have a lot of!).


Something ML-derived perhaps. Strong typing, mostly functional, but practical.

I once wrote a large part of a CSS+HTML renderer in OCaml (think: the very core of something like Firefox), and the ability to match over data structures and use trees naturally was a huge advantage.

ML was devised as a language to write compilers in, so LLVM is covered.

For an operating system you really want a lot of different languages because it's a huge undertaking that covers many domains. MirageOS is an OS written in OCaml, so that's a proof that it's possible at least.


I was under the impression Rust was being developed by Mozilla to eventually be their language of choice for implementing software like Firefox precisely because C/C++ leads to too many (security) bugs among other things. At least one of the reasons, anyway..


Just for utter clarity, the FAQ states:

Q: What will Mozilla use Rust for?

A: Mozilla intends to use Rust as a platform for prototyping experimental browser architectures. Specifically, the hope is to develop a browser that is more amenable to parallelization than existing ones, while also being less prone to common C++ coding errors. The name of that project is Servo.

Q: Are you going to use this to suddenly rewrite the browser and change everything? Is the Mozilla Corporation trying to force the community to use a new language?

A: No. This is a research project. The point is to explore ideas. There is no plan to incorporate any Rust-based technology into Firefox.

https://github.com/mozilla/rust/wiki/Doc-project-FAQ


I was being careful and said software _like_ Firefox :) From discussions I had with people about Rust it seemed obvious that if it reached maturity then it could be considered for new projects starting from scratch.


Yes, Rust is great, all the lessons learned what not to do with C++.

I could only hope Rust is (still) just a codename.....


Windows: for lower level, C. like Linux and Mac OS X. For higher level development, C++ or just go with C#

Firefox/Chrome: C++ looks like a good choice, still, there's a lot of JS behind them as well if I'm not mistaken. Now, Go may be a good choice

LLVM has interesting requirements, it needs to be both fast and needs a lot of 'flexibility'.

I would probably try making the next LLVM version in PyPy (which uses LLVM itself), so it maybe bootstrap itself using CPython first, hence bringing us one step closer to Skynet.

But in general Go/C#/PyPy may be steps in the right direction (Java is too afraid of new things being added to C# like anonymous functions, so it's behind)


> For higher level development, C++ or just go with C#

The facts:

C# was created in 2000. After 12 years Microsoft still does not sell a single app written in C#. Not one.

C# is used for PowerShell (free) and MSN (free, the backend is mixed C# and Java).

This is not likely to change anytime soon: pretty much all Microsoft job openings require C++. Also for new projects MS recommends JavaScript or C++.

Python is not better off either: Google does not allow Python code in anything that can be seen by end user. (Youtube is Python, but it was bought, not built.)

I'm not saying C++ is perfect, just that for some use cases it is pretty good. For some other use cases obviously it is not the best choice.

Peter Norvig: "I think that language choice is not as important as all the other choices" http://news.ycombinator.com/item?id=1803815


The URLs of some of the links at http://support.google.com/adwords/, for example, suggest the use of Python for user-facing web pages.

Notice that some of those URLs contain:

- http://support.google.com/adwords/bin/answer.py

- http://support.google.com/adwords/bin/static.py

- http://support.google.com/adwords/bin/topic.py

Do you know if those are actually written in Python, or are those implemented using some other language?


I have heard these things about C#. Too bad, because I think this is one thing Microsoft nailed. Sure, it has its warts, some parts of the library have to be improved, etc, still.

Also for new projects MS recommends JavaScript or C++. This was one of the clashes between Microsoft divisions, the division between the new Metro (JS) and the rest, can't remember which side Sinofsky was on this.

Of course, to work at MS you have to know C++

" Google does not allow Python code in anything that can be seen by end user" really?! Didn't know that, maybe it has to do with their infrastructure and the way it scales. Can't say I blame them (still, GAE runs python)


Python at Google:

A discussion from 2009: http://news.ycombinator.com/item?id=933493

2011: "Languages like Python are shunned upon because they're too slow for web frontends" http://slacy.com/blog/2011/03/what-larry-page-really-needs-t...

It is used for internal tool scripting like build, testing:

http://www.quora.com/Google-Chrome-for-iOS/Is-Chrome-for-iOS...

http://www.quora.com/What-kind-of-projects-at-Google-use-Pyt...


Interesting.

Python being 'too slow' makes sense, but at the same time it doesn't. For example, it has much more behaved GC (and reference counters)

I guess if Google wanted to make it 'super fast' it could. Or use PyPy. Or Jython


That's not true. At least Dynamics CRM is written almost completely in C#


How about Lisp? I know, I know, it's a religion and all that, but let's put it this way: you can get high-performance Lisp code, there are Lisp compilers that allow you to do things at the machine level (SBCL, for example, has support for pointers and inserting assembly language instructions), and OSes have been written in Lisp in the past.

Why this over C++? Well, first of all, basically anything is better is C++ at this point, but as for why Lisp in particular, there are a few reasons. First, I won't deny my own biases -- I know Lisp, I use it in my work, and I know that the tools to do the things I mentioned above already exist (perhaps an ML fan can answer whether or not such things are available in SML or OCaml). Second, Lisp is never really "out of date," in the sense that you do not need to rewrite your compiler to introduce a new language feature (consider what was required to add lexical closures to C++, and compare to something like CLOS, which can be implemented in macros for Lisps that do not have object oriented constructs). Finally, there is the expressive power of Lisp; an experienced Lisp programmer will run laps around an experienced C++ programmer, simply because it is easier to describe a complicated program in Lisp than in C++ (this argument also applies to ML, Haskell, Python, and dozens of other languages; again, I will not deny a personal bias towards Lisp).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: