From: Brian Drummond on
On Wed, 20 Jan 2010 17:46:09 +0100, "Alex R. Mosteo" <alejandro(a)mosteo.com>
wrote:

>alexandru.chircu(a)gmail.com wrote:
>
>> http://www.edadesignline.com/showArticle.jhtml?articleID=222300710
>>
>> I leave the witty remarks to the more regular posters here :).
>
>I just took it, and scored 7/10, with the caveat that
>
>2 of my failures were partial (I chose one were several were valid), so I
>didn't chose wrong code.

7/10 here too. Similar reasons, plus (where I got it wrong) the knowledge that
if I met the question in real life I'd take time to look it up.

What might be interesting would be to port the questions to Ada (as far as can
be done) and see (a) how many of them become trivial, and (b) how well people do
on the translated test...

One might plot the results against Ada experience as recorded in one additional
question:

I have used Ada:
(a) as a professional
(b) as a hobbyist
(c) never, but I've used Pascal, Modula-2 or VHDL
(d) none of the above

If the Ada scores were significantly different from the C scores, that ought to
say something about the best choice of language.

Or would it make sense to try to set Ada-specific traps for the unwary? I can't
help thinking they would be found in much more advanced aspects of the language
than constant and array declarations!

Hmmmm, anyway, here's a lame attempt at porting a couple of the questions.

Q: Which of the following is the most portable way to declare an Ada (which has
no preprocessor) constant for the number of seconds in a (non-leap) calendar
year?

(a) Seconds_Per_Year : constant natural := 60 * 60 * 24 * 365;
(b) no preprocessor traps from textual substitution, so no ( ) subtleties
(c) literals of type Universal Integer, so no explicit size qualifiers
(d) all of the above are true, why make it more complex than (a)?

Q: Which of the following statements accurately describes the intended effect of
the declarations:

type int_array is array (1..10) of integer;
type int_array_ptr is access int_array;
a: int_array_ptr;

Answers
(a) An array of ten integers
(b) A pointer to an array of ten integers
(c) An array of ten pointers to integers
(d) An array of ten pointers to functions


- Brian
From: Keith Thompson on
Brian Drummond <brian_drummond(a)btconnect.com> writes:
[...]
> Q: Which of the following is the most portable way to declare an Ada
> (which has no preprocessor) constant for the number of seconds in a
> (non-leap) calendar year?
>
> (a) Seconds_Per_Year : constant natural := 60 * 60 * 24 * 365;
> (b) no preprocessor traps from textual substitution, so no ( ) subtleties
> (c) literals of type Universal Integer, so no explicit size qualifiers
> (d) all of the above are true, why make it more complex than (a)?

(b), (c), and (d) aren't really choices. But the correct answer
is (e) none of the above. Since Natural'Last isn't required
to be bigger than 32767, and 60 * 60 * 24 * 365 is 31536000,
your declaration of Seconds_Per_Year is illegal on some systems.
(Where it's legal, you probably won't get a warning from the
compiler, which is a pity.)

A better answer IMHO is:

Seconds_Per_Year : constant := 60 * 60 * 24 * 365;

Why specify subtype Natural if you don't need to?

As I recall, the corresponding C question presented a similar issue.
Ada does have a better solution, but only if you use it.

--
Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
From: Brian Drummond on
On Mon, 25 Jan 2010 15:22:24 -0800, Keith Thompson <kst-u(a)mib.org> wrote:

>Brian Drummond <brian_drummond(a)btconnect.com> writes:
>[...]
>
>A better answer IMHO is:
>
> Seconds_Per_Year : constant := 60 * 60 * 24 * 365;
>
>Why specify subtype Natural if you don't need to?

Good point; it coerces the solution to be other than Universal Integer sooner
than needed.

>As I recall, the corresponding C question presented a similar issue.
>Ada does have a better solution, but only if you use it.

And that's the important point; what level of skill is needed to find the better
solution?

Clearly more than mine ;-)

But then I am, so far, just an Ada dabbler.
VHDL would have required some type specifier here; there are many similarities
between them; this is not one of them.

My feeling is that it's easier to find the right answers with Ada, but a feeling
isn't very convincing.

- Brian