Live data from Hacker News

Facebook Launches Flow, Static Type Checker for JavaScript

code.prod.facebook.com

261–270 of 282 posts

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#261
post #103
post #78

Earlier quoted context omitted.

Well, here are some things that it does that other tools don't: - It type checks JSX - It supports some ES6 features others don't (like destructuring) as the build step - It has union types (TS will get those soon, already in master) - It does a lot more inference and a lot more assumptions. It assumes you won't multiply a string by a number for example (although technically '10' * 5 is legal in JS). So it's opiniona…

I digress but... you're not wrong, but out of curiosity, I just genuinely wonder how often modern programmers really hit type errors on smaller projects (obviously not FB size). I don't think I've ever had a type cast bug in my js code, provided we don't include accidental nulls in that statement. So in my experience, if I were ever told that I now had to always use annotations, I would feel like I was losing flexibi…

I have written a couple of thousand lines in an app the last year and I have already had problems with restructuring my app. Creating new modules and moving "classes" into them or splitting classes and renaming them are very useful things and those things get easier with types. Having tests actually don't help that much with this in my opinion since I have to rewrite the tests also. Also reading old code could get easier with some type information in the code. Just my experience so far.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#262
post #202

Earlier quoted context omitted.

I suppose he was talking about TypeScript and CoffeeScript.

CoffeeScript has no types. I have no clue why people keep including CoffeeScript when they talk about static type alternatives to JavaScript.

My bad

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#263
post #226
post #103

Earlier quoted context omitted.

I digress but... you're not wrong, but out of curiosity, I just genuinely wonder how often modern programmers really hit type errors on smaller projects (obviously not FB size). I don't think I've ever had a type cast bug in my js code, provided we don't include accidental nulls in that statement. So in my experience, if I were ever told that I now had to always use annotations, I would feel like I was losing flexibi…

I do hobby level small js projects, I make type errors quite often, but they are easily found the moment I run the tests/the app. I would prefer to find them at compile time, but it's not a big deal. Interstingly it's almost always the same kind of type error- accessing nested maps/arrays and forgetting to go deep enough before I call some method on the elements in that collection. I can't remember one example of typ…

And in a large app it is hard to know if all relevant code has ran. Finding pieces that uses the code you just changed is much easier in static languages. We might not go to a fully statically typed javascript but supporting optional typing seems like a really good idea.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#264
post #227

Earlier quoted context omitted.

Is this a serious post, or are you being sarcastic? I honestly can't tell. JS the language of the future? Why? It has probably the worst gotchas of any language I've coded in, it's verbose, and weird scoping. Nor is it especially nice to optimize for/with. I can certainly see being stuck with Javascript (just like we're stuck with the x86 instruction set even if simpler alternatives exist), but I'm not sure it's some…

From http://steve-yegge.blogspot.com/2007/02/next-big-language.ht... - Rule #1: C-like syntax - Rule #2: Dynamic typing with optional static types - Rule #3: Performance - Rule #4: Tools - Rule #5: Kitchen Sink - Rule #6: Multi-Platform This tool provides #2 for Javascript, the NBL.

He got Rule #2 slightly wrong, should be: "Strong static typing with optional dynamic typing".

Makes much more sense, but I am going to forgive him.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#265

There's some tremendous effort being poured into making a crippled language like javascript usable, but when talking about solutions for maintainable frontend code, I'm more excited about compile-to-js languages like haxe [0], purescript [1] or ceylon [2]. The caveats I heard about transpilers often boil down to difficulty of debugging and lack of libraries. But with the amazing browser dev tools we have, debugging p…

If everybody agreed that most other languages are much better and more productive than javascript then we should have had one of them in the browsers already. And if the problem is just social/organizational then we might never get anything better than javascript, in which case Flow is awesome.

