TL++ [So much ++ its Meta] - Page 3
Blogs > CecilSunkure |
Meta
United States6225 Posts
| ||
Jacmert
Canada1709 Posts
On June 28 2013 22:36 BisuDagger wrote: Your loop only runs once. Ha ha! Good, I'm not crazy. I don't usually code in C++ (I work with a C++ like language), but I was like, "doesn't return break out of the loop?" And I've NEVER heard/known about i++ returning any value, nor the difference between i++ and ++i. Good to know. Thanks! | ||
mizU
United States12125 Posts
| ||
Shana
Indonesia1814 Posts
| ||
wherebugsgo
Japan10647 Posts
On June 29 2013 02:44 spinesheath wrote: So now instead of
you always write
Yes, that's an assignment too, even though there is no = sign in the function call. Granted, the sequence vector<int> v(10, 0);Can resolve to pretty much anything your compiler wants it to, but is that a reason to avoid ++? My C++ got really rusty from all that C# lately, geez. Had to look up all of this to make sure I'm not making mistakes... Actually, I'm almost 100% sure this is exactly why some programmers suggest avoiding ++ and --, because when you use them inline with other things, it tends to confuse people who did not write the code themselves. The professor I had that required += instead of ++ was not the only one who suggested this, though he was the most vocal about it. A few that I've had have said that increment and decrement operators should only be used by themselves on a single line, i.e.
instead of
The fact that you had to look up documentation to see if you were doing everything correctly is another indication that perhaps you should consider simplifying your style, regardless of whether you've spent time programming in C#. Good programming practices lead to simple and readable code. I don't think what you suggested is very simple. Even if it takes more time to write it initially, clean and simple code is much easier and less painful to maintain. For example, what does this mean?
Sometimes with pointer arithmetic in C the increment operators can become really confusing too. The point is not that you CAN do these things. Sure, you can do them. It doesn't mean you should. I'm personally of the belief that code should not be a labor to read or understand. It's a pain in the ass to debug someone else's code when it's written poorly and not commented. Then again, maybe I am significantly biased, since the first three languages I learned to program in were Fortran, Scheme, and Python, none of which use the ++ operator. It was only after I used them for 2 years that I moved onto Java and C. | ||
rabidch
United States20287 Posts
On June 28 2013 19:20 spinesheath wrote: The # is actually just two overlapping + signs. So it's C[++ in a single character]. or it could be 4 smaller +s | ||
aNGryaRchon
United States438 Posts
On June 28 2013 16:55 haduken wrote: So.... why is C# called C Sharp... instead of C pound sign or C hash.. Good question | ||
spinesheath
Germany8679 Posts
On June 29 2013 09:58 wherebugsgo wrote: Actually, I'm almost 100% sure this is exactly why some programmers suggest avoiding ++ and --, because when you use them inline with other things, it tends to confuse people who did not write the code themselves. The professor I had that required += instead of ++ was not the only one who suggested this, though he was the most vocal about it. A few that I've had have said that increment and decrement operators should only be used by themselves on a single line, i.e.
instead of
The fact that you had to look up documentation to see if you were doing everything correctly is another indication that perhaps you should consider simplifying your style, regardless of whether you've spent time programming in C#. Good programming practices lead to simple and readable code. I don't think what you suggested is very simple. Even if it takes more time to write it initially, clean and simple code is much easier and less painful to maintain. For example, what does this mean?
Sometimes with pointer arithmetic in C the increment operators can become really confusing too. The point is not that you CAN do these things. Sure, you can do them. It doesn't mean you should. I'm personally of the belief that code should not be a labor to read or understand. It's a pain in the ass to debug someone else's code when it's written poorly and not commented. Then again, maybe I am significantly biased, since the first three languages I learned to program in were Fortran, Scheme, and Python, none of which use the ++ operator. It was only after I used them for 2 years that I moved onto Java and C. I had to look this stuff up because things like the comma operator are pretty damn exotic and I would never use them in real code unless I had a very specific reason to use it. Also to make sure the example of undefined behavior is actually undefined behavior. Increment operators are generally fine if you only have a single occurence of the incremented variable in the whole statement and don't have any side effects on the variable. Sure, it means you need to be careful, but in fact compilers should be able to warn you about these things nowadays and I wouldn't give up proper ++ usage (which really is just in cases where it is clear what it does) where appropriate just for a little false security. You're not allowed to be any less careful just because you avoid ++, anyways. | ||
Mobius_1
United Kingdom2763 Posts
| ||
docvoc
United States5491 Posts
On June 28 2013 15:49 CecilSunkure wrote: u gotta skate The moral of the story. | ||
Scorpion77
98 Posts
| ||
Blisse
Canada3710 Posts
On June 28 2013 16:55 haduken wrote: So.... why is C# called C Sharp... instead of C pound sign or C hash.. =.= -removed comment- | ||
MaGariShun
Austria305 Posts
On June 28 2013 16:55 haduken wrote: So.... why is C# called C Sharp... instead of C pound sign or C hash.. Because calling it 'Java' would have been to obvious of a ripoff | ||
XCetron
5225 Posts
On June 28 2013 16:55 haduken wrote: So.... why is C# called C Sharp... instead of C pound sign or C hash.. | ||
Rayeth
United States883 Posts
On June 29 2013 09:58 wherebugsgo wrote: For example, what does this mean?
Sometimes with pointer arithmetic in C the increment operators can become really confusing too. The point is not that you CAN do these things. Sure, you can do them. It doesn't mean you should. I'm personally of the belief that code should not be a labor to read or understand. It's a pain in the ass to debug someone else's code when it's written poorly and not commented. I can show off my knowledge of old languages, whee!
This is straight up undefined behavior by the C standard. I don't know about C++ or C# (as I don't use them), but the C standard says this will lead to undefined behavior. You are using the ++ operator in such a way as to make its use dependant on what the compiler chooses to do first. It is equally undefined to say:
Now something will happen, but what you get is dependent on what system, what compiler and who knows how many other variables. The correct way to write the above would simply be u++; The technical reason for these being incorrect is that you are modifying the stored value more than once between sequence points. As for what a sequence point is refer to the Wikipedia article as it is much clearer than I could ever be. The end result here is that you are right. No one should ever use expressions like that. They are sometimes used in classrooms to demonstrate bad code for a reason! I will disagree with you about the pointers though. Yes bad code can be created using silly means, but a competent coder should not fear to use pointers. They are really useful! Don't shy away from such a powerful tool because they can be confusing, just make sure you are not the one writing the bad code. =) | ||
Targe
United Kingdom14103 Posts
+ Show Spoiler + this thread hurts my head | ||
CecilSunkure
United States2829 Posts
On July 02 2013 07:26 Targe wrote: u gotta skate hahaha, I wonder if anyone got the baller reference in there too | ||
wherebugsgo
Japan10647 Posts
On July 02 2013 06:07 Rayeth wrote: I can show off my knowledge of old languages, whee!
This is straight up undefined behavior by the C standard. I don't know about C++ or C# (as I don't use them), but the C standard says this will lead to undefined behavior. You are using the ++ operator in such a way as to make its use dependant on what the compiler chooses to do first. It is equally undefined to say:
Now something will happen, but what you get is dependent on what system, what compiler and who knows how many other variables. The correct way to write the above would simply be u++; The technical reason for these being incorrect is that you are modifying the stored value more than once between sequence points. As for what a sequence point is refer to the Wikipedia article as it is much clearer than I could ever be. The end result here is that you are right. No one should ever use expressions like that. They are sometimes used in classrooms to demonstrate bad code for a reason! I will disagree with you about the pointers though. Yes bad code can be created using silly means, but a competent coder should not fear to use pointers. They are really useful! Don't shy away from such a powerful tool because they can be confusing, just make sure you are not the one writing the bad code. =) I never once said that a good programmer should not use pointers. I use pointers all the time, I just don't necessarily increment them using ++. edit: btw, I used those examples because I've actually seen them in codebases. yep, that's right. I have seen real code written by real people that looks that confusing. | ||
| ||