Live data from Hacker News

Why C++ is not my favourite language

snell-pym.org.uk

31–40 of 53 posts

Re: Why C++ is not my favourite language

#31
post #17
post #8

Earlier quoted context omitted.

one of the requirements for this kind of speed is for a language to be statically typed No, one of the requirements for static optimization is that a language be statically typed. It does not follow that there are no ways to make dynamic languages fast, just that they mostly have to use different techniques.

You need to make languages fast on both dimensions, static and dynamic. A dynamically typed language can only be optimized in one dimension, which is why they usually trail behind statically typed languages in performances (since those are optimized along both axes).

I've not seen anything like the dynamic-dispatch optimisations the Self team came up with in the 1990s done in C++, nor problem-domain optimisations expressed as macros as is often done in Lisps, nor the aggressive constant-propagation of closures and their eventual inlining that Factor does.

Perhaps some of them could be applied, but a highly complicated base language with extensive mutation semantics (including pointer aliasing) probably mean they'll be so limited in their applicable scope, and so difficult to implement, that it's not an attractive activity for C++ compiler writers...

Re: Why C++ is not my favourite language

#32
post #3

That's really cool that this guy thinks dynamic languages have the potential to be faster than C++. Maybe he can write a second article when they are actually faster, with some properly done benchmarks or some valid technical examples.

Common Lisp is already quite fast and dynamic. And for the same number of hacker-hours spend in optimizing, you probably get a larger speedup. Also Python+C can be quite a fast combo. Fast to develop and fast to execute. Forth is also quite fast and dynamic, if you grok it. A lot of functional programming languages have also become quite fast in the last decade. While there are in a sense more fluid than C++, they ar…

I've found Python/C++ (via boost::python) to be a fantastic combo. There's also luabind which does similar lua/C++ two-step.

Re: Why C++ is not my favourite language

#33
post #15
post #6

Earlier quoted context omitted.

Indeed. So many of these articles can be boiled down to: "As long as we limit the comparison to things (our language) does well, and exclude things C/C++ do that (our language) can't do at all, (our language) totally 0wnz C/C++".

Please never, never, never ever write C/C++. С - simple and stable, C++ - huge and changing. C - portable and easily parseable, C++ - unpredictable and unparseable. C - good, C++ - bad.

Actually, my reason for writing "C/C++" was simply because they're the two languages I see targeted by articles like these. It wasn't to lump them together as one; it was like writing "Ruby/Python".

Re: Why C++ is not my favourite language

#34
post #21
post #3

Earlier quoted context omitted.

Common Lisp is already quite fast and dynamic. And for the same number of hacker-hours spend in optimizing, you probably get a larger speedup. Also Python+C can be quite a fast combo. Fast to develop and fast to execute. Forth is also quite fast and dynamic, if you grok it. A lot of functional programming languages have also become quite fast in the last decade. While there are in a sense more fluid than C++, they ar…

I can't help feeling that Common Lisp should be doing better, considering that it's a language where you can effectively tell the compiler "It's OK to store this variable in a register". It's currently doing about the same as Mono, which IIRC doesn't JIT, and worse than Java. The king of dynamic language performance right now is LuaJIT, which crushes Perl, Python, and Ruby and performs admirably relative to Smalltalk…

The quality of the individual programs plays a large role. E.g. GHC (Haskell) has made huge strides in the past thanks to better libraries and implementations for the benchmark, despite nearly the same compiler.

On a side note, a lot of the benchmarks had to be reformulated after lazy languages got fast. As far as I know, a benchmark at this side prescribes which algorithm you should use. Haskell (and e.g. Clean) just ignored a lot of the baggage because it was not used any further.

Re: Why C++ is not my favourite language

#35
post #19
post #12

Earlier quoted context omitted.

Hardly, I know many people who spent years learning C++ in the 90's only to avoid it now. The reason is they had no love for the language. The C++ language design has serious flaws that whenever someone brings them up there's the usual, rolling of the eyes and the "yeah we know" sort of look. The if you criticise you must be a dumb attitude is encouraged by the C++ community too, and that was not borrowed from the C…

