Personal computing discussed

Moderators: SecretSquirrel, just brew it!

 
just brew it!
Gold subscriber
Administrator
Topic Author
Posts: 51649
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

C++11 and Boost

Wed Mar 23, 2016 5:59 am

After approximately a decade in the wilderness (a.k.a. embedded development), I now find myself doing systems and server programming at my day job. A decision has been made to go with C++11 and Boost for the current project.

Man, I feel like a n00b. It doesn't help that my prior C++ experience was over a decade ago. Not only do a lot of the new C++11 language (and standard library) features (not to mention Boost) look and feel somewhat alien; I'm a little bit rusty with the language overall.

Anyhow, I'm getting back up to speed by writing and running little test programs on my laptop while I'm commuting (I take public transit), to help me understand the new language features and the Boost libraries. So far I (mostly) like what I'm seeing, but I do have one complaint: Boost's heavy use of nested templates and scopes makes for some rather difficult-to-decipher error messages from the compiler when you do something wrong. On some of my little exercises, decoding the compiler errors has taken longer than writing the actual code.

For those unfamiliar with Boost, it's a large collection of portable C++ utility libraries, across a wide range of application domains. It seems to have evolved into a sort of incubator, with some of the Boost libraries becoming candidates for inclusion in the C++ standard runtime library.

And what would we do without Stack Overflow? :lol: It's amazing how Stack Overflow (founded 7 years ago) and Slack (a mere 2 years old) have become such integral parts of being a developer.
Nostalgia isn't what it used to be.
 
meerkt
Gerbil Elite
Posts: 981
Joined: Sun Aug 25, 2013 2:55 am

Re: C++11 and Boost

Wed Mar 23, 2016 9:22 am

What compiler are you using? Maybe this could be useful: http://clang.llvm.org/diagnostics.html
 
RuiFig
Silver subscriber
Gerbil
Posts: 30
Joined: Tue May 19, 2015 4:46 am
Location: Edinburgh, Scotland
Contact:

Re: C++11 and Boost

Wed Mar 23, 2016 10:02 am

I can imagine how alien it must look to you.
I've been using C++ non-stop for the last 20 years or so, and sometimes I still choke on those error messages. :)
Clang is probably the best at the moment pinpointing where the problems probably are. Visual Studio just spits out a huge wall of text. You then need to dig and figure out the problem. haha
I haven't touched GCC for a few years, so no idea on the side.

Lots of those new things you see in the language now have been around for ages as "experimental", but the last few years 5 years or so, there has been an amazing push adding those goodies to the standard.
It's a monster of a language, and very intimidating. But I guess it comes with C++'s mantra of "zero overhead". You only pay for what you use. And then the backwards compatibility thing. :/
If you focus on modern stuff, it's really a more concise language and refreshing compared to a decade ago. But in practice you still need to interact and understand older code :)

