Recent

Author Topic: Making the semicolon useless  (Read 9843 times)

Zoran

  • Hero Member
  • *****
  • Posts: 1555
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Making the semicolon useless
« Reply #15 on: April 02, 2020, 09:43:07 pm »
I also want to reiterate the error handling point again, but I whipped up an example as illustration. Each time you change  fundamental (block-statement structure) of the language you have to rethink error handling.
Ok now that you gave an example I see what you are thinking about. Line endings.

Well that's not a problem. Without semicolons this would be:
Code: Delphi  [Select][+][-]
  1.  
  2. procedure aa(j:integer)  begin end
  3. procedure bb begin end
  4. procedure cc begin end
  5. function yy(j:integer):integer begin end
  6. function zz(j:integer):integer begin end
  7.  
  8. begin
  9.  aa(yy(zz(33))
  10.    bb()
  11.    cc()
  12.  end
  13.  
bb would not be considered as a parameter in anyway. Following a ")" by an identifier is not a continuation of instruction, it is in implicit end of instruction.

You obviously missed the point - in "aa line" there is one more open parentheses than closed. Compiler will not be able to notice anything wrong in that line, and will treat bb as (still) part of parameter of aa.
« Last Edit: April 02, 2020, 09:45:05 pm by Zoran »

circular

  • Hero Member
  • *****
  • Posts: 3307
    • Personal webpage
Re: Making the semicolon useless
« Reply #16 on: April 02, 2020, 09:45:11 pm »
Without semicolons it looks " naked". That will be forbidden in the USA.
:D

You obviously missed the point - in "aa line" there is one more open parentheses than closed. Compiler will not be able to notice anything wrong in that line, and will treat bb as parameter of aa.
Nope I understood the point. But as there is no comma, it will not be considered as the next parameter.
Conscience is the debugger of the mind

440bx

  • Hero Member
  • *****
  • Posts: 1824
Re: Making the semicolon useless
« Reply #17 on: April 02, 2020, 10:07:41 pm »
Nope I understood the point. But as there is no comma, it will not be considered as the next parameter.
That makes statements "fragile" because one missing comma can change the semantics of the statement.  Usually, and hopefully, the compiler will catch the error later, maybe 3 or 4 tokens later, when that missing comma ends up creating something that is not semantically valid.

Worse is the possibility that the missing comma doesn't create a semantically invalid statement later.  In that case, the compiler will generate code that won't reflect the programmer's intentions.  This is the kind of stuff that makes C a lousy language.  One typo somewhere and, since the language is so poorly designed, the compiler is totally oblivious of the problem.  The result: the programmer has to get into the debugger to find out that a simple typo caused the program not to work as intended.

It's probably possible to make a version of Pascal that wouldn't need semicolons as statement separators but, the compiler implementation would be more complicated (since it has to infer the statement end) and diagnosing syntax errors would very likely result in less informative error message because there is more room for ambiguities in a syntactically incorrect statement.

The semicolons may be "useless" for the programmer but, they are far from useless for the compiler.


FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

kupferstecher

  • Sr. Member
  • ****
  • Posts: 388
Re: Making the semicolon useless
« Reply #18 on: April 02, 2020, 10:17:05 pm »
Uh, and I do hope you wouldn't want line endings to be significant in any way.
Why not? The line ending is quite intuitive for being the end of a statement.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8368
  • FPC developer.
Re: Making the semicolon useless
« Reply #19 on: April 02, 2020, 10:26:16 pm »
Nope I understood the point. But as there is no comma, it will not be considered as the next parameter.

It will be interpreted as an syntax error in the parameter block of aa(), while bb() isn't. 

So the question is

- what will you detect (as said well missing operator or so)
- where (as said probably at the BB token)
- how will you detect what is really going on (missing ")" on aa.

It is not the end of the world. C is also pretty bad at this (small syntax errors lead to errors a long way from the place where this mistake happens), and its programmers often don't even understand what you are talking about.

But it is step back in error generation quality. And something you will need to work on to at least minimize the regression

circular

  • Hero Member
  • *****
  • Posts: 3307
    • Personal webpage
Re: Making the semicolon useless
« Reply #20 on: April 02, 2020, 10:49:00 pm »
There are things to think about for sure, though I don't think it will be more fragile. I find the "if then" fragile as one semicolon, not easy to spot, can disable it. Or the otherwise statement that can be confused with an else statement. I don't find the current state to be so safe regarding the semicolon. Maybe the line ending can be used by the compiler as an additional information, making it more "humain".
Conscience is the debugger of the mind

RayoGlauco

  • Full Member
  • ***
  • Posts: 101
  • Beers: 1567
Re: Making the semicolon useless
« Reply #21 on: April 02, 2020, 11:41:30 pm »
Pascal is as it is. It use semicolons to separate the declarations. Breaking the compatibility of billions of lines of code by changing this is not a good idea. If someone doesn't like semicolons, he/she better find another programming language!
To err is human, but to really mess things up, you need a computer.

Zath

  • Sr. Member
  • ****
  • Posts: 352
Re: Making the semicolon useless
« Reply #22 on: April 03, 2020, 12:57:25 am »
Pascal is as it is. It use semicolons to separate the declarations. Breaking the compatibility of billions of lines of code by changing this is not a good idea. If someone doesn't like semicolons, he/she better find another programming language!

I have to say I agree with this.

Just what is the issue with using the semicolon?

lainz

  • Hero Member
  • *****
  • Posts: 3565
    • Lainz
Re: Making the semicolon useless
« Reply #23 on: April 03, 2020, 01:52:07 am »
Pascal is as it is. It use semicolons to separate the declarations. Breaking the compatibility of billions of lines of code by changing this is not a good idea. If someone doesn't like semicolons, he/she better find another programming language!

why to break compatibility? making it optional doesn't break any code
kotlin does that, just ignores the semicolon
https://lainz.github.io - My Website
https://lazpaint.github.io/ - LazPaint Downloads

440bx

  • Hero Member
  • *****
  • Posts: 1824
Re: Making the semicolon useless
« Reply #24 on: April 03, 2020, 02:13:04 am »
why to break compatibility? making it optional doesn't break any code
It does have the potential to break code.  The example given in a previous post
Code: Delphi  [Select][+][-]
  1. var
  2.  a: integer = 1;
  3. begin
  4.   case a of
  5.     1, 2: if a = 2 then
  6.               writeln(2);
  7.   else
  8.     writeln(1);
  9.   end;
  10. end;
  11.  
shows that the statement is semantically different if the semicolon after the "writeln(2)" is not there.  I wish I could think of other examples but, none come to mind at this time but, that doesn't mean there aren't other cases like the one above.

My point is that, it is very dangerous to conclude the semicolon can be made optional in all cases without a careful analysis of the language's grammar.  As previously stated, even if it can be done, the compiler's complexity will increase because it will have to infer where/when statements end which could definitely have an impact on its compilation speed.  (a fast compiler is a very nice thing to have.)

kotlin does that, just ignores the semicolon
but it has a different grammar that allows it (and may even be designed) to make the semicolon optional.  Pascal's grammar relies on the semicolon to clearly establish the end of a statement.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

lainz

  • Hero Member
  • *****
  • Posts: 3565
    • Lainz
Re: Making the semicolon useless
« Reply #25 on: April 03, 2020, 04:47:37 am »
why to break compatibility? making it optional doesn't break any code
It does have the potential to break code.  The example given in a previous post
Code: Delphi  [Select][+][-]
  1. var
  2.  a: integer = 1;
  3. begin
  4.   case a of
  5.     1, 2: if a = 2 then
  6.               writeln(2);
  7.   else
  8.     writeln(1);
  9.   end;
  10. end;
  11.  
shows that the statement is semantically different if the semicolon after the "writeln(2)" is not there.  I wish I could think of other examples but, none come to mind at this time but, that doesn't mean there aren't other cases like the one above.

My point is that, it is very dangerous to conclude the semicolon can be made optional in all cases without a careful analysis of the language's grammar.  As previously stated, even if it can be done, the compiler's complexity will increase because it will have to infer where/when statements end which could definitely have an impact on its compilation speed.  (a fast compiler is a very nice thing to have.)

kotlin does that, just ignores the semicolon
but it has a different grammar that allows it (and may even be designed) to make the semicolon optional.  Pascal's grammar relies on the semicolon to clearly establish the end of a statement.

No I think it doesn't break old code. Because you will not be removing the semicolon in old code.

Also why not replace that odd else with something like "default " that's verbose as well.

Languages changes, evolves or die.
https://lainz.github.io - My Website
https://lazpaint.github.io/ - LazPaint Downloads

440bx

  • Hero Member
  • *****
  • Posts: 1824
Re: Making the semicolon useless
« Reply #26 on: April 03, 2020, 05:46:53 am »
No I think it doesn't break old code. Because you will not be removing the semicolon in old code.
ok, that point is valid.

Also why not replace that odd else with something like "default " that's verbose as well.
That would mean a version of Pascal that allows "else", "otherwise" and "default" for the same thing.  That kind of stuff gives a strong impression that the language wasn't well thought out or, is driven by "Christmas tree design"  (shiny feature!.. we'll hang it over here.)

Languages changes, evolves or die.
Yes but, the evolution usually happens in ways that are significant and coherent with the essence of the language.   A change that causes the compiler to be slower and emit even less precise error messages doesn't seem to be evolution in the right direction.

There are more important capabilities that can be added to Pascal than not using a semicolon to separate statements.  Honestly, I think removing the semicolon separator between statements would be a step backwards since it would require the programmer to infer where statements end instead of having the semicolon as a clear end-statement marker.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

circular

  • Hero Member
  • *****
  • Posts: 3307
    • Personal webpage
Re: Making the semicolon useless
« Reply #27 on: April 03, 2020, 08:36:51 am »
Also why not replace that odd else with something like "default " that's verbose as well.
That would mean a version of Pascal that allows "else", "otherwise" and "default" for the same thing.  That kind of stuff gives a strong impression that the language wasn't well thought out or, is driven by "Christmas tree design"  (shiny feature!.. we'll hang it over here.)
In fact you can already write otherwise instead of else. There you have your Christmas tree.

