Skip to main content
Tweeted twitter.com/StackSoftEng/status/1077806372501311488
Question Protected by gnat
Grammatical changes
Source Link
gnat
  • 20.5k
  • 29
  • 117
  • 310

In the Google C++ Style Guide it sezsays:

Preincrement and Predecrement

Use prefix form (++i) of the increment and decrement operators with iterators and other template objects.

When a variable is incremented (++i or i++) or decremented (--i or i--) and the value of the expression is not used, one must decide whether to preincrement (decrement) or postincrement (decrement).

When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression. If i is an iterator or other non-scalar type, copying i could be expensive. Since the two types of increment behave the same when the value is ignored, why not just always pre-increment?

The tradition developed, in C, of using post-increment when the expression value is not used, especially in for loops. Some find post-increment easier to read, since the "subject" (i) precedes the "verb" (++), just like in English.

For simple scalar (non-object) values there is no reason to prefer one form and we allow either. For iterators and other template types, use pre-increment.

I really must disagree with "When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression."

At least when it comes to pointers (and pointer registers can be used as integers).

Going back to my hardware days, there were plenty of machine instructions that had a form of addressing modes that had post-increment, post-decrement, and pre-decrement built in. The post-inc and post-dec modes cost 0 extra instruction cycles more than no increment at all. The incrementing happened after the instruction was executed while the next opcode was being fetched, but the pre-dec required an additional instruction cycle before the register was used. So, I don't really get it. Can someone explain google's case to me?

In the Google C++ Style Guide it sez:

Preincrement and Predecrement

Use prefix form (++i) of the increment and decrement operators with iterators and other template objects.

When a variable is incremented (++i or i++) or decremented (--i or i--) and the value of the expression is not used, one must decide whether to preincrement (decrement) or postincrement (decrement).

When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression. If i is an iterator or other non-scalar type, copying i could be expensive. Since the two types of increment behave the same when the value is ignored, why not just always pre-increment?

The tradition developed, in C, of using post-increment when the expression value is not used, especially in for loops. Some find post-increment easier to read, since the "subject" (i) precedes the "verb" (++), just like in English.

For simple scalar (non-object) values there is no reason to prefer one form and we allow either. For iterators and other template types, use pre-increment.

I really must disagree with "When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression."

At least when it comes to pointers (and pointer registers can be used as integers).

Going back to my hardware days, there were plenty of machine instructions that had a form of addressing modes that had post-increment, post-decrement, and pre-decrement built in. The post-inc and post-dec modes cost 0 extra instruction cycles more than no increment at all. The incrementing happened after the instruction was executed while the next opcode was being fetched, but the pre-dec required an additional instruction cycle before the register was used. So, I don't really get it. Can someone explain google's case to me?

In the Google C++ Style Guide it says:

Preincrement and Predecrement

Use prefix form (++i) of the increment and decrement operators with iterators and other template objects.

When a variable is incremented (++i or i++) or decremented (--i or i--) and the value of the expression is not used, one must decide whether to preincrement (decrement) or postincrement (decrement).

When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression. If i is an iterator or other non-scalar type, copying i could be expensive. Since the two types of increment behave the same when the value is ignored, why not just always pre-increment?

The tradition developed, in C, of using post-increment when the expression value is not used, especially in for loops. Some find post-increment easier to read, since the "subject" (i) precedes the "verb" (++), just like in English.

For simple scalar (non-object) values there is no reason to prefer one form and we allow either. For iterators and other template types, use pre-increment.

I really must disagree with "When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression."

At least when it comes to pointers (and pointer registers can be used as integers).

Going back to my hardware days, there were plenty of machine instructions that had a form of addressing modes that had post-increment, post-decrement, and pre-decrement built in. The post-inc and post-dec modes cost 0 extra instruction cycles more than no increment at all. The incrementing happened after the instruction was executed while the next opcode was being fetched, but the pre-dec required an additional instruction cycle before the register was used. So, I don't really get it. Can someone explain google's case to me?

