Original Creators Are Better at Maintaining a System Than Their Replacements

12 December 2023 by Phillip JohnstonEven with the best documentation, those who originally created the product are usually better at fixing/modifying it than their replacements. This is because they hold context and design paradigms within their head that may not have been documented or effectively communicated with others. However, there are limitations: People forget, which means that an original creator may be no better than one of their successors after time has elapsed. Fundamental concepts and design goals change over time and/or may have been invalidated by successors, rendering their knowledge useless. As the original development team cycles off, software …

Design Pattern Template

21 March 2022 by Phillip Johnston • Last updated 24 March 2022Here is the Markdown template we use for documenting design patterns used in our repositories and on our website. Put a 1-2 line summary description up top. Include a brief classification of this pattern (Structural, Decoupling, etc.) if relevant for your purposes. ## Aliases – List any known aliases for this pattern ## Context It can be helpful to give readers brief context and description of the pattern prior to reading the rest of the pattern document. You can also use this as an “Intent” section. – How does …

Case Study: A-7E Project

13 December 2021 by Phillip JohnstonIn the mid-1970s, the Naval Research Laboratory (NRL) in Washington, D.C. launched a project to redesign the flight software the A-7E aircraft using the latest in computer science research and technology being developed in academia and laboratories. The purpose was to create a convincing demonstration of the value of these techniques in real-world applications. The original A-7 aircraft was considered a successful program because it worked reliably. However, it was expensive to maintain due to common software problems: it barely met its time and space limitations it was not fully understood by the maintenance personnel …

Case Study: 737 MAX Electrical Grounding Issues

8 June 2021 by Phillip JohnstonOn 9 April, Boeing announced that it notified 16 airlines and the U.S. Federal Aviation Administration (FAA) of a potential electrical grounding problems with the backup power control unit, the storage rack the power control unit is mounted in, and the main instrument panel. In response to this announcement, active aircraft were pulled out of service. The FAA released an airworthiness directive describing the problem and its consequences: Degradation of bonds essential for the electrical grounding of equipment, if not addressed, could affect the operation of certain systems, including engine ice protection, and result in …

Source Control Commit Guidelines

Preparing quality commits in a source control system is an underrated skill. Commit messages help explain the context for set of changes. We can’t always find an explanation or context for why code was changed by looking at the code. We must keep a detailed project history in some other way, and the commit tree is one of the best places. This history is invaluable when debugging future problems or trying to understand why a previous change was made.

Additionally, how we structure our commits matters. With commits that are too large, reviewers will have trouble processing all of the information. Future debugging efforts are also hindered, because developers cannot pinpoint exactly where an error was introduced when large commits are the norm. We want to build a project history that is truly a future resource for future developers.

The following commit guidelines are used on Embedded Artistry open source software projects to provide a consistent organization style. If your commits and messages are not of sufficient quality, you may be asked to amend them before a pull request is accepted.

In general, these guidelines will serve you well no matter your organization. For other takes on writing quality commit messages, see the Further Reading section below.

Table of Contents:

  1. Prefer Atomic Commits
    1. Splitting Commits
    2. Whitespace and Formatting Cleanup
  2. Commit Message Guidelines
    1. The Subject
    2. The Message Body
    3. Reference Issue Numbers
    4. On Cherry-Picked Commits
  3. Revise Your Commits Before Submitting a PR
  4. Further Reading

Prefer Atomic Commits

In general, the smaller the commit, the better. We prefer atomic commits, which apply a distinct and related set of changes in a single action.

What does this mean in practical terms?

  1. All changes in a commit should be related.
    1. Don’t combine changes that address different problems into a single commit.
  2. All changes in a commit should address a single aspect of a problem or change.
    1. Don’t be afraid to break up a new feature, bug fix, or refactoring effort into multiple distinct changes.
    2. This will help you keep track of what works and what doesn’t: if there’s a problem, you can always revert back to the last known good state. If you wait too long between commits, you may lose a lot of work or spend too long finding the source of the problem.
  3. Prefer small commits to large commits.
    1. This helps reviewers by allowing them to focus on a small set of related changes.
    2. This helps future debugging efforts by increasing the probability that a git bisect operation will quickly identify the source of the problem.

Splitting Commits

Sometimes, we accidentally commit distinct sets of changes together. Or we might mess up a rebase effort, accidentally squashing two unrelated commits.

To undo this problem, review our process on splitting up git commits in the middle of a branch.

Whitespace and Formatting Cleanup

