Live data from Hacker News

Facebook Launches Flow, Static Type Checker for JavaScript

code.prod.facebook.com

111–120 of 282 posts

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#111
post #101
post #94

Does someone know how these types of projects come to fruition in a big company like Facebook? Are people working on them full time (with no other workload)? Do engineers build them on the weekend? How do they get 'funded'?

That is a surprisingly hard question to answer. I think the key is that these projects actually provide value - they make things faster, more reliable, more scalable - whether that's the code's execution or the people writing the code (or debugging issues, or whatever). They generally aren't solutions seeking problems - they are responses to problems that exist. Engineers generally don't build things like this on the…

It sounds like there is enough slack in the schedule that teams can decide they want to spend non-trivial amounts of time on these projects. It's surprising to hear that anyone, even the companies with big budgets, are able to hire enough people to do this without the projects getting an official seal of approval and budget. Even just taking the time to document, package, and publish is non-trivial.

It seems like the vast majority of companies are not far enough out in front of their production issues and requests from the business side that engineers could do this sort of thing. So I guess it's impressive that Facebook (and probably Google) are in that position.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#112
post #104

Looks like a great tool. The documentation at http://flowtype.org/ is excellent. Should be easy to add it to a Gulp/Grunt workflow.

I'm confused by the usage of the utility itself. I ran it on the hello.js, and it reported the expected type mismatch. I then tried to run it on the file in the answer sub-directory, but it kept telling me about the previous file.

That's because it checks every file that has /* @flow */. I'm guessing you're not running it on a specific file but instead on all files in the current dir and sub directories.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#113
Or you can just use GWT which saves you from having to use javascript at all, and lets you write java (along with all its IDEs, type checking, code structure, and other benefits) which is compiled to highly efficient javascript: http://www.gwtproject.org/learnmore-sdk.html

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#114
Make sure to checkout http://ternjs.net/ too. It does not have types validation I believe, but it does many other things and in combination with eslint allows catching most errors before packaging.

Tern.js actually detect types, and may be it would be possible for eslint to incorporate it somehow to detect invalid use of types.

One big ternjs plus for me is the fact that tern.js knows about require.js modules and can look in other require'd files.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#115
post #101

Earlier quoted context omitted.

That is a surprisingly hard question to answer. I think the key is that these projects actually provide value - they make things faster, more reliable, more scalable - whether that's the code's execution or the people writing the code (or debugging issues, or whatever). They generally aren't solutions seeking problems - they are responses to problems that exist. Engineers generally don't build things like this on the…

I find this type of work within companies (like google's famous 20% rule) an interesting contrast with non-tech companies. At a "normal" company if you attempt to spend time doing something of this sort, you'd get immediate pushback from higher ups who would likely say "this is not our core competency". With the secondary excuse being that they would not want to release any work like this for fear that it would help…

Different people find different things exciting/sexy to differing degrees. Some people like building stuff that others can see. Some people like building stuff that others will use. Some people like building stuff that makes other people build stuff faster. Some people like building stuff that is highly reliable, really fast, really scalable, or really efficient. Some people even find improving advertising really exciting - they expound on how ads can be win-win, and even that they can only find their full effectiveness when they are, or something like that.

I don't think anyone is "avoiding" any work - there's just tons of work that needs to get done, and people mostly choose to work on that stuff that interests them. One could say that product engineers "avoid" infrastructure work and infrastructure engineers "avoid" product, but I think that would be inaccurate in most cases.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#116

Or you can just use GWT which saves you from having to use javascript at all, and lets you write java (along with all its IDEs, type checking, code structure, and other benefits) which is compiled to highly efficient javascript: http://www.gwtproject.org/learnmore-sdk.html

"Java" which "compiles" to javascript is not Java. It's javascript with a ludicrous amount of syntactic sugar applied.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#117
post #14

From my perspective, the static type checking is more or less the same as TypeScript's `--noImplicitAny` option as the first example on flowtype [1] shows, the same can be achieved with tsc --noImplicitAny hello.tsc which will result in hello.ts(2,14): error TS7006: Parameter 'x' implicitly has an 'any' type. I do not see much difference. [1]: http://flowtype.org

Is there any reason we cannot use both TypeScript and Flow.

Besides perhaps the extra 'compile' time added to do both translation with TypeScript and then static analysis with Flow. Both tools have their advantages and disadvantages.

May as well throw in a linting tool as well..

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#118
post #44

Earlier quoted context omitted.

Strongly typed JS is actually pretty hard - probably not by Haskell and Scala standards - but if you take promises for example the signature of `then` is: Promise -> ((A -> (Promise | B)),(E -> (Promise | C))) -> Promise That is - a promise's then - takes the promise (as this) and executes either a `.then` fulfillment handler or a catch handler. If the `fulfill` handler executes the value is unwrapped and either a ne…

I don't want to say what I'm about to say, but... I don't care about the type signature of promises. I actually don't care about the type of anything which has a complicated type; I think it's just incredibly winning that I will now be able to describe the shape of the raw data circulating in my code. I've always found really annoying, in Haskell, to see incredibly complex type idioms emerging to allow stuff that doe…

I'd like to argue from a Haskell backend perspective that monad transformers deserve exactly the complexity they expose. They give you a handle to factor side effects in sensible ways and to express that code requires exactly some set of effects and no others.

It is not always clear how to factor code which does not have this rigor into effect-typed form. It can be extraordinarily difficult to recognize what effects are being carried out in which parts of code at first—especially if you haven't been forced into the discipline early. Thus, I find it unsurprising that you feel the translation effort is challenging.

But, coming from the other angle—building things with well-defined effect typing from day zero and composing pieces atop one another to reach your final complexity goal—works exceedingly well. Better, it forms a design which can be translated to untyped settings and retain its nice composition properties.

Which is to say not much more than: there is some logic to all that madness and once you're on the "other side" it's hard to judge these "incredibly complex type idioms" as anything other than useful and nearly necessary for sane code reasoning.

I miss transformer stacks a lot when using other languages.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#119
post #54

At last! This all seem extremely cool. I went straight from hacking Scala and Haskell as a hobbyist to doing (mostly) front-end JS job, and I've always found that my code, and a lot of good libraries I read, naturally emulate something close to Hindley-Milner typing, by using objects as tuples/records and arrays as (hopefully well-typed) lists, as well as the natural flexibility of objects as a poor substitute for Ei…

You can't really use sum types as they are found in Haskell in Javascript. With Haskell option types you do a pattern matching and create a new binding for the non-null value but in Javascript you don't do that - you keep using the same object that you tested against null. case mx of Just x -> f(x) vs if (x != null){ f(x) } What you can do in a Javascript-like language is use union and intersection types. However, th…

What about

  function nothing() {
    return {
      match: function(cases) { return cases.nothing(); }
    };
  }

  function just(x) {
    return {
      match: function(cases) { return cases.just(x); }
    };
  }

  just(1).match({
    just: function(x) { return x + 1; }
    nothing: function() { return 0; }
  });

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#120
post #68

This looks like such a better step in the right direction than than the types of tools MS and Google have been putting out. Dynamically discerning the underlying code, and allowing optional type annotation works _with_ javascript, as opposed to attempting to turn js into a completely different (and weakened) language. That said, I am curious what solutions this solves that isn't already solved by enforcing good code…

>That said, I am curious what solutions this solves that isn't already solved by enforcing good code coverage.

The (supposed) need to have "good code coverage" is itself a problem I'd like solved.

Post reply on HN