|
++ is commonly pronounced as "plus plus".
Lets get down to business: the ++ operator in C and C++ is crazy. Here some rules off the top of my head:
+ Show Spoiler [rules] +i represents a whole number i++ represents post-increment post increment has the following properties: -increments the value i and returns a copy of i made before the increment -generally creates unnecessary copies of things when used with builtin types -Cannot be used on rvalues afaik
++i is pre-increment Properties of pre-increment -generally the preferred operator for increments -most of the time has less side-effects than post-increment -usually results in more readable code -increments i and returns the incremented i value
The ++ operator is like an addon to the normal + operator. It's an extension like many other ++ things.
An example of a ++ thing that exist as an extension to another thing
Now enough of that. ++ is also used in the name of the language C++ as C++ was built by some dude named Bjarne Stroustrup. C++ can be thought of as mostly a big expansion set to C.
Okay computer sciency things are done.
There's a thingy called Notepad++ and acts as a replacement for Microsoft's shitty Notepad program that comes packaged with Windows. Notepad++ has a bunch of other features that really should have been in Notepad (like reading Linux newlines -.-).
See? ++ things exist.
LASTLY there's TL+. Sure, we all have seen TL+ and it's pretty cool to support TL. However there's also TL++. Clearly we can see that ++ is significant in the C and C++ language in multiples ways. Notepad++ is like an extension or replacement for Notepad.
So this begs the question... Could there be a TL++ expansion to TL+? Is this getting meta on you? Lets call TL++ TLMeta. All the ++.
In TLMeta there's lots of news about the news that goes in the TL+ forum. All the information and all the posts in TLMeta are about the stuff in TL+. How is this fun? Well the magic is that if someone posts in TLMeta about something, even if it isn't truly in TL+ then it will become true.
This is magic. TLMeta is not only about TL+ but it is the keeper of TL+. What happens in TLMeta comes to be.
How can we get TLMeta or get to TLMeta? It's like the 4th dimension. We can only mathematically or logically think about the 4th dimension but we can't really experience it or understand it in a very intuitive or natural way.
Warped time because TLMeta
It exists and it is happening. People are posting in TLMeta all the time, and these people are actually about the people in TL+. I know all this meta is getting a little crazy.
The point is, here's a logimagical proof that TLMeta exists for all you non-believers:
TL is a website TL+ exists and we are in it Therefor to keep the ball rolling TLMeta exists and it is about we
It is the only way imo. u gotta skate
   