C++ hits a certain sweet spot. In some cases - whether you like it or not - it's just the right tool for the job. Two examples I can think of are: * VM implementations (I mentioned Factor, but also HotSpot, Microsoft's CLR, SquirrelFish, TraceMonkey, V8 and Opera's Carakan are all high-performance VMs written in C++ (x). Note also that all major layout engines are written in C++. Complex but fast and highly-tuned bea…

How about D? A friend of mine uses it as a better C++ for mathematical programming (optimization, graphs and so on).

Perhaps nobody would have invented C++ if D would have come earlier.

Re: Why C++ is not my favourite language

#36
post #3

Earlier quoted context omitted.

Common Lisp is already quite fast and dynamic. And for the same number of hacker-hours spend in optimizing, you probably get a larger speedup. Also Python+C can be quite a fast combo. Fast to develop and fast to execute. Forth is also quite fast and dynamic, if you grok it. A lot of functional programming languages have also become quite fast in the last decade. While there are in a sense more fluid than C++, they ar…

OCaml does quite well against C++ in the shootout. OCaml's Functors and type inferrence are a big win over C++ templates. Yeah, the syntax takes some getting-used-to, but all in all the language seems to hang together much better than C++ (perhaps not saying much)

I agree. I like Haskell's syntax better. But their syntaxen are nearly isomorphic for the most common stuff.

Re: Why C++ is not my favourite language

#37
post #30
post #18

Earlier quoted context omitted.

I hear good stories about D from colleagues: http://digitalmars.com/d/2.0/overview.html

D's great for at least two reasons: 1) it set out to be a no-compromise systems programming language 2) it's being designed by people with an deep and intimate knowledge of C++ (Walter Bright wrote a C++ compiler - no mean feat, and Alexander Stepanov was Mr STL) These guys know the good, the bad and the ugly of C++ much better than most. From the stuff I've seen so far (check out Stepanov's presentations on an itera…

3) You can declare functions to be pure. A lot of optimizations become possible.

Re: Why C++ is not my favourite language

#38
post #20
post #15

Earlier quoted context omitted.

Please never, never, never ever write C/C++. С - simple and stable, C++ - huge and changing. C - portable and easily parseable, C++ - unpredictable and unparseable. C - good, C++ - bad.

So, you don't use a C++ compiler for your C code? The old C infrastructure is really outdated already -- you can use C and a very limited subset of C++ (without OO), and be perfectly happy.

No, I'm using GCC.

How's it outdated? Linux kernel is written in it.

As for limited subset, people would push and push the boundaries until your code grows fangs and horns

Re: Why C++ is not my favourite language

#39
post #11

From my perspective, most of the stuff about C++ complexity rings untrue. Most people I know seem to know enough about C++ that they can produce pretty good code. Yes, there's a lot of depth to C++ but you derive a lot of benefit from other's wizardry even if you're not a magician yourself. Maybe this guy didn't invest as much time on C++ as he did on his other languages.

FWIW, I'm working in C for my day job (and resisting calls to move up to C++), as my day job involves shuffling bytes around rather than particularly complex code; it's ~20KLOC. Then we build the tools to manage it in Python with a bit of shell scripting here and there. However, I code Scheme in my spare time, and would do the lot in that if I didn't then have to justify training new developers in Scheme! C's the rig…

Is there an easy way to shuffle bytes and bits in Scheme? I was quite delighted when I found Data.Binary (http://code.haskell.org/binary/) for Haskell.

Re: Why C++ is not my favourite language

#40
post #25
post #11

From my perspective, most of the stuff about C++ complexity rings untrue. Most people I know seem to know enough about C++ that they can produce pretty good code. Yes, there's a lot of depth to C++ but you derive a lot of benefit from other's wizardry even if you're not a magician yourself. Maybe this guy didn't invest as much time on C++ as he did on his other languages.

I think that's not the right criteria though. Are most of the people you know capable maintaining other people's C++ code? The idea that you can write (!) sane code in C++ by using a simple/sane subset is of course true. But the problem is that in a language of this complexity no two people are going to be able to agree on what that sane subset is. One person may love auto_ptr and use it everywhere, confusing her cow…

I agree. (Might I add that reference counting is evil (and slower than true garbage collection).)
Post reply on HN