A question of style

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?
 
G

Guest

Hmm, rereading the post, it has some possible confusion:

I normally use if( o == null ) and the source has if( null == o )
 
M

Morten Wennevik

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

Guest

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

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top