Recent

Author Topic: how to break out early of a case ?  (Read 66084 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: how to break out early of a case ?
« Reply #90 on: November 29, 2021, 05:03:13 pm »
I don't believe that any occasional verbosity automatically warrants a language expansion.  Moreover because FPC is not a language experimentation project in the first place.
The multiple initialization feature isn't about eliminating some verbosity.  It is about giving the language a mechanism that allows it to show that 2 or more variables should have the same initial state.

Please explain this in more detail. What are concrete practical benefits of doing this, other than for some fuzzy feeling of orthogonality/symmetry for the grammar police? What checks or features do you envision on top of this?

Quote
This would be error prone if each variable had to be declared individually and, it would make maintenance more difficult.

More syntactical features also make a language harder to read, and thus increase failure rate, specially for rarely used constructs like this. So I would wager it is is a net loss.

Quote
For those same reasons, the language should support multiple variable initialization.  I believe you know this but, instead you pretend it's about "verbosity" and FPC not being an "experimentation project".

No. I mean those things seriously, and am not just pulling reasoning out of a sleeve to delay the adding. If wanted to that,  I'd be like the others and keep silent, letting threads like this just rage till they run out of fuel, and the status quo persists, with some baseless extra anti-core sentiment added.

I'm actually here and investing the time to discuss with you. Please respect that.


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: how to break out early of a case ?
« Reply #91 on: November 29, 2021, 05:05:39 pm »

As I've said twice already, that doesn't work because when called all parameters are evaluated (with potential side-effects) before the condition is evaluated. I'm sorry, but this one really is an old chestnut.

I don't know- and am not going to investigate- whether ALGOL W had this form of conditional. If for some reason it didn't then it might explain why it didn't get into Pascal.

Wirth notoriously liked orthogonal and simple grammars. Like 440bx but in a more subtractive than additive way.

I think the feature simply didn't make the cut to be considered "base algol subset".

Keep in mind that in those days there were years between language definition and implementation. (68-70 in Pascal's case)
« Last Edit: November 29, 2021, 05:16:11 pm by marcov »

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: how to break out early of a case ?
« Reply #92 on: November 29, 2021, 05:38:52 pm »
I'm actually here and investing the time to discuss with you. Please respect that.
I respect that but...

Please explain this in more detail. What are concrete practical benefits of doing this, other than for some fuzzy feeling of orthogonality/symmetry for the grammar police? What checks or features do you envision on top of this?

More syntactical features also make a language harder to read, and thus increase failure rate, specially for rarely used constructs like this. So I would wager it is is a net loss.
The answer to your concerns is very simple and, it is shown quite well by the fact that the language allows defining a group of variables of the same type.  i.e,
Code: Pascal  [Select][+][-]
  1. var
  2.   VariableA, VariableB : TSOME_TYPE;
With that mechanism the language ensures that 2 or more variables that must be of the same type are declared in a group all having the same type.  If that feature wasn't there and 2 or more variables had to be of same type then, ensuring they are of the same type would require the programmer to inspect every variable declaration to ensure they are of the same type and, if during maintenance, a programmer changes the type of one variable, it would not be obvious that the types of the other variables also has to be changed.  That is a problem.

Exactly the same reasons apply to group initialization.  Group initialization is _not_ about mere syntax and embellishments. It's about the language having a mechanism to declare that two or more variables should have the same initial state thereby relieving the programmer from having to inspect and update the initial state of multiple variables which makes it a distinct possibility that one or more will be omitted by mistake.

Hundreds of little things like that are what makes language definition standards useful.  Unless I am mistaken, the extended Pascal standard includes group variable initialization.  Also, symmetry, which you seem to deride, isn't just something "nice to have", when implementing symmetry is not possible it often indicates a problem in the design.


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: how to break out early of a case ?
« Reply #93 on: November 29, 2021, 05:45:34 pm »
In addition to that, the missing multiple variable initialization shows there is an inconsistency in the grammar and that the grammar is gratuitously intransitive where it could easily be.  Specifically,
Code: Pascal  [Select][+][-]
  1. var
  2.   VariableA                       : integer = 0;  { no problem initializing this }
  3.   VariableB, VariableC, VariableD : integer;      { no problem with that either - and it _not_ about eliminating verbosity }
but, when you try
Code: Pascal  [Select][+][-]
  1. VariableB, VariableC, VariableD : integer = 0;   { sorry, no can do }
A language that allows the first two, should also allow the third simply for symmetry, consistency and completeness (of course, why would anyone care about those things.)
I second that. In the case of Pascal, it is either because of language compatibility issues (the compiler modeled after an existing language), or it is a compiler design flaw. I don't think that targeting multiple architectures would make it more/too difficult to support such basic feature. I remember QuickBASIC had some limitations with declaring variables, simply because the developers didn't think of it or they felt it was not significant enough to them to implement. But that's talking of a 1980s compiler.
keep it simple

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: how to break out early of a case ?
« Reply #94 on: November 29, 2021, 05:46:53 pm »
Keep in mind that in those days there were years between language definition and implementation. (68-70 in Pascal's case)

Very true.
keep it simple

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: how to break out early of a case ?
« Reply #95 on: November 29, 2021, 06:02:02 pm »
Wirth notoriously liked orthogonal and simple grammars. Like 440bx but in a more subtractive than additive way.

How can that statement possibly be reconciled with the const, type and var divisions, which could easily have been wrapped in some sort of block structure? I use the COBOL term advisedly, since by the late 60s people- particularly in the ALGOL community- were already beginning to realise what a mess that sort of thing was.

Quote
I think the feature simply didn't make the cut to be considered "base algol subset".

Keep in mind that in those days there were years between language definition and implementation. (68-70 in Pascal's case)

The bulk of the work was done between May and October 1969, but the details were still fairly fluid in '70.

The problem is that Wirth was still using recursive ascent which was notoriously difficult to maintain... have you looked at the source of his early compilers?

The syntactic differences between Pascal and ALGOL were intended to break backwards compatibility: Wirth felt that he'd been stabbed in the back (possibly by McCarthy) and wanted nothing more to do with it. But the difficulty of actually working with his codebase of the time limited his options, in which case it's surprising that he removed a facility which was presumably not broken.

Unless of course it was a casualty of e.g. an attempted fix of e.g. the dangling else issue, which he'd had to walk back in a hurry when he hit his time constraints.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: how to break out early of a case ?
« Reply #96 on: November 29, 2021, 07:17:12 pm »
Code: Pascal  [Select][+][-]
  1. procedure Bla;
  2. var
  3.   i:Integer;
  4. begin
  5.   i := 0;
  6.   ..
  7. end;  

In the above code, initializing i to 0 is superfluous, as all variables are zeroed by default. The same goes for the function result. But it makes it much more readable.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: how to break out early of a case ?
« Reply #97 on: November 29, 2021, 07:23:00 pm »
Code: Pascal  [Select][+][-]
  1. procedure Bla;
  2. var
  3.   i:Integer;
  4. begin
  5.   i := 0;
  6.   ..
  7. end;  

In the above code, initializing i to 0 is superfluous, as all variables are zeroed by default. The same goes for the function result. But it makes it much more readable.
No, actually local variables of a function/procedure are not zeroed. Members of a class are zeroed.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: how to break out early of a case ?
« Reply #98 on: November 29, 2021, 07:25:17 pm »
Code: Pascal  [Select][+][-]
  1. procedure Bla;
  2. var
  3.   i:Integer;
  4. begin
  5.   i := 0;
  6.   ..
  7. end;  

In the above code, initializing i to 0 is superfluous, as all variables are zeroed by default. The same goes for the function result. But it makes it much more readable.

Manual section 4.4:

By default, simple variables in Pascal are not initialized after their declaration. Any assumption that they contain 0 or any other default value is erroneous: They can contain rubbish.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: how to break out early of a case ?
« Reply #99 on: November 29, 2021, 07:35:03 pm »
No, actually local variables of a function/procedure are not zeroed. Members of a class are zeroed.

And with languages that do not zero variables upon declaration, multi-initialization is not merely a detail.
keep it simple

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: how to break out early of a case ?
« Reply #100 on: November 29, 2021, 08:39:31 pm »
With that mechanism the language ensures that 2 or more variables that must be of the same type are declared in a group all having the same type.  If that feature wasn't there and 2 or more variables had to be of same type then, ensuring they are of the same type would require the programmer to inspect every variable declaration to ensure they are of the same type and, if during maintenance, a programmer changes the type of one variable, it would not be obvious that the types of the other variables also has to be changed.  That is a problem.

Which perfectly demonstrates that allowing one shorthand only needs to the next.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: how to break out early of a case ?
« Reply #101 on: November 29, 2021, 08:54:55 pm »
No, actually local variables of a function/procedure are not zeroed. Members of a class are zeroed.

Aren't managed variables like strings initialised to guaranteed minimum length as well?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: how to break out early of a case ?
« Reply #102 on: November 29, 2021, 09:02:38 pm »
No, actually local variables of a function/procedure are not zeroed. Members of a class are zeroed.

Aren't managed variables like strings initialised to guaranteed minimum length as well?

Afaik that is considered an implementation detail, and to keep compatible with shortstrings, it was advised (*) not to abuse that, so that string code could be swapped betwixt them.

(*) in FPC 1.x and early FPC 2.x times. Haven't heard much about it since though.
« Last Edit: November 29, 2021, 09:07:29 pm by marcov »

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: how to break out early of a case ?
« Reply #103 on: November 29, 2021, 09:05:45 pm »
Ah, so I got it wrong, but I never noticed because I initialize everything. Interesting.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: how to break out early of a case ?
« Reply #104 on: November 29, 2021, 09:06:27 pm »
Wirth notoriously liked orthogonal and simple grammars. Like 440bx but in a more subtractive than additive way.

How can that statement possibly be reconciled with the const, type and var divisions, which could easily have been wrapped in some sort of block structure?

How is that related to removing rarely used features or not?  It is not that if you instinctively think, "no, this one not?", that you are forced reevaluate each and every feature ad nauseam on the penalty of death ?


Quote
The bulk of the work was done between May and October 1969, but the details were still fairly fluid in '70.

But probably also recycled ideas from the Algol-W period

Quote
The problem is that Wirth was still using recursive ascent which was notoriously difficult to maintain... have you looked at the source of his early compilers?

No.

Quote
Unless of course it was a casualty of e.g. an attempted fix of e.g. the dangling else issue, which he'd had to walk back in a hurry when he hit his time constraints.

That does make some sense. That dangling else made him wary of the construct. But still, probably if he considered it crucial he'd found a solution

 

TinyPortal © 2005-2018