Emile Keith

Emile Keith

Future emperor of the world and all things code


What I write about


Recent Posts

I wrote a Cryptowatch Library in Dart

Sometimes you gotta get out of your comfort zone.

Recently I've felt like I was in a bit of a rut. I hadn't taken on any new career challenges since EtherWorldCup almost 2 years back (With the exception of a CompTIA Security+ Certification). While I've advanced a lot as a dev since then (working with great people helps), I didn't stray too far from my comfort zone. I wanted to make a change, I wanted to push the boundaries and get outside my comfort zone.

A bit of soliloquy; I have never build a GUI application. There, I've said it, it's out there, and I can't take it back. Well, I've built some GUI applications, but they were either quite simple or absolutely horrendous. The best GUI application I've ever built is LinkGuard:

https://github.com/infinityCounter/LinkGuard

I mean it literally doesn't get any simpler than this.

Anyway, so to expand the breath of my knowledge I decided to build a GUI App! A real big one! But that was a bit of a big step for me as I wasn't sure what to build, much less how. I mean I know how but I would rather not go back to the days of using C++ and Qt to try and piece together some frankensteins' monster. But I digress.

I decided to build a mobile app and was aware there were a few paths I could take. I could use any set of languages, sdks, and or frameworks: React Native, Xamarin, Ionic, Kotlin, plain old Java, etc. Frankly I had a lot of choices. I'm not going to play at being an erudite by explaining the differences between them, and their individual strengths and flaws, or why one should choose one or the other. There are a myriad of articles and blog posts discussing the topic, but this won't be one of them.

Eventually I settled on giving Flutter a try. Why? Simple, it was written in Dart, a language I'd only heard of once on the 2017 StackOverflow developer survery. I didn't know anything about it, and since I was already trying to get out of my comfort zone, it seemed like a good place to start.

Now I'm a firm believer in "A developer is only a good as his or her tools, but a tool is only as good as the person using it". It's a lesson that's been engraved into my bones after a few years of working with some really amazing folks. I'd spend time trying to build solutions, or find hacky ways to fix problems only for a teammate of mine to point out that there's a solutions for this in a dependency we're already using. I was trying to re-invent the wheel, and a shoddy one at that.

Dart was going to be my tool, so I had to get to know it inside and out. Not just how to use it, but what were the intentions behind its design, what is it good at, what is it bad at, did it accomplish the creators intended, and how? For programming lanugages at least, this kind of information is usually found in its most detailed form in books. So after reading a few reviewes I ended up purchasing The Dart Programming Language by Gilad Bracha.

https://www.amazon.com/Dart-Programming-Language-Gilad-Bracha-ebook/dp/B01929VVHU/

I committed to reading the entire thing before I wrote so much as Hello World. And I'll admit it was a bit thick, and put me to sleep a few times, but after two or three weeks I got through it (I'll probably give a review of the book and discuss the language some other time). As with all things, now that I had theoreitcal knowledge I needed to apply it before I could truly grasp it. I didn't immediately go to writing a mobile app in Flutter, because that was a whole other tool I hadn't learned about yet. First I wanted to build a proper foundation in Dart. Slow and steady wins the race as they say.

I like crypto, and charts, so obviously I love Cryptowatch (If you're reading, I'll work for peanuts). They have a REST API, and a websocket API. The websocket API in particular has trading support, so I decided to build a Cryptowatch SDK since there didn't seem to be one for Dart. SDK is a strong word, it's a really simple library, but I chose it because Cryptowatch already has an SDK in go (my favourite programming language).

https://github.com/cryptowatch/cw-sdk-go

I got to work and with the advice and support of the Dart style guide, I had a fully functional REST API client (Websocket API client still to be implemented). I documented it and added some unit tests, and babam I had a working library that could be imported into any Dart project, including Flutter apps! I've published it to the public dart package repository:

https://pub.dev/packages/cw_sdk_dart

The REST client that has full support for documented Cryptowatch market data REST API (https://docs.cryptowat.ch/rest-api/). Despite this I've kept the code in alpha, as there's still a lot of stuff I want to work on, and I might change just about anything. However I plan to add websocket steaming support for streaming market data relatively soon. I'll add trading support afterwards.

I spent a lot of time in particular setting up the tests. Tests in Dart remind of writing tests in Javascript, which I hate! But that is to be expected of Dart. Still I refused to write it! However what kind of dev would I be if I didn't properly test my code, or at least try. Don't get me wrong, I like writing tests. In fact I love Go's style of writing tests, but it would be unfair of me to expect that every language designer would feel the same, and I coudln't force Dart tests to be Go tests....or could I??

That's exactly what I set out to do! I attempted to replicate Go's style of tests in Dart using Dart's reflection implementation, Mirrors. You can see how I did it here: https://github.com/infinityCounter/cw-sdk-dart/blob/master/test/rest_client_test_suite.dart

I'll definetely revise my implementation more but I think I'm going to follow this general approach to my testing for the SDK, as sacrilegious as it may be.

At the end of the day I still haven't built a GUI application yet, but I'll get there. The next step is to get some context on Flutter by repeating the same process, and once I have both a good understading of Dart and Flutter, I'll be building my first mobile app. What that is gonna be, I'm still not sure yet. But you'll be the first to know.

"ex nihilo nihil fit"