Live data from Hacker News

Writing Linux Modules in Ada (2016)

nihamkin.com

51–60 of 87 posts

Re: Writing Linux Modules in Ada (2016)

#51
post #23
post #8

I've never used Ada, and I also don't really do systems stuff, but it does seem like it's a pretty neat language, at least compared to C. From what I have seen, it looks like it has better memory guarantees while still being fast and low-level. With be the popularity of Rust, it makes me kind of wonder why Ada isn't more popular. I should give the language a go.

There wasn't an open source compiler from the beginning, and thus a lot of the compilers where expensive. You could only use the language in an awful legacy setting behind a wall of NDAs and security clearances. Not my experience, just a bunch comments on HN of actual retired Ada devs on why the language didn't take when I was researching the language. Adacore in the last few years have been investing heavily in mode…

>> Adacore in the last few years have been investing heavily in modernizing the tool chain, but now it seems they are also investing in Rust.

Adacore is working with Ferrous Systems on Ferrocene (https://ferrous-systems.com/ferrocene/), a Rust toolchain for use on safety critical applications:

https://blog.adacore.com/announcing-publication-of-the-draft...

https://ferrous-systems.com/blog/ferrous-systems-adacore-joi...

I am hoping that Ferrocene's work will help the drive the standardization of Rust over the next few years:

https://github.com/rust-lang/rust/issues/113527

Re: Writing Linux Modules in Ada (2016)

#52
post #22
post #17

Earlier quoted context omitted.

Only true for those stuck in Ada83. People keep repeating this nonsense without updating themselves beforehand. EDIT: To simply education on Ada, Yes there was an optional GC, no one ever implemented it, so in Ada2012 got removed from the standard. Almost everything can be allocated on the stack, so a strategy is to catch exceptions of not enough stack space and retry the same function with a smaller size for the dat…

What’s your sense of the size of the Ada job market? High hundreds? Close to 10,000? Is it static or growing or shrinking? Is there a preferred online community for Ada devs?

The Ada job market is still large in aerospace and defense industries where lives are on the line.

Re: Writing Linux Modules in Ada (2016)

#53
post #5

Memory safety might not be a bad idea for Linux in general.

Ada’s take on memory safety is pretty limited. Heap allocation is explicit; there’s a procedure literally named Unchecked_Deallocation to free a pointer. It does have thread-scoped locals and arenas, but nothing like declared lifetimes or borrowing. The spec allows for GC but I believe it’s rarely offered. It’s safer than C, but I’m not quite sure where recent specs line up against C++.

It does have Rust like borrowing in SPARK subset of the language.

There was attempt to have it in Ada 2022 Standard, but it came late. Committee decided it's best not to rush and let compiler vendors implement how they think is best and go from there.

>It’s safer than C, but I’m not quite sure where recent specs line up against C++.

Ada allows to return objects of variable size, so it's not that common that you actually need to explicitly allocate stuff. The general guideline for dynamic memory allocation is:

1) Use Second stack (this is how Ada allows to return object of variable size) 2) If cant use containers 3) If cant use controlled types (RAII) 4) Only then use New.

Re: Writing Linux Modules in Ada (2016)

#54
post #42

Earlier quoted context omitted.

I personally think that its 'representation clauses' are a really awesome feature for bare-metal programming. It's a shame other languages haven't borrowed this idea.

Representation clauses are by far the biggest feature for embedded programming: https://learn.adacore.com/courses/advanced-ada/parts/data_ty... http://www.ada-auth.org/standards/22rm/html/RM-13-1.html Wouldn't it be nice in C to be able to define how a struct is laid out in the machine representation? In Ada, you can and it is part of the standard, so it is portable: https://learn.adacore.com/courses/advanced-ada/par…

