Reactive Conf 2017 takeaways - Datomic, Logux and CSS with Elm
Some of my highlights and notes on the recent conference in Bratislava. 3 days, 2 tracks, lots of cake and some Angular.
@swannodette on Datomic
David Nolen of Cognitec and Clojure gave a good overview of issues we're experiencing today when implementing mid to large scale apps, before explaining how Datomic database might solve some of them. Some of my thoughts here inspired by his talk.
If you have a choice of investing into tests vs investing into a simpler system, latter is always better. Less moving parts mean fewer things to break and less time for debugging issues. You still have to invest time into designing simpler systems though. Making large and complicated systems is easy and straightforward in a short term, this is what we're all doing after all.
PLOP aka place-oriented programming - a term Rich Hickey used in his classic talk to describe our traditional approach to mutable programming. Originally was required by limitations of old computers with little memory available. Things have changed quite a bit since then.
Conventional databases in the system are effectively huge mutable variables with all the applicable consequences. Debugging large systems is hard because it is impossible to replicate the exact state of it during the issue. We've figured this quite some time ago for React - if the state of the app is immutable things become much easier to control. We haven't transcended, however (for the most part) beyond just the apps - our systems are still full of mutable parts making a life of a developer hard and miserable. Datomic is effectively an immutable database, like a huge Redux store.
I've tried setting up Datomic in the past though, and it was not an easy task. It is also not free, although they do have a free tier. It was also only useful for Clojure apps. Things are getting better, however - Datomic JS client is coming, and you'll be able to start a Datomic instance from AWS Marketplace in a couple of clicks soon. Even today people manage to run it for their Node.js apps, but that does require some setup.
- Couple of true classics - Rich Hickey - Value of Values and also Hammock driven development
- Out of the Tar Pit book
- How to solve it book by mathematician George Pólya describing methods of problem-solving
Focal from Grammarly
Neat FRP UI library from Grammarly and also used by them in web and desktop apps. Written in TypeScript.
Jest as a platform by Rogelio Guzman
Apparently, Jest is becoming a full-fledged platform. The good news is that gives us some neat customisation options, as well as allows to peek inside Jest itself.
As of today most of our unit tests are quite a mess of libraries and conventions. Sometimes it is Jest. Sometimes it is Mocha + Sinon. Add a bunch of extra tools for better mocking, reporting results, linting the code. What Jest is trying to do is to pick and swap parts of itself to other things you prefer. Will we ever end up with a perfect testing setup working with all apps? Probably not. But you could have conditions in that setup.
A basic lifecycle of a Jest run consists of
- Finding all the relevant files
- Running tests
- Reporting results
Jest contains tools for achieving that, quite a few of them. What you can do today is to pick the tools you need, leave out the tools you don't need, and replace some default parts with other alternatives. You can swap test runner to Mocha, or even write your own.
Jest used to be a highly opinionated test framework that made choices for you, but they are opening the hood now for everyone to tinker with.
Sean Larkin on Webpack and OSS community
I've missed the 2 hours long workshop on Webpack but managed to attend an AMA with Sean Larkin. The good stuff:
- There is a SurviveJS Webpack book, free to use.
- A fascinating insight into how community influences feature picking decisions and the overall development of the project. Also how to deal with frustrated members of the community. Apparently, you have to show them love <3. In the words of Sean "The best weapons against trolls is show that you care". The general idea is transparency of the backlog. Another important influencing factor is potential sponsors of the OSS project. A company might decide to sponsor your OSS so they could get a preferential treatment, which is totally fair.
- OSS is done best when done full time, but that's not really the news - and that's why sponsors are important.
Richard Feldman on CSS as byte code
This talk might've been also titled "Why you should use Elm for CSS", but we'll get there in a moment.
"CSS was never meant to be used for creating user interfaces"
Not really. Back in 1990:s HTML was conceived as a content-only language, but users wanted to make the content look pretty. So around 1996 CSS started to happen so that users could write it in the browser and format the content the way they wanted it to look. Yep, CSS was meant to be written by users. This explains my long-standing question on why there is default CSS in each browser - because this is where all of the CSS where suppose to be by design.
Things are rarely used the way they are originally designed. Well, most of the time, but not always. Today Web is the biggest user interface delivery platform.
We're quite used to JS transpilers as of 2017. Yes, we have a bunch of browsers with different implementations of the new ECMAScript features, but this is why we have handy tools to make the shiny modern code we write compatible with every outdated browser there is. Most of this today is done automatically. Compiled JS is effectively today's bytecode.
You could draw some parallels into the CSS world - there are PostCSS and LESS and SASS, and CSS3 is sort of happening. But the vertical positioning of a content is still a tricky thing (unless you're all flexbox that is). There's room for more effective tools offering more powerful features and transpiling it all into browser compatible CSS. Hence Elm-CSS. It doesn't just build on top of existing CSS conventions maintaining the old mindset of "oh well it's still CSS", but tries to invent a new UI building language, evolved from CSS but not inheriting any of its bad parts. You also get full benefits of this being written in Elm - all CSS in JS ideas work here too, but the code looks much prettier.
Igor Minar and Evan You on client side app optimisations
Make the client side app as light and fast as you can they say. The art of optimising frontend bundles slowly moves towards the dark arts - and both Igor and Evan did a great job at demystifying it. Most of the job is done by Webpack anyway.
Today there are handy tools allowing you to peek into the compiled Webpack bundle and see what's really going on in there. Source-map-explorer got a special recommendation, I've tried it - it totally deserves its reputation. You have to have a certain understanding of the needs of your code in order to use it effectively - but even deep diving into the unknown codebase might give you some insights. The trick is to look at the way the modules are imported and question the need to import the whole module or only the necessary parts.
There's also a flip side - when writing a module, make sure it is, well, modular. Allow clients to pick what they need instead of dumping everything into
Webpack is capable of concatenating modules, but not by default. For that, you have to enable
Code splitting is still a good idea. My general argument about it was the speed of HTTP requests on slow mobile networks - but this is where http/2 comes in handy - and you can totally use it today. Code splitting is very effective for single page apps where your landing page does not necessarily need the rest of the app straight away - something we still do almost always, letting our users wait for the whole thing to load before anything meaningful can happen.
Honorable mention - Webpack Dashboard from Formidable. "Now when you run your dev server, you basically work at NASA".
Prop based testing by Gave Scholz
When testing things we need test data. Most often than not the data would be hardcoded. Sometimes (if we feel generous enough) we might write a generator. The idea of randomised prop testing is to use generators that understand types of the objects and can generate unique objects every time within the set type.
Why would this be possibly a good idea? This is effectively introducing entropy into your otherwise perfectly isolated test environment. That's exactly why. To design a fail-proof system you have to define boundaries of it, and let the robots test those boundaries properly. An average unit test will perform a very niche scenario with a single given value out of sometimes millions of possible values. Sometimes it is possible to test all of them for every build. Sometimes not. Randomisation is a middle ground.
Andrey Sitnik on Logux in production
We're notoriously bad at handling errors when it comes to the client side. Well, maybe also server side. But mostly client side. The forgiving nature of an app in the browser is that once a user is frustrated, they can always hit a reload button.
This was not always the case - in a native app, there is an option of hanging helplessly and hoping a user knows how to kill an app that is stuck. Or throwing the whole OS into a BSOD state.
But I digress.
Single page apps are easy to get into a stuck state because they rely on a good network connection. Which is rarely the case. Andrey brings an example of the internet in China where packet loss can reach 40%. It's just the way it is, there is no way around. Network connection is actually mostly bad in most parts of the world. Africa, New Zealand and Bethnal Green are among these places. You have to face the fact and address it as a web developer.
Logux is a solution to synchronise app state with a server in a reliable, fault-tolerant way. You could sort of compare it to Apollo and Relay Modern in a way - but it is much more minimalistic, relies on WebSockets and doesn't force you to use GraphQL or wrap your React components into containers. Its API is Redux compatible. It allows you to define app actions and have central app state, parts of which are automatically synced to a server side.
The secret sauce is The Log (hence, LOGux). The log is timestamped and allows to figure out the ultimate state of the app at a given time. Logux also implements its own timestamping, since you can't really rely on clients, or, in some cases - even servers. All it is, in the end, is the log of actions, coming from either client or server. Once the actions are received and reduced to the app state, all of that is rendered and presented to a user.
Logux has grown to a version 0.2 since its announcement on React London conflict in March 2017 and is used today by Evil Martians in production.
- Did a vlog on the conference - check it out
I should probably explain why there are no fresh blogs here. The reason is daily vlogging.
For the past 43 days I would film an episode, cut it, and publish. YouTube is my primary platform for now. Every day a small short film is finished and revealed to the world.
This takes a bit of dedication, concentration, passion and self organising. Latter one is probably the most important. Editing, rendering and publishing of an episode takes anything between 2-4 hours, each day. That’s a significant chunk of time which just has to be made available. The rest of the day has also be organised into something that would offer an opportunity to film a short story. I’m still working on that one.
A simple recording of a mundane day is, well, boring. You have to do something about your life, then live through it, experience it and then pour it into a vlog episode. It is sort of like blog, which in my mind is a more refined form of self expression. You need to master the punctuation, wordsmithing, organise your thoughts perfectly and create a chunk of information filled with elegancy. For me to write a proper blog usually takes anything between one week to couple of months. Bear in mind the nature of a language which is not my native, although slowly becoming my first.
Podcasting is another beast. It takes a bit of preparation, then we generally are able to talk effortlessly into mics for an hour or two. You could release that straight into the Internet, but I usually listen to the whole thing and edit it. That takes another 2-3 hours. Podcasting requires less efforts to express what you think from the hosts, but it sort of outsources that onto the audience. They have to invest their own time into processing the information, which is rarely fine filtered, and in worth case scenario just a stream of consciousness.
In my mind vlogging sites somewhere in between. There is heavy editing process involved. There is also unpredictability of the, well, life. You plan for certain things to happen - and they don’t - and you have to embrace the day and live it to the fullest - literally make the best of it. You are constrained by the circumstances, but you have time and some resources to figure out a topic.
A single topic can make the film.
It is also pointless if you have nothing personal to say. Look - Big Ben.
I’m struggling every day, but it is huge fun. It pushes me to my human and artistic limits. It is highly challenging, there are no rewards, and it is exhilarating.
Let’s see how long this’ll last.
You can follow my struggles too.
Daily vlog live from the USSR
We're off to the epic trip in Russia, and I'm implementing a new season of the daily vlog. 5 episodes released so far, much more to go. You can follow our adventures on this YouTube playlist. All new episodes are being added there daily.
This is the longest stretch of daily vlogs I've ever done.
Expect Saint-Petersburg, Cherepovets, Vologda region, small villages, countryside, trains, metro, super fast boats from USSR times, lots of coffee, vintage soviet arcade video machines and hunt for rare vintage film cameras.
Freedom of movement
It’s early summer morning. I’m 15 years old. I and my mum are standing in a long crowded queue outside of the embassy of Finland in Moscow. The consulate reception is not opened yet, but the queue is already impressive. Tourists, businessmen, travel agents. Our case is somewhat different - a couple of months ago I was picked as an exchange student to be sent to a foreign country, together with another dude from our college. We’re not from Moscow. We’re from Cherepovets - a small town the size of Helsinki, famous for the density of local factories and purple clouds around the industrial area.
Cherepovets is considered the largest town in the region, and in my first 15 years of life I never been to Moscow. Up to that point, Cherepovets was my biggest town, cultural centre and the place to be. The general path of a career in Cherepovets consisted of finishing the school, getting into a professional school, maybe local university, doing a summer internship at one of the factories, and eventually working for the next 40 years there. Your freedom was largely represented by the variety of factories. You were free to pick from a chemical factory, matchstick factory, ship factory, dairy product factory. Despite that, you would likely and inevitably end up working for a metallurgical conglomerate, one of the largest in the country. In fact, the college I ended up after the school also belonged to that corporation and was in practice an incubator for the skilled people going straight to metal production.
There was a student exchange program however with a small town in Finland. Most of the towns in Finland are small. This one was especially tiny, with around 20k people, far up north, next to the gulf of Bothnia. What made is special is that also had a metal production plant, a professional school and a university.
Let’s recapture for a second. I’m a 15 years old dude from Cherepovets. I need to get to Finland. How hard can this be?
Normally you’d get your passport at the age of 16. You can apply earlier, but you’d need a special reasoning for that. I think it took me about few weeks to get that done.
Passport for travelling
In Soviet Russia, no one needed to travel abroad, since everything was perfect in the place of your residence. If you did need to travel, that would require you a bunch of paperwork, recommendations from you place of work or study, release papers from the army, background checks by the KGB and lots of questioning. This has changed slightly after the USSR was gone, and a new era was begun. Slightly, but not hugely. You would still need to apply for a special passport that would have your name written in latin letters, and be valid for foreign visas.
And of course, you would need to have your “main” passport done first.
It took an impressive pile of paperwork and about a month (I think) to get the travel passport done.
Because I needed a student visa valid for a year, I had to travel personally to the consulate of Finland in Moscow. I should mention that if you’re a lucky resident of Saint-Petersburg, you would also find a local consulate in your town. Everyone else had to travel to Moscow. I mean, I was lucky to live in the European part of the country, just a train day away.
It also wasn’t really well organised at the consulate. No appointments, a live queue outside of the fence, then getting through the security inside of the consulate and queueing to the bulletproof reception windows. Most of us were also hastily filling up the long forms and glueing profile photos. Another impressive pile of papers, forms for myself and the second dude who was also picked to be exchanged. Finally, we’re told to wait for a month, call and check on the status. After the decision is done you’d have to come down again (just a day on a train away) and pick up the passports.
We got visas 2 months later and an extra slice of bureaucracy from Finnish consulate - one of the papers was missing and they delayed the answer for an extra month, up to the point when we already needed to go.
All in all, 4 months of paperwork, and you were good to go.
Sometimes I feel like people don’t appreciate the freedom of movement. This is largely concentrated around people who have always had it. It’s one of those things that feel essential while you have it, but you are shocked once it is taken away.
As far as I know, freedom of movement implemented in the EU is unique and only experience, that no other union or country has done. At least not on the same scale. Can you consider the United States as a bunch of different countries? A bit, maybe. But culture wise Europe is an amazingly diverse package, bundled with a million of different languages, foods and traditions. Yet somehow there’s an agreement to let everyone (within the Union) travel and work freely, anywhere you want.
With zero paperwork.
I remember my first time crossing the border of Finland and Sweden. We were driving in a car. It was forest, then more forest, then a bridge across the river. And a sign saying “Welcome to Sweden”. No delays, no paperwork, no one guarding the border with a barbed wire. I was shocked.
At this point, you want to be a part of this amazing thing. You want to be part of the EU, contribute, and make it even better. You make it the purpose of your life. Because this is one of the most amazing things humanity has ever achieved. Instead of fighting each other - give everyone freedom to live anywhere you want, to be anything you want. Free medicine, free education, social support for everyone in the union, doesn’t matter which language you’re speaking. That’s something that inspires you.
This is humanity at its best.
A very special cookie
First few countries you visit while living in Finland are most likely to be Sweden, Norway and Estonia. This is when you learn that Norway is not in the EU, but somehow the border between Finland and Norway looks exactly the same, as between Sweden and Finland. No one is guarding it, and if you miss the “Welcome to Norway” sign, you might later notice that speed limits have changed, as did colours of the road signs. This is when you start learning about the special status of the Norway. In addition to the EU, there is the Schengen agreement. You might not be an EU citizen, just a tourist (or a student) - but you’re still going to enjoy a good portion of the same freedom of movement as the EU citizens do. Yes, you will not be able to work in another country, but you will be able to freely visit almost all of them. And more - as in the case of Norway, which is not even a part of the EU.
As you progress in your travels and reach the farthest reaches, you are likely to encounter an ancient island of Britain. This will be another eye-opening discovery - despite the UK being part of the EU, they will not let you in with a Finnish visa. The reason being that the UK was never a part of the Schengen agreement, hence you have to apply for another visa. The UK visa. Unless you are a proper EU citizen, in which case you can freely come and go as you please.
My first visit to the UK was in 2009. I’ve filled 36 pages long form - this achievement still holds my personal record for being the longest form I’ve ever filled in my life. Paid 90 euros of processing fees. Arranged an appointment at the UK consulate in Helsinki. Gave up my fingerprints and retina scan. All of this only to find out that they are unable to process my request. The reason being that I was planning to travel in April, while my Finnish visa was expiring in May. According to The Rules, a visa from the origin country must be valid for at least 2 months after my visit to the UK is concluded. I guess the UK was secretly afraid I’d illegally stay on the island.
Now let’s combine the bureaucracy of one country with the bureaucracy of another.
The Finnish visa that was about to expire was, in fact, 3 years long visa. After that, I could apply for a permanent residentship (doesn’t equal citizenship, completely different topic). However, because I had to renew it before full 3 years of that visa would expire, I couldn’t apply for the permanent visa just yet. At that point, Finland gave me 4 years long visa, and I could finally apply for a UK tourist visa.
I’m sorry for the amount of the details, but I really want you to feel the absurdity of the whole system.
The problem is, it doesn’t feel absurd at all, as long as you don’t think about it. This is the way we’ve arranged our travels for a past couple of hundreds of years (we all know that before that you’d simply gallop into another country on a horse while swinging your sword).
London was a nice place in 2009, but somewhat unattractive in terms of interesting software related jobs. And back at home Nokia was still dominating the world - although some signs of the decay were coming through. The most talented software people in Finland would likely be employed by Nokia at a time, and then maybe poached by one of the Silicon Valley -based companies. Fast forward 5 years and everything has changed. Nokia is no more, and London somehow managed to turn things around and became one of the most attractive places to work in the software industry. I also got my EU citizenship and could finally exercise proper 100% pure freedom of movement. You would think that the story ends here with a nice happy ending. That’s a big fat nope.
While I was living in Finland I got married to a girl from Russia. She got Finnish residentship (~6 months of processing and 150 euros in fees). Then we moved to the UK. She got the UK residentship (~6 months of processing with both her and my passports taken by the Home Office). Unlike Finnish residentship, UK residentship sucks at freedom of movement - it is simply not appreciated anywhere beyond the UK borders. Not even in the Commonwealth Countries (a term you learn after moving here). UK residentship allows you to stay in the UK, and that’s about it. If you’d like to travel to the EU, you have to apply for a visa.
I did quite a bit of research on this topic. Technically there is an EU law that allows family members of the EU citizen to travel without a visa. However, people tend to agree that explaining this to a Ryanair employee might not get you on a flight. So, let’s be honest, the law doesn’t work and you need a visa.
Things get more interesting at this point. You can apply for a normal tourist visa (~£60 fee), or a family member visa (£0 fee). You will still have to fill in a lengthy form of a country you want to visit, attach profile pictures (£10), proof of address (free, but you have to order it at least 2 weeks in advance) and marriage certificate (phone call to Finnish magistrate, 27 euros of fees and 2 weeks of delivery). Family member visa only allows you to travel together with your “more entitled” family member. Same-sex partners are ok. If you want to travel alone, you would still have to apply for a normal tourist visa.
Once again you’ve probably noticed how quickly things became complicated. Let’s for a moment compare this to a scenario when you have a residence of a Schengen area country. You want to visit another EU country - you jump on a flight and go.
My wife could eventually get a UK citizenship (7 years of residence, £1200 in fees), and we could both enjoy a freedom of movement. However, Brexit happened. The UK is aiming at the Norway special cookie case. Considering that the UK already was a special cookie within the EU, that makes them a very special cookie. However, it’s not going to be exactly a Norway case, since Norway is a part of Schengen area. Freedom of movement is something the UK residents wants to limit by all cost. This obviously cuts both ways, but sometimes you have to get what you really want. From the freedom of movement perspective, UK citizenship gets massively devalued. You’ll get to stay in the UK, but is it something you really, really want? Home Office is inflating immigration fees and tightening rules, Brexit campaigners want immigration to stop completely and get all the foreigners out. And let’s be honest, the best way to do that is to ruin the country and make it complete unattractive on a global scale.
After living in a few countries you start to view the world from a different perspective. It’s a hugely diverse world, but it should be open for everyone. Freedom of movement should be universal. It is likely not to happen on a global scale anytime soon. But somehow the EU made it work on a significant part of the planet. This is an incredibly huge achievement.
Implementing freedom of movement is considered hard and is opposed by many people. But it transcends us as a humanity. This is when you start thinking about the planet as a whole, and not just about your personal lawn. And we are having global problems on our hands - like the ever heating planet that might as well destroy all of us tomorrow, despite the residence statuses or saving accounts. Should we maybe grow up a bit, develop a sense of empathy and maybe just a tiny bit of tolerance for each other?
And, eventually, cancel all the paperwork.
Agfa Flexilette twin reflex 35mm camera
TLR means twin lens reflex. Unlike SLR:s, TLR features 2 lenses and a mirror. Most TLR cameras are made for medium format film. 35mm film TLR:s are a rare breed, Agfa Flexilette being one of those.
Flexilette itself is a rare find. It’s been manufactured in 1960-61, succeeded by Agfa Optima Reflex camera. Agfa struggled to compete with the growing range of SLR cameras and gave up after producing these 2 models. Today Flexilette represents a unique camera with an unusual design, waist-level viewfinder, twin lenses, durable mechanics, and it is guaranteed to draw at least some attention in today’s world full of technology.
We got Flexilette during one of the recent camera fairs in Westminster. In perfectly working condition, with original case. Since then I’ve been using it as an everyday 35mm film camera, compact enough to always fit into my backpack. It is not the lightest camera, most of the body is made of metal after all. But it feels very good in hands, with no sharp edges, nice and rounded body and easy to press buttons.
Now that you are the proud owner of an Agfa Flexilette twin-lens reflex camera you will be able to take wonderful photographs as a constant reminder of the past. You are to be congratulated on your choice. — Official manual.
A word of warning if you are reading this on mobile connection - this post contains lots of pictures.