Live data from Hacker News

Giving Ada a Chance

ajxs.me

71–80 of 261 posts

Re: Giving Ada a Chance

#71

I really like Ada's ranged types (VHDL has them also - it inherited them from Ada). You can say: type OperatingTemp is range 33 .. 90; And then declare variables of that type and they will be range checked - an exception will be thrown if the variable goes out of that range. Wish more languages had this feature.

In JavaScript it is possible to define getter and setter method of an object. So this behaviour can be emulated by adding a validation in the setter method. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... In Java too, don’t know about other languages though...

Basically any language with objects and methods can do this

Re: Giving Ada a Chance

#72

I tend to like Ada, but it is a tiring language to read with the all caps. Also, it 'feels' like it has a gatekeeper group and really doesn't come up in any mobile conversation. I still believe someone will do something akin to a syntax substitution and come up with a well liked language. Also, modern Fortran is not that bad of a language much like the modern parts of C++.

The tradition of all caps keywords (just a convention, not required as others have noted) was common in most languages in the era before most editors had syntax highlighting. It wasn't meant to be "tiring" but rather the opposite, to make reading code easier. Of course modern syntax highlighting makes the convention obsolete.

Re: Giving Ada a Chance

#73
post #39

> I can’t help but think that complicated programming paradigms would seem more intuitive to beginners if taught through Ada instead of C and its derivative languages, as is common in computer science and engineering faculties worldwide. At my university, the first courses you took in CS used Ada. I think it was a really good choice but I was in the minority I guess because after my year they switched to either using…

When I went to school the instructor talked a bit about Ada, but as far as I know there weren't any compilers available that mere students could afford. This was in the mid-90s.

I remember doing a bit of comparison of the syntax between languages, and Ada's lack of anything like a switch/case statement stood out, but the instructor did talk up the idea that if you could get it to compile it would run in Ada, assuming you didn't hit a compiler bug. Apparently getting the compilers working properly was a problem at the time.

Re: Giving Ada a Chance

#74

I really like Ada's ranged types (VHDL has them also - it inherited them from Ada). You can say: type OperatingTemp is range 33 .. 90; And then declare variables of that type and they will be range checked - an exception will be thrown if the variable goes out of that range. Wish more languages had this feature.

In JavaScript it is possible to define getter and setter method of an object. So this behaviour can be emulated by adding a validation in the setter method. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... In Java too, don’t know about other languages though...

Right, it's emulated but not universal or built-in. Nothing in JavaScript will enforce using getters/setters, it's 100% up to programmer discipline or adding a linter (if any linter has this as an option) to ensure both the creation of the accessors and their use.

The benefit of this in Ada is that it is universal, and it requires the programmer to do nothing special later on except to not turn off the runtime checks. Using that above example, this would be a runtime error:

  Reading : Integer := Get_A_Reading(...); -- In some run Reading gets 0 for some reason
  Temperature : OperatingTemp;

  ...
  Temperature := OperatingTemp'Value(Reading); --  runtime error in Ada if Reading is invalid
And because OperatingTemp is a distinct type, you never even have the option to do:

  Temperature := Reading; -- doesn't compile
Also, in most OO languages where you'd make temperature an internal, private variable you can prevent external users of the class from interacting with it incorrectly, but you can't control internal users. Consider this Java-ish example:

  class Thermostat {
    private int temperature; // should only be in [33,90]
    public void SetTemperature(int value) { // check range and set }
    public void AnotherMethod(int value) {
      // good discipline would be:
      SetTemperature(f(value));
      // but it's not strictly required so this is also allowed
      temperature = f(value);
    }
  }

Re: Giving Ada a Chance

#76

Earlier quoted context omitted.

In JavaScript it is possible to define getter and setter method of an object. So this behaviour can be emulated by adding a validation in the setter method. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... In Java too, don’t know about other languages though...

Basically any language with objects and methods can do this

Sure, although in languages like Java that lack operator overloading the syntax gets messy.

Re: Giving Ada a Chance

#77
post #69

I really like Ada's ranged types (VHDL has them also - it inherited them from Ada). You can say: type OperatingTemp is range 33 .. 90; And then declare variables of that type and they will be range checked - an exception will be thrown if the variable goes out of that range. Wish more languages had this feature.

Ranged types are directly from Pascal. You can also use them to specify the valid indexes for an array (so a given array might be zero-based, or one-based, or 1900-based, or even -32768-based). A very positive feature, I agree.

And, even better, arrays in Ada (can't speak to Pascal) can be any discrete type so long as it is a range:

  type Character_Histogram is Array (range 'A'..'Z') of Integer;
  -- syntax may be off, not enough practice to do this cold right now

Re: Giving Ada a Chance

#78
post #39

> I can’t help but think that complicated programming paradigms would seem more intuitive to beginners if taught through Ada instead of C and its derivative languages, as is common in computer science and engineering faculties worldwide. At my university, the first courses you took in CS used Ada. I think it was a really good choice but I was in the minority I guess because after my year they switched to either using…

When I went to school the instructor talked a bit about Ada, but as far as I know there weren't any compilers available that mere students could afford. This was in the mid-90s. I remember doing a bit of comparison of the syntax between languages, and Ada's lack of anything like a switch/case statement stood out, but the instructor did talk up the idea that if you could get it to compile it would run in Ada, assuming…

I don't know when it was added, but Ada does have a switch/case equivalent construct and I can't imagine it wasn't available early on.

  case X is
    when 1 => ...;
    when 2 => ...;
    when 3 | 4 | 100 => ...
    when others => ...
  end case;

Re: Giving Ada a Chance

#79

I really like Ada's ranged types (VHDL has them also - it inherited them from Ada). You can say: type OperatingTemp is range 33 .. 90; And then declare variables of that type and they will be range checked - an exception will be thrown if the variable goes out of that range. Wish more languages had this feature.

I agree. I learned Ada in university (my professor was on the Ada committee) and used it for an embedded development course. The language was really good (many fewer foot guns than C or C++; clearly Ada was holistically designed), but I recall having issues with the tooling and the ecosystem, and the community was super defensive and hostile. If something wasn't working for your use case and the community didn't have a solution, then your use case was invalid. If you politely asked for help, you were incompetent or too lazy to figure it out on your own. This was a decade ago, so maybe things have changed since, but I can honestly understand why the language is niche. The type system and other intra-language features are very interesting but ultimately not the most important aspects of a programming language.

Re: Giving Ada a Chance

#80
post #36

Earlier quoted context omitted.

I enjoyed Fortran/FORTRAN. Is a nice succinct language. "Lovecraftian hieroglyphics of Fortran" <-- the author never programmed in Perl, I presume.

> "Lovecraftian hieroglyphics of Fortran" Or in Fortran, it's a relatively verbose language from what I remember of it (that said, I learned Fortran 90/95, so maybe the older variants were worse)

More likely the author was faced with numerical code in FORTRAN and confused large formulas with the language syntax being heavy in symbols.
Post reply on HN