mercredi 6 juillet 2016

The devil codes in Pramda - Wandering in the JavaScript Functional programming world

 Article originally published on Hello.js

As a Perl coder, I'm a big fan of functional programming.

If that sounds odd to you, think about all that features that are considered as idiomatic Perl :
  • List processing (map, grep)
  • High order functions (Mark Jason Dominus ;-) )
  • Lazy evaluation (iterators)
  • Lamda calculus (closure)

Functional programming is a fascinating thing but it’s not so easy to use consistently. We all love the concept, feel the inner power. We all use lists, closure, functions as parameter, but how many of us manage to fully apply functional programming everywhere and commit to pure functions and immutability ?

I recently discovered a wonderful library for functional programming in JavaScript that could help you embrace functional programming even more and I'd like to share it with you: it's called Ramda.
There are several other functional programming libraries (more on that below) but what makes Ramda so practical and somewhat unique is its combination of auto-currying and the design choice to put the data last. These two things empower you and give you endless possibilities through composition.

You probably already know how map and grep can compose to solve many different tasks in a clean way. Now imagine that Ramda offers you one hundred of such functions. The number of combinations, solutions and tasks that you can solve easily just explodes! *1
This might seem theoretical, but for a simple demonstration of how Ramda can ease your life, just read  “Why Ramda ?” by Scott Sauyet.
Among the other things that make Ramda so powerful, Iis its ability to mix with promises through ‘pipeP’ and ‘composeP’. Being able to use both functional programing and promises through a clean syntax is priceless to me.

I should also underline the fact that Ramda promotes immutability: it doesn’t mutate input data by default but still allows you to produce modified one through 'assoc'.
As a final note: Don’t be scared by Ramda’s API, it offers probably far more than you want,  but everything you need. Follow the easy path:  just pick/learn functions one by one.

That being said, it would be unfair to limit functional programing in Javascript to Ramda. If you'd like go further and explore the domain, here are some other projects that I'd suggest to examine:

The well known  'generic' libraries offer functional tools, like the venerable  underscore,  lodash and it’s speedy brother lazy to name a few.

The reactive programming world also provide functional features with RxJs, Kefir or Bacon for the UI.

And if you want to experiment immutability, the choice is your : You can climb on the shoulders of a giant and use Facebook’s immutable or favour speed with mori or try the frozen object approach of icepick.
In a future article I'd like to talk about my current favourite youtube tech channel : 'funfunfunction'  so stay tuned! It's a really great channel about functional programing, JavaScript and other topics of interest.


Oh, and if you wonder about the title:
I like Ramda so much that I wanted to use it in my daily work, and started to write a port in Perl: Pramda (Perl Ramda). Any resemblance to any film title is purely coincidental...

*1 Functions like ‘transpose’, ‘unfold’, ‘times’, ‘allPass’, ‘cond’ are the first examples that come to my mind, but I bet you’ll learn to love the others while using Ramda.

vendredi 3 juin 2016

JavaScript for Perl lovers.

Article originally published on Hello.js

This time I feel really qualified to write this article, because believe me, I love Perl ! I think in Perl, I dream in Perl, and I really appreciate the whole Perl community. I’ve been in love with this language for more than a decade but I decided that I needed a change.

I’ve already said in a previous article why I chose to learn JavaScript this year (instead of getting involved in Perl 6 for example) but let me tell you why you might also enjoy learning JavaScript if you love Perl. Perl developers form a very unified community that all too often, resist outside influences, but learning a secondary language as JavaScript can really be a very enlightening experience.

It’s expressive 

JavaScript, like Perl, is an expressive language. You get your work done with just a few lines of code. When talking about programming languages, I really like the tent analogy:

In a tent you have functional things (tent fabrics) whose purpose is to provide a function to the user (protect the user) and structural things (tent pegs) whose purpose is only to provide a structure to make the functional things “work”.

The same goes for a programming language, one part of the syntax serves the function and another part of the syntax serves the structure.

Perl and JavaScript and the other expressive languages minimize the structural part, whereas some other languages require more structural code like Ada, Java for example.

It gets the job done 

With a gazillion of available modules, you can do everything from highly dynamic Web pages, networking code, command line tools, daemons, desktop to phone applications. JavaScript right now is on a roll, it’s both a front end and a back end language through node.js and with the existent frameworks and libraries it goes as far as robotics. It’s powerful and practical. You can do a lot of things with it, quite easily.

There is more than one way to do it 

Let’s state it, I love diversity, I love choice.
Of course I felt overwhelmed at first when I delved into the JavaScript tools, but that was more the discomfort of learning a whole new ecosystem than a real issue. I’m still a programmer at heart and in mind, I think like a programmer no matter the language that I’m using, it’s only a matter of adapting to syntax and structure.

