Shared from Sylo's Medium account.
John Carlo San Pedro is a Senior Engineer at Sylo. Read on for a first-hand account from him of what it took to retrain in our programming language of choice — Pure Script.
‘Functional Programming (FP) differs quite significantly from the more popular programming paradigms of Imperative and Object Oriented Programming (OOP). Imperative programming describes computation as changes of state, and OOP attempts to abstract the real world into data structures known as “objects”, bringing together data and its associated behaviour in one place.
In contrast, FP emphasizes the avoidance of mutation of state, and treats a program as a composition of various mathematical evaluations. For developers like myself, who have spent years thinking in an Imperative/OOP manner, the stark contrast in approach, combined with the need to become familiar with various new mathematical concepts, makes learning functional programming to be fairly challenging.
It’s also undeniable that Imperative/OOP focused languages like Java, Python, and Javascript are far more popular than FP languages like Haskell, Purescript or F#. Even throughout my years studying software engineering at the University of Auckland, OOP was repeatedly asserted as the solution to producing simple, understandable, and maintainable software, whilst FP was barely mentioned.
So then why did I learn FP in the first place?
My first real exposure to the potential benefits of FP occurred within my first few months of working at Sylo. A co-worker of mine, Felix Schlitter, rewrote the entirety of our calling framework in Purescript; an FP language based off Haskell which compiles to Javascript.
It was clear that our calling framework could be improved, as we had issues with reliability and long connection times. Felix made the decision to rewrite the entire framework in Purescript, as the existing imperative implementation suffered from egregious mutation of state, lack of typing, and a general lack of conciseness. These problems made it difficult to reason with, which could be addressed through the use of FP.
The result of his work showed that there were great benefits to using FP for certain applications, as our calling connections became much more reliable, and connected significantly faster. Later on in the year, we kept finding issues with our End to End Encryption implementations and due to the success of the calling framework rewrite and the nature of our message encryption technology, these frameworks became clear candidates for a functional programming rewrite.
A large portion of the E2EE rewrite was completed relatively quickly, only leaving smaller tasks at hand. As I was involved in the initial implementation of our End to End frameworks, completing the remaining small tasks presented an opportunity for me to finally learn Purescript.
At first, I was enthusiastic to learn FP. Programming is something I genuinely enjoy, and I hadn’t learned a new language in a while. The idea of having to alter my approach to programming was exciting and it would improve my ability as a developer overall. I also figured that my existing experience with programming and learning other languages would provide a solid foundation for me to learn FP.
However, over time I realised that even though an existing understanding of Javascript and imperative programming is a prerequisite to learn Purescript, the shift in approach was distinct enough to feel like I was learning programming from scratch.
In retrospect, my approach to learning FP was also probably inefficient. I dove head first into the remaining tasks, and only referenced Purescript documentation as I needed it to complete the task at hand.
This approach was effective for learning other languages (due to existing knowledge), and I generally prefer to just get my hands dirty, rather than read through documentation and theory for several days straight. But I then realised I lacked enough knowledge in foundational concepts such as Functors, Applicatives and Monads for this approach to be effective. I also found these concepts difficult to grasp without significant effort.
Eventually I dialled back my approach and decided to learn the basics through actually writing code in unrelated, but simpler programs.
Another problem I faced was that Purescript was far less popular than common OOP languages. If you encountered a bug or error in Java, it was very likely that the solution to your problem could immediately be found on StackExchange or other forums.
With Purescript, not only are errors difficult to diagnose at first, the solutions are less readily available as well. Fortunately, my co-worker Felix was already highly competent with regards to functional programming and was enthusiastic to help me with any problem I encountered.
Over time, my feelings towards FP transitioned from excitement, to frustration, then finally satisfaction.
Once I became more versed in applying concepts like Functors and Monads, I started to see the benefits of functional programming. I began to appreciate how a lack of side effects and state mutation could improve understandability, and operations like function composition could improve conciseness.
It was extremely satisfying to finally have a grasp on a technology that I spent weeks struggling to learn. I’m also confident that having to think in a new approach will benefit my ability to write maintainable, bug-free code in other languages as well.
Overall, I’m proud of myself for being able to persevere through the challenge of FP, and I wish I was exposed to FP much earlier in my software development career.’
[link] [comments]
from Cryptocurrency news and discussions. http://bit.ly/2PDEn81
via
No comments:
Post a Comment