473,484 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Correct Identation/Contex can solve the too many compiler error messages problem when a closing bracket is missing.

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 begin/end statements etc"
and today when I woke up I suddenly released a very simple solution for this
problem by simply using something called "contex". Which is something
autistic people have great trouble recognizing and since many autistic
people work in the tech industry here is a short example to explain how
"context" can solve the problem.

Let's look at two identation styles.

The first one is my preferred style which is commonly used in pascal/delphi.
Some people in the delphi community recommended to use 2 spaces for identing
a few years ago. I do hope that they by now realize that using tabs is much
more efficient and works faster. I myself use 4 spaces for each tab
character. (Which is also used further down in this example (tabs converted
to spaces) )

Anyway let's get back to the styles.

The first style: pascal/delphi style/my style (the smart style):

begin
<identation>code
<identation>if a<b then
<identation>begin
<identation><identation>code
<identation><identation>code
<identation>end;
end;

The second style: perverted C/Java style (the dumb style):

{
<identation>code
<identation>if a<b {
<identation><identation>code
<identation><identation>code
<identation>}
}

Let's compare both styles.

The second/dumb style is much more hard to figure out where a missing
bracket is located.

Here is an example of the "dumb" style in action:

Can you tell where the missing closing bracket is ?

{
xxxxxxxxxxxxx{
xxxxxxxxxxxxxxxxxxxx{
xxxxxxxx}
xxxxxxxxxxxxxxxxxxxxxxxxx{
xxxxxxxx}xxxxxx{
xxxxxxxx}
xxxxxxxxxxxxxxxxxx{
xxxxxxxxxxxxxxxxxxxxxxxxx{
xxxxxxxx}
xxxx}
}

If you did manage to find it it must have costs you lot's of time to figure
it out ;) Since to figure it out a complex algorithm is necessary to find
the missing bracket.

Now I present to you the smart style:

{
xxxxxxxxxxxx
xxxx{
xxxxxxxxxxxxxxxxxxx
xxxxxxxx{
xxxxxxxx}
xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxx{
xxxxxxxx}xxxxx
xxxxxxxx{
xxxxxxxx}
xxxxxxxxxxxxxxxxx
xxxx{
xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxx{
xxxxxxxx}
xxxx}
}

You didn't spot it the first time ? Take a closer look ! ;)

Yeah now you see it don't you ;)

The 9th bracket is missing in both examples.

However it did cost you much less time to figure out where the missing
bracket is in the smart style.

Why can't a compiler do this ? Why does a compiler have to produce so many
error messages when a closing bracket is missing ? Why isn't the compiler
smart like us ? (well at least some of us)

The answer is: in the context. We are aware of the context.

The context is the identation. The identation indicates where a statement
block begins and ends.

The compiler works like an autistic person. The compiler doesn't recgonize
the context and only looks at the opening and closing brackets.

The compiler could be made more smart like us who use the smart style by
looking at the context. Even the more complex style (the dumb style) could
be used to figure out where a closing bracket should have been... since even
in the dumb style the closing brackets are located at the same positions as
in the smart style.

This shows you how important correct identation is. I myself requested
automatic identation on-the-fly simply because that would be much more
productive, especially when code needs to be cut and pasted in some other
section. In those cases the identation has to be changed everywhere in the
pasted code and it would be really handy if that was automatically done.

However automatic identation can conflict with the solution above. Automatic
identation depending on it's implementation could start moving the
brackets/identations back and forth when a bracket is accidently deleted,
thereby possibly cancelling the usefull information in the
context/identation. Solving this secondary problem remains a challenge for
now ;) =D(ofcourse it's not such a big problem in pascal/delphi since it's
impossible to delete begin/end with a single touch of a button, since it's a
multiple character word ;) unless
it somehow gets cut/deleted away :) )

And in case you were wondering what the real code was here it is:

"dumb style version":

{
if (a<b) {
if (sdfd<c) {
}
if (sqfd<342563) {
} else {
}
}

if (dddd=234) {
if (dsdfssdf=23) {
}
}
}

"smart style version":

{
if (a<b)
{
if (sdfd<c)
{
}
if (sqfd<342563)
{
} else
{
}
}

if (dddd=234)
{
if (dsdfssdf=23)
{
}
}
}

And here is how any other revealing arbitrary code/information was replaced
by x's to soley focus on the identation and brackets themselfes as to see
how easy or hard it would be to recognize where a bracket was missing in an
eye's blink ;) (the 9th bracket below is still present for completeness
sake.)

