- quick confirmation needed - 3 Updates
- Applying modern C++ (was: Which book is better for C++14 : Effective Modern C++ or C++14 FAQs ?) - 4 Updates
- Circular Racecourse Puzzle - 2 Updates
- Applying modern C++ - 2 Updates
Doug Mika <dougmmika@gmail.com>: Apr 16 12:55PM -0700 Hi, could someone quickly confirm if the following last line calls the copy constructor? Thanx bitset<4> fourBits1("1010"); bitset<4> fourBits2("1111"); bitset<4> result(fourBits1 & fourBits2); |
Victor Bazarov <v.bazarov@comcast.invalid>: Apr 16 04:34PM -0400 On 4/16/2015 3:55 PM, Doug Mika wrote: > bitset<4> fourBits1("1010"); > bitset<4> fourBits2("1111"); > bitset<4> result(fourBits1 & fourBits2); The compiler is allowed to optimize away copy construction. Just keep that in mind. The semantics might require creating a copy but the reality can be slightly different in the name of performance. You can only confirm that the copy constructor is called by putting the breakpoint in it and running under a debugger, or by introducing some kind of side effect code and observing that the side effect takes place. V -- I do not respond to top-posted replies, please don't ask |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Apr 16 09:46PM +0100 On 16/04/2015 21:34, Victor Bazarov wrote: > only confirm that the copy constructor is called by putting the > breakpoint in it and running under a debugger, or by introducing some > kind of side effect code and observing that the side effect takes place. Note: attempting to introduce a side effect to copy ctor is not enough to prevent copy constructor elision taking place sausages. /Flibble |
"Öö Tiib" <ootiib@hot.ee>: Apr 16 01:44AM -0700 On Thursday, 16 April 2015 01:02:39 UTC+3, Stefan Ram wrote: > write software, but /maintain/ existing software. Of course, > in doing so, they write lines of code, but they also remove > lines of code and read lines of code. So therefore "It can't be picked up from few tutorials, manual and trial and error; that would take lot of years." (that you snipped) applies. Or what was your point? > A maintenance programmer cannot choose which features of the > language the existing parts of the code use. Maintenance programmer has to behave by coding standard of project, by best practices, by what the environment (compiler, platform and tools) supports/allows and by what the actual piece of code under maintenance does. So that is a puzzle and good books help to find the vital highlights in such a situation. Besides, reading itself helps to learn to read and C++ programmer has to read a lot. ;-) For example I don't know decent books that teach to use C++ that is stripped of exceptions, RTTI, major part of standard library etc. and by MISRA C/MISRA C++ coding standards compliance. Such goal-posts tend to move. So we have to learn to read bad books too. Chandra Shekhar Kumar's book seems unfortunate since it claims to be about bleeding edge C++14. We should next to never use bleeding edge features in maintenance project. |
Juha Nieminen <nospam@thanks.invalid>: Apr 16 09:26AM > lines of code and read lines of code. > A maintenance programmer cannot choose which features of the > language the existing parts of the code use. If you don't know the tool you are using, then perhaps you should not sell yourself as a "maintenance programmer" then? --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
"Öö Tiib" <ootiib@hot.ee>: Apr 16 07:01AM -0700 On Thursday, 16 April 2015 14:07:28 UTC+3, Stefan Ram wrote: > The point was to contrast your idea of a language > for writing software with the idea of a language for > reading software (readable source code). The sentence that "C++ contains far more features and alternative possibilities than anyone needs for writing software" does not mean that "C++ is write-only language" It means that "Same little thing may be written in C++ in number of alternative ways". So if you argue with "my idea" that "C++ is write-only language" then you apparently argue with idea that I did not have and with a point that I did not make. Please avoid misrepresenting others. |
"Öö Tiib" <ootiib@hot.ee>: Apr 16 08:11AM -0700 On Thursday, 16 April 2015 15:49:17 UTC+3, Stefan Ram wrote: > >maintenance project. > So, you believe, a maintenance programmer should avoid > make_unique, and prefer unique_ptr( new ... ) instead? Possibly. Only few months ago I helped a totally new project where combo of 'shared_from_this()' and 'std::make_shared()' of the library of the compiler used was defective and did crash. Note that it was 2014. I think it was Peter Dimov who added working 'shared_from_this()' to boost ~2003 and 'make_shared' ~2008. So 'make_unique' may be easily unavailable even for a totally new project started right now but I would then likely write one myself or loan it from boost. What I actually meant was that maintenance programmer should make minimal changes needed for fixing the issue under hand. She should continue using style what the code was using. For example if maintained code used 'boost::scoped_ptr' then she should not introduce usage of 'std::unique_ptr' instead. Otherwise it may break unit tests, the subtle differences may cause more defects and result is needless waste of effort of her and the team over the putrid onion of program. Sometimes code that is decades old is maintained. For example just because currency in a country did change. Someone needs it but few can pay ~$500K for a total rewrite of 1000 file code-base. Even if they are eager to pay such money then why not to do just $50K worth of fixes and enjoy the $450K? So the maintainer of it should continue using the "C with classes" style of it and fix only what became broken. |
sergei.nakariakov.5@gmail.com: Apr 15 05:08PM -0700 Along a circular racecourse are N pits, clockwise numbered from 0 through N -1. The amount of petrol available at pit i equals p[i], whereas the amount of petrol needed to travel from pit i to the clockwise next pit equals q[i]. Write a program to determine all pits from which a car, with an initially empty and sufficiently large tank, can start and complete the whole course in clockwise direction. The complete description of the problem (along with sample solution) is given at : https://www.dropbox.com/s/pvyd1qnarg05pdh/circular_racecourse.pdf?dl=0 This problem is from my book "Cracking Programming Interviews: 500 Questions with Solutions", and I am trying to improve the solution of this problem. Kindly let me know your inputs. Thanks, Sergei |
"Öö Tiib" <ootiib@hot.ee>: Apr 16 06:48AM -0700 > is given at : https://www.dropbox.com/s/pvyd1qnarg05pdh/circular_racecourse.pdf?dl=0 > This problem is from my book "Cracking Programming Interviews: > 500 Questions with Solutions", and I am trying to improve the Looking at the pseudocode in the snippet that you drop-boxed it is a bad book. Throw it away. I dislike code that uses numeric literal 1 and names l and I in mix. I value readability over efficiency. The few places that deserve fixing because of efficiency are always lot easier to fix in readable code. > solution of this problem. Are the 'N', 'p[N]' and/or 'q[N]' compile-time or run-time values? Have you achieved implementation of described solution in C++? If no, what does hold you back? Can you post what you have achieved? In what direction you try to improve it? What you have done or plan to do to improve it? > Kindly let me know your inputs. Inputs to where? |
ram@zedat.fu-berlin.de (Stefan Ram): Apr 16 11:07AM >So therefore "It can't be picked up from few tutorials, manual and >trial and error; that would take lot of years." (that you snipped) >applies. Or what was your point? The point was to contrast your idea of a language for writing software with the idea of a language for reading software (readable source code). |
ram@zedat.fu-berlin.de (Stefan Ram): Apr 16 12:49PM > it claims to be about bleeding edge C++14. >We should next to never use bleeding edge features in >maintenance project. So, you believe, a maintenance programmer should avoid make_unique, and prefer unique_ptr( new ... ) instead? |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment