Interesting post. So, after quite some time, what's your opinion on Golang for fast trading systems?
Thanks!!
If I may chime in. Of course it always depends on your needs. If you and your system is highly mathematical, you'd maybe want to optimize using GPUs, ASIC, whatever. But that takes extra effort and time, which could be better spent getting everything to work together instead. So if you're like me, and want to avoid premature optimization and not afraid of later refactoring / rewrite,
if required, you could fancy "The Go Way". It promotes a simple and easy code style where you just write code as it is supposed to execute, and much of Golang is actually optimized to work highly efficiently out of the box.
There are some dark sides to Golang as well:
- It doesn't produce all logging-context needed in stack traces and doesn't point you directly to faulty code through exception handling. Java succeeded because it provides full function trace, though no additional / useful contexts like arguments, return values or contract-info. Golang provides even less in this area, is not hopeless, but you may miss errors or need to hunt down the right scope of the root cause on a few occations.
- Sometimes the default handling in Golang is directed at power-users, and you can spike your hand if you're not extra careful how datastructures are actually handled in the specification (which is quite short and simple), ie. types like arrays, slices and maps are handled in machine-efficient, but slightly different and unintuitive ways than other languages. These ways saves memory and CPU by default, naive use, but may sometimes provide unintended sideeffects and the rare WTF scenario.
That's it really. The rest is beautiful, lean and mean. Using it for trading, though on very slow timeframes like daily bars. You may compare Golang speed to Java and C#, and it could approach (probably not exceed) C++ sometime, has a very concurrent GC, especially in latest versions, and kept stable and mature so language, stdlibs and tooling don't change too much under your feet. In terms of runtime memory and compile times, it's faster and smaller than anything comparable, unless you go with C/C++ and especially like to inspect coredumps and fancy an illegal instruction or two. Yeah, Golang is made to be safe as well, but runs natively without VM and minimal dependencies. Can't complain.
Though Golang is quite easy to learn, it is really a language geared at the niche:
systems languages, like C, but with GC, safety and lots of standard libraries and tooling (though not exhaustively so). Golang is the programming language you'd want to use to build: cmdtools, databases, proxies, (micro)services, and yes, Trading systems.. Though
actual needs and
preferences always come first.