473,387 Members | 1,303 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A question of style

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?

--
Barny
Oct 27 '06 #1
5 1103
Hmm, rereading the post, it has some possible confusion:

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

--
Barny
"Barny" wrote:
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?

--
Barny
Oct 27 '06 #2
On Fri, 27 Oct 2006 10:42:01 +0200, Barny
<Ba***@discussions.microsoft.comwrote:
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.

--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 27 '06 #3
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.

--
Barny
"Morten Wennevik" wrote:
On Fri, 27 Oct 2006 10:42:01 +0200, Barny
<Ba***@discussions.microsoft.comwrote:
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.

--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 27 '06 #4
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

"Barny" wrote:
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?

--
Barny
Oct 27 '06 #5
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
"Barny" wrote:
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?

--
Barny
Oct 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
1
by: Roy | last post by:
Hey all. All I'm trying to do is get a darn double solid bar in my datagrid footer. Doesn't seem to work. Any tips? The weird thing is all the other stylesheet attributes work. If I increase the...
0
by: cedoucette | last post by:
I just wrote code to support sortable columns in a datagrid. It seems to work fine; but, it doesn't look right. The problem is that I have a generic style for links and a different style for the...
1
by: RonY | last post by:
I have a dropdown which calls SetTimePeriod method on change the selection. In the JS function, I reset the field style.display based on what the selection is. This works fine with IE but not working...
8
by: JT | last post by:
Hi, I have done a fair amount of style editing inline in ASP. I'm now using VS 2005 with a standard web project (not Web Application Project). This is my first foray into CSS in a style sheet...
6
by: rongchaua | last post by:
Hi all, I want to change the style of a button. But I don't know how to do it. For example, I have already a button OK on form. I want to add these styles to this button (WS_CHILD || WS_VISIBLE ||...
1
by: Armin Gajda | last post by:
Hi, I have the following problem: An input field get a border assigned by a style class (e.g. 2px solid red). When the field gets the focus, we set the border to green. element.style.border...
0
by: =?Utf-8?B?QXR1bA==?= | last post by:
When .Net 1.0 webservice (VS2003) generates a wsdl - <wsdl:binding name="TestSoap" type="tns:TestSoap"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/(note:...
3
by: Michellevt | last post by:
Hi I am working on a project (for college) and wondered if anyone can help me with my problem. In the project we are not allowed to make use of any "style" attributes but "class" attributes...
3
Claus Mygind
by: Claus Mygind | last post by:
I want to move some style setting into a javaScript function so I can make them variable but I get "invalid assignment left-hand side" error? see my question at the bottom of this message. It...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.