Compiling

Aesthetics

Some languages, such as Python, incorporate the aesthetics of the language into the grammar. This is (in spite of my love to Python) utterly ridiculous.

Presentation is a good practice, that's a given, but the sense of the program should not change based in aesthetic choices such as tabulation. Language is not a graphical medium.

In Ada, even when we highly encourage you to have a clean, nice, and even artistic ( code can be an art form) aesthetic, the truth is that will not affect the compiler, which will ignore all white-spaces characters and read them as a single space, and change all capitalization out of literals to lower cases.

A typical Hello_World will look like this to the compiler:

with ada.text_io; procedure hello is begin ada.text_io.put("Hello world!"); ada.text_io.new_line;end hello;

Read > Write

Read over write simplicity is the norm for Ada.

Also explicit over implicit.

In spite of the compiler, I encourage you to follow some rules of thumb for aesthetic coding:

  • Container is indented more than contingent.
  • One line, one step.
  • Capitalize names and identifiers. Separate words in the identifier with underscores ( _ )
  • Use clear and explicit names, not short names. Be sensible.
  • Similar elements should be presented similarly.
  • Different elements should be presented separately.
  • Comment when something is not so explicit.
  • Operators should be spaced before and after, except the power operator (**)
  • Don't be smart. Write for dummies.
  • Reserved words' rules vary on time: in the 80's where all capitalized. Nowadays, is all lower case. My take? go with your context.

Identifiers

Identifiers are the names of variables and functions. They can be a set of words separated by underscore, as capitalization will not translate into the language. Or a clear acronym, or a representative symbol.

Ada compilers support all Unicode characters.

This means that Greek characters or Emojis can be used in identifiers (variable names, types, elements in enumerations...)

Make sure you support them, as Ada was designed to compile in 8bit compilers too, so it might be not so straightforward.

But they will always be supported in the comments.

Check your style

You can order GNAT to check that you write code with (according to them) Good style. 😎 using the command order option:

  • gnatmake -gnatg program.adb

This is one of those little treats that I enjoy so much when programming Ada.

⚠️ Warning: Some stylistic errors may cause a failure when compiling, even if the code is good. Use it as a second check.

Tabs must be 3 spaces.

Spaces are followed by 2 spaces.

Operators must be spaced before and after.