lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Updating code to use C++11


From: Greg Chicares
Subject: Re: [lmi] Updating code to use C++11
Date: Mon, 25 Jan 2016 02:58:00 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0

On 2016-01-25 01:31, Vadim Zeitlin wrote:
> 
>  Now that we're close to making the build system work using a modern C++11
> compiler, I'd like to ask about the next steps -- if there are going to be
> any.

Yes, of course there should be further steps.

>  Personally I'd like to start at least the following new C++11 features in
> the code:
> 
> - "auto" for the variables to avoid duplicating the type of the RHS
> - short loop syntax for the "for each" loops
> - lambdas for the wxWidgets event handlers
> - nullptr instead of 0 or NULL for type safety
> - "override" to make sure methods are really overridden when meant to
> - "= delete" instead of "lmi::uncopyable<>"
> 
>  Of this, I think, only the first one can be potentially controversial, but
> please let me know if I'm wrong and if you have anything against the other
> ones and/or also agree with the first one or, at least, don't disagree with
> it violently enough to make any attempt to convince you to start using
> "auto" doomed in advance.

>From what little I've read about it, 'auto' sounds like a good idea, and I
like 'nullptr'--I've just always spelled it "0" in preference to "NULL",
as did Stroustrup in the last of his books that I read (which was some
time ago). I guess I'll need to buy another book or two.

Wasn't 'override' part of the original C++ language? No, that was 'overload'.
Well, I've got some catching up to do. Are the old guys like Stroustrup and
Scott Meyers still writing? Or has a new generation arisen to rival them?

>  Assuming we do agree on using to start at least some of these features in
> the new code, the question is what to do about the existing code. The path
> of the least resistance is to keep it unchanged, but I don't, and I suspect
> you wouldn't, like the discrepancy between the "old" and "new" code which
> would arise in this case.

It would not be concinnous.

> So I'd like to propose to change the existing
> code to follow the new C++11 rules too. Obviously, this will take some
> time, although perhaps not as much as one might think, thanks to the new
> clang-based tools allowing to find the occurrences of old style constructs
> and replace them with the new ones, but I still believe it would be worth
> it.
> 
>  What do you think?

I guess I'm pretty much in favor of what little I understand about C++11.
If you want to move forward with this faster than I learn about it, it
would be a good idea to share a small snippet of each idea first. I can't
provide a C++11 example, but if we were moving from C to C++, you might
suggest changing

  int j = 0;
  for(j; j < 9; j++)

to

  for(int j = 0; j < 9; ++j)

(counter declaration inside for-loop; pre- instead of post-increment) so
that I can ask questions or present objections before you put in a lot of
effort. But I might actually have few or no objections. I guess the C->C++
example above is pretty similar to the new 'auto' keyword: once understood,
one wonders why the language didn't always work that way.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]