|
I'm wondering if somebody spiked Cecil's drink... or if he has too much free time on his hands.
|
So.... why is C# called C Sharp... instead of C pound sign or C hash..
|
On June 28 2013 16:55 haduken wrote: So.... why is C# called C Sharp... instead of C pound sign or C hash..
i assume its because its creator preferred music of telephones or drugs
|
Oh no, we've been discovered
|
the +ception is strong in this blog, 5/5
|
On June 28 2013 16:59 Klonere wrote:Show nested quote +On June 28 2013 16:55 haduken wrote: So.... why is C# called C Sharp... instead of C pound sign or C hash.. i assume its because its creator preferred music of telephones or drugs Indeed, C# is actually written C♯ by Microsoft on boxart etc, C# is used simply because the hash is easier to write on a keyboard.
|
The # is actually just two overlapping + signs. So it's C[++ in a single character].
|
United Kingdom3482 Posts
TL++ isn't far enough we need TL#.
|
Yay, Bjarne Stoustrup was from my Uni. Aarhus, Aarhus, Aarhus!!!!!!
|
Cecil, due to time being warped, I do not know of this thing you call 'TL+' and thus I have no knowledge of how an expansion could ever be made. If you wouldn't mind going into more detail, I would be grateful.
|
I wanted to gift you TL++ for this blog, but couldn't find the button. Then I realized you had already transcended to the level where you were already a part of TL++. well played
|
|
Yay C++, the only language that I'm pretty competent with (I guess I know a bit of Java). I have so much to learn
|
I say TL switches things up and upgrades TL+ to +TL+ or started with TL. And incrementally went to TL.. TL... all the way past 9000.s
|
What is reality but what's perceived? Life imitates art. Wait, I must have that wrong.
|
On June 28 2013 20:52 Burrfoot wrote: I say TL switches things up and upgrades TL+ to +TL+ or started with TL. And incrementally went to TL.. TL... all the way past 9000.s Ahh so do something like
BOOL newday; //is it a new day? Yes or no answers only.
//other code to define newday would most likely go here.
if(newday = YES) // if it is a new day... { double TLplus = 9000; //9000 TL+ for (int TL=1; TL < TLplus; TL++) //endless loop is endless { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //Say hi to R1CH printf("/n you are now %i R1CH in TL",TL); //TL, new currency. TLplus ++; //OVER 9000 TL+! newday = NO; //not a new day anymore :( return TL; //because why not? } }
|
Bisutopia19194 Posts
On June 28 2013 21:24 3FFA wrote:Show nested quote +On June 28 2013 20:52 Burrfoot wrote: I say TL switches things up and upgrades TL+ to +TL+ or started with TL. And incrementally went to TL.. TL... all the way past 9000.s Ahh so do something like BOOL newday; //is it a new day? Yes or no answers only.
//other code to define newday would most likely go here.
if(newday = YES) // if it is a new day... { double TLplus = 9000; //9000 TL+ for (int TL=1; TL < TLplus; TL++) //endless loop is endless { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //Say hi to R1CH printf("/n you are now %i R1CH in TL",TL); //TL, new currency. TLplus ++; //OVER 9000 TL+! newday = NO; //not a new day anymore :( return TL; //because why not? } }
//endless loop is endless Your loop only runs once.
|
That indentation is genius.
Is that a MS troolean type? It should be obvious, but if YES resolves to true, the condition will always be true. Well, if operator= isn't overloaded in some way at least.
|
Does it go to the if statement first? I thought it went to the for statement first. >.>
|
|
On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.>
its the return statement that makes your loop only run once.
|
Bisutopia19194 Posts
On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.>
BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once :( //you return the value of Tl which is 1 } }
|
United States24613 Posts
I'm rusty...
i = 5; return i++;
i = 5; return ++i;
In which case will it return 5, and in which will it return 6?
|
On June 29 2013 00:11 micronesia wrote:I'm rusty... i = 5; return i++;
i = 5; return ++i;
In which case will it return 5, and in which will it return 6?
5 for the first, 6 for the second.
|
On June 28 2013 23:44 BisuDagger wrote:Show nested quote +On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once :( //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about.
|
|
Bisutopia19194 Posts
On June 29 2013 00:37 3FFA wrote:Show nested quote +On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once :( //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code.
|
On June 29 2013 01:21 BisuDagger wrote:Show nested quote +On June 29 2013 00:37 3FFA wrote:On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once :( //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code. Hehe. Trust me, I'm doing tons of practice in the years ahead. In fact, I'm experimenting with making a tile-based game app at this very moment.
|
I really prefer +=. In fact I actually had a stylistic guide in a class once that would not allow you to use the ++ operator. The autochecker for assignments would throw an error until you changed it.
|
On June 29 2013 01:50 3FFA wrote:Show nested quote +On June 29 2013 01:21 BisuDagger wrote:On June 29 2013 00:37 3FFA wrote:On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once  //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code. Hehe. Trust me, I'm doing tons of practice in the years ahead. In fact, I'm experimenting with making a tile-based game app at this very moment. I think I learned more in this thread than I did in class... (why was there always some gsl/pl/gstl on when I'm in school?)
|
On June 29 2013 02:12 wherebugsgo wrote: I really prefer +=. In fact I actually had a stylistic guide in a class once that would not allow you to use the ++ operator. The autochecker for assignments would throw an error until you changed it. So now instead of
void func(int i) { } int i = 42; func(i++);
you always write
void func(int i) { } int i = 42; int t; func((t = i, i += 1, t));
Yes, that's an assignment too, even though there is no = sign in the function call.
Granted, the sequence
vector<int> v(10, 0); int i = 0; v[i] = i++; 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...
|
Bisutopia19194 Posts
You're doing it wrong if you are using the '+' symbol at all.
#include <iostream> using namespace std; int add(int x, int y) { int a, b; do { a = x & y; b = x ^ y; x = a << 1; y = b; }while(a); return b; }
int main() { cout << add(2,6); system("pause"); return 0; }
|
wait... what are you trying to do in this code? I got lost at the beginning and then the code just changed into so many different formats that I was like then and finally,
|
Bisutopia19194 Posts
On June 29 2013 03:25 3FFA wrote:wait... what are you trying to do in this code? I got lost at the beginning and then the code just changed into so many different formats that I was like  then  and finally,  Write it out on paper. These are bitwise operators. It means you manipulate the bits.Convert 2 and 6 in the binary format from decimal and then follow it along.
|
On June 29 2013 03:29 BisuDagger wrote:Show nested quote +On June 29 2013 03:25 3FFA wrote:wait... what are you trying to do in this code? I got lost at the beginning and then the code just changed into so many different formats that I was like  then  and finally,  Write it out on paper. These are bitwise operators. It means you manipulate the bits.Convert 2 and 6 in the binary format from decimal and then follow it along. Oh binary! I haven't worked with those for a whole year. That explains it. Thanks, I think I understand it now
|
I'm going to have to fix this.
int add(int x, int y) ??< int a, b; do <% a = x bitand y; b = x ??' y; x = a << 1; y = b; ??> while(a); return b; %>
And while we're at it, we should create a wrapper class for int, maybe called inT, and only use that instead of the built in type. Then we overload the +, += and ++ operators for great success.
|
On June 29 2013 01:50 3FFA wrote:Show nested quote +On June 29 2013 01:21 BisuDagger wrote:On June 29 2013 00:37 3FFA wrote:On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once  //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code. Hehe. Trust me, I'm doing tons of practice in the years ahead. In fact, I'm experimenting with making a tile-based game app at this very moment.
Incidentally, I'm also working on a tile based game at this very moment. Using LÖVE, which is nice, because Lua is a pretty cool language and I don't have to write all the boilerplate code or all the low level opengl stuff just to do 2d rendering. Just found someone's component based entity system and I'm working on building off that.
|
On June 29 2013 04:56 Bobbias wrote:Show nested quote +On June 29 2013 01:50 3FFA wrote:On June 29 2013 01:21 BisuDagger wrote:On June 29 2013 00:37 3FFA wrote:On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once  //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code. Hehe. Trust me, I'm doing tons of practice in the years ahead. In fact, I'm experimenting with making a tile-based game app at this very moment. Incidentally, I'm also working on a tile based game at this very moment. Using LÖVE, which is nice, because Lua is a pretty cool language and I don't have to write all the boilerplate code or all the low level opengl stuff just to do 2d rendering. Just found someone's component based entity system and I'm working on building off that. Huh. I don't believe I've heard of Lua before. I may check it out sometime in the distant future.
|
Bisutopia19194 Posts
On June 29 2013 05:37 3FFA wrote:Show nested quote +On June 29 2013 04:56 Bobbias wrote:On June 29 2013 01:50 3FFA wrote:On June 29 2013 01:21 BisuDagger wrote:On June 29 2013 00:37 3FFA wrote:On June 28 2013 23:44 BisuDagger wrote:On June 28 2013 22:58 3FFA wrote: Does it go to the if statement first? I thought it went to the for statement first. >.> BOOL newday = false; //Initialize it to avoid warnings //YES or NO answers only. I fixed the caps because C++ is character specific
if(newday = YES) //newday has been assigned the value of YES, it will always evaluate to true { double TLplus = 9000; //TLPlus is now worth 9000 for (double TL=1; TL < TLplus; TL++) //Make TL a double otherwise you are comparing an int to a double //loop will attemp to run until TL >= TLplus { printf("Sup Oh Great And All Powerful Master Wizard R1CH" ; //reads the string printf("/n you are now %i R1CH in TL",TL); //starts a new line and then reads the string, //using %d allows for morepercision TLplus ++; //OVER 9000 TL+! Increments TLPlus by 1 newday = NO; //newday is assigned to the value of no return TL; //you have just exited your code so your for loop did not run over 9000 times. Only Once  //you return the value of Tl which is 1 } } See... this is why I got a ton of handwritten quizzes wrong in my programming class this past year >.> I overlook things that the compiler warns me about. You and me both. When I went through school I bombed all those quizzes. But after all that schooling and practice and a year or so of industry work and you will have a hawks eye for code. Hehe. Trust me, I'm doing tons of practice in the years ahead. In fact, I'm experimenting with making a tile-based game app at this very moment. Incidentally, I'm also working on a tile based game at this very moment. Using LÖVE, which is nice, because Lua is a pretty cool language and I don't have to write all the boilerplate code or all the low level opengl stuff just to do 2d rendering. Just found someone's component based entity system and I'm working on building off that. Huh. I don't believe I've heard of Lua before. I may check it out sometime in the distant future.
Lua is the scripting language blizzard uses to create the UI in WoW. Its one of the most popular along with python. They are really useful tl know.
|
|
On June 28 2013 22:36 BisuDagger wrote:Show nested quote +On June 28 2013 21:24 3FFA wrote:On June 28 2013 20:52 Burrfoot wrote: I say TL switches things up and upgrades TL+ to +TL+ or started with TL. And incrementally went to TL.. TL... all the way past 9000.s Ahh so do something like BOOL newday; //is it a new day? Yes or no answers only.
//other code to define newday would most likely go here.
if(newday = YES) // if it is a new day... { double TLplus = 9000; //9000 TL+ for (int TL=1; TL < TLplus; TL++) //endless loop is endless { printf("Sup Oh Great And All Powerful Master Wizard R1CH"); //Say hi to R1CH printf("/n you are now %i R1CH in TL",TL); //TL, new currency. TLplus ++; //OVER 9000 TL+! newday = NO; //not a new day anymore :( return TL; //because why not? } } 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!
|
|
So there will be TL++ soon?
|
On June 29 2013 02:44 spinesheath wrote:Show nested quote +On June 29 2013 02:12 wherebugsgo wrote: I really prefer +=. In fact I actually had a stylistic guide in a class once that would not allow you to use the ++ operator. The autochecker for assignments would throw an error until you changed it. So now instead of void func(int i) { } int i = 42; func(i++);
you always write void func(int i) { } int i = 42; int t; func((t = i, i += 1, t));
Yes, that's an assignment too, even though there is no = sign in the function call. Granted, the sequence vector<int> v(10, 0); int i = 0; v[i] = i++; 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.
i++; a[i] = x;
instead of
a[++i] = x;
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?
i = i++ + ++i;
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.
|
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
|
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
|
On June 29 2013 09:58 wherebugsgo wrote:Show nested quote +On June 29 2013 02:44 spinesheath wrote:On June 29 2013 02:12 wherebugsgo wrote: I really prefer +=. In fact I actually had a stylistic guide in a class once that would not allow you to use the ++ operator. The autochecker for assignments would throw an error until you changed it. So now instead of void func(int i) { } int i = 42; func(i++);
you always write void func(int i) { } int i = 42; int t; func((t = i, i += 1, t));
Yes, that's an assignment too, even though there is no = sign in the function call. Granted, the sequence vector<int> v(10, 0); int i = 0; v[i] = i++; 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. i++; a[i] = x;
instead of a[++i] = x;
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? i = i++ + ++i;
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.
|
doubleplus? Are we at war with Eastasia or Eurasia?
|
On June 28 2013 15:49 CecilSunkure wrote: u gotta skate The moral of the story.
|
idk, this sounds like it would disturb the fabric of the metagame
|
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-
|
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
|
On June 28 2013 16:55 haduken wrote: So.... why is C# called C Sharp... instead of C pound sign or C hash..
|
On June 29 2013 09:58 wherebugsgo wrote:For example, what does this mean? i = i++ + ++i;
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!
i = i++ + ++i;
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:
u = u++;
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. =)
|
United Kingdom14103 Posts
|
On July 02 2013 07:26 Targe wrote: u gotta skate hahaha, I wonder if anyone got the baller reference in there too
|
On July 02 2013 06:07 Rayeth wrote:Show nested quote +On June 29 2013 09:58 wherebugsgo wrote:For example, what does this mean? i = i++ + ++i;
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! i = i++ + ++i;
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: u = u++;
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.
|
|
|
|