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...
Giving Ada a Chance
71–80 of 261 posts
Re: Giving Ada a Chance
#72I 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++.
Re: Giving Ada a Chance
#73> 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…
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
#74I 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...
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
#75I take it the Author hasn't seen any APL code.
Re: Giving Ada a Chance
#76Earlier 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
Re: Giving Ada a Chance
#77I 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.
type Character_Histogram is Array (range 'A'..'Z') of Integer;
-- syntax may be off, not enough practice to do this cold right nowRe: Giving Ada a Chance
#78> 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…
case X is
when 1 => ...;
when 2 => ...;
when 3 | 4 | 100 => ...
when others => ...
end case;Re: Giving Ada a Chance
#79I 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.
Re: Giving Ada a Chance
#80Earlier 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)