Announcement

Collapse
No announcement yet.

AdaCore Has Been Developing A GNAT/Ada Front-End To LLVM

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Originally posted by pal666 View Post
    he is still alive
    Yeah, but I don't think we'll ever see volume 5.

    Comment


    • #22
      Originally posted by totoz View Post
      You have to work with a language that don't provide mechanisms for checking your inputs at compile time like Ada typing, and you always wonder if the caller won't put shit in your arguments (because it's just an "int" or "float" instead of an "hour" or a "longitude", etc.) and how your method will have to deal with that.
      Well, in C++, you can define types for that purpose.

      Originally posted by totoz View Post
      What were your looking for, a launch_missile() pre-built function?
      Now that robotics is becoming a lot more popular, that could be a useful thing to have in the standard library.

      Originally posted by totoz View Post
      in 2019 you still have to guard your includes in C/C++, and to put them in proper order to make them compile...
      Any decent library doesn't place any restrictions on the order in which you include its headers.

      Originally posted by totoz View Post
      Ok, so you live under a rock and don't know what you're talking about. The language is not strictly procedural-oriented as you can do Object-Oriented programming with it like in C++
      The biggest thing to come to C++, in the 2011 update, is decent support for functional programming. How is Ada, on that front?

      Comment


      • #23
        Originally posted by wizard69 View Post
        Personally I like languages that are readable years latter and even if I never used the language before. That is one of the reasons I adopted Python for many of my pet projects. Being easy to remember or refresh what you did years ago is a big thing. C++ can be good but it also can end up looking like APL written by a wizard (not a good wizard).
        Oh, man. If I could show you some numpy code I've had to deal with...

        You can write bad code in pretty much any language. I guess what varies is how easy it is to write good code.

        And I'll go ahead and define good code as being easy to understand, verify, and modify - ideally, with minimal impact on performance.

        Originally posted by wizard69 View Post
        In other words people are knocking ADA here for one of the more important features of the language. That is nice clear verbose syntax.
        Verbosity isn't always a good thing. If it takes too much space to express something fairly simple, then the loss of information density makes it harder to see the bigger picture. You also don't want to get bogged down in details and minutiae, all the time, or else important local details become less salient. That's one reason I like exceptions - to get the most of the error-handling code out of the way, so it doesn't clutter up and compromise readability of the normal code path.

        What I seek is the ability to express thoughts and ideas in a clear and concise manner. To that end, you need a somewhat diverse and flexible set of abstraction mechanisms. In a word: expressive.
        Last edited by coder; 10-08-2019, 03:32 AM.

        Comment


        • #24
          Originally posted by coder View Post
          Well, in C++, you can define types for that purpose.
          How do you define the Hour type for example? In Ada, it will look like:

          Code:
          type Hour is range 0 .. 23;
          Then, if I have a procedure taking an Hour as argument, the language will ensure me that the input argument is correct, and the compiler will prevent me from doing things like:

          Code:
          procedure Foo (H : in Hour);
          
          I : Integer;
          
          ...
          
          Foo (30); -- Illegal (compiler warns that an exception will be raised at execution)
          Foo (I);  -- Illegal (compiler expects an Hour data, but found an Integer data)
          
          Foo (Hour (I)); -- Valid: you do the conversion,
                          -- you take the risk of 'I' not being in range and thus raising an exception.
                          -- This is where you decided to handle bad input (imagine an exception handler here)
          Another example from real life: a longitude type defined as follow (from page 96 of https://www.eurocontrol.int/sites/de....12-092010.pdf)

          Code:
          Octets no. 4-6 (3 bytes)
          In WGS.84 in two’s complement form.
          Range -180 ≤ longitude < 180 deg.
          LSB = 180/2^23 degrees
              = 2.145767 * 10-05 degrees.
          Note that this is not an IEEE 754 float, but a fixed point type.

          In Ada, such type is easily defined like:

          Code:
          Longitude_LSB : constant := 180.0 / 2**23;
          
          type Longitude is delta Longitude_LSB range -180.0 .. 180.0 - Longitude_LSB
               with
                 Size  => 24,
                 Small => Longitude_LSB;
          Then you can directly manipulate longitude data (-180.0, 45.0, 0.0, ...), but the data binary representation is a 24-bit integer in two’s complement form (-180.0 is represented by -2^23, 45.0 by 2097152, 180.0-LSB by +2^23, etc), as defined by the protocol specification.

          In other languages, you'll have to define the conversions yourself, or depend on a library, but it won't be as elegant and convenient as a native language feature.

          Originally posted by coder View Post
          Any decent library doesn't place any restrictions on the order in which you include its headers.
          It's just moving the burden from the client to the library level, but:
          - there will always be someone who will have to deal with that (the library developers);
          - you also have includes inside your own project, so the problem arise at this level anyway.

          Modules are coming in C++, I hope this feature will be nicely designed.

          Comment


          • #25
            Originally posted by totoz View Post
            How do you define the Hour type for example? In Ada, it will look like:
            First, you just seemed to be talking about constraining inputs, semantically. Now, you want to talk about range-checks? We can go there, but I never said C++ had equivalent such capabilities as Ada.

            Originally posted by totoz View Post
            Code:
            procedure Foo (H : in Hour);
            
            I : Integer;
            
            ...
            
            Foo (30); -- Illegal (compiler warns that an exception will be raised at execution)
            Foo (I); -- Illegal (compiler expects an Hour data, but found an Integer data)
            
            Foo (Hour (I)); -- Valid: you do the conversion,
            -- you take the risk of 'I' not being in range and thus raising an exception.
            -- This is where you decided to handle bad input (imagine an exception handler here)
            C++ doesn't currently support overload based on constexpr, although it's been proposed.

            http://www.open-std.org/jtc1/sc22/wg...8/p1045r0.html

            Without that, if you wanted assured compile-time range-checking, you'd need to use template parameters and construct instances with a function template.

            Originally posted by totoz View Post
            Code:
            Longitude_LSB : constant := 180.0 / 2**23;
            
            type Longitude is delta Longitude_LSB range -180.0 .. 180.0 - Longitude_LSB
            with
            Size => 24,
            Small => Longitude_LSB;
            That's interesting syntax.

            Originally posted by totoz View Post
            Then you can directly manipulate longitude data (-180.0, 45.0, 0.0, ...), but the data binary representation is a 24-bit integer in two’s complement form (-180.0 is represented by -2^23, 45.0 by 2097152, 180.0-LSB by +2^23, etc), as defined by the protocol specification.

            In other languages, you'll have to define the conversions yourself, or depend on a library, but it won't be as elegant and convenient as a native language feature.
            Hmmm... implicit conversions, by default? Not sure I like that.

            BTW, thanks for sharing (especially actual code).

            Comment


            • #26
              Originally posted by coder View Post
              First, you just seemed to be talking about constraining inputs, semantically. Now, you want to talk about range-checks? We can go there, but I never said C++ had equivalent such capabilities as Ada.
              Well, not necessarily with range checking. I could also define:
              Code:
              type Hour   is new Integer;
              type Minute is new Integer;
              in order to be sure to not mess between minutes and hours, but type declaration comes often with range checking because it's convenient.

              I know it's not totally impossible to do such things in C++, and my point is not to say that Ada is superior than XXX language. I think every language has its pros and their cons, and suits better for such or such case.

              I wanted to react to some outdated stereotypes that make some interesting technologies forgotten, whereas some ideas could be reused in other languages. Because a reader not knowing Ada that finds posts only depicting it as an old gun, will end up with a cognitive bias based on a totally wrong picture and never get back on it. I like too when other people defend technologies I don't know myself, it makes me learn new things.

              Comment


              • #27
                Originally posted by totoz View Post
                Being a niche language doesn't make it obsolete, and safety-critical software is not going to disappear.
                but its niche is different. niche of safety-critical software is taken by c++ https://www.youtube.com/watch?v=3SdSKZFoUa8
                ada's niche is something government-mandated
                Originally posted by totoz View Post
                in 2019 you still have to guard your includes in C/C++, and to put them in proper order to make them compile...
                modules ts was released in 2018

                Comment


                • #28
                  Originally posted by pal666 View Post
                  but its niche is different. niche of safety-critical software is taken by c++ https://www.youtube.com/watch?v=3SdSKZFoUa8
                  Heh:
                  at that point all rover FSW development was mandated to be done mainly in the C programming language.
                  The argument of C vs. C++ is more easily tipped in favor of C++ than perhaps it would be with other languages.

                  Comment


                  • #29
                    Originally posted by totoz View Post

                    How do you define the Hour type for example? In Ada, it will look like:

                    Code:
                    type Hour is range 0 .. 23;
                    how do you define even hour in ada? c++ doesn't have builtin syntax for integer ranges, but it can define types with any restrictions on values which can be checked by c++ code
                    Originally posted by totoz View Post
                    In other languages, you'll have to define the conversions yourself, or depend on a library, but it won't be as elegant and convenient as a native language feature.
                    but in c++ you can have library of units so when you divide length type by time type you get speed type and compiler will not allow you to use wrong type. ada is limited to few builtin tricks. depending on library is not as bad as not having feature at all

                    Comment


                    • #30
                      Originally posted by coder View Post
                      The argument of C vs. C++ is more easily tipped in favor of C++ than perhaps it would be with other languages.
                      but still no ada in mission-critical software

                      Comment

                      Working...
                      X