Hacker News new | past | comments | ask | show | jobs | submit login

>> Having a terse little file where I can scan the interface of a module, rather than having to scroll through the implementation and see which declarations have `public` in front of them, is a great way to quickly refresh your mental model of a module's API.

> That information is trivial to extract, there is no reason to force the developer to maintain it and keep it in sync.

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?

Any less than satisfactory answer to these questions will make this worse in practice than having the developer maintain it.




> 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?

You could use your build system to extract it to a website (eg. https://docs.rs/)


  > 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/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_0...

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-...

https://gcc.gnu.org/onlinedocs/gnat_ugn/Generating-Bindings-...


I 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.


The compiler should be able to provide it




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: