Re: Funny loop with post-increment.

Jon Skeet <[email protected]> Tue, 19 Feb 2008 10:11:04 +0000
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <[email protected]>
Frans Bouma wrote:
>> 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++;

They're just expressions though - how would you go about forbidding
their use without completely mangling the language.

Also, it can be very handy to use it as an argument for a method call -
so long as you know what you're doing.

As I keep saying, avoid cargo cult programming - if you make sure you
know what your code means, you'll be okay.

>>> 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'.

I've very rarely seen this to be a problem on the newsgroups.
Occasionally, yes - but there are much more frequent issues, and it's
easy enough to point out that it's a bad idea.

Jon

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com