I Wrote Some Javascript, It Wasn't Horrible

This is going to be painful to write. Like many, I’ve sat back and watched the world go mad. I’ve always thought of Javascript as an ugly, awkward, ill-suited language for disabling buttons on websites that somehow accidentally became the most popular language in the world. I subscribed to the belief that it broke the web with bloated webUIs doing unnatural things, it behaves completely unpredictably, it spread to the server like a virus, it took over my window manager, and now it’s starting to take over mobile as well.

However I’d never really used the language the way it’s used today. We had a small Javascript component in Candlepin that let us transfer business logic from the upstream subscription service down to on-site customer Satellite’s and such, it was a nice feature and a pretty good solution to the problem, so we tolerated the language and used it minimally for this purpose.

Per my previous post I got to looking into React Native a few weeks ago and thinking about what it might mean if I could develop faster (Android’s pace is killing me as free time is in short supply), get really close to an iOS version for free, and open the door for a webUI all from predominantly shared code. I decided to test the waters by porting a core Java library from my NetWorth Android app over to a plain Javascript npm library. This means modeling some object hierarchies for someone’s financial situation and budget, some light financial calculations, and unit tests.

I’ve been working on this for the past few weekends when I could. I haven’t even made it to the really interesting part yet but my overall impression so far is that it’s just not as bad as I expected.

Using ECMAScript 6 syntax for defining classes/inheritance went a long way for me, it’s just syntax sugar but it made me feel a LOT better about what I was writing. (considering the alternative I think this is fair) By and large the objects behave like I would expect. The overall syntax still feels a little clunky in places, it’s definitely not Python, but I feel like I can work with it just about as quickly.

Despite this weeks debacle, npm was perfectly pleasant to use to define my library modules and add dependencies for what I needed. There are clearly some problems with using micro-deps, but it is easy to use and you can of course choose what you add as a dep vs write yourself. npm/nodejs also went a long way for me getting my head around how the language is used for generic libraries outside the browser, and how you run and test it locally.

Writing tests with Mocha was quite familiar, clean, and enjoyable.

Weirdly, I’m finding Javascript a lot more ready out of the box for financial calculations than Java, you’ll need third party libraries there to do exponents and logarithms. I haven’t gotten far enough to do a performance comparison of a big calculation 30 years into the future, will be interesting to see how fast the JS version is. It could kill this whole effort especially on mobile. However everything so far feels blazing fast.

While I just barely touched React Native thus far, this is what I’m really marching towards. From what I’ve seen, being able to spend my time in Vim instead of Android Studio is a treat. The Javascript / React Native code should be much quicker to write. Being able to live reload the app from a npm development server on my workstation, without having the phone plugged in, is very near revolutionary.

I’m still not sure I’ll ever complete this library let alone the longer term goal of a React Native rewrite, but I am enjoying the process, and I don’t really loathe the language anymore.

comments powered by Disqus