I think Dart seems to be a great language and IE, Firefox and Safari should have implemented it years ago, but they didn't. Now I think TypeScript is a great addition to javascript and I hope they build it into the browsers but I suppose they won't (maybe EcmaScript 7 will have some parts of TypeScript in it, or parts from AtScript from Google).

By the way, you probably still want minification and concateneted files when you create js from other languages. That stops me from using them, I would have many levels of tools between my source code and the production code.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#266
post #164

Earlier quoted context omitted.

I don't think you're seeing my point. You may be coding java, but none of the tangible benefits of java over javascript actually translate, because you're actually writing javascript, with all of the warts and limitations and weirdness therein. The javascript exported will not be truly type safe, because javascript is not, and cannot be. It may appear to act like it, within the context of the code when run as predict…

The point is, that you don't have to deal with any of those issues with javascript. I've been using GWT for over a year, and I've never had to dive into the compiled javascript to debug something. I only ever edit my java code, and I compile it, that's it. Its exactly the same as your C code compiling to assembly, or the java code compiling to bytecode. You never have to look at the compiler's output.

I think Google created Angular in part because of some problems with GWT. Of course some developers still uses GWT but others have switched to AngularJs and seems to think it is much more productive. And some combines Dart with Angular which really looks interesting.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#267
post #226

Earlier quoted context omitted.

I do hobby level small js projects, I make type errors quite often, but they are easily found the moment I run the tests/the app. I would prefer to find them at compile time, but it's not a big deal. Interstingly it's almost always the same kind of type error- accessing nested maps/arrays and forgetting to go deep enough before I call some method on the elements in that collection. I can't remember one example of typ…

And in a large app it is hard to know if all relevant code has ran. Finding pieces that uses the code you just changed is much easier in static languages. We might not go to a fully statically typed javascript but supporting optional typing seems like a really good idea.

Yes I know, I mostly work in java these days.

BTW it's funny how many times late binding was reinvented in j2ee ecosystem :)

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#268

Can someone explain in simple words what is the problem that this would fix? I've never felt the need for this, why should I care?

It makes it easier to catch some types of bugs without having to run the code. http://en.wikipedia.org/wiki/Type_system#Static_type-checkin...

Thanks, I guess for those who separates runtime from devtime it might be a problem

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#269
post #58

Earlier quoted context omitted.

If only to remove syntactically invalid type annotations, I guess. Strong typing is not incompatible with the absence of run-time typing information, due to the magic of type erasure.

Type erasure is only safe if the whole program is statically typed though - you are still going to need to use runtime checks if you want to interface with dynamic code.

Based on the inference, we can imagine a case where Flow would flag certain boundaries as 'unsafe', allowing a transform to inject dynamic type safety checks using the same type information Flow has available.

For instance, you could imagine a function calling into some unknown api, where we would need to constrain the type of the variable to the expected one to avoid `any` being applied to it. While the library files do provide typing of external dependencies, this doesn't protect you from bugs in those libraries! The same applies to api's that are explicitly typed as `any`, but which should return a certain type.

Having Flow add a dynamic assertion on the type here would allow the rest of the program to remain type safe, knowing that a violation is guaranteed to halt execution.

While dynamic strong typing is also used at Facebook, we're not quite ready to launch this as an extension to Flow.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#270

Earlier quoted context omitted.

The point is, that you don't have to deal with any of those issues with javascript. I've been using GWT for over a year, and I've never had to dive into the compiled javascript to debug something. I only ever edit my java code, and I compile it, that's it. Its exactly the same as your C code compiling to assembly, or the java code compiling to bytecode. You never have to look at the compiler's output.

I think Google created Angular in part because of some problems with GWT. Of course some developers still uses GWT but others have switched to AngularJs and seems to think it is much more productive. And some combines Dart with Angular which really looks interesting.

GWT is open source and is being used / developed outside of Google, so it'll hardly be abandoned even if google left it. But Google is still using it heavily, see Inbox which just came out and uses GWT.

Also, angular and dart are slow as shit compared to GWT.

Post reply on HN