Home | Documentation | Atomic Chat | Github

Atomic code conventions for C++, C#, JavaScript/TypeScript


As part of the effort to document working on Atomic (and help with pull requests), I’ve posted the C++ code convention guide. It is basic, clean, and best yet, already mostly adopted.

We’re also going to need code style guides for C# and TypeScript/JavaScript engine code.

@mattbenic Do you have a working draft or link to C# standards you use, or just maybe some style rules that should be adopted? :heart_eyes:

@shaddockh I think TypeScript code style is pretty much universal and (mostly) auto-formatted by the IDE? Do you have any thoughts or maybe we just link to an official style guide? JavaScript style seems pretty universal too, though my tastes aren’t very refined on that subject :camel:


I’ll take a look this weekend and see if there are some good resources. One thing I like to use is a combination of linters and code formatters so that I don’t have to think about it and everything looks consistent.


We do actually have a style guide that covers a number of languages. For the most part it specifies which existing standards to follow and calls out exceptions. For example in the case of C++ it sort of looked like existing Atomic code roughly followed Google’s standards. The original doc is Luma internal, so I’ve copied it across to here:

I’ve sanitized all Luma references out of it, but it would still need some massaging. For example there’s an Atomic section under “Project Specifics” at the bottom, that would need to be worked into the general conventions.

I’ve named it “Proposed Atomic Game Engine…”, just to differentiate it from our internal one for my sanity :slight_smile: I’d expect ultimately those conventions should live in the wiki, and may well borrow from this doc but might not at all.


@shaddockh Sounds great, I love how your TypeScript looks and is structured, anything you’re using to help achieve that would be good to document, thanks

@mattbenic That document is super valuable, as it is from your production team implementing in C#, thanks for sharing it :thumbsup:

Ok, so we’ll boil down the most important C# conventions, unlike the C++ conventions, I do want to get into C# structure a bit with properties, etc. Though, really want to keep it simple, we’re not writing a C# manual and the standard needs to be easily digestible.

We can then adapt the current Atomic C# engine stuff to the standard. This won’t be a huge undertaking, though important to get off on the right foot… hard keeping up a standard when you’re working in code which flagrantly violates it… I am looking at you UI.h :fire::camel::fire:

For how small Atomic’s repo is, it is really deep, we’re making great strides though sometimes it feels like shoveling sand, a good example of sand shoveling is making the same comments in code reviews without having a standard to quickly point to… and more importantly nothing for new folks to go off… also gotta keep in mind we don’t need 1 coding standard like back in the day, we need 3! :astonished:


C# standards are actually super simple, because of MS actually having detailed specifications for them and mostly sticking to those specs. The single biggest thing I find most people struggle to get used to is capitalized public fields (so they can seamlessly be promoted to properties). Many Unity devs have also picked up the annoying habit of making all their editor-exposed fields public, but the fact that Atomic only does that with attributes should prevent it happening. Basically, just point to these:




Excellent, Microsoft has really great developer support, and things have only been getting better there lately :slight_smile:

For the most part, this will be “just let Visual Studio/MonoDevelop auto-formatting do their thing”, which is pretty much already the case. We’re in good shape on engine API at least for reference style docs, as these are autogenerated… and we’ll be able to punch these up with typed parameters, etc in the XML style C# docs. There is a fair amount we can do with monodoc too, in order to make them look better.

The AtomicNET C# source, on the other hand, is pretty much undocumented, as you know :wink: This needs work and we’ll make progress on it. We’ve kept it pretty simple though, which I like in a core, so will be manageable to document.


Style Guide
For coding style, I have been using the AirBnB JavaScript style guide for years. It’s been updated with ES6 features which can also be used in TypeScript.

The style guide is at: https://github.com/airbnb/javascript

For day to day TypeScript, I use TSLint which has plugins for both Atom and VSCode and it’s also being run during the build. For JavaScript, I use ESLint which also has plugins for most editors.

TSLint - https://palantir.github.io/tslint/
ESLint - http://eslint.org/

TSLint for Atom - https://atom.io/packages/linter-tslint
ESLint for Atom - https://atom.io/packages/linter-eslint

Check the Visual Studio marketplace for ESLint and TSLint plugins for VSCode.

As for code beautifiers, VSCode has built in auto-formatting and for atom I use atom-beautify.

Atom Beautify uses typescript-formatter for TypeScript (https://github.com/vvakame/typescript-formatter) and js-beautify (https://github.com/beautify-web/js-beautify) for JavaScript. Both of these should be able to be run from the command line outside of the editor if needed.


The current TSLint configuration that is used in the build of the editor is located at:

It’s purposely pretty loose so that everything didn’t break when linting was enabled. The idea is that this will get stricter over time as the code gets more standardized.


@shaddock Awesome! That is also great wiki material for setting up a nice JavaScript/TypeScript dev environment for working with/on Atomic, thanks! :slight_smile:


We do have this external editor’s documentation for TypeScript which mentions linting at the bottom: https://github.com/AtomicGameEngine/AtomicGameEngine/wiki/Using-TypeScript-with-External-Editors

A goal is to have solid guides for setting up to work with/on Atomic for the currently supported IDE’s, this includes linking to coding conventions, setting up linting, etc:

JavaScript/TypeScript - VSCode, Atom, and embedded Monaco editor

C# - Visual Studio, Visual Studio for Mac (aka Xamarin Studio), MonoDevelop

C++ - Visual Studio, XCode, QtCreator

Hm, am I missing any? Wow!