4 ms·
I am not sure what C++ brings in as a language. If you want to get an idea how your code will work or even if it going to work at all you have to first underst
by mpu 12y ago
I am not sure what C++ brings in as a language.
If you want to get an idea how your code will work or even if it going to work at all you have to first understand type deduction rules which are seemingly completely unprincipled. When I compare the "rules" of C++ type deduction to functional languages' type inference algorithms I can easily understand how the latter work but I have no clue about what justifies the former.
Yet, in C++, if I want auto type inference on my recursive factorial function I have to write "return 1;" syntactically before (i.e. where the order is the relative position of bytes fed to the compiler) "return n*fact(n-1);", otherwise the compiler is unable to find the type. I just don't understand. The type deduction rules (say reference collapsing) are rocket science and take a full blog post as their justification, but basic unification algorithms known in the PL community for literally decades cannot be implemented in the standard?
This language seems plain crazy, this kind of article makes me wonder why people think it can be a reasonable choice for any kind of software project.
At least, C can fit in a brain.
- th0ma5 12y agoI have for a long time considered C++ to be a language creation language, and to understand a particular codebase in C++, you'd have to survey the whole thing first for the greater patterns that could be redesigning the way the whole codebase works. All the debates of static vs. dynamic, strong vs. weak, GC vs not, are arguments you can play out within in the same file of a C++ project. I think this is why arguments about it take hold so much, that is, given various conditions, just about anyone's arguments about C++ are right.
- Guvante 12y agoI thought functional languages had to give up on most forms of overloading as well as implicit conversions for their algorithms to work. While the former is not a big deal, the latter would be a deal breaker (as much as I have learned to live without).
- mpu 12y agoYou are right. But these problems can be solved using annotations. Your comment helped me to narrow my complaint: While functional languages require annotations for things that are not obvious (when to subclass, when to change the type of an object, what overload should I use) and infer the obvious ("n*fact(n-1)" is an integer); C++ infers the non-obvious and requires you to add annotations on the obvious! Phrased that way, it is striking.
- pjmlp 12y ago> I am not sure what C++ brings in as a language. C speed of execution, while offering support for large scale programming, OOP, functional, generic and plain old imperative programming. Ability to treat user defined types as first class citizens. Standard library that offers all mechanisms to avoid the traditional C pitfalls in terms of memory/resource leaks and out-of-bounds errors. > This language seems plain crazy, this kind of article makes me wonder why people think it can be a reasonable choice for any kind of software project. Except for Ada, very few languages offer similar capabilities and Pascal like syntax is out of fashion. > At least, C can fit in a brain. Can you master all compiler specific behaviours not covered by the standard?!?
- mpu 12y ago> Can you master all compiler specific behaviours not covered by the standard?!? No, and the good part is: I don't need to :). All my programs are standard C11 (- concurrency).
- pjmlp 12y agoSo how you fit it all in the brain, then?
- yoklov 12y agoI think his point was that the standard (even C11) leaves a great deal of implementation-specific behavior. C++11 has the same problem (as it has the same implementation specific behavior as C), but the standard library allows you to avoid most of it.
- sjolsen 12y ago> At least, C can fit in a brain. A typical programmer's mental model of C can fit in a brain. Actual C is every bit as complex and nuanced as C++; it just has a narrower scope. I mean, C++ may be crazy, but don't pretend a language where uint64_t foo = 1 << 48; has undefined behaviour, int a [3]; declares an array while void foo (int a [3]); declares a function taking a pointer, and polymorphism is achieved by erasing all types and parsing a string at run time to figure out where to pull stuff off the stack: printf ("%d%s\n", 3.0, " s"); // Whoops, "%d" doesn't mean "double." It's a shame I don't have a type system for catching that sort of error. is anything remotely resembling sane.
- JoeAltmaier 12y agoPretty crazy; but C++ has extra crazy all its own, so it wins the crazy contest.
- sjolsen 12y agoI won't contest that! But C is crazy enough that suggesting it as an alternative to C++ because C++ is crazy is, well, crazy. If you can handle the crazy of C, you can probably handle C++, because the crazy specific to C++ usually at least converges to reasonable behaviour. I mean, you'll drive yourself nuts trying to wrap your head entirely around either language, so you may as well at least mentally approximate the one that gives you basic type-parameterization.