473,546 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

missing out braces

I thought the two bits of code should be the same?

They aren't evaluating the same for me ....

Can someone tell me why please?

Thanks

Andrew
if (X != 0)
if ((float)(nud.Va lue) > 0.0)
coords.Add(new Coord(X, Y, (float)(nud.Val ue)));
else
if (Y != 0)
if ((float)(nud.Va lue) > 0.0)
coords.Add(new Coord(X, Y, (float)(nud.Val ue)));

///////////////////////

if (X != 0)
{
if ((float)(nud.Va lue) > 0.0)
coords.Add(new Coord(X, Y, (float)(nud.Val ue)));
}
else
{
if (Y != 0)
if ((float)(nud.Va lue) > 0.0)
coords.Add(new Coord(X, Y, (float)(nud.Val ue)));
}
Feb 18 '06 #1
14 1602
Andrew,
if (X != 0)
if ((float)(nud.Va lue) > 0.0)
coords.Add(new Coord(X, Y, (float)(nud.Val ue)));
else


Your indentation is misleading, the else pairs with the second if
statement.

if (X != 0)
if ((float)(nud.Va lue) > 0.0)
coords.Add(new Coord(X, Y, (float)(nud.Val ue)));
else
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 18 '06 #2
Mattias Sjögren wrote:
Andrew,
if (X != 0)
if ((float)(nud.Va lue) > 0.0)
coords.Add(new Coord(X, Y, (float)(nud.Val ue)));
else


Your indentation is misleading, the else pairs with the second if
statement.

if (X != 0)
if ((float)(nud.Va lue) > 0.0)
coords.Add(new Coord(X, Y, (float)(nud.Val ue)));
else
Mattias


Oh of course!

Idiot!!

Can you tell I've been working all day?

:(

Thanks :)
Andrew
Feb 18 '06 #3
This is precisely why every coding standard ever written mandates the use of
braces.

C# is unnecessarily picky in all sorts of areas (e.g. forbidding the use of
redundant access qualifiers) so it is slightly odd that MS allow both braced
and braceless constructs.
Feb 20 '06 #4
Nick Hounsome wrote:
This is precisely why every coding standard ever written mandates the use of
braces.

C# is unnecessarily picky in all sorts of areas (e.g. forbidding the use of
redundant access qualifiers) so it is slightly odd that MS allow both braced
and braceless constructs.


Indeed. It's particularly unfortunate that the part of the ECMA
language specification which smugly (and accurately) claims the
benefits of having a "bool" type uses the following code:

int i = ...;
F(i);
if (i = 0) // Bug: the test should be (i == 0)
G();

It demonstrates the superiority of C# in one respect, which
unfortunately showing that another problem of C *hasn't* been fixed :(

Jon

Feb 20 '06 #5

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Nick Hounsome wrote:
This is precisely why every coding standard ever written mandates the use
of
braces.

C# is unnecessarily picky in all sorts of areas (e.g. forbidding the use
of
redundant access qualifiers) so it is slightly odd that MS allow both
braced
and braceless constructs.


Indeed. It's particularly unfortunate that the part of the ECMA
language specification which smugly (and accurately) claims the
benefits of having a "bool" type uses the following code:

int i = ...;
F(i);
if (i = 0) // Bug: the test should be (i == 0)
G();

It demonstrates the superiority of C# in one respect, which
unfortunately showing that another problem of C *hasn't* been fixed :(


In this day and age I would be "dissapoint ed" in any C/C++ compiler that
didn't flag it as a warning.

[It is totally trivial to implement because you just need to look for an
assignment at the root of the condition parse tree]
Feb 20 '06 #6

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Nick Hounsome wrote:
This is precisely why every coding standard ever written mandates the use
of
braces.

C# is unnecessarily picky in all sorts of areas (e.g. forbidding the use
of
redundant access qualifiers) so it is slightly odd that MS allow both
braced
and braceless constructs.

IMHO the right way to fix this is to just make indentation significant a la
Python, and loose the braces (except for obfuscated or auto-generated code)
all-together. With anonymous delegates, some type inference and tuple-syntax
coming, C# would be the best of most worlds if it looked as nice as
Python...

m

Indeed. It's particularly unfortunate that the part of the ECMA
language specification which smugly (and accurately) claims the
benefits of having a "bool" type uses the following code:

int i = ...;
F(i);
if (i = 0) // Bug: the test should be (i == 0)
G();

It demonstrates the superiority of C# in one respect, which
unfortunately showing that another problem of C *hasn't* been fixed :(

Jon

Feb 20 '06 #7
Mike <vi********@yah oo.com> wrote:
C# is unnecessarily picky in all sorts of areas (e.g. forbidding the use
of
redundant access qualifiers) so it is slightly odd that MS allow both
braced
and braceless constructs.


IMHO the right way to fix this is to just make indentation significant a la
Python, and loose the braces (except for obfuscated or auto-generated code)
all-together. With anonymous delegates, some type inference and tuple-syntax
coming, C# would be the best of most worlds if it looked as nice as
Python...


I'm very nervous of white-space being significant. It makes cut and
paste a much riskier business, for starters. Then again, I haven't used
Python significantly - maybe one gets used to being careful.