inIn the Google C++ Style Guide it sez:

Preincrement and Predecrement

Use prefix form (++i) of the increment and decrement operators with iterators and other template objects.

When a variable is incremented (++i or i++) or decremented (--i or i--) and the value of the expression is not used, one must decide whether to preincrement (decrement) or postincrement (decrement).

When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression. If i is an iterator or other non-scalar type, copying i could be expensive. Since the two types of increment behave the same when the value is ignored, why not just always pre-increment?

The tradition developed, in C, of using post-increment when the expression value is not used, especially in for loops. Some find post-increment easier to read, since the "subject" (i) precedes the "verb" (++), just like in English.

For simple scalar (non-object) values there is no reason to prefer one form and we allow either. For iterators and other template types, use pre-increment.

iI really must disagree with "When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression."

atAt least when it comes to pointers.   (and pointer registers can be used as integers.).

goingGoing back to my hardware days, there were plenty of machine instructions that had a form of addressing modes that had post-increment, post-decrement, and pre-decrement built in. the The post-inc and post-dec modes cost 0 extra instruction cycles more than no increment at all. the The incrementing happened after the instruction was executed while the next opcode was being fetched. but, but the pre-dec required an additional instruction cycle before the register was used. so i So, I don't really get it. can Can someone explain google's case to me?

in the Google C++ Style Guide it sez:

Preincrement and Predecrement

Use prefix form (++i) of the increment and decrement operators with iterators and other template objects.

When a variable is incremented (++i or i++) or decremented (--i or i--) and the value of the expression is not used, one must decide whether to preincrement (decrement) or postincrement (decrement).

When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression. If i is an iterator or other non-scalar type, copying i could be expensive. Since the two types of increment behave the same when the value is ignored, why not just always pre-increment?

The tradition developed, in C, of using post-increment when the expression value is not used, especially in for loops. Some find post-increment easier to read, since the "subject" (i) precedes the "verb" (++), just like in English.

For simple scalar (non-object) values there is no reason to prefer one form and we allow either. For iterators and other template types, use pre-increment.

i really must disagree with "When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression."

at least when it comes to pointers. (and pointer registers can be used as integers.)

going back to my hardware days, there were plenty of machine instructions that had a form of addressing modes that had post-increment, post-decrement, and pre-decrement built in. the post-inc and post-dec modes cost 0 extra instruction cycles more than no increment at all. the incrementing happened after the instruction was executed while the next opcode was being fetched. but the pre-dec required an additional instruction cycle before the register was used. so i don't really get it. can someone explain google's case to me?

In the Google C++ Style Guide it sez:

Preincrement and Predecrement

Use prefix form (++i) of the increment and decrement operators with iterators and other template objects.

When a variable is incremented (++i or i++) or decremented (--i or i--) and the value of the expression is not used, one must decide whether to preincrement (decrement) or postincrement (decrement).

When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression. If i is an iterator or other non-scalar type, copying i could be expensive. Since the two types of increment behave the same when the value is ignored, why not just always pre-increment?

The tradition developed, in C, of using post-increment when the expression value is not used, especially in for loops. Some find post-increment easier to read, since the "subject" (i) precedes the "verb" (++), just like in English.

For simple scalar (non-object) values there is no reason to prefer one form and we allow either. For iterators and other template types, use pre-increment.

I really must disagree with "When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression."

At least when it comes to pointers  (and pointer registers can be used as integers).

Going back to my hardware days, there were plenty of machine instructions that had a form of addressing modes that had post-increment, post-decrement, and pre-decrement built in. The post-inc and post-dec modes cost 0 extra instruction cycles more than no increment at all. The incrementing happened after the instruction was executed while the next opcode was being fetched, but the pre-dec required an additional instruction cycle before the register was used. So, I don't really get it. Can someone explain google's case to me?

edited tags
Link
Blrfl
  • 20.5k
  • 2
  • 53
  • 76
Source Link
Loading