3 ms·
> That's true, in theory. In reality though, when is that information extracted? What do you use to extract it? Where is it saved once extracted? How easy is it
by gavinray 5y ago
> That's true, in theory. In reality though, when is that information extracted? What do you use to extract it? Where is it saved once extracted? How easy is it to review it? Do you need to use an IDE to do that?
This is part of the GNU Ada toolchain.
I don't write Ada, but I have looked into it. I strongly dislike having to write an entire separate type/interface file that repeats the type definitions from the implementation.
This information exists -- a tool should be able to extract the signatures and spit out the interface file automatically (IE a header for C/C++)!
In Ada, this tool is called "gnatchop"
https://learn.adacore.com/courses/GNAT_Toolchain_Intro/chapters/gnat_tools.html#gnatchop https://learn.adacore.com/courses/GNAT_Toolchain_Intro/chapt...
Instead of writing an ".ads" and ".adb" file (like ".h" and ".c"), you just write an ".ada" file and feed it to "gnatchop", it creates the two files for you and you're ready to compile.
gnatchop example.ada # (example.adb + example.ads created)
gprbuild p_main # (builds from example.adb)
Another neat thing Ada can do is interop with C++! It has C interop, but can ALSO support C++.
https://gcc.gnu.org/onlinedocs/gnat_ugn/Interfacing-with-C_002b_002b-at-the-Class-Level.html https://gcc.gnu.org/onlinedocs/gnat_ugn/Interfacing-with-C_0...
https://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/interfacing_to_other_languages.html#id3 https://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/i...
It can take C/C++ headers and auto-generate the interop code you need as well
$ g++ -c -fdump-ada-spec -C /usr/include/time.h
$ gcc -c *.ads
https://gcc.gnu.org/onlinedocs/gnat_ugn/Running-the-Binding-Generator.html#Running-the-Binding-Generator https://gcc.gnu.org/onlinedocs/gnat_ugn/Running-the-Binding-...
https://gcc.gnu.org/onlinedocs/gnat_ugn/Generating-Bindings-for-C_002b_002b-Headers.html#Generating-Bindings-for-C_002b_002b-Headers https://gcc.gnu.org/onlinedocs/gnat_ugn/Generating-Bindings-...
- foerbert 5y agoI can understand your hesitancy, but I think in practice I strongly disagree. A big part of why I like Ada so much is the fact it lets me hold such a strong mental model of the program. I can specify quite a bit about how it should all work, and the compiler holds me to it. Most or all of that sort of information is tied up in the .ads file. If I want to refer to the model, I can check the .ads file, even if my project doesn't compile yet. Everything I need to know is there, from the very first line of code. Most importantly, if I'm working in the .ads file, I'm changing the model. Changes here are Important. If I unknowingly make a change here, I've lost my understanding of the model. I really don't want that to be possible. Meanwhile the .adb is more the implementation. If I'm changing the .adb, I'm just altering the details, but the overall model stays the same. Maybe what I'm doing in the .adb tells me I really do need to change the .ads because the model has a problem, but that doesn't mean I should just go make the easiest little change to the model that makes the .adb work. Frankly, I think that extra little bit of friction in having two files that need to be in sync makes it easier to write better programs. Something as huge as changing the model should have something that helps cue me in that I'm doing something Big.