4 ms·
3 questions before moving to C++11 - which architectures is the author discussing when he talks about performance gains, what are the ISA requirements and numb
by toemetoch 14y ago
3 questions before moving to C++11
- which architectures is the author discussing when he talks about performance gains, what are the ISA requirements and numbers?
- what compilers are supporting it?
- why is it good to have "magic" happening in the background? E.g. reason 4 is not something I'd promote.
- cageface 14y ago#4 isn't really magic. It's just a way to let the compiler fill in the blanks with information it already knows. The benefits are debatable for simple, obvious types but for the hairier generic types you often encounter in C++ it's a godsend. Of course, the fact that this is so useful might make you wonder if C++'s type system is too complex in the first place.
- JamesLeonis 14y agoOf course it's complex. The template system is Turing complete! http://stackoverflow.com/questions/189172/c-templates-turing-complete http://stackoverflow.com/questions/189172/c-templates-turing...
- nknight 14y agoIt's absolutely not "magic", it's clearly-defined, easily-understood syntactic sugar that makes code smaller, simpler, and cleaner. There is never a case where you have to wonder what the type of an "auto" variable is, it is always the return type of whatever function or method you are invoking. If you don't already know what that return type is, you won't be able to use the result anyway.
- pubby 14y agostd::initializer_list is pretty magical.
- nknight 14y agoI don't really buy that. It enables a syntax that otherwise wouldn't be possible, but so does struct. The only thing really "magical" about it is the optimizations it makes possible, but if that were your concern, it would be the first time I heard anyone complain that compiler optimization is "magical" in any negative sense.
- JamesLeonis 14y agoI can answer 2 and 3 2. Apache maintains a list of which compilers support what. http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport 3. The auto keyword isn't supposed to be magic. Rather it's for catching complex types that aren't easily to discover, such as the returns of template functions and iterators, and making it easier on the programmer by not forcing the typing out of long types. The type is resolved at runtime (as best as I am able to tell) and can help clean up some of the messiness of template programming.
- pja 14y agoNo, the type implied by an auto declaration is resolved at compile time.
- JamesLeonis 14y agoDOH! My mistake! Thanks for the catch.
- toemetoch 14y agoThanks for answering those two. The reason I'm not happy with "auto" is that as a programmer you'll end up hunting down types in source. Even more so if you inherit code from someone else. So we'll add them in comment as mental note instead of properly declaring them? You call it messiness (visual clutter in the article) but in my experience it'll promote laziness and pitfalls for beginners. It's just a matter of time before you'll see questions like 'why does the compiler infer the wrong type here?' on StackOverflow. Re-reading my post I see it's easily interpreted as arrogant. That wasn't my intention.
- darklajid 14y agoFor 'auto'/magic: There's a looooot of material about pro and contra arguments, if you look at C#'s type inference. Replace auto x = ... with var x = ... and you can read a good amount of arguments about the benefits and (potential) downsides, and where people deem it useful and clear or where brittle and questionable. The argument you're making was discussed at length when this feature was first introduced. I think it applies 100% here as well.