¿How wrong is this ada code?



  • An anonimized jewel of code

    
      type device_error_enum is (  
                                device_e1,    
                                device_e2,   
                                device_e3, 
                                device_e4, 
                                device_e5,     
                                device_e6,
                                device_e7,
                                device_e8);  
    
      type device_error is array(device_error_enum) of boolean;
      for device_error'Component_Size use 1;
      type device_desc is array (device_error_enum) of UnBounded_String;
    
      device_description : constant device_desc:=(
                device_e1=>To_UnBounded_String( "device error flag 1"),   
                device_e2=>To_UnBounded_String( "device error flag 2"),
                device_e3=>To_UnBounded_String( "device error flag 3"),
                device_e4=>To_UnBounded_String( "device error flag 4"),
                device_e5=>To_UnBounded_String( "device error flag 5"),
                device_e6=>To_UnBounded_String( "device error flag 6"),
                device_e7=>To_UnBounded_String( "device error flag 7"),
                device_e8=>To_UnBounded_String( "device error flag 8")
              );  
       type device_error_register is record
          error : device_error;
       end record;
         
       for device_error_register use record
          error at 0 range  0..7;
       end record;
    
       for device_error_register'Size      use 8;
       for device_error_register'Bit_Order use System.Low_Order_First;
       
      function unsigned_8_to_deviceError is
        new Ada.Unchecked_Conversion(Source => unsigned_8,
                                      Target => device_error);
    

    This thing works, However the (ab)use of Component_Size and Unchecked conversion to turn a modular type into an array of booleans looks... strange

    I edited the post to solve errors introduced in the code while anonymizing



  • Are we supposed to disregard the fact that it is written in Ada while deciding how wrong it is?



  • Well the intent of the post is, at least partly to let people marvel at the features of Ada, so not necessarily.
    Anyway Ada is probably as good a tool as any for what we do.
    I must admit I have even taken a liking to it.


  • Grade A Premium Asshole

    @Piko said:

    Anyway Ada is probably as good a tool as any for what we do. I must admit I have even taken a liking to it.

    That's the Stockholm Syndrome talking.


  • BINNED

    @Piko said:

    Anyway Ada is probably as good a tool as any for what we do.

    TIL that there really are places that have Ada code.

    Anyway, someone needs to read the style guide. Keywords should be lower case and identifiers pascal cased, or vice versa, or something. I don't remember and CBA to look it up, but either way emacs will do it for you automatically.

    Also, you guys can scoff all you want, but admit it: you read the code and understand exactly what it does, even though you don't know a thing about Ada except that it's too verbose to use.



  • @antiquarian said:

    Also, you guys can scoff all you want, but admit it: you read the code and understand exactly what it does, even though you don't know a thing about Ada except that it's too verbose to use.

    Yeah, well, that is the case for pretty much every not-designed-by-asshats programming language since assembly.

    Also, all I know about Ada is that it kinda sorta looks like VHDL, which I had a passing familiarity with (which is now gone like 90% of the things I learned during my studies).



  • @Maciejasjmj said:

    every not-designed-by-asshats programming language

    And what languages are those? Because here every other language is TRWTF.

    @Maciejasjmj said:

    all I know about Ada is that it kinda sorta looks like VHDL

    I don't know how you may have gotten that impression,



  • @Piko said:

    And what languages are those? Because here every other language is TRWTF.

    "(pretty much) every not-designed-by-asshats programming language is easily readable" does not imply "none of the easily-readable languages were designed by asshats". PHP is, in fact, quite readable...

    @Piko said:

    I don't know how you may have gotten that impression,

    Must be the =>s and the "x is y" syntax.


  • Discourse touched me in a no-no place

    @Maciejasjmj said:

    all I know about Ada is that it kinda sorta looks like VHDL

    VHDL is a descendant of Ada, specialised for working with hardware, and all done for the same customer originally (the US DOD). At least with hardware, a fussy type system makes sense (since you really have to care what happens with the bits).



  • It looks like a fussy verbose Pascal.
    :wtf: is ' as a namespace separator though?



  • @tar said:

    :wtf: is ' as a namespace separator though?

    Yes, it was used as such in perl, too, until Larry came to his senses and changed it to :: (although ' is (I think) still recognized for backward compatibility).



  • @HardwareGeek said:

    Yes, it was used as such in perl, too, until Larry came to his senses and changed it to :: (although ' is (I think) still recognized for backward compatibility).

    TIMTOWTDI



  • Of course!


  • Discourse touched me in a no-no place

    @HardwareGeek said:

    it was used as such in perl, too

    Ah, the “glories” of Perl 4. Perl 5 was genuinely much better, but then so was being beaten senseless in a dark alley in Akron, OH…



  • MOAR NECKRO PLZ KTHXBAI

    Anyway, since no one seems to have actually read the code and critiqued it, I'll do so now. From what I can tell, the basic goal here is converting a raw 8-bit field to a record of eight packed booleans (IIRC, Ada automatically packs boolean arrays into bit-fields by default), which should be a fairly straightforward conversion of the sort that a C programmer would abuse the union type to perform (I say abuse because it is an implementation-dependent conversion - one which works in almost every implementation, true, but still a misuse from a pendantic standpoint). Most of the code is there to work around the constraints of the Ada type system in a more or less reliable way. I am sure that a more concise (by Ada standards) approach would be possible, but it might not be implementation-independent; while this is hardware specific anyway, that still would be a possible WTF to an Ada programmer, as it might cause problems if the compiler changes how it implements things. Give me some time to dig a bit and I think I can find out some more.



  • @tar said:

    It looks like a fussy verbose Pascal.

    Ada pretty much is a fussy verbose Pascal, or rather, an even more fussy and verbose Modula (the immediate successor of Pascal and predecessor of Modula-2), which was one of the languages its design drew from, along with Concurrent Pascal and a few other Wirth-language derivatives that went into the mix.



  • @ScholRLEA said:

    IIRC, Ada automatically packs boolean arrays into bit-fields by default

    Oops, it seems I was wrong on this; according to what I just read, the implementation of Boolean variables in Ada95 is not defined - as long as it is an ordered enumeration of values of (FALSE, TRUE), it can be implemented in any way the compiler writer chooses. I forgot just how fussy and pendantic the RM really is.

    IOW, this is still officially implementation-dependent, which is a huge no-no in the Ada community.


  • BINNED

    @ScholRLEA said:

    I forgot just how fussy and pendantic the RM really is.

    Ironic, isn't it. You'd think Ada would be more popular here on a forum full of pendants.


  • Discourse touched me in a no-no place

    @antiquarian said:

    You'd think Ada would be more popular here on a forum full of pendants.

    It's too fussy for me. A whole programming language of dickweedery.


  • Discourse touched me in a no-no place

    @dkf said:

    It's too fussy for me. A whole programming language of dickweedery.

    I found it tedious to write, too.


  • BINNED

    Haskell gives you just as much pendantry but doesn't wear out your keyboard you don't have to write something the size of War and Peace to get anything useful done. 🚎


  • Discourse touched me in a no-no place

    @antiquarian said:

    Haskell gives you just as much pendantry but doesn't wear out your keyboard.

    I was more put off by the verbosity of everything.


  • BINNED

    That's what I was getting at. Coding anything useful in Ada will have you doing as much typing as thinking.


  • Discourse touched me in a no-no place

    @antiquarian said:

    That's what I was getting at.

    Gotcha. I wasn't thinking of verbosity as pendantry.


  • BINNED

    Maybe the edit I just did will clear things up?



  • I was considering writing a compiler that took some non-esoteric language (like a subset of x86 assembly or something) and translated it to BIT a few days ago. I decided against it when I realized I couldn't be belgium­ed.


  • Java Dev

    Easiest way to do that is probably implement bit as a clang output.



  • This post is deleted!

Log in to reply