Don’t mix code changes with whitespace or formatting changes! If you are fixing code formatting, include those changes separately from your code changes. If your request is unreadable due to whitespace changes, it will be rejected.

Many of our projects enforce automated code formatting using clang-format. Formatting is enforced by the Jenkins build server which runs continuous integration for this project. Your Pull Request cannot be accepted if the formatting check fails. If your changes are rejected by the server, please include the auto-format updates in a separate commit.

You can auto-format your code to match the style guidelines by issuing the following command:

make format

If you don’t have clang-format installed, we can apply the format changes for you.

Commit Message Guidelines

Below is a visual representation of the Embedded Artistry git commit message format:

50-char-ish"subject" which summarizes the change

After the first line, include additional explanatory text. Include
one blank line in between the summary and the body. Various tools
like git log, git shortlog, and git rebase get confused if the two
sections run together.

You can also include bullet points:
* A
* B
* C

Reference issues at the bottom, like this:

Fixes #102
Relates to #100, #8

The Subject

Treat the first line of a commit message like an email subject line.

We recommend a maximum length of 50 characters because it works best with git’s command line tools.

We also recommend using the imperative mood for subjects. This might be what you think of as “commanding” or “instructing”. Examples include:

  • Refactor subsystem X
  • Implement feature Y
  • Remove deprecated methods
  • Update version to 1.2.3

Another way to look at it is to have your subject line complete the following sentence:

If applied, this commit will [subject line here].

We don’t worry about manual line breaks in our commit message bodies. Text wrapping works well in modern tools.

The Message Body

Please separate the body from the subject with a blank line.

Most importantly, the commit message body should be used to explain what you are doing and why you did it that way, rather than how you did it. The code itself serves to explain the how. Focus on side effects, compatibility changes, or other consequences that are not immediately obvious from reviewing the code. Also include any important factors that helped you arrive at your particular approach.

Not all commit messages require both a subject and a body. You can include only a subject if it is sufficient for a given commit.

Reference Issue Numbers

When working with GitHub projects, reference relevant issue numbers in your commit message body.

You can have a commit automatically close an issue when it is merged to master by saying something like the following in your message body:

Fixes #123
Fixes: #123
Resolves: #123

You can also reference issues in other repositories by adding a prefix for organization/repository:

Fixes octo-org/octo-repo#100
Further reading

The full list of keywords that will close an issue is found in the GitHub documentation.

If other issues or PRs are related to this commit, but it doesn’t address the problem, you can include the issue/PR number without using a keyword like “fixes” or “resolves”. This will link the commit and the issue in GitHub’s web interface.

On Cherry-Picked Commits

Sometimes, we cherry-pick changes from one branch to another. We recommend using the -x flag with git cherry-pick, which references the original commit ID.

For more information, see Git Cherry-pick Recommendations.

Revise Your Commits Before Submitting a PR

While you’re working on a problem on your own branch, don’t worry about getting these commit details perfect. Instead, clean up your branch before you submit a PR. You can perform a git rebase to squash commits, amend commit messages, and more.

We often use a visual tool, such as Sourcetree, for complex rebase process.

Further Reading

For more on writing quality git commit messages:

For more valuable processes to follow:

Safety Plan

31 October 2019 by Phillip Johnston A safety plan is a cornerstone of embedded device safety with respect to safety-critical systems. The safety plan outlines the relevant safety standard(s), identifies hazards and risks, enumerates safety goals, and describe how and why system safety is ensured. You can explore other aspects of embedded systems safety in the main topic. Table of Contents: Elements Anti-Patterns Lectures Articles From Around the Web Elements A a safety plan should reference a safety standard that is compatible with the target application and its intended use case. With the framework of the chosen safety standard, multiple …

Security Plan

30 October 2019 by Phillip Johnston • Last updated 24 March 2022 A security plan is a written document that outlines your product’s security requirements, threat model, and the steps you will take to make the product secure. A security plan is a cornerstone of embedded device security. You can explore other aspects of embedded security in the main topic. A Process for Creating a Security Plan If you are looking for a process that can be used to create your security plan, see our entry “A Process for Defining Your Device’s Security Requirements”. Capture the outputs of this process …

Documenting Architectural Decisions Within Our Repositories

I recently discovered Michael Nygard's article on the subject of Documenting Architecture Decisions. I immediately became interested in using Architecture Decision Records (ADRs) with my projects. I will provide a brief ADR summary, but I recommend reading Michael Nygard's article before continuing. Table of Contents: An Overview of Architecture Decision Records Using ADRs in Your …