It's difficult for someone with 0 knowledge of the language to really understand representation clauses. It does seem to be similar to enum values in C++?

    // Ada
    for Day use (Mon => 2#00000001#,
                 Tue => 2#00000010#,
                 Wed => 2#00000100#,
                 Thu => 2#00001000#,
                 Fri => 2#00010000#,
                 Sat => 2#00100000#,
                 Sun => 2#01000000#);
    // C++
    enum Day {
        Mon = 0b00000001,
        Tue = 0b00000010,
        Wed = 0b00000100,
        Thu = 0b00001000,
        Fri = 0b00010000,
        Sat = 0b00100000,
        Sun = 0b01000000,
    };
As for the record representation, my understanding is that it is equivalent to having a normalized __attribute__((__packed__)), where smart compiler padding is disabled and you can arbitrarily decide the memory layout of your struct?

Re: Writing Linux Modules in Ada (2016)

#55
post #48

Earlier quoted context omitted.

>Ada95 introduced controlled types, which is basically Ada's version of RAII, no need to call Unchecked_Deallocation outside implementation details. Hardly any different from Rust code that uses unsafe underneath. This is basically like C++ destructors, but the problem is there are no move semantics in Ada, so you can't implement something like unique_ptr. It's hardly comparable with Rust.

Yeah, that is what happens when one doesn't understand contracts and formal proofs are used, my dear newly created account to advocate for Rust.

I've noticed a pattern that many Ada advocates on HN don't really seem to know the language. So they often conflate SPARK with Ada (as you just did) and make unfounded claims about Ada's memory safety, portraying it as being on par with Rust.

It isn't on par, Ada has no lifetime management whatsoever. It doesn't even provide C++ style smart pointers out of the box. It is possible to implement something like shared_ptr, AdaCore even has a tutorial[1], but as the other commenter pointed out, the language doesn't provide the primitives necessary for unique_ptr.

SPARK does have something like this. In fact, in SPARK, every pointer assignment transfers the ownership. But SPARK and Ada aren't synonymous. SPARK is a formal verifier built on top of Ada. Like most such tools, it's very constraining and time-consuming. It's not something that every (or even most) Ada projects use.

Nevertheless, Ada is a perfectly good language, and it's probably safer than C++. It has some really cool features. I'm really fond of in/inout/out references (cppfront stole this), named function parameters, secondary stack, fine-grained control over records (struct) layout, etc.

However, I'm not so fond of the extreme verbosity. It isn't just because of Algol-like keywords, Pascal is less verbose than Ada. Even basic stuff like instantiating generics is very noisy:

   procedure do_something is
     package Integer_Vectors is new
       Ada.Containers.Vectors
         (Index_Type   => Natural,
          Element_Type => Integer);

       vec : Integer_Vectors.Vector;
     begin
       return;
     end;
In C++ that would be:

    void
    do_something(int arg) {
        std::vector vec;
    }
[1] - https://www.adacore.com/gems/gem-97-reference-counting-in-ad...

Re: Writing Linux Modules in Ada (2016)

#56

Earlier quoted context omitted.

Ada’s take on memory safety is pretty limited. Heap allocation is explicit; there’s a procedure literally named Unchecked_Deallocation to free a pointer. It does have thread-scoped locals and arenas, but nothing like declared lifetimes or borrowing. The spec allows for GC but I believe it’s rarely offered. It’s safer than C, but I’m not quite sure where recent specs line up against C++.

Recent work have introduced lifetimes and an ownership model into SPARK (the reduced easier-to-prove Ada subset) https://blog.adacore.com/using-pointers-in-spark and hopefully it'll trickle down soon in Ada. Edit: there's also reference counting and controlled types of course. And the secondary stack makes many uses of heap allocation go away.

That secondary stack is cool! I want it for my C++ programs, particularly std::string which always heap alloc.

begin

   return "Forty Two";
end Get_Answer;

Re: Writing Linux Modules in Ada (2016)

#57

Earlier quoted context omitted.

I think it mostly refers to the build in functions in Ada for Bit fiddeling. You can represent registers and bitmaps in Ada data structures and use relatively simple to understand functions on them instead. https://learn.adacore.com/courses/intro-to-embedded-sys-prog...

There are a lot of aspects where Ada is better than C. Just a few things that came to mind: General lack of dumb C stuff like switch fallthrough, null terminated strings (Arrays in Ada are passed with fat pointers), undefined behavior, no need for memcpy, no preprocessor bullshit etc. Ada is more like C++ in functionality so it has Generics, Tasks (Threads), Exceptions, Packages, Strong types, Design by contract etc…

I know berating C is trendy, but it feels a bit gratuitous and uncalled for in your comment...

> Ada is better than C

> lack of dumb C stuff

Back to your comment, strong types and generics look super nice for embedded. Not sure I would like fat pointers, exceptions and threads in my embedded code though.

Re: Writing Linux Modules in Ada (2016)

#58
post #2

Back in university I took a course in legacy programming. We did a project in each of Fortran, COBOL and Ada. I enjoyed Ada very much. The module system made a lot of sense to me and the compiler found a lot of mistakes (compared to C). Thanks for sharing this article. It brought me back and makes me want to give Ada another go now that I have 10 years of real world experience.

Ada module made me make sense of java oo somehow.

I'd love to get a gig in ada.

Re: Writing Linux Modules in Ada (2016)

#59
It's interesting to see the positive talk about Ada in here. I think that's good, but also indicative of perhaps a change in perspective. I feel like if the topic of Ada had come up here 10 years ago (probably did), the responses would have been quite different and more along the lines of "that annoying stuffy/overly-verbose/old/obsolete/design-by-committee language" .

I think there's a good growing consciousness of the fairly terrifying unsafety of C/C++, and the relative success of Rust is some evidence of that, at least.

Many moons ago I bought an Ada 95 manual, and learned a bit of the language with intent to fiddle with it but never finished. I like the idea but not sure I'd be wanting to give up various... modern conveniences... I get from Rust in order to work in that world.

Re: Writing Linux Modules in Ada (2016)

#60
post #54

Earlier quoted context omitted.

Representation clauses are by far the biggest feature for embedded programming: https://learn.adacore.com/courses/advanced-ada/parts/data_ty... http://www.ada-auth.org/standards/22rm/html/RM-13-1.html Wouldn't it be nice in C to be able to define how a struct is laid out in the machine representation? In Ada, you can and it is part of the standard, so it is portable: https://learn.adacore.com/courses/advanced-ada/par…

It's difficult for someone with 0 knowledge of the language to really understand representation clauses. It does seem to be similar to enum values in C++? // Ada for Day use (Mon => 2#00000001#, Tue => 2#00000010#, Wed => 2#00000100#, Thu => 2#00001000#, Fri => 2#00010000#, Sat => 2#00100000#, Sun => 2#01000000#); // C++ enum Day { Mon = 0b00000001, Tue = 0b00000010, Wed = 0b00000100, Thu = 0b00001000, Fri = 0b000100…

[deleted]
Post reply on HN