Ada Programming Practices

Reading the Style Guide is boring. How about listening to a live discussion? As an experiment, I used Google NobebookML to create such a discussion for three topics from the Programming Practices chapter of Ada’s style guide. The 16 minutes of discussion included

I added the slides myself. I think it turned out very interesting.

What do you think of this format?

PS There is no part 1 and 2 yet.

1 Like

The preview showed a couple of anime characters, so I expected a couple of anime characters to be chatting. That’s not what I got.

Otherwise, it looks (and sounds) pretty neat. The use of “uh” and the variation in tone of voice was pleasant. The questions they used seemed a little contrived. “So, in a large codebase, why would I care about visibility?” :thinking:

I haven’t had a chance yet to watch the video, but from my own experience, the question at least kinda hits home. I’ve worked on a couple of code bases with millions of lines of code where whoever started it thought that they should make all the variables public package level variables and just use them everywhere. Most of our bug reports were when someone changed a variable in one module and it broke another. It was a huge mess. I wish more folks cared about visibility from my own experience, but I know it isn’t everyone’s experience.

3 Likes

Geez. I take the point, so I think I’m explaining myself badly. What I meant is that the question, in context of where it came up in the video, and in the tone of voice used, sounded contrived. Not sure I know how to explain it better. Or, maybe I just don’t have enough experience cleaning up after people who make that mistake. Usually I find myself wishing people were hiding less, because I need to read some data that (in Rust) hasn’t been marked pub (which is a good idea) and for which there is no method to reveal its value (often painful).

Oh definitely. I can understand that. It happens to me in GNAT all the time. Like when I wanted access to CTS and RTS on the serial port, my copy of GNAT doesn’t give direct access to those in their serial port package. The stuff I needed was there in the private section of that package though.

What I’ve done for my own projects is make use of child packages since they can see into the private section of their parent packages. So like for my emulator, I restrict visibility a lot some of my components (so I am not easily able to just dive in and bypass code by manipulating internals). However, for testing I do want to sometimes use some of those internals, so in my testing projects, I’ll make child packages of the ones I want to peek into (or modify).

Since child packages can see into the private sections of the parent, that gives me some ways to bypass the safety when I need to, while at least hindering me in my main project (which doesn’t have those child packages).

It’s a feature of Ada that I feel is a safety hazard, so I don’t typically make use of it in “product” code, but for testing, I don’t mind it as much.

yeah, on reading what you wrote above this, my reaction was…

:astonished:

Interesting that you feel using child packages in that way is a “safety hazard”. I find it a nice way to breakup functionality, especially to limit how much ripple effect a change can make by allowing the user to “with” just what they want. This is especially for functionality that I might think of after the fact.

I don’t feel like using child packages in general is a problem. Using child packages to expose private fields and variables to the public though can be particularly dangerous. I use child packages to break up code all the time

Another way to look at it is you are partitioning the global scope so that each subsystem has it’s own “private” global scope. Specifically, a parent package’s private section is the private global scope available to all the child packages in the hierarchy rooted at that parent.

When using a package hierarchy to implement a large subsystem, this way of managing the “global” scope within the subsystem seems like a really nice feature of Ada.

3 Likes