QCon New York - Day 2: Garbage Collection on steroids
At monday the author attended a process related session about Kanban and that’s the reason tuesday should be about my other passion: programming. Within our company we already have focus on functional programming languages and with our knowledge events I learned a lot. However, I never made time to do some actual functional programming myself. Besides, I love the principles of reactive programming and also believe that it’s already applicable and will be applied more in the near future. Those are the reason’s I chose “Functional Programming in JS with focus on Reactive Programming (Rx in JS)” hosted by Jafar Husain from Netflix.
Well to summarize: I wanted to go handson and that’s exactly what I got! The session started with: Go to http://jhusain.github.io/learnrx/ and let me know if you have any questions…. And I had some…
The first couple of exercises are about applying and learning the basic concepts of functional programming with map, filter and mergeAll. When every attendee finished excercise 12, Jafar clarified what we learned so far with a couple of key points:
- – “The future of computing is describing WHAT we want to do, not HOW” referring to the difference between writing down code to loop over a collection versus only describing what we want from the collection.
- “With functional programming you write code, you come back two years later and it will run faster” making a key point to the fact of parallel and concurrent programming and that the computer itself wil best know in which runtime conditions it’s in.
- There is no need for a gargage collection; this is garbage collection on steroids meaning that someone or something else manages the state and you don’t need to be bothered with it and only think about what you want.
During the first 12 exercises I got the concepts but also experienced how frustrating it can be if you don’t know a language good enough to write down the concepts your thinking about because you’re wondering where to put the semicolon. Besides, at first I found it challenging to deal with these kind of deep collections and keeping up how far in a collection I am. Something Jafar as well referred to as one of the issues people face when starting functional programming.
In the afternoon Jafar started with a presentation about how the core concepts we learned this morning (about functional programming and collections) aren’t any different then asynchronous event handling. Bottomline is that events are actually an unlimited collection source over time. This was introduced very well by explaining design patterns such as the well known Observable pattern.
In the Reactive Extensions (RX) framework a datatype called Observable is introduced for Javascript. A dataproducer can push data to one or more consumers via the Observable type, as with events, and it can send a signal when it’s done with producing (for now) so that the consumer has the information to start processing data.
After a nice presentation the attendees continued with their exercises now fully focused on RX and asynchronous Javascript programming. How and when to use the mergeAll, concateAll and swithLatest is something you need to get used at. It is really amazing to experience that everything is possible with these three methods (if applied well) and with so few lines of code. For instance, if someone presses a button 10 times in a row (switchLatest) or to create UI effects when events arrive such as fading in and out a advert (real use cases at Netflic).
To conclude: Nowadays it’s all about Javascript and to be fairly honest: I don’t like it. Yes, I know it’s very powerful and one can create amazing things with it, but it’s also a language that doesn’t help a lot in writing clean code.