Thread: new standard

  1. #16
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by phantomotap View Post
    My prediction is that programmers who understand the intent and capabilities of "rvalue references" will always use them. (Providing at least move assignment and move construction operators for anything not trivially copied.)
    The whole problem is one of what is a "trivial" copy versus a move essentially being a destructive copy. To use the example of a swap() function

    Code:
    template<class T> swap(T &a, T &b)
    {
          T tmp(move(a));
          a = move(b);
          b = move(tmp);
    }
    Where move() essentially enables the move construction or assignment. The thing is, in the first line it effectively destroys the object a. The second line then reconstructs a, with the contents of b, and destroys b. The last line then reconstructs b with the data that was in a.

    Granted, there are efficiency gains ... if everything goes right. But one of the common maintenance problems in classes with user-supplied copy constructors or assignment operators has been the problem of ensuring those functions work correctly (eg correctly copy all members). And what does the "move construction" introduce ..... a requirement to potentially maintain a larger set of such functions. Unless performance is highly critical - which it is in some applications, but not in many - that is, on the face of it, a maintenance burden.

    All this is at odds with accepted best practices, that encourage getting code functionally right first in the simplest and most maintainable form, and then worrying about addressing any performance deficiencies - in other words, discouraging premature optimisation. Instead, what we have is an encouragement for programmers to perform premature optimisation. That will eventually yield a series of constraints and guidelines concerning whether a class should support move construction/assignment or not. We already have an example where constraints have to be imposed related to exceptions. A few more such constraints - particularly if they rely on losts of care and consideration by the programmer - and it will be easier for programmers (who, let's face it, are often careless and inclined to waste productive time with premature optimisation) to use other techniques.

    Yeah, I'm sure others will make different predictions to mine. The proof will be in the practice down-track, I guess. As a matter of fact, I hope I'll be proven wrong, but don't think I will be.
    Quote Originally Posted by King Mir View Post
    Perhaps, if they depreciate throw declarations now, then ten years time it will make sense to replace it with something else, but no sooner.
    There are only two possible circumstances I can see in which changing exception specifications will cause confusion.

    1) Addition of new constructs, which fail to compile at present anyway. This will only cause confusion if new code is ported to old compilers, but that's a common problem with all new language features. Deprecation will not stop programmers from running new code through old compilers.

    2) Practical problems associated with turning run-time checks (eg calling abort() when an unexpected exception is thrown) into compile time checks.

    Would you care to characterise practical circumstances in which changing current run-time enforcement of exception specifications to compile time checks presents a real disadvantage?

    Yes, it is true that some old code will fail to compile. I consider those circumstances are a non-issue. Firstly, the amount of such code is small (since exception specifications have been actively discouraged - to the extent there is consideration of deprecating exception specifications). Second, the cause of failure will, most likely, be related to existing undiagnosed faults in code.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  2. #17
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by grumpy View Post
    Firstly, the amount of such code is small (since exception specifications have been actively discouraged - to the extent there is consideration of deprecating exception specifications).
    Sure, the amount of code is small, but the committee decided to be extra conservative here. Better to not break any previously valid code at all.

    Second, the cause of failure will, most likely, be related to existing undiagnosed faults in code.
    No I think the greatest the cause of the failure will be due to inconsistent use of throws decelerations.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    But one of the common maintenance problems in classes with user-supplied copy constructors or assignment operators has been the problem of ensuring those functions work correctly (eg correctly copy all members). And what does the "move construction" introduce ..... a requirement to potentially maintain a larger set of such functions. Unless performance is highly critical - which it is in some applications, but not in many - that is, on the face of it, a maintenance burden.

    All this is at odds with accepted best practices, that encourage getting code functionally right first in the simplest and most maintainable form, and then worrying about addressing any performance deficiencies - in other words, discouraging premature optimisation. Instead, what we have is an encouragement for programmers to perform premature optimisation.
    We have two types of classes that should have move constructors.

    One is objects that aren't copyable, but where it would be an interface advantage to have them movable. Examples of this are unique_ptr and thread. There is no copy constructor there, so you maintain exactly one state transfer function. This is more than if there were no move constructors, but at the gain of interface expressiveness, so it's not about optimization.

    The other is objects that are copyable, but where copying is very slow, while moving would be fast. In this case, the move constructor is a performance optimization, but at the same time, it's also easily added later. So it's not an encouragement to do premature optimization.

    Another point is that moving an object is very well encapsulated in that object and thus easy to test, so libraries that provide movable types should be able to say with high confidence that these work.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't like the idea that we're forced to ensure move constructors are non-throwing. I don't know if a move constructor should throw or not, probably not, but to be on the safe side...
    I also think the current suggestion is a mess.
    First they suggest concepts. Then the noexcept specifier. Then implicit noexcept. Then throw specification (eg throw(...)), and finally a noexecpt block!
    Come on!
    Would it hurt to have just two types of keywords--one of throwing and one for not throwing? The exception specifications are there... they just need to be static. And the throw(...) exception extension already exist, so why not make it the universal may throw?
    They are complicating this too much.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Elysia View Post
    They are complicating this too much.
    Bingo!

    When programming language features become too complex, programmers tend to abuse them. The deliberate abuses tend to become problems for their successors (the poor suckers who must maintain the code) and accidental abuses create immediate problems of debugging and maintenance. Not to mention the burden for compiler vendors to get their compilers right, introduce particular interpretations of the grey areas, etc etc.....

    The move construct, on it's own, strikes me as deceptively simple and elegant. But some of the associated consequences are pretty intrusive. And it is that wider picture that concerns me.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #21
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    So... you think "a lot of serious programmers will actively avoid rvalue references"... because it is easy to get it wrong the first time?

    *shrug*

    I don't know of any programmers I would even call good who avoid templates or exceptions. (I am talking about writing them, not just using the STL.)

    ^_^

    You must be calling the cowboys "serious programmers".

    Soma

  7. #22
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by phantomotap View Post
    O_o

    So... you think "a lot of serious programmers will actively avoid rvalue references"... because it is easy to get it wrong the first time?

    *shrug*
    I said nothing of the sort.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  8. #23
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I really wanted the for each style loops --

  9. #24
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Edit: You know what... it doesn't matter. It is your prediction, your rationale, your problem. I just hope people don't screw up by avoiding move semantics because of the same flimsy rationale.

    I said nothing of the sort.
    Well, from my perspective you didn't say anything else either.

    It's hard to get templates right for every case, good programmers don't avoid them.

    It's hard to get exceptions right, good programmers don't avoid them.

    No existing compiler handles templates perfectly, good programmers don't avoid them.

    Programmers abuse the simplest aspects of a language as readily as the complex ones.

    If you can move from a linear algorithm to a constant algorithm, you usually should.

    It is usually correct to start with a better algorithm than try to replace an algorithm used in an existing implementation.

    Some of the problems you are apparently worried about wouldn't even exist if the move overloads were required. (If every operation is non-throwing, the total is non-throwing.)

    Just like for exceptions and templates, if you use the right primitives, the correct implementation of the various move overloads is almost trivial. The problem is, if programmers don't implement the move overloads correctly, these primitives will not be available. By avoiding them, programmers guarantee their source can't be trusted in many contexts.

    It's just like coding under the assumption that you can avoid exceptions just because you don't personally employee them, you potentially break everything.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Standard efficiency
    By Jorl17 in forum C Programming
    Replies: 3
    Last Post: 06-18-2009, 11:48 AM
  2. Bug in iterator comparison in C++ standard?
    By steev in forum C++ Programming
    Replies: 14
    Last Post: 07-12-2008, 12:02 AM
  3. Abstract Base Class and References
    By Thantos in forum C++ Programming
    Replies: 9
    Last Post: 10-13-2004, 01:35 PM
  4. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM