A question of style

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Recently I noticed something that seems strange to me in .NET source that I
wasn't originally involved in producing.

I was wondering if this was a preferred .NET style (or indeed general
style). I believe not as the code also uses Hungarian notation.

In summary I had always used, for example, something like:

if( a > 0 )

wheras the source has

if( 0 < a )


or,

if( o == null )

as opposed to

if( null == o )


Comments please?
 
Hmm, rereading the post, it has some possible confusion:

I normally use if( o == null ) and the source has if( null == o )
 
Recently I noticed something that seems strange to me in .NET source
that I
wasn't originally involved in producing.

I was wondering if this was a preferred .NET style (or indeed general
style). I believe not as the code also uses Hungarian notation.

In summary I had always used, for example, something like:

if( a > 0 )

wheras the source has

if( 0 < a )


or,

if( o == null )

as opposed to

if( null == o )


Comments please?

I think you should stick with your instead of the 'source way' as you
compare an object with a value. Comparing a value against an object is
much harder to grasp mentally when scanning the code.

I don't think I have ever encountered the 'source way', but it isn't
really wrong, just unusual.
 
Thanks.

I have seen it used in a couple of other places and thought it was pants
there as well. For the purpose of consistancy, mods to this strange code
will have the brain yanked method used.
 
Mmmmmm have you tried Bulgarian notation? I had the same problems as you but
after trying the different notation method I wouldn't go back to using the
Hungarian method.

Cheers
 
Using a literal on the lhs of an equality test is something that is done in
C++ to avoid accidental assignmnet ("if (a = 0)" instead of equality testing
("if (a == 0)".
This is not an issue in C# since C# will not let you code "if (a = 0)", so
the more natural human readable "a > 0" is what you'll find nearly everyone
else coding in C#.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
 
Back
Top