Coding Conventions

Source code organization

Source file names

Hades files can either be script files (non instantiable proto), resource files (with instantiable protos like classes or structs) or mixed files (both script and resource files).

Script files

Script files, in Hades, are named after their function. If a script calculates something, call it calculateSomething.hd, if a script starts up a web server, call it startWebServer.hd and so on and so forth.

Resource files

Since there are no namespaces in Hades, the closest thing to a namespace structure is nesting classes and naming the source file after the highest, unique sub-namespace name.

So for a project that is organized like so:

src/
 org/
  example/
   hades/
    main.hd
libs/
project.json

With a class called connection and a subclass called client, in the namespace org.example.hades.weather (so the full class name of client would be org.example.hades.weather.connection.client), the correct filename would be weather.hd.

And the import statement would look like this:

Mixed files

Mixed files can be both script and resource files, so they can be executed as a script, but you can also load classes or structs from it. Mixed files use the same naming convention as script files.

So the import statements would look like so:

Project structure

For smaller projects, just put the source files in one folder.

For bigger projects, use the Hades project initializer, which creates a Hades project with the following structure (example for a project with the organization name example.org and the project name testing):

Naming rules

Most things in Hades follow Lower Camel Case, except for preprocessor variables which are uppercase and underscore separated, and native libraries which are named like so: native library name : library file. Classes, constructors and struct names follow PascalCase while proto names are in Lower Camel Case.

These are not "best practices". These are just recommendations. If you wish to change these conventions for your project, do so.

Preprocessor variables

Functions (Lower Camel Case)

Classes (PascalCase)

Structs (PascalCase)

Native library names

Formatting

Lambdas

Lambdas that have more than one expression (complex lambdas) are formatted like Java methods (the parameters on the first line) and need a manual put:

Same for match:

Pipelines

Pipelines don't have indentation. A pipeline statement uses the indentation of the pipeline source.

Tabs vs spaces

It is absolutely irrelevant whether you choose tabs or spaces for indentation. As long as you stay consistent and don't mix tabs and spaces, it doesn't matter.

Miscellaneous

Ignored catch block

If you choose not to handle a exception, mark the block as ignored with a comment.

Last updated