For now, we have found very few specific examples that suggest that the semicolon would be necessary. That's the whole point of the discussion: if no one finds a reason to keep the semicolon, maybe there is no need for it.

In other words, if you are afraid of the danger of not having semicolon but cannot explain why, maybe there is no danger and it is safe. Hence the discussion to see together what could actually happen without semicolon.

I've thought a bit about it and maybe we don't have to change the compiler at all. It could be just some preprocessing. For example, the "semicolon-less" preprocessor could:
- check that there are no semicolon at the end of lines, otherwise throw an error
- at the end of the line, if the token is not line-continuing, and that there isn't an else at the begining of the next line, add a semicolon

Note that this is a theoretical discussion, it is not a demand and not even a request until there is a satisfactory way of doing it.
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 3307
    • Personal webpage
Re: Making the semicolon useless
« Reply #28 on: April 03, 2020, 08:44:58 am »
Pascal is as it is. It use semicolons to separate the declarations. Breaking the compatibility of billions of lines of code by changing this is not a good idea. If someone doesn't like semicolons, he/she better find another programming language!
Is it that you are afraid of loosing unity and that you would rather reject people to preserve it?
Conscience is the debugger of the mind

RayoGlauco

  • Full Member
  • ***
  • Posts: 101
  • Beers: 1567
Re: Making the semicolon useless
« Reply #29 on: April 03, 2020, 09:28:40 am »
Maybe I didn't express myself well. My english is poor. I just believe that a programming language that does not use semicolons to separate sentences can hardly be called Pascal. It's just my opinion!
To err is human, but to really mess things up, you need a computer.

 

TinyPortal © 2005-2018