News for hackers. Stuff that matters.
Re:Ada is not just another programming language (1986) by tasty_freeze on Saturday October 30, 2021 @01:27AM (#29046213)
Pascal had subrange types before Ada, not only for integers but characters too.

    var day : 1 .. 31;
        letter : 'A' .. 'Z';
And you could specify ranges on array subscripts as well:

    var weight : array[-5 .. 5] of integer;
Re:Ada is not just another programming language (1986) by mseepgood on Saturday October 30, 2021 @03:51AM (#29046893)
Wirth removed this again in Oberon, because experience with Pascal and Modula showed that it is not worth it.
Re:Ada is not just another programming language (1986) by vrotaru on Saturday October 30, 2021 @11:07AM (#29049343)
Not sure that is the actual reason. (Also define worth it)

Wirth had developed that original, but misguided (IMO) notion that the faster a compiler can compile itself the better it is.

Consequently he has removed a lot from latest iterations of its languages/compilers

Pascal had an enum-like feature we could define an enumerated type.

Wirth removed it because... `CONST` should be enough for everyone.

Obviously it has simplified the compiler and increased the self-compilation speed. But I would not call that an improvement.

Re:Ada is not just another programming language (1986) by tored on Saturday October 30, 2021 @11:49AM (#29049707)
If you read the paper, From Modula to Oberon by Wirth, I already linked in a pervious comment when answering the question about subranges, you can also find the reasoning behind the removal of enumerations.

"Enumeration types appear to be a simple enough feature to be uncontroversial. However, they defy extensibility over module boundaries. Either a facility to extend given enumeration types has to be introduced, or they have to be dropped. A reason in favour of the latter, radical solution was the observation that in a growing number of programs the indiscriminate use of enumerations(and subranges) had led to a type explosion that contributed not to program clarity but rather to verbosity. In connection with import and export, enumerations give rise to the exceptional rule that the import of a type identifier also causes the (automatic) import of all associated constant identifiers. This exceptional rule defies conceptual simplicity and causes unpleasant problems for the implementor."

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.578...

Re:Ada is not just another programming language (1986) by mananaysiempre on Saturday October 30, 2021 @11:27AM (#29049514)
I’m not sure this was the reasoning. None of the languages in the direct Algol heritage have any sort of parametric polymorphism, including for range bounds, so working with arrays (which were, at least in Pascal, the primary application of range types) was either constant and repetitive fighting with the compiler or unsafe escape hatches all the way. (Usually both.) I believed this was the primary motivation for the removal of ranges.

(Of course, it’s literally impossible to make polymorphic range bounds work completely, due to the undecidability of Peano arithmetic. The most convincing attempt I’ve seen that doesn’t just go full dependent types on you is ATS, and even that is not exactly the friendliest of environments.)

Another system whose evolution was explicitly guided by self-compilation speed is Chez Scheme, and it’s a fine one. Generally it seems to me that it’s a valid optimization principle, but not a global one: you can fall into an unfortunate local minimum if you start in the wrong place. ... Well, so what, it’s not like there are any infallible design principles in programming.

Re:Ada is not just another programming language (1986) by open-source-ux on Saturday October 30, 2021 @05:45AM (#29047404)
That's very interesting. Subranges is a feature that I have always liked in Pascal and other languages.

You do have any more detail about the reasoning why Wirth thought this feature was "not worth it" for Oberon? Were programmers not using this feature in Pascal and Modula-2? Did Wirth consider it more noise or complexity in those languages?

Re:Ada is not just another programming language (1986) by tored on Saturday October 30, 2021 @06:47AM (#29047725)
Found this paper "From Modula to Oberon" by Wirth himself

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.578...

"Subrange types were introduced in Pascal (and adopted in Modula) for two reasons: (1) to indicate that a variable accepts a limited range of values of the base type and to allow a compiler to generate appropriate guards for assignments, and (2) to allow a compiler to allocate the minimal storage space needed to store values of the indicated subrange. This appeared desirable in connection with packed records. Very few implementations have taken advantage of this space saving facility, because the additional compiler complexity is very considerable. Reason 1 alone, however, did not appear to provide sufficient justification to retain the subrange facility in Oberon."

"... was the observation that in a growing number of programs the indiscriminate use of enumerations (and subranges) had led to a type explosion that contributed not to program clarity but rather to verbosity."

Instead the proposed solution is to use SET.

"With the absence of enumeration and subrange types, the general possibility of defining set types based on given element types appeared as redundant. Instead, a single, basic type SET is introduced, whose values are sets of integers from 0 to an implementation-defined maximum."

Re:Ada is not just another programming language (1986) by open-source-ux on Saturday October 30, 2021 @07:29AM (#29047953)
Thank you :-)

It seems subranges could be something of a double-edged sword. Too many enumerations and subranges in a program adds complexity. However, without them I presume the guards need to be coded manually elsewhere in the program.

It's really fascinating to see the reasoning a programming language designer makes when choosing what feature to include - or exclude.

Re:Ada is not just another programming language (1986) by tored on Saturday October 30, 2021 @01:13PM (#29050416)
> without them I presume the guards need to be coded manually elsewhere in the program.

That is my conclusion as well, reading the Oberon manual a SET seems just to be a normal set but for integers only, thus you have to manually check if your integer value is part of the set within the procedure itself, however that check will be a runtime check, not a compile time check if you had a proper enumeration type (I assume). And to my understanding Oberon doesn't have any error handling, so how exactly you would promote a out of range check to an error is unknown to me.

I guess that you would probably want to define constants to fill the set with, thus adding some more noise.

  CONST RED = 1;
  CONST GREEN = 2;
  CONST BLUE = 3;
  SET COLORS = (RED, GREEN, BLUE)
So you can use it a procedure call

  draw(RED);
Compare to Pascal enumeration

  type COLORS = (RED, GREEN, BLUE);
It feels like Wirth was somewhat obsessed with the idea of type extension with Oberon, it should be possible to import any module (program) and extend it without restrictions and enumerations created a problem how you would extend it.

If you have a color module defining the enumeration COLORS together with a bunch of procedures accepting COLORS, then in another custom module you want extend COLORS with the color YELLOW plus some YELLOW specific procedures.

But if you pass an extended enumeration E' to a procedure that accepts the base enumeration E, which should be legal similar how you can pass T' as T, the procedure would receive illegal values, in this case YELLOW. What you need to do instead is create your own CUSTOM_COLORS enumeration, manually include every color from COLORS and add YELLOW, and when calling procedures within the colors module type cast from CUSTOM_COLORS to COLORS enumeration. Perhaps this is the type explosion Wirth was referring to.

Out of range would still be problem if you extend a SET, but you avoid type casts.

This is how I interpret Wirth reluctance to enumerations (and subranges).

https://www.inf.ethz.ch/personal/wirth/Oberon/Oberon07.Repor...

Re:Ada is not just another programming language (1986) by elcritch on Saturday October 30, 2021 @02:20AM (#29046470)
Nim borrows from both. It's nice using it for embedded work:

    proc set_mode(mode: range[0..3]) ## SPI mode (0-3)
Re:Ada is not just another programming language (1986) by andi999 on Saturday October 30, 2021 @04:22AM (#29047046)
Now let's say your name includes one of these weird 'Ä' characters...
Re:Ada is not just another programming language (1986) by adrian_b on Saturday October 30, 2021 @07:54AM (#29048076)
Yes, but Ada extended the number of usable types for ranges, e.g. including fixed-point numbers.

All those that existed in Pascal also exist in Ada.

Re:Ada is not just another programming language (1986) by Cloudef on Saturday October 30, 2021 @01:29AM (#29046222)
Ah yes, it's been a while since I've touched pascal.. Good times