![]() |
lingua-franca 0.10.1
Lingua Franca code generator
|
This repository hosts the source code for the Lingua Franca compiler, which is written in Java and Kotlin. We welcome contributions from the community and provide these guidelines in order to make contributing a smooth, efficient, and fun process.
You can work on the Lingua Franca code base in your favorite editor and build using Gradle. We recommend to use the IntelliJ IDE.
An integral part of contributing code is writing tests.
Unit tests for the compiler are located in the org.lflang.tests package (found in the directory core/src/test/java/org/lflang/tests, in the core gradle subproject) and are implemented using the JUnit test framework. These tests are invoked using Gradle. For example, to run all the tests in the org.lflang.tests.compiler package, use the following command:
Integration tests consist of complete Lingua Franca programs that are located in the test directory in the root of the repository and are organized first by target, then by category. These tests get indexed automatically and are also invoked using Gradle. For instance, to run all the tests for the C target, use the following command:
For more details, see test/README.md.
All code contributions must go through a pull request (PR), pass all tests run in CI, and get an approving review before it is merged. Pushing to the master branch is restricted. All code review is conducted using the Github review system on PRs. Before requesting a code review, ensure that you have:
The Lingua Franca compiler is implemented in Java and Kotlin. The overarching advice is to use each language's most widely used idioms and conventions, which are fortunately very similar. Documentation for the code should use Javadoc comments with Markdown formatting for the content. See also documentation generation.
The code base is shipped with a Spotless configuration to check and enforce style compliance. Lingua Franca code (e.g., tests) in this repository is also automatically formatted via Spotless.
Java code formatting in IntelliJ
Follow the directions here to install the Spotless Gradle plugin. We are not currently aware of a way to run Spotless automatically on file save, but it is possible to configure a keybinding.
There is a plugin specifically for enforcing Google's style guide, but we have found difficulty getting it to work properly.
Lingua Franca code formatting in VS Code
Formatting is provided by the Lingua Franca VS Code extension.
You can enable formatting on save by going to Settings and searching for "format" and checking the box Editor: Format on Save. This can be either a user-level or workspace-level setting.
Checking using Git hooks
If you prefer not to use formatting on save but would still like to avoid committing unformatted code, you can add a file .git/hooks/pre-commit with the contents:
Comments
Please adhere to the following principles when writing documentation for your code:
We use the Google Java style guide, which leaves a few things unspecified that we discuss here in a bit more depth.
Ordering of class contents (S3.4.2)
The order you choose for the members and initializers of your class can have a great effect on learnability. However, there's no single correct recipe for how to do it; different classes may order their contents in different ways.
What is important is that each class uses some logical order, which its maintainer could explain if asked. For example, new methods are not just habitually added to the end of the class, as that would yield "chronological by date added" ordering, which is not a logical ordering.
When in doubt, the following suggestions might help:
Visibility
Avoid public non-final fields and public collection fields (making them final does not make their contents immutable).
Inheritance
Design for inheritance or prohibit it. Make new classes final by default, and avoid using protected members. The class should only be unsealed if a use case for inheritance shows up, which is in many cases never. Often, composition can offer a better solution than inheritance (also see a blog post on this).
Collections
Use interfaces like List, Set, Map to type variables, constructor parameters, and method signatures, not concrete implementations like LinkedList, HashSet, or LinkedHashMap.
Collection mutability
In Java, instances of collection classes may be read-only. They will throw an exception when modification is attempted. Read-only views on collections are used to prevent external code from modifying an internal collection by accident, which may break class invariants. Encapsulating modifications to the collection into extra mutator methods is good practice, because it allows maintaining class invariants if the class evolves.
Please follow the Kotlin coding conventions.