Skip to content

Coding guidelines

DCxDemo edited this page May 29, 2024 · 13 revisions

Documentation

Default Visual Studio triple-slash documentation functionality is used to document functions.

Class design

Classes are designed to be read and written in a uniform way. Every IO class is expected to contain:

  • an empty constructor() (fields better be initialized with some default values).
  • a constructor(BinaryReaderEx) that calls Read method
  • a Read(BinaryReaderEx) method that reads class data starting from current position, IRead interface
  • a Write(BinaryReaderEx) method that writes class data starting from current position, IWrite interface.
  • a static factory method FromReader(BinaryReaderEx) that returns a new class instance

If class data can be serialized to a standalone binary file, additionally include:

  • a serializer: Save(string filename) method that wraps writer creation and saves class data to file
  • a deserializer: a static factory method FromFile(string filename) that wraps reader creation and returns a new class instance

BinaryReaderEx and BinaryWriterEx are extension classes derived from standard System.IO classes.

Arrow functions

Arrow function => is a preferred way to format oneliners or readonly fields (for example, a static method that just returns a new object)

var usage

var keyword is generally accepted for local declarations and foreach iterators, where the var type is obvious.

Return early

Early returns are preferred for arguments validation, file system checks, etc.