Why does Ada/GNAT require a .ads file?

My guess is it would increase compilation times for large projects as files that once only depended on a spec file might now depend on both a spec and body. So changes that wouldn’t have forced a recompile on other files now might start forcing more recompiles. Only speculation on my part though.

The only other thing is I don’t know how it affects the level of data hiding by moving it to the body. Currently Ada’s private section is more like a “protected” visibility (if you’ll excuse the non Ada definition…think “public, protected, private” in other languages, nothing related to synchronization). Moving the private section to the body would make them fully “private”, so that might make things like dependent child packages fail to compile (as things they were able to see in the private section of the spec are no longer visible). For this case I think having the option to still use a private section in the spec would be good so you can maintain those “protected visibility” relationships.

For what it’s worth, .1.ada and .2.ada were the file extensions that the Rational Ada compiler used for spec and body, and Grady was one of the founders of Rational. GNAT is happy to use them as well if you tell it those are the extensions you are using.

The original Rational compiler generally didn’t preserve the source code as text files. It represented everything in Diana files, and reconstructed the textual representation of the source on demand.

2 Likes