Re: Computer programmers' habits in electronics



"Puckdropper" <puckdropper@xxxxxxxxx> wrote in message news:43aa45f3$0$69835$892e7fe2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Can I do it in Ada? I can do C++, but I'm not too fond of it. Note that

Cool!

Ada doesn't have an unsigned type, so I'm using an integer instead.  The
code would be the same regardless.

I recall vaguely that Ada lets you define ranges? Something like type uint32 is integer[0..4billionsumthing]? In any case, integer would be less restrictive. Is this an advantage or disadvantage in the application?



/http://www.adahome.com/Ammo/cpp2ada.html

function IsPowerOf2(val: integer) return boolean is
 result: integer;
 begin
   result := val rem 2;
   if result = 0 then
     return true;
   else
     return false;
   end if;
 end IsPowerOf2;

That returns true for even numbers. (I think. Is rem the modulus operator? returning the remainder of division by 2?) I was looking for true if val is 2 raised to some integer power, 2^n, where n is a positive integer. How would you write that in Ada?


Also, this seems a good time to discuss the read-mostly intent of Ada's more verbose coding style, versus the (alleged) "write-only" brevity of some other languages. For example, I would likely write the above function in C++ as a one liner:

bool IsEven(unsigned val)
{
   return 0 == val % 2;
}

Bit-operation equivalence aside, what are your thoughts on the readability of both versions, in context of both a large application and just this one simple function in isolation?

.



Relevant Pages

  • Re: IDE
    ... It is real madness with our managers (just the same as several ... As for me - it is only "refreshing" my knowleadge about Ada received ... Of course it is habbit to use IDE and I am not going to get out ...
    (comp.lang.ada)
  • Re: Major League Ultimate - coming this summer
    ... disadvantage coming from such a large number of teams? ... lot of players and styles to be assimilated very quickly. ... Regardless, ... I wish I was going to Potlach to see it. ...
    (rec.sport.disc)
  • Re: Another article involving Ada on /.
    ... It called Ada an expensive disaster. ... Regardless of whether that's ... it's definitely a negative opinion. ... omb jor ers @sv ge. ...
    (comp.lang.ada)