Why is this bad practice

  • Thread starter Thread starter philipl
  • Start date Start date
Vincent Lascaux said:
If you dont write such things, then i++ and ++i has the exact same meaning,
and ++i is what you mean.

If they have exactly the same meaning, then i++ must be what I mean as
well, surely.
But I agree with you (even if it is laughably
ridiculous) that i++ is more easy to read than ++i because we are used to
put the operator after the variable (like in i+1). But it's not really hard
to read ++i, and I bet your brain will learn that really quickly... I still
think that it's sad that people are tought to write i++, and actually write
i++ when the meaning of ++i is much more simple.

I don't think it's actually that much simpler, to be honest.

i++:
The value of the expression is the initial value of i, and i is
incremented.

++i;
i is incremented, and the value of the expression is the new value of
i.


As I've said, when you rely on the difference, you're likely to make
code less readable than if you separate the statements out anyway.
 
Jon Skeet said:
If they have exactly the same meaning, then i++ must be what I mean as
well, surely.

Hehehe... yes exactly Jon, of course. That's the kind of thing I meant
about his comments being ridiculous and there being no point to this any
longer.
 
Vincent Lascaux said:
Here you wont get the same answer every time you read the Number property...
It's bad : I expect that x.Number + x.Number == 2*x.Number, but it's not the
case. You should not modify any variable within the get member of a
property...


That's ok : I'll get the same answer every time I read the Area property
(provided 'side' doesnt change)...

Thnaks for the info, I tried using the the first suggestion and the
variable became unpredictable!
 
Back
Top