Skip to main content
added 168 characters in body
Source Link
Kenneth
  • 2.7k
  • 2
  • 22
  • 30

First of all it doesn't affect readability IMO. Its not what your used to seeing but it would only be a short while before you got accustomed to it.

Second unless you use a ton of postfix operators in your code you're likely not to see much of a difference. The main argument for not using them when possible is that a copy of the original var's value has to be kept until the end of the arguments where the original var could still be used. That's either 32bits or 64bits depending on the architecture. That equates to 4 or 8 bytes or 0.00390625 or 0.0078125 MB. Chances are very high that unless you're using a ton of them which need to be saved for a very long period of time that with today's computer resources and speed you wouldn't even notice a difference making a switch from postfix to prefix.

EDIT: Forget this remaining portion as my conclusion was proven false (except for the part of ++i and i++ not always doing the same thing... that's still true).

Also it was pointed out earlier that they don't do the same thing in a cases. Be careful about making the switch if you decide to. I've never tried it out (I've always used postfix) so I don't know for sure but I think changing from postfix to prefix will result in different results: (again I could be wrong... depends on the compiler/interpreter too)

for (int i=0; i < 10; i++) //the set of i values here will be {0,1,2,3,4,5,6,7,8,9}
for (int i=0; i < 10; ++i) //the set of i values here will be {1,2,3,4,5,6,7,8,9,10}

First of all it doesn't affect readability IMO. Its not what your used to seeing but it would only be a short while before you got accustomed to it.

Second unless you use a ton of postfix operators in your code you're likely not to see much of a difference. The main argument for not using them when possible is that a copy of the original var's value has to be kept until the end of the arguments where the original var could still be used. That's either 32bits or 64bits depending on the architecture. That equates to 4 or 8 bytes or 0.00390625 or 0.0078125 MB. Chances are very high that unless you're using a ton of them which need to be saved for a very long period of time that with today's computer resources and speed you wouldn't even notice a difference making a switch from postfix to prefix.

Also it was pointed out earlier that they don't do the same thing in a cases. Be careful about making the switch if you decide to. I've never tried it out (I've always used postfix) so I don't know for sure but I think changing from postfix to prefix will result in different results: (again I could be wrong... depends on the compiler/interpreter too)

for (int i=0; i < 10; i++) //the set of i values here will be {0,1,2,3,4,5,6,7,8,9}
for (int i=0; i < 10; ++i) //the set of i values here will be {1,2,3,4,5,6,7,8,9,10}

First of all it doesn't affect readability IMO. Its not what your used to seeing but it would only be a short while before you got accustomed to it.

Second unless you use a ton of postfix operators in your code you're likely not to see much of a difference. The main argument for not using them when possible is that a copy of the original var's value has to be kept until the end of the arguments where the original var could still be used. That's either 32bits or 64bits depending on the architecture. That equates to 4 or 8 bytes or 0.00390625 or 0.0078125 MB. Chances are very high that unless you're using a ton of them which need to be saved for a very long period of time that with today's computer resources and speed you wouldn't even notice a difference making a switch from postfix to prefix.

EDIT: Forget this remaining portion as my conclusion was proven false (except for the part of ++i and i++ not always doing the same thing... that's still true).

Also it was pointed out earlier that they don't do the same thing in a cases. Be careful about making the switch if you decide to. I've never tried it out (I've always used postfix) so I don't know for sure but I think changing from postfix to prefix will result in different results: (again I could be wrong... depends on the compiler/interpreter too)

for (int i=0; i < 10; i++) //the set of i values here will be {0,1,2,3,4,5,6,7,8,9}
for (int i=0; i < 10; ++i) //the set of i values here will be {1,2,3,4,5,6,7,8,9,10}
Source Link
Kenneth
  • 2.7k
  • 2
  • 22
  • 30

First of all it doesn't affect readability IMO. Its not what your used to seeing but it would only be a short while before you got accustomed to it.

Second unless you use a ton of postfix operators in your code you're likely not to see much of a difference. The main argument for not using them when possible is that a copy of the original var's value has to be kept until the end of the arguments where the original var could still be used. That's either 32bits or 64bits depending on the architecture. That equates to 4 or 8 bytes or 0.00390625 or 0.0078125 MB. Chances are very high that unless you're using a ton of them which need to be saved for a very long period of time that with today's computer resources and speed you wouldn't even notice a difference making a switch from postfix to prefix.

Also it was pointed out earlier that they don't do the same thing in a cases. Be careful about making the switch if you decide to. I've never tried it out (I've always used postfix) so I don't know for sure but I think changing from postfix to prefix will result in different results: (again I could be wrong... depends on the compiler/interpreter too)

for (int i=0; i < 10; i++) //the set of i values here will be {0,1,2,3,4,5,6,7,8,9}
for (int i=0; i < 10; ++i) //the set of i values here will be {1,2,3,4,5,6,7,8,9,10}