Personally I'd be happy with the braces being compulsary.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 20 '06 #8

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Mike <vi********@yah oo.com> wrote:
>> C# is unnecessarily picky in all sorts of areas (e.g. forbidding the
>> use
>> of
>> redundant access qualifiers) so it is slightly odd that MS allow both
>> braced
>> and braceless constructs.
IMHO the right way to fix this is to just make indentation significant a
la
Python, and loose the braces (except for obfuscated or auto-generated
code)
all-together. With anonymous delegates, some type inference and
tuple-syntax
coming, C# would be the best of most worlds if it looked as nice as
Python...


I'm very nervous of white-space being significant. It makes cut and
paste a much riskier business, for starters. Then again, I haven't used
Python significantly - maybe one gets used to being careful.


No - You just need an intelligent IDE.

[it's only a problem if you use tabs and they are not expanded - the IDE has
to ssume either 8 or whatever you have set (which could be a proble,) - it's
certainly not a problem between bits of your own code]
Personally I'd be happy with the braces being compulsary.


I suppose that you can just use FxCop or something similar to enforce it(?)
Feb 21 '06 #9

"Nick Hounsome" <nh***@nickhoun some.me.uk> wrote in message
news:8Q******** **********@fe3. news.blueyonder .co.uk...

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Mike <vi********@yah oo.com> wrote:
>> C# is unnecessarily picky in all sorts of areas (e.g. forbidding the
>> use
>> of
>> redundant access qualifiers) so it is slightly odd that MS allow both
>> braced
>> and braceless constructs.

IMHO the right way to fix this is to just make indentation significant a
la
Python, and loose the braces (except for obfuscated or auto-generated
code)
all-together. With anonymous delegates, some type inference and
tuple-syntax
coming, C# would be the best of most worlds if it looked as nice as
Python...
I'm very nervous of white-space being significant. It makes cut and
paste a much riskier business, for starters. Then again, I haven't used
Python significantly - maybe one gets used to being careful.


No - You just need an intelligent IDE.


Yes, the editors seem to be good at doing the right thing. (I think the lack
of braces is actually less error-prone, not more.)
Also, Python functions, because the "noise"/code ratio is smaller, tend to
be much smaller than c# functions, so there isn't much chance of messing
things up too bad with repsect to indentation. (Hopefully closures and type
inference will help c# as well.) C#'s Odes map to a bunch of smaller Python
Haikus. (Of course Python has it's own set of issues...)
[it's only a problem if you use tabs and they are not expanded - the IDE
has to ssume either 8 or whatever you have set (which could be a
proble,) - it's certainly not a problem between bits of your own code]
Personally I'd be happy with the braces being compulsary.

To me something being compulsary syntactically is a prime pointer to its
lack of necessity - if it *has* to be there, the compiler should figure it
out. (I will conveniently omit all cases to the contrary...)

m

I suppose that you can just use FxCop or something similar to enforce
it(?)

Feb 21 '06 #10

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

Similar topics

97
4330
by: Kjetil Torgrim Homme | last post by:
often when re-factoring code, I need to change the indent level of some chunk of code. due to the lack of an end marker, my Emacs has to use heuristics when re-indenting, and this will occasionally lead to mistakes. of course this is really _my_ fault, not Emacs', but it's annoying all the same. a colleague uses #fi, #yrt etc. to mark the...
16
3319
by: Jason | last post by:
Programming recently I was the habit of leaving out the braces on if statements if the branch only applied to a single line, assuming it would all work and be equivalent to "if(condition) { statement; }" I implemented an algorithm and it did not work for a while and when i tracked the problem down it was as if a certain action was not being...
3
13921
by: Old Wolf | last post by:
For the following code: struct S { char t; int flags; }; void func(void) {
102
5610
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler can't tell where a bracket is missing.... a few weeks have past, I requested a feature for the delphi ide/editor "automatic identation of code in...
12
13435
by: Pawel | last post by:
Hallo group members Could You tell hw to write this code in order not to get warning from subject: #include <iostream> using namespace std; using namespace __gnu_cxx; struct entry {
2
1586
by: mauricioarango | last post by:
Hi everybody, I'm a PHP beginner, so please forgive me for this question. I am working on code someone else wrote a long time ago. The code was written without curly braces in many places, which for the most has been ok. However I am getting an error message that -for the code snippet I posted below- would read like this: Notice: Undefined...
22
2378
cat
by: Jag | last post by:
I've read parts of K&R's ANSI C v2 and this is what their cat looked like but when I compared the speed of this code to gnu cat, it seems very slow. How do I optimize this for greater speeds? is there an alternative algorithm? void catfile(FILE *in, FILE *out) { register int num_char; /*Get characters*/ while ((num_char = getc(in)) !=...
4
1865
by: =?Utf-8?B?VG9yZW4gVmFsb25l?= | last post by:
Was editing code, am getting the following errors } expected Type or namespace definition, or end-of-file expected Eyes crossed cannot find code below! using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
9
22116
by: dissectcode | last post by:
I couldn't find an anser on google...The following code is a tiny made-up example showing the problem I am looking at, at work. I have a struct: struct door_t { BOOL color; BOOL size; char name; char keys; }
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7698
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.