If I wanted for the “one best way to do it”, I probably would have gone for Python.

You’re at home 

  • Like CPAN? get NPM.
  • Use closure, functional programming, asynchronous programming, OOP? JavaScript has it all!
  • You think that blessing is a bit curious but an efficient way to achieve Object Oriented Programming? You’ll love prototypal inheritance.
  • Want more? What about an open and heterogeneous community, an efficient interpreter, lot of tooling (tests, modules, frameworks)

You don’t blindly follow the pack 

Remember all the silly things you’ve heard about Perl?
Imagine, just for one moment, that the same goes for JavaScript:

  • What if the language isn’t that slow?
  • What if the language enables you to produce quality software?
  • What if the quirk of the syntax (callback hell, hoisting etc) can now be managed?
  • What if the language enables you to code everything and not just Web Page animations?

Why don’t you check by yourself, you might well be surprised.


I don’t subscribe to the Perl is dying trend (In fact I think the contrary), I believe in Perl as a powerful and important language in the developing world. I’m not abandoning my Perl roots by learning JavaScript, I’m just growing as a programmer.
But, I must there are advantages here, the JavaScript crowd is bigger, and although that’s by no means a criteria of quality to me, it is an opportunity to meet even more interesting people or discover new paradigms/tools/ideas.


I hope I’ve presented plenty of reasons to at least make you take into consideration that you might love JavaScript as much as you love Perl. In any case don’t take my word for it, give JavaScript a try.
Next time, I’d like to get into the details and talk about code, if there are some area that you’d like to be covered, don’t hesitate to comment; Your feedback/suggestions are welcome.

dimanche 22 mai 2016

Why Javascript in 2016 ?

Many of my friends express their surprise when I say I chose to learn JavaScript in 2016.

With so many cool languages to learn, why using a "toy language" of the past instead of, let's say Haskell, Go, Nimrod, Rust (just to name some)?

First and foremost, for me it's not as much as learning JavaScript in 2016 as learning a new language in 2016. But whatever your reasons : not become fossilized, improve your efficiency with new tricks/paradigms/tools or just plain fun you'll probably feel the urge to learn a new language sooner or later.
This bring us back to the question why JavaScript in 2016?

Reason to choose JavaScript


It could be handy to be able to do everything in one unique language (from command line tools, front-end Web dev,  server coding, phone applications to robots programming) and JavaScript now allows that. That wasn't the case before but with node/express/commander/ionic/cylon.js (to name few) you'll have all your needs covered.
Data mining, 3D display, efficient network agents, whatever the task, you can do it efficiently in JavaScript.


Every study will tell the same story: Javascript developers are on high demand, and the demand is growing.
  • CodingDojo list Javascript as the 3rd top requested language.
  • give interesting figures on the growth.
  • ...
This makes JavaScript an excellent skill to possess.


When learning, the community is as much important as the technology studied.
I find in the Javascript community the same things I've learnt to love in the Perl community : efficient tools, diversity, an unorthodox/innovative/open/somewhat messy but pragmatic approach.
This community is easily reachable through the numerous quality blog and sites :


You could evaluate a language ecosystem by many ways but let's consider the JavaScript ecosystem by it's users base and by its language central repository.

The site modulecounts lists NPM as the first module repository whatever the language (be it for total modules count or average growth) and even if some things are to be improved, npm offer a really easy way to manage/reuse the impressive JavaScript's modules list.

Concerning the users base, a github study on languages (2015)  place Javascript as the top language.

That is just numbers of course, but whatever the criterion you choose, chances are that the Javascript's community will score well against all the other languages.


Although not as disruptive for your coding habits as another language (like Haskell) could be.
JavaScript brings many things to play with and extend your confort zone.
Want to play with asynchronicity (would be a good Idea if you still haven't done so in 2016 ;-) )? What about trying promises?
Want to try functionnal programming? Check Ramda or Immutable.
Love to explore new Web paradigm? I suppose things like React / Flux or Koa might interest you.
With the language itself being in constant improvement and the use of transpilers, even the syntax evolves regularly.


That's another area where JavaScript shines. As a developer, having  many configurable linters (JSHint, ESLint...), transpilers (Babel), test libraries/frameworks (Jasmine, Mocha, Chai, PhantomJS...), task runners (Grunt, Gulp) enable you to enforce good practices, better code quality/consistency and globally speed up langage learning.


For some the abundance of choice and constant change may be daunting.
But if you're not among them, be prepared, with JavaScript, to explore a world where there are always plenty of new options and no consensus on the "best" tools to use.
New tools/projects pop up faster than you can list them and issues tend to be solved in no time.


If you're embracing change, 2016 could be the perfect time to learn JavaScript.
I hope this article gave you enough information to convince you. In all cases, don't hesitate to comment and give your feedback.