Fog Creek Software
Discussion Board




One more thing about semi-colons

That other thread reminded what gets my goat about every C compiler under the sun. Why do they just give you an error number & message when you miss one out? I mean, given that the compiler has worked out that it is missing, it could just bloody well add the thing (even if it were only to do so "in its head", it could emit the error and then carry on as though it was there).

And the new line requirement at the end of the file. What kind of half-witted implementation could not just add it automatically if it is needed? Answer: all of them.

Bah! Humbug!
Thursday, March 25, 2004

It might know that a semi-colon is missing, but there could be more than one place where it logically could be, so it can't just automatically fill it in.

T. Norman
Thursday, March 25, 2004

Most compilers do try to recover from an error and keep going so that they can report more than the first error to you.

Have you noticed that sometimes the compiler will report 10s of errors, then when you fix the first error all the other errors dissappear.

Matthew Lock
Thursday, March 25, 2004

Yeah.  Ever misspell "ENVIRONMENT" in Cobol?

Russell Thackston
Thursday, March 25, 2004

ORGANISATION man,

oops ORGANIZATION

Simon Lucy
Thursday, March 25, 2004

Oh, this could get interesting.

Is a semi-colon a statement terminator, (C), or a statement separator (Pascal) ?

What about languages like Eiffel that decided to duck the issue?  Bertrand Meyer (Eiffel's designer) decided that the best option was to make them optional when one statement per line was used.

Of course, we can go further, because the *real* way to look at a semi-colon is as neither of the above, but rather as a "sequencing operator".

statement_A ; statement_B ; statement_C

The first semi-colon means perform statement_A and then perform (statement_B ; statement_C).

And the second semi-colon means perform statement_B and then perform statement_C.

I think I can now safely predict that having stated the above, the next action in the sequence is that I am going to be flamed...

David B. Wildgoose
Thursday, March 25, 2004

Damn, and there's me without my Zippo.


Thursday, March 25, 2004

It might be possible, in some situations, for a computer to be able to correctly decide where a semicolon is missing. In general, the situation is ambiguous -- otherwise the semicolon wouldn't be needed in the first place.

When the compiler tells you that you made a mistake, that should sound an alarm bell in your head: you think you told the computer one thing, but in actual fact you told it something different. Turn all your compiler warnings on and make it report them as errors. Then investigate every one. You'll improve the quality of the code.

That the code compiles doesn't mean it's correct.

C Rose
Thursday, March 25, 2004

When the hell is Visual Studio going to catch up with Word, and put one of those red squiggly underlines under anything that won't parse, or any symbol that is unrecognized!

Keith Wright
Thursday, March 25, 2004

>Have you noticed that sometimes the compiler will report 10s of errors, then when you fix the first error all the other errors dissappear.

That is exactly what I mean. If the compiler is able to continue after the missing ";" then it can take that into account when parsing the following code which generates errors ("fred not defined". My arse.)

T.Norman - I'm not really suggesting that it should automatically change your source code, certainly not before you have a chance to look at it. Maybe you could launch some kind of "doohickey" afterwards which allowed you to confirm changes on a case by case basis. Like I say, as a first step I'd accept the above (not generating errors which do not really exist).


Thursday, March 25, 2004

> Ever misspell "ENVIRONMENT" in Cobol?

It is a good job Dubya isn't a CoBOL programmer. I can just see him now, screaming at his computer "There is no problem with thu enviruhment section!"


Thursday, March 25, 2004

> When the hell is Visual Studio going to catch up with
> Word, and put one of those red squiggly underlines
> under anything that won't parse, or any symbol that is
> unrecognized!

For C# code it does (and probably VB.Net)

Of course, parsing C# and deciding if it is valid is a lot simpler than C++

I remember stories from back in school about how early compiler -- punch card early on mainframes -- would attempt to correct errors just because the cycle time for that missing character was so long.

Rob Walker
Thursday, March 25, 2004

"For C# code it does (and probably VB.Net)

Of course, parsing C# and deciding if it is valid is a lot simpler than C++"

Yes, it should be a language thing, because JBuilder does that, too.

Paulo Caetano
Thursday, March 25, 2004

You can get an open source beastie for Delphi which does this. But then Delphoids are so cool we never make mistakes and our compiler is so fast it finishes before you hit go, corrects your mistakes and remembers to send valentines/anniversary cards to your Most Significant Life Partner too.

And that's only the 'pro' version.

Woodentongue
Thursday, March 25, 2004

Try missing out an end tag in HTML and see what some programs can do to your page :)

Stephen Jones
Thursday, March 25, 2004

HTML is not comparable with a programming language, nor is it comparable with a programming enviroment.

Notice that HTML editing enviroments like Macromedia Dreamweaver atomatically end tags. What some programming enviroments lack, is the same ability.

Peter Monsson
Thursday, March 25, 2004

You're right about Dreamweaver ending tags. The result can be disastrous. Any HTML editor that tries to second guess you can competely destroy your effort. Surpisingly enough Front Page is guiltless in this respect.

The point I was making is that any program that tries to amend your code will quite likely make a hash of it, whether you are  working with a simple mark-up language like HTML or a fully-fledged programming language.

Stephen Jones
Thursday, March 25, 2004

I dont get it, why are you unable to fix your own code?

Compiler warnings and errors are there for a very very good reason and I hope to god no compiler ever goes about editing source.

Fisty
Thursday, March 25, 2004

As most people know, semis are automatically inserted when missing in JScript. (I wrote a blog entry on the subject here: http://blogs.msdn.com/ericlippert/archive/2004/02/02/66334.aspx)

What is not so well known is that when we built the JScript .NET compiler we put in a mode -- which, unfortunately cannot be turned on from the command line compiler -- which turns EVERY "missing token" error into automatically inserting the offending token and issuing a warning.

It's pretty cool.  You can practically type VB into that thing and it will compile up a reasonable facsimile of the intended semantics. I should write an article on that as well.

Eric Lippert
Friday, March 26, 2004

> I dont get it, why are you unable to fix your own code?

Obviously I can. I can also write my code using switches on the front of the box if I really wanted[1], but my point is that we should really be moving away from that kind of thing. Besides which, like I said, I really want to see what the real errors are (the missing ";" is one, but the many "undefined variable" messages are not, because the line with the missing ";" defined it).


[1] Ok, that's an exaggeration


Friday, March 26, 2004

asdfsadf

test
Thursday, April 01, 2004

*  Recent Topics

*  Fog Creek Home