r/programming • • Apr 01 '13

Ten C++11 Features Every C++ Developer Should Use

http://www.codeproject.com/Articles/570638/Ten-Cplusplus11-Features-Every-Cplusplus-Developer
469 Upvotes

283 comments sorted by

View all comments

Show parent comments

1

u/sol_aries Apr 01 '13

I wish I could upvote this more. The simple, even subconscious, process of visually parsing through code becomes a laborious one, opening a myriad of windows as you track down what's happening in there. Eg, "auto jj = foo();" on code I'm trying to get to compile (so limited ide support) means I have to track down 'foo()' to figure out what's happening. IMO, this is one terrible feature meant to cover up another.

9

u/ascii Apr 01 '13

Dynamic programming languages have shown that this is a quite feasible tradeoff for decades.

11

u/geaw Apr 02 '13

Also, I never hear C# programmers complain about var, nor Haskell programmers about type inference. This all kind of sounds like "it's different so it's bad" to me.

5

u/stusmith Apr 02 '13

Yep I remember when C# got the 'var' keyword. The debate went as follows:

  • I don't want dynamic variables!

  • Oh, it doesn't mean dynamic... why would I use it for 'int'?

  • Actually, it makes sense... use it everywhere. (*)

  • Oh look ReSharper agrees with me.

(*) - Unless a variable isn't being initialized, or needs to be typed as a different interface type.

-2

u/sidneyc Apr 02 '13

That's funny; I consider dynamic languages completely unusable for anything non-trivial for this reason, among others.

Explicit types are seatbelts. Sure you can drive without seatbelts, but it will mess you up good when things go wrong.

2

u/ascii Apr 02 '13

Not that tired old song again. Yes, dynamic languages trade away some safety in order to gain some expressivity. Yes, by itself, that can make code slightly harder to maintain. But guess what? Most of that safety can be regained using various best development practices. Static types are a type of mental seat belts. But they are far from the only one. And even so, most dynamically typed languages can simulate them very well.

Your opinion is demonstratably wrong, a number of the worlds largest, most sophisticated code bases are written in dynamic languages. A large swath of all Google services. Most of the Spotify backend. NASA makes frequent use of Python. The list goes on. People write, evolve and maintain enormous code bases over decades in various dynamic languages.

It's a tradeoff. You can argue 'til you're blue that dynamic types may be the wrong tradeoff, but the truth is that thousands of successful software projects have demonstrated that both statically and dynamically typed languages can be used to solve the most difficult problems a programmer face. It is therefore an objective fact that neither is completely unusable/a toy/whatever other lame description you can come up with. Both types of type system work just fine. Significant amounts of research has gone into determening which is better, and the results have been inconclusive.

-1

u/sidneyc Apr 02 '13

Yes, dynamic languages trade away some safety in order to gain some expressivity.

More importantly: they do away with a lot of compile-type type checking that makes non-trivial software engineering possible, such as deep refactoring.

Most of that safety can be regained using various best development practices.

Not that tired song again. If you want to write unit tests for type checking, that is your problem; serious people who write serious software use compilers for that (and no, Spotify is not serious software).

[...] NASA makes frequent use of Python. The list goes on. [...]

Show me a piece of mission-critical software that's written in Python and we'll talk.

Anything else is just toys and scripts.

2

u/ascii Apr 02 '13

Saying anything written in a dynamic language is a toy, covering your ears and singing about no true Scotsmen doesn't make you right. Nor does it make you an interesting discussion partner.

1

u/sidneyc Apr 02 '13

Nice dodge.

7

u/PurpleSfinx Apr 01 '13

Won't any halfway decent IDE show the type on a mouseover or something?

2

u/sol_aries Apr 01 '13

Not if you're trying to port something, get a code dump to compile, or working on a platform without such ide.

0

u/[deleted] Apr 01 '13

[deleted]

1

u/TheDeputy Apr 01 '13

Or using Visual Studio without Visual Assist X

1

u/Tasgall Apr 02 '13

You could use a good text editor like Sublime :/

8

u/[deleted] Apr 01 '13

[removed] — view removed comment

7

u/imMute Apr 01 '13

IMO if you're using auto then the type should literally not matter. So that's just for loops and iterators.

6

u/mb86 Apr 02 '13

How about when declaration and initialization both require typing out the full (perhaps very convoluted) type? Example I extended from someone else's above

std::shared_ptr<std::unordered_map<int,std::vector<int>>> m = std::make_shared<std::unordered_map<int,std::vector<int>>>(args);

versus

auto m = std::make_shared<std::unordered_map<int,std::vector<int>>>(args);

Here the auto makes it much cleaner and doesn't make any ambiguity when reading.

4

u/s73v3r Apr 02 '13

If you're actually caring about memory in that way, then please, don't use it. But not everyone is in the same boat.

4

u/ascii Apr 01 '13

In cases where you care about unint16 vs. uint8, it sounds like it might make a lot of sense to skip auto. Nobody is forcing you to use it everywhere. But I would say that's the exception, not the rule.

2

u/sidneyc Apr 02 '13

Of course I'd prefer a system more like what ADA has, with proper bloody subtypes that can be ranged.

You and me together. I was raised on Turbo Pascal and going to C and C++ felt like such a regression in terms of type expressiveness.

The Algol family of languages (Algol, Pascal, Modula, ADA, ...) had it right. It is so bad they lost out.

→ More replies (2)

4

u/geaw Apr 01 '13

The simple, even subconscious, process of visually parsing through code becomes a laborious one

I think that ship sailed for C++ a loooong time ago. Anyone not bothered by parsing C++ is not going to bothered by parsing C++11 before long.

-3

u/sol_aries Apr 01 '13

So when updating the language your thinking is, "well the language is already screwed up, let's screw it up some more!"

6

u/geaw Apr 02 '13

Well, it's more like, being easy to parse is not a design goal of C++. Neither is having your structs' sizes be easy to determine at a glance, for that matter.

It's just when I hear any complaint that C++ is getting too complex it's really baffling to me. It's complaining about the very premise of the language. You know what's not complex? C.