

Squants: The Scala API for Quantities, Units of Measure and Dimensional Analysis - saryant
http://www.squants.com/

======
scalaMonkey
This library is a good example of what Dan Describes in this talk

Daniel Spiewak discusses problems and design considerations which arise when
dealing with multiple data that must work together in the same function- which
is to say most functions.

[https://www.youtube.com/watch?v=gVXt1RG_yN0](https://www.youtube.com/watch?v=gVXt1RG_yN0)

------
bronty
Java 8 adds support for type annotations, which enables developers to write
code such as:

@Currency("USD") double amount;

These annotations can be checked automatically using a compiler plug-in, such
as the Checker Framework [1]. The Checker Framework comes pre-packaged with a
units checker [2] along with checkers for null pointer errors, locks, string
formatting, security, and many more.

Java's domain-specific language (DSL) features aren't as rich as Scala's.
However, you could implement some DSL-like features using aspect-oriented
programming (AOP) tools or other similar compiler plug-ins.

[1] [http://types.cs.washington.edu/checker-
framework/](http://types.cs.washington.edu/checker-framework/) [2]
[http://types.cs.washington.edu/checker-
framework/current/che...](http://types.cs.washington.edu/checker-
framework/current/checkers-manual.html#units-checker)

~~~
jf5s2
I would strongly discourage the use of compiler plug-ins, especially those
which modify the bytecode. Not only does it make for code which is hard to
follow and difficult debug, but most of them break with each new JDK release,
often in unpredictable ways, forcing you to wait for updates.

Given the choice I always pick Scala over Java. Maintaining legacy Java code
with AspectJ, Lombok and other behind-your-back bytecode manipulations are
literally the bane of my existence.

~~~
bronty
There's two different issues here: (1) whether or not to use compiler plug-
ins, and (2) whether or not to use compiler plug-ins for metaprogramming.

Using plug-ins for automated analysis improves the quality of your codebase.
The annotations serve as a machine-checked documentation which make the code
easier to debug.

As you point out though, the benefits of plug-ins for metaprogramming (such as
implementing a DSL) is not always as clear-cut: you have to pay the price of
maintenance, much of which is not always obvious up-front.

You face many of the same issues when designing a DSL in Scala --- the DSL may
generate code that depends on a custom run-time or library.

------
kclay
Nice, seems like this would fit well for cryptocurrencies.

------
jf5s2
Nice work!

