โŒ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

Why does elaboration require the programmers attention in Ada? [closed]

I stumbled upon an in depth explanation of elaboration, it's standardized ordering scheme, and the options available to the programmer for controlling it in unsuccessful cases.

http://www.cs.uni.edu/~mccormic/4740/documentation/elaboration

First, it's still unclear why elaboration needs to be addressed by the programmer at all. I've never dealt with it in any other language such as C, Pascal or C++ where the order of allocation and assignment variables, as well as code execution, are rarely of concern. Why isn't it automatically handled and what benefits does it offer to the developer?

Second, elaboration failures are often not detected statically, but at runtime only as a "program error" exception. I find it a bit disconcerting, considering it can suddenly occur in a number of scenarios, including changes in the runtime, the code base, the compiler or its version. It seems to belie Ada's core tenet of code safety and reliability.

How do you handle resourece release while handling an exception in ADA?

Does ADA have an equivalent of C++'s destructors or Java's try-with-resources? That is, a technique where I can say that a resource acquired in this function is released when this function exits: whether normally or due to the handling of an exception. Is there a way to express such concept in ADA?

How can I make my If-statements less complicated

I'm making a program that lets you write in the date and then it returns the previous day aswell as the next day. If you write a date that doesnt exist, the program will tell you that it doesnt exist and exit the program. When making the procedure to check the day and month I used if statements. I always have issues using if-statements because I always make them too complicated but this time I atleast got it to work but as I guessed its overly complicated and I dont know how to shorten it.

   procedure Check_Day_And_Month (Date : in Date_Type) is 
      
   begin
      
     if Date.M <= 0 or Date.M > 12 then
        raise Month_error;
     
     elsif Date.D > 31 or Date.D <= 00 then
           raise Day_Error;
     
     elsif Date.D = 31 and(Date.M = 4 or Date.M = 6 or Date.M = 9 or Date.M = 11) then
           raise day_Error; 
     
     elsif Date.D > 29 and Date.M = 2 then 
           raise Day_Error;
     
     elsif Date.D = 29 and Date.M = 2 and Check_Leap(Date) = false then
           raise Day_Error;
     end if;
      
   end Check_Day_And_month;

I feel like every elsif I have is needed and I dont know how I could shorten this and make it less complicated. But at the same time i'm very new to coding so I most likely am missing something.

โŒ
โŒ