Observables and Finnish Notation

Ben Lesh
3 min readJun 29, 2016

Once in a while I’m asked what I think about naming observables with an $ suffix. For example:

const click$ = Observable.fromEvent(button, 'click');

Well, I personally could take it or leave it, but I know some of you can’t live without it. What I want to write an article about, however, is the origin of “Finnish Notation” and different dialects.

Hungarian Notation

With Hungarian Notation, one adds a prefix to their variable names that denotes the type the variable contains. Generally, this prefix is about one to three characters in length. For example:

const sTest = "test";
const nShortPI = 3.14;
const obsClicks = Observable.fromEvent(domButton, 'clicks');

Pros:

  • In an untyped language like JavaScript, it becomes clearer what type might be in your variable.

Cons:

  • In an untyped language like JavaScript, sometimes variables like arguments to functions take more than one type, then what do you do?
  • It’s a lot more typing for minimal benefit.
  • May hurt readability in some cases?
  • With the advent of TypeScript and modern IDEs, Hungarian Notation isn’t really necessary in most languages, because the IDE gives you a lot of information about the variable while you’re working.

Non-Finnish Notation (ordinary variable names)

As a rule, I generally don’t use either Hungarian notation or Finnish notation with my code. Here’s what that looks like:

const test = "test";
const shortPI = 3.14;
const clicks = Observable.fromEvent(button, 'click');

Pros:

  • Generally easy on the eyes. Not a lot of special character clutter or non-words. Just words you can read that ideally signify the intent of the variable.
  • Easy to use in situations where a variable may store more than one type at any given time. This happens a lot in JavaScript code, whether it’s good practice or not.

Finnish Notation

This is a naming paradigm that I’ll attribute to Andre Staltz. Who is Finnish… Therefor, “Finnish notation”. The idea here is that you pluralize all variable names that contain observables. Like so:

const test = "test";
const shortPI = 3.14;
const click$ = Observable.fromEvent(button, 'click');

Pros:

  • Observables are REALLY easy to spot now. Before you might have just looked for a `subscribe` call or something.
  • Might be ideal for codebases where observable use is prolific. Things like Cycle.js or Angular 2 applications.

Cons:

  • Things aren’t always pluralized with an “s”, so $ doesn’t always make sense.
  • Why are we doing this with just observables? what about promises? or functions?
  • You have to reach for $ a lot on your keyboard (your IDE will probably solve this problem though)

Finnish-Goldman Notation

This is a sub-dialect of Finnish notation. This dialect comes from Sam Goldman. The idea is that it addresses one of the problems listed above, that some words are not pluralized with an “s”. In Finnish-Goldman notation, what you do is pluralize observable variable names with a unicode character that matches the last letter of the pluralized word. For example:

const oxeÑ = Observable.from(olleyOlleyOxenStream());
const mic€ = Observable.from(threeBlindStreams());
const peopl€ = Observable.from(allPeopleReadingThisNow());

So what do you choose???

The jury is out. But choose wisely, the fate of your entire project, and perhaps the WORLD depends on using the proper variable naming conventions!

--

--