3 ms·
To make it clear, I don't mean to rag on C, which is a great mid-level language. It's the ++ that I hate. Assembly is infantry: can do a lot of fine-grained wor
by michaelochurch 15y ago
To make it clear, I don't mean to rag on C, which is a great mid-level language. It's the ++ that I hate. Assembly is infantry: can do a lot of fine-grained work, but limited to about 5 mph with equipment. C is a tank-- a pretty powerful and impressive machine. It can shoot on the run and do 50 mph off-road. High-level languages are airplanes, perfect at 500 mph but coarse-grained from an operational standpoint. C++ exists because someone saw a tank and a plane and said, "I'm going to put wings on a fucking tank and see what happens." Thus, the tank-plane was born. The wings destroy its maneuverability on the ground and the weight of the tank makes it a shitty plane, and it looks fucking ridiculous, but there you go. Java exists because someone else concluded that the problem with tank-planes was that people were trying to fly them too fast and built an equally ridiculous invention-- the tank-icopter.
After I have defined a high-performance algorithm, they often want to modify it to make it "more beautiful" (which means functional) and in the process destroy the performance.
That's annoying. They should understand the concept of interface as separate from implementation. Implementations are allowed to be (and sometimes should be) ugly if performance concerns merit it.
Besides, mutable state, intelligently used, isn't "ugly". A lot of programs are simpler and more attractive when mutable state is used. Mutable state just needs to be used with taste.
What really pisses me off about that behavior pattern is when the tinkering is unnecessary. If it's working code, then who cares? I'm a hard-core FP advocate but I write stateful programs all the time. I try to wrap them behind interfaces that are as functional as possible. I will use state in controlled ways when appropriate; I just don't want to impose it on other people.
I work on low-level algorithm design in A.I., where performance is everything and there are many interlocking, low-level and complex algorithms and data structures.
I think what makes C++ appropriate for your purposes is that once code is written to spec, it doesn't need to be maintained (except for performance optimizations). I'm guessing that (except possibly for some STL usage) you're actually C.
Where C++ and Java really drop the ball (legacy disasters) is when code has to be read more times than it is written. If your goal is to write fast software one time and, once it's working code, never need to look at it again, C++ is probably appropriate.
- nickknw 15y ago> C++ exists because someone saw a tank and a plane and said, "I'm going to put wings on a fucking tank and see what happens." What a great metaphor. Hilarious, great imagery, and it's even mostly true! Thanks for that, I'll remember it.
- Someone 15y agoTo that, C++ proponents will reply: when done well, that gives you an awesome flying tank, as in http://en.wikipedia.org/wiki/Fairchild_Republic_A-10_Thunderbolt_II http://en.wikipedia.org/wiki/Fairchild_Republic_A-10_Thunder.... It may not be sexy, but it sure gets the job done. I think that is apt for C++, too. It is not sexy as in 'objects all the way down', 'functions all the way down', 'consign all the way down', or whatever else rocks one's boat, but it is sturdy and does get the job done.
- CJefferson 15y agoThanks for your reply, it was very interesting. One small comment - what makes C++ appropriate for my usage is mainly templates. Lots and lots of templates. It is very useful to be able to easily compile an algorithm for different types. If compiling a whole 10,000+ line algorithm 4 times for char/short/int/long inputs with templates and doing run-time branching between the algorithms (but not in the algorithms) saves 15% CPU time, then that is well worth the work. I don't know (well) any other language that offers that. Obviously if you introduce some kind of abstract base class / interface like Java, you will immediately lose the benefit of going int -> short -> char, when a class is alway at least... 12 bytes? 16?) In C doing that requires a lot of macros and rapidly gets unusable, in Java it requires introducing lots of interfaces and hoping things get inlined. What I like about C++ (compared again to Java/C, not Haskell), is that I can without fear of cost (other than compile time) introduce another layer of abstraction. When benchmarking code this is amazing, I can easily swap in a vector, or a deque, or an optimised fixed-size stack array. In Java it is common for people to 'un-Java' code, introducing arrays of primitives instead of arrays of classes for example. I don't know how well Haskel does at that kind of thing.
- michaelochurch 15y agoI think C++'s template feature is pretty unusual in languages. Lisps have macros, which are much more fully-featured and more hygienic than C macros, but I don't think any Lisps are fast enough to be interesting to you. I know that the Scala community is working on putting macros in. Have you looked at Ocaml and Scala? Those might be close enough to suit your needs, and I think it's only a matter of time before Scala (or something like it) starts outperforming C++ on parallel problems. What I'll say for C++ is that, in the style of development you're doing, it's definitely faster. The problem I have with C++ is all the use of it that occurs where it's not appropriate and actually makes performance worse because per unit time, programmers can accomplish less in it. It's clearly possible for expert programmers to optimize the hell out of C++ in a way that just doesn't exist in GC languages, but I don't think average-case code is better, especially if it's framed as an economic problem and programmers of equivalent skill are involved and given the exact same amount of time to do it. Under those constraints, for a large problem, I would bet on Ocaml and Scala winning just because the programmers would have more time to spend on optimization. For a small problem, though, I'd bet on C++.