Menu

Adam Rosien

Computation: “There is no try”

Often a complex, multi-step calculation requires your code to react to many circumstances. Typically you use exception handling to separate the normal control flow from error handling: Option<BigDecimal> result = Option.none(); try { result = compute(); } catch (WhateverException e) { // Perhaps rethrow. } if (result.isEmpty()) { // Perhaps retry, or set a dummy […]

November 09, 2010
Kevin Peterson
Kevin Peterson

Type inference puzzler

Does this compile? public class Puzzle { static Object one() { return 1; } static <T> T safeOne() { return (T) one(); } public static void main(String[] args) { int one = safeOne(); System.out.println(one); } } Take a look at it carefully and think before answering. Why or why not? Once you’ve thought it through, […]

August 31, 2010

Julien Wetterwald

Creating TypeLiterals in Scala

In case anyone wondered, here is how one can easily create instances of Google Guice’s TypeLiteral in Scala. Type literals are used for reifying types. def typeLiteralOf[T](implicit m: scala.reflect.Manifest[T]): TypeLiteral[T] = (m match { case m: ClassManifest[T] if m.typeArguments.isEmpty => TypeLiteral.get(m.erasure) case m: ClassManifest[T] => TypeLiteral.get(new ParameterizedTypeImpl(m.erasure, m.typeArguments.map { case n: ClassManifest[_] => typeLiteralOf(n).getType }.toArray)) […]

August 30, 2010

Pascal-Louis Perez

Type Safe Bit Fields Using Higher-Kinded Polymorphism

Refering to securities, such as stocks or bonds, is far from standard. We all know Apple’s ticker AAPL; But what about the Oracle of Omaha’s company Berkshire Hathaway? Google says BRKA, Yahoo! BRK-A, Bloomberg BRK/A and Reuters BRKa. Due to these oddities, every serious automated trading system like kaChing’s has at its core a powerful […]

August 13, 2010

Julien Wetterwald

I Can Has Invariant Mapz?

If I had to pick one of the major source of bugs in large refactorings I recently went through, it would probably be the bunch of methods in the java.util.Map interface which are contravariant on the key type. For instance, one can retrieve an element from a map using a supertype of its key type […]

July 29, 2010

Pascal-Louis Perez

We Need More Than One; Why Programming Languages Matter

When we started kaChing’s architecture, one core design principle was set in stone: our systems would be language neutral. We strive to combine the best ideas from all languages and employ a good number of them on a day-to-day basis (Java, Scala, Ruby, Python, bash, Clojure, Erlang and so on). We use simple data formats […]

July 26, 2010