Earlier quoted context omitted.
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
Giving Ada a Chance
81–90 of 261 posts
Re: Giving Ada a Chance
#82Earlier quoted context omitted.
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
I don't think it even needs to be a range, you can index using enums
type Colors is (Red, Green, Blue, Black, Gray, White);
It has to be a consecutive group of them, taken in order, as the specification of even this enumeration has an ordering to it as far as Ada is concerned. So I can make an array using all of Colors as the index, or some subset but it has to be, say, Red..Blue and not Red|Blue skipping over Green.Re: Giving Ada a Chance
#83Earlier quoted context omitted.
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
type
TPerson = record
name: string;
age: integer;
end;
TThrteenPersons = array[10..22] of TPerson;
procedure Check(const aPerson: TPerson);
var
vPerson: TThrteenPersons;
begin
vPerson[11] := aPerson; // this is ok
vPerson[1] := aPerson; // this one gives compile error
end;
alternatively if runtime range checking is on then vPerson[i] = aPerson will raise the exception if i is out of rangeRe: Giving Ada a Chance
#84Earlier quoted context omitted.
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
type TPerson = record name: string; age: integer; end; TThrteenPersons = array[10..22] of TPerson; procedure Check(const aPerson: TPerson); var vPerson: TThrteenPersons; begin vPerson[11] := aPerson; // this is ok vPerson[1] := aPerson; // this one gives compile error end; alternatively if runtime range checking is on then vPerson[i] = aPerson will raise the exception if i is out of range
Histogram : Character_Histogram;
...
Histogram['A'] := Histogram['A'] + 1;
(Ok, a bit more work because I didn't initialize the histogram to 0.)Re: Giving Ada a Chance
#85I love Ada, unfortunately it’s real world use seems to be relegated to old legacy code. I’d like to use it a little more on the side, but I also need to keep my priorities focused on realism, which sadly means ignoring Ada and learning something like C++ which seems unapproachable from any angle. Ada also seems to have a weirdly negative rep in many circles it seems. I recall looking around for an Ada compiler for a…
Skimming my local jobs list(SE England) I see new listings from both Airbus and BAE Systems looking for Ada developers in the past week.
Re: Giving Ada a Chance
#86Re: Giving Ada a Chance
#87> 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 am not sure if this is still the case today, but Computer Engineering in EE Department used to teach Pascal / Ada / C as the first programming language. With the expectation that making a program to compile correctly is hard. Before you move off to something like Perl / Java / Python. While in CS they tends to start to Python or Java. And you start learning all the OO, Procedure or whatever paradigm before going in…
After a few years in industry, I believe that CS should start with either C or Scheme. C to teach you about real machines, Scheme to ignore the machine and do math (algorithms).
Re: Giving Ada a Chance
#88> 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…
> after my year they switched to either using Java or Python They do this because of intense negative feedback from students who don't like having to learn languages for which there is no job market.
Re: Giving Ada a Chance
#89Earlier quoted context omitted.
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
#90In answer to what appears to be a misunderstanding about Rust: > Its foreign function interface seems particularly poorly implemented. The official Rust documentation suggests the use of the external third-party libc library (called a 'crate' in Rust parlance) to provide the type definitions necessary to interface with C programs. As of the time of writing, this crate has had 95 releases. Contrast this with Ada’s Int…