React, etc. Tech Stack

React, Flux, GraphQL, Hack, HHVM...? All of this and more!

Flow is a type checker for JavaScript, so what is it?

JavaScript has been and continues being a hot topic. In the last few years we've seen the rise and fall of libraries, utilities and other tools such as Angular.js, React, Mootools, CoffeeScript and more. Nowadays the ideal way to develop JavaScript would be to use a transpiler: a tool that allows you to write a future specification of the EcmaScript specification and compiles it down to something compatible and available to users today.

Transpiling your JavaScript from a future implementation of a standard like ES7 is a great approach. But the fact is that JavaScript is a dynamically typed language. In a dynamically typed language the type of the variable (string, float, integer) is not known at compile time. Statically typed languages like Java, C and C++ require the user to define the type of the variable each time.

On the server side PHP7 will also have improvements in regards to type handling. André Rømcke gives a good explanation of weak typing in his article discussing typing in PHP 7.0:

So weak type handling is basically a feature for the consumers of interfaces/methods/API’s, it allows the use of a interface to not care so much about type. While the implementation, written by a library developer, gets the exact type it expects, and nothing else. This should thus technically please both sides of the interface(/fence).

Facebook's own adaptation of the PHP language, Hack, also has type annotations: Hack Type Annotations

Type checking in JavaScript

For a scripting language such as JavaScript, using dynamically typed language provides an advantage as it lowers the barrier of using the language as a developer. This convenience also has a down side which often slows developers down; Bugs are harder to find and maintaining the code base of a complex application such as Facebooks web properties can become very hard.

Flow is a statical type checker for JavaScript from Facebook. Flow adds static typing to JavaScript to improve developer productivity and code quality. Flow is a tool that is run at build time of your application, usually with the build toolchain of your choice such as Gulp.js, Grunt.js or WebPack. Checking types is optional, so you do not need to apply type checking to your whole application all at once.

Learn more about Flow and how to use it your own project:

In addition to Flow, there are alternative implementations of static type checking for JavaScript such as TypeScript. Like Flow at Facebook, TypeScript is also used for ambitious projects such as Angular 2. Both are production ready.

Written by Jorgé on Saturday September 19, 2015

Permalink - Tags: flow, javascript, hack, php7

« GraphQL is SQL for Knowledge, not Data - Rendering React.js in Twig (for Drupal 8) »