Re: Funny loop with post-increment.
Frans Bouma <[email protected]> Tue, 19 Feb 2008 11:05:26 +0100
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <00b301c872de$f2ea59d0$d8bf0d70$@nl> |
> Ryan Heath wrote: > > On Feb 19, 2008 9:44 AM, Frans Bouma <[email protected]> wrote: > >>> Don't forget that this is a POST-increment. The return value of i++ is the > >>> original value of i, before it was incremented. > >> Then it makes sense. (but the compiler should throw a warning, as > it's > >> non-obvious code. For the 99% of the C# users who don't know the spec in > every > >> detail) > > > > That's my whole point. The behaviour is documented but its not > > obvious. So why is C# supporting this behavior? > > What would you prefer? Do you want to forbid pre and post increments > completely? They shouldn't be able to be used in: - assignments - method calls. Most people use them for incrementing an int. And I'm pretty sure that of that group the vast majority thinks that x will be 1 after: int a = 0; int x = a++; > > You *could* compare it to macroes, C# does not support macroes, and I > > am glad it does not. > > Too often macroes led to code that was not so obvious at all... > > True - but this one rarely comes up. People don't often assign and > pre/post increment in the same statement, fortunately. In the C/C++ world it's pretty common to use them inside code. I wouldn't be surprised if this habit leaks through to C# as well, especially since some constructs in C# are there precisely to make these developers feel 'at home'. FB =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com