(Fixed character width font needed for easy viewing of the text below, like
courrier.)

"the dumb style:"

{
if (a<b) {
xxxxxxxxxxxxx{
if (sdfd<c) {
xxxxxxxxxxxxxxxxxxxx{
}
xxxxxxxx}
if (sqfd<342563) {
xxxxxxxxxxxxxxxxxxxxxxxxx{
} else {
xxxxxxxx}xxxxxx{
}
xxxxxxxx}
}
xxxx}
if (dddd=234) {
xxxxxxxxxxxxxxxxxx{
if (dsdfssdf=23) {
xxxxxxxxxxxxxxxxxxxxxxxxx{
}
xxxxxxxx}
}
xxxx}
}

"the smart style":

{
if (a<b)
xxxxxxxxxxxx
{
xxxx{
if (sdfd<c)
xxxxxxxxxxxxxxxxxxx
{
xxxxxxxx{
}
xxxxxxxx}
if (sqfd<342563)
xxxxxxxxxxxxxxxxxxxxxxxx
{
xxxxxxxx{
} else
xxxxxxxx}xxxxx
{
xxxxxxxx{
}
xxxxxxxx}
}
xxxx}
if (dddd=234)
xxxxxxxxxxxxxxxxx
{
xxxx{
if (dsdfssdf=23)
xxxxxxxxxxxxxxxxxxxxxxxx
{
xxxxxxxx{
}
xxxxxxxx}
}
xxxx}
}

Bye,
Skybuck.
Nov 15 '05
102 5565
On Mon, 19 Sep 2005 19:44:47 GMT, "Oliver Wong" <ow***@castortech.com>
wrote or quoted :
orthogonal to the concept of intelligent error message supression, which is
a moderately well understood problem.


The problem is {} are not linked, and they can be come offset to match
many layers incorrectly generating the strangest code. If, as in some
other languages you have a different token to end a method or a loop
or a block, then {} mispairings are automatically corralled to a
narrow range, and the compiler sees a much more plausible program. It
does not have to suppress error messages.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Nov 15 '05 #101
On Tue, 20 Sep 2005 20:35:54 GMT, "Oliver Wong" <ow***@castortech.com>
wrote or quoted :
"The development of the language Pascal is based on two principal aims.
The
first is to make available a language suitable to teach programming . . .
The second is to develop implementations of this language which are both
reliable and efficient on presently available computers."


However, if the person who designs the language also designs the first
compiler he will unconsciously tend to make the job of the compiler
writer easier at the expense of the application programmer.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Nov 15 '05 #102

"Roedy Green" <lo*****@mindprod.com.invalid> wrote in message
news:tl********************************@4ax.com...
However, if the person who designs the language also designs the first
compiler he will unconsciously tend to make the job of the compiler
writer easier at the expense of the application programmer.


I don't think that is a given. Wirth was a cs professor at the time he
designed Pascal. His primary goal was achieving a language design that was
eminently suited to teaching a 1st programming language. If you examine
Pascal and its early compilers I think you will find that that goal was
achieved. In your examination, use the proper historical context to judge
the language. We have 35+ years more design experience and hardware vastly
more capable - our tools and expectations are correspondingly more
sophisticated.
Nov 15 '05 #103

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

Similar topics

3
2075
by: doug | last post by:
I am working on a C++ program in .NET. The compiler generates error messages that are associated with the wrong line numbers (which is extremely frustrating). Also, the debugger arrow is...
2
1898
by: Jon Maz | last post by:
Hi All, To allow myself to make development changes directly on a remote server *without* having to compile on my local dev machine and then upload the dll's to remote, I have created a...
1
2632
by: intl04 | last post by:
I am getting strange print-related error messages when trying to create (not print!) reports. For example, when I click 'new' to create a report then choose 'design view', I get an error message...
2
1240
by: Timbit | last post by:
Hi, this is probably an old question, and I have had no luck finding answers to this one on the internet that has helped me out. I installed VS .NET 2003, then I installed IIS 5.1 after that. I...
0
3717
by: Jono | last post by:
Hello, I've been getting this message when closing excel (not necessarily when closing the workbook by itself, but when closing Excel and the workbook at the same time): ...
1
5544
by: Artie | last post by:
Hi, Is there any way to tell an XSD Schema that you want custom error codes for particular validation failures in an XML document? To show what I mean, here's an example: XSD excerpt ...
0
6947
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...
0
7102
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,...
1
6808
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...
0
5401
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,...
1
4837
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3043
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...
0
3037
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1352
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 ...
0
232
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...

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.