For example, I have a fairly advanced low level knowledge ( see my pet project https://bitbucket.org/ruifig/g4devkit ), but nowadays I don't think I have a single naked new/delete in my code. As long as you know what you are doing, there is no excuse not to use smart pointers.

I recently started writing some long articles for my blog that might help you catch up. Multi thread goodies and all, like this one: http://www.crazygaze.com/blog/2016/03/17/how-strands-work-and-why-you-should-use-them/
I'll be covering a lot more things. Some based on boost's ideas, other of my own.
Last edited by RuiFig on Wed Mar 23, 2016 10:41 am, edited 1 time in total.
Code Monkey at Cloudgine Ltd. Personal blog on coding: http://www.crazygaze.com
 
Flying Fox
Gerbil God
Posts: 25448
Joined: Mon May 24, 2004 2:19 am
Contact:

Re: C++11 and Boost

Wed Mar 23, 2016 10:14 am

RuiFig wrote:
If you focus on modern stuff, it's really a more concise language and refreshing compared to a decade ago.

I am not convinced heavily lambda'ed code is refreshing. I started with classic C/C++ but learned lambdas on C#, coming back to C++ the expressions just look very weird. Shoehorning the concept onto an older language with limited tokens makes the thing totally weird without having a cheat sheet on the side every time. And if you abuse it a lot, it makes for some fairly readable mess to me.

But I do agree, over the last decade the inclusion of modern features plus some of Boost's stuff into TR1 and subsequently the standard is a good thing (smart_ptr into std, auto variable type deduction). They do improve development "at a higher level".
The Model M is not for the faint of heart. You either like them or hate them.

Gerbils unite! Fold for UnitedGerbilNation, team 2630.
 
223 Fan
Gold subscriber
Gerbil
Posts: 58
Joined: Wed Jun 26, 2013 4:41 pm

Re: C++11 and Boost

Wed Mar 23, 2016 10:23 am

I am not convinced heavily lambda'ed code is refreshing. I started with classic C/C++ but learned lambdas on C#, coming back to C++ the expressions just look very weird. Shoehorning the concept onto an older language with limited tokens makes the thing totally weird without having a cheat sheet on the side every time. And if you abuse it a lot, it makes for some fairly readable mess to me.


+1. C++ lambdas are just terrible syntactically. Also, for the rest of C++11/14 if you read Scott Meyer's "Effective Modern C++", recommended by the way, he says in multiple places "this code does not do what you think it does".
 
RuiFig
Silver subscriber
Gerbil
Posts: 30
Joined: Tue May 19, 2015 4:46 am
Location: Edinburgh, Scotland
Contact:

Re: C++11 and Boost

Wed Mar 23, 2016 10:24 am

Flying Fox wrote:
And if you abuse it a lot, it makes for some fairly readable mess to me.


As with any new toy, of course it gets abused, and then you learn. Remember all the craze about OOP. Everything and the kitchen sink needs to be an object. No free-functions anywhere? Multiple-inheritance is the thing man!

I had my fair share of mess caused by lambdas too, like for example having no idea what function is that in the callstack somebody just sent you.
But used sparingly it avoids lots of boilerplate code.
Code Monkey at Cloudgine Ltd. Personal blog on coding: http://www.crazygaze.com
 
RuiFig
Silver subscriber
Gerbil
Posts: 30
Joined: Tue May 19, 2015 4:46 am
Location: Edinburgh, Scotland
Contact:

Re: C++11 and Boost

Wed Mar 23, 2016 10:39 am

223 Fan wrote:
+1. C++ lambdas are just terrible syntactically. Also, for the rest of C++11/14 if you read Scott Meyer's "Effective Modern C++", recommended by the way, he says in multiple places "this code does not do what you think it does".


Personally I think they are "so-so". Given the need to keep backwards compatibility with everything else, I can't think of any other way they could have done it. Yeah, it's messy.
Give it a few more years, and things start making sense in our heads as we recognize patterns and such. Like for example, Scott Meyers came up with a somewhat cleaner way to think about all the references mess, with the concept "Universal references", in that same book you mentioned.

I'm quite comfortable with lambdas now, but one thing that still gets my head spinning are variadic templates. I use them in some library code, but every time I need to write some, I need to look at examples and documentation. :|
Code Monkey at Cloudgine Ltd. Personal blog on coding: http://www.crazygaze.com
 
Buub
Maximum Gerbil
Posts: 4761
Joined: Sat Nov 09, 2002 11:59 pm
Location: Seattle, WA
Contact:

Re: C++11 and Boost

Wed Mar 23, 2016 6:28 pm

Flying Fox wrote:
RuiFig wrote:
If you focus on modern stuff, it's really a more concise language and refreshing compared to a decade ago.

I am not convinced heavily lambda'ed code is refreshing. I started with classic C/C++ but learned lambdas on C#, coming back to C++ the expressions just look very weird. Shoehorning the concept onto an older language with limited tokens makes the thing totally weird without having a cheat sheet on the side every time. And if you abuse it a lot, it makes for some fairly readable mess to me.

But I do agree, over the last decade the inclusion of modern features plus some of Boost's stuff into TR1 and subsequently the standard is a good thing (smart_ptr into std, auto variable type deduction). They do improve development "at a higher level".

It may look weird, but it's extremely valuable. For example, using algorithms (std algorithms, not the generic concept) is significantly simpler with lambdas than the old C++98 world where you needed to supply a named function.

Who is online

Users browsing this forum: No registered users and 1 guest