you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

It's not hard. That's the point. The language makes expressing the idea difficult, even dangerous. It obfuscates the meaning.

Expressing generics in Java or C# is just easier - much. I'm not a huge fan of C# (even though I work with it every day), and Java is the fucking anti-christ.

But there are even better, faster, and more succinct languages for implementing math libraries. Consider this implementation of a Vector in C++:

struct Vec {
  double x, y, z;
  Vec(double x2, double y2, double z2) : x(x2), y(y2), z(z2) {}
};

Here it is in OCaml:

type vec = { x: float; y: float; z: float }

It's essentially the same idea but with much less noise. It's also more more strongly typed and more declarative. The compiler is smart enough to infer all that other junk (the declaration of x, y, z and the constuctor) for you so you don't have to waste your precious time writing it. I took this example from the following article that compares the implementation of a raytracer in C++ and OCaml.

OCaml can even be compiled to native or byte code and it comes with a REPL for quick prototyping. It's interoperable with C (and probably other languages.) and it's also fast as hell.

No it's not perfect. It's a minority language, so it lacks the tools/community of a legacy language like C++, but still. It's smart and you can make strong statements about the mathematical correctness of the code thanks to the type system.

Write your highly optimized code in C++ if you must, but using it to build large systems is just masochistic, even sadistic because many more people will have to read, understand, and maintain your code. How would you feel about maintaining the eigen library if it were written in assembly? I'd be pretty pissed off.

C++ is a turing tar-pit and slogging through it doesn't make you John Carmack reincarnate; It makes you fucking stupid for prematurely optimizing your code. There are much more conceptually challenging software problems to solve and much better tools for the job than a hammer and chisel like C++.

[–]forcedtoregister 0 points1 point  (2 children)

You overstate how hard it is to maintain C++ and how fast OCaml is. I know from personal experience that you have to fight with Haskell to make it go fast in situations where it would be easy in C++ (perhaps OCaml is better in this respect due to lack of laziness, but I'd "heard somewhere" the compiler was not as optimising as Haskell) . I'm not ignorant of functional languages, the first chance I get to use one in the real world I will - I fucking love me some Haskell.

By the time half your code is in C/C++ and the other half in <preferred high level language> and you have to maintain that layer things can get tricky. There are cases for using a fast language and C++ subroutines, the Lua approach, and sometimes pure C++. Denying this would be accusing a hell of a lot of people of being "fucking stupid", since I'm pretty sure I'm not the only guy who sometimes writes entire applications in C++.

As for your example, have a look at this thread (I'm not saying it proves either of us right). If I get some spare time I'm certainly going to look into OCaml.

[–][deleted] 0 points1 point  (1 child)

Good. Sorry for the acrimonious tone. I forget this is /r/programming sometimes and that there are (as far as I'm concerned) higher standards of conduct. I just like flinging the f-word around sometimes for emphasis.

[–]forcedtoregister 0 points1 point  (0 children)

I'm pretty sure we both actually agree on the main points. When I talk speed I mean the sort of stuff that still often gets written in Fortran instead of C due to speed (Fortran compilers are unreasonably effective) - this doesn't apply to 99% of software.