Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added section on formatting.

...

Much of the code does not follow these guidelines. As it evolves the goal is to make new code follow these guidelines, and to evolve existing code toward them.

See also Code Style GuidelinesCoding for Performance

Formatting

We use the standard Scala formatting as implemented by the unmodified defaults of the Scalariform tool.

Note: If you are coding using ScalaIDE (or other Eclipse configuration), the default indentation settings for Scala are not correct (as of 2019-05-21).

You must explicitly uncheck two options that they enable by default:

  • Align parameters on different lines in the same column
  • Align the arrows of consecutive single-line case statements

64-bit vs. 32-bit

Our goal is all-64-bit capabilities. Unfortunately, many Java and Scala libraries do not allow offsets or positions larger than a signed 32-bit Int can hold.

...

  • bitPosition0b : ULong - means position, measured in bits, first bit is at position 0, type unsigned long.
  • mCharWidthInBits: MaybeInt - measured in bits, but note that sizes, lengths, widths, don't have 0 or 1 base stuff. Note also use of MaybeInt type.
  • childIndex1b - child index, first child is at index 1.

Exercise for Reader!

Create a scala ZeroBased and OneBased AnyVal wrapper type with explicit (or some implicit) conversions.

The point is to let the scala compiler give you an error when you mix zero and one-based things, or pass a zero-based thing to an argument that wants a 1 based thing.

So the type of bitPosition0b (which is ULong currently) would be 

Code Block
var bitPosition0b = ZeroBased[ULong]

var bitPosInByte1b = OneBased[UInt]

For examples on how to do number types along these lines, look at UInt which is an AnyVal type.

Identifier Naming Conventions

...

Code Block
import org.apache.daffodil.equality._

...


There are two operators:

  • a =:= b provides "Type Equality" for use when a and b have a subtype relationship, including the most obvious case of a and b both being of the same type.
  • a =#= b provides "View Equality" for use when a and b are convertible, that is, a can be implicitly converted to b's type, or b can be implicitly converted to a's type. Numbers and number-like types are common cases for this so the "#" in the operator is suggestive of  "number"

...