Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Hey! Author here - let me know if you have any questions about anything in that post (or, you know, anything else... like, erm, Electron).


> To improve our situation, we decided to give static type checking a shot.

I wonder why it took you years to realize this. I'd never use a dynamically typed language for more than a few hundred lines of code, it becomes an unmaintainable mess afterwards. So serious question: Why?


It's probably worth pointing out that Slack _also_ contains a ton of native code, written in C++ (with a bit of C++/CX and Objective-C). All of us on our small team have an extensive background in typed languages, including giant code bases (Windows, for example).

We just also happen to really like JavaScript, feeling that it and the ecosystem around us makes us more productive given our needs. TypeScript a few years ago was simply not good enough, and neither were the alternatives.

It's okay if you feel otherwise, but trust that there are quite a few developers out there who are comfortable with building and maintaining rather large JavaScript codebases, building pretty impressive applications with it. This post isn't yet another "JavaScript is terrible" rant, I quite like it.


In case you are wondering about the downvotes:

There are millions(trillions?) of lines of code out there that is maintainable and dynamically typed.


Maintainable, but at what cost? A large chunk of unit tests for dynamically typed code is dedicated to checking types.


I'm right there with you, but dynamically-typed languages still have their advocates (though it seems they're losing out more recently).

(I think this is because a lot of the advantages associated with dynamic typing were in fact portable back to statically typed languages. If you're comparing C++98 to Python, the dynamically typed language seems pretty nice. If you're comparing Javascript to Golang or TypeScript, not so much.)


When discussing static-vs-dynamic typing and the argument from the dynamic advocate is "I don't want to type types everywhere", the debate is over.

There are a few valid arguments in favor of dynamic typing - but that isn't one of them.


I have to ask the obvious, Flow vs TypeScript. I'm sure as React users you took your time weighing the two; care to comment on what drove your final decision?


I'll be careful not to tell anyone not to use Flow - we're using many of Facebook's tools and we're grateful for their gifts to the community. If Flow works for people, that's great!

That said, back when we got started, we found that TypeScript is all around a better team player. For us, we found that it worked better with npm modules, different operating systems, vanilla JavaScript, and various coding tools (VIM, Visual Studio Code, Atom, etc).


I 've used both. Flow wins hands down:

(1) It is less intrusive. Flow's type system is built on annotations which are simply stripped away at runtime (as opposed to writing in another - albeit similar - language that gets transpiled to JS. Sure the transformations are always "file-local" as TS folks say but still it is another, totally unecessary level of abstraction and transpilation.

(2) Flow's type system is at least equally and quite possibly much more expressive and nuanced than TS.

(3) Flow annotations can be applied in a much more piece-meal way than TS.

(4) zero issues integrating with 3rd party libraries (because of 1) - and that includes the ability to type-check said 3rd party libraries (which is a breeze with flow-typed)

(5) To take advantage of TS you have to write JS code in the "JS with classes" style (a.k.a "JS for C# coders"). In contrast Flow allows you to take advantage of its type checking while coding: (a) in idiomatic JS (prototypes) (b) in JS with classes (c) any combination and mix of the two approaches. Flow feels a lot less opinioned as to your JS programming style.

(6) Flow it is not coming from microsoft (but hey, don't you know we've changed, please give us another chance and we won't fuck you over this time, please we love you so). TS team is trying very hard (perhaps too hard) to distance themselves from the negative brand value of microsoft

(7) Flow is not a blueprint for the Mother of all embrace-extend-extigunish strategies (see #6).


I have not used Flow, but there's a few misconceptions about TypeScript in the above comment.

- There's an implication that Flow is vastly different than TypeScript because its annotations are stripped away - that's how TypeScript works too.

- There's an implication that TypeScript has some sort of unusual syntax - Modern JavaScript (ES6+) and TypeScript code is identical (except for the addition of type annotations where desired).

- Flow may have a nuanced and expressive type system - I don't know - but TypeScript attempts to accurately model the type system of JavaScript.

- TypeScript can be used in a very loose mode where it type-checks plain .js files with no annotations at all, all the way up to a very strict mode where it must know the type of everything (which you can set to `any` on a per-variable basis if you don't care).

- TypeScript is JavaScript, so it has no issues integrating with any JavaScript library. If you want perfect strong typing of a given version of a given JS library, someone has to do that work and this is where some people do struggle. Microsoft has put forth a lot of effort to help here recently. Flow-type may be a great resource (I don't know), but I can scroll its list of supported libraries on its repo on GitHub. https://github.com/flowtype/flow-typed/tree/master/definitio... . The DefinitelyTyped repo breaks GitHub with the number of libraries it has definitions for: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/mast... (nearly 2000 entries are omitted).

- Item 5 is flatly false. For example, TypeScript is itself written in TypeScript and there is not a class in the entire code base - it is 100% idiomatic functional JS. By contrast, Flow is not self-hosted.

- Regarding item 6, TypeScript is the poster child for the new Microsoft. It has been open source (Apache 2.0) and cross platform from its original release in 2012. And regardless of what happens with TypeScript (I forsee it tracking ECMAScript standards for the next several years at a bare minimum), the emitted JS is basically identical to your TypeScript code (minus the annotations) so worst case scenario if Microsoft somehow magically deleted all copies of TypeScript in the world, you'd just keep going with the ES6+ code you have.


I'll go out on a limb though and posit that classes are now idiomatic JS when doing OO. Shops are not cutting modern JS with objects built up via direct prototype manipulation.


Dunno, but I hope not. We built a moderate-sized TS codebase with _no objects at all_. Just functions and data types. Roughly functional ... with the caveat that nothing was preventing us from mutating incoming params (though our intent was not to do so).

I'd like to hope many people are using TS in a functional style.

EDIT -- there was one object ... we had to create an exception class for some reason ... don't fully recall the details.


It's a bit wordy, but I think you can do something like:

    function test ({param1, param2}: {readonly param1: string, readonly param2: number}) {
        return
    }


A codebase with no objects... I am guessing you mean no classes.


Seeing how functions are objects in JavaScript and all...


:rollseyes:


Agreed. ES6 class syntax is superior to constructor functions and prototype mutation, because it's declarative and statically analysable.

I think the only legitimate reason left not to use ES6 class syntax is (for perf sensitive code) performance, but that's a negligible and temporary problem as the JS engines will fix that over the next 6 months.


Thank you. I wanted to say almost exactly the same thing, but you worded it much better than I could have.

Point number one in particular bothered me since both languages are transpiled (in both cases that just means types stripped). However, I think MarcusBrutus was talking about Flow type comments which can be added to Javascript files to get type checking, but which will not need to be transpiled at all as all nonstandard stuff is in the comments.


Flow is not a transpiler, there is no concept of "emitting code", only of stripping away the annotations. In contrast, TypeScript is a transpiler. TypeScript being a transpiler means what gets executed at runtime is not what you wrote but some other sources emitted by the TypeScript transpiler. You say that presently (apparently due to the delta between ES6+ and TypeScript being currently very small) what is emitted is not materially (for some definition of "materially") different from the input sources. Even if that's true, this is simply a transient situation that may not hold next year (we're still in the "embrace" stage after all) and certainly didn't hold when I looked at TypeScript circa 2013.

Otherwise, can you please explain why bother implementing a transpiler if the emitted sources are identical to the input sources minus the annotations?

Even the names should give you a hint: "TypeScript" is a language name (the microsoft version of ECMAScript more specifically). "Flow" is not. That's why it's called "Flow" and not "FlowScript".


Realistically, you are going to do the same thing with TypeScript and Flow, except with different tools: with TypeScript, you'll use the transpiler, and with Flow, you'll use Babel. In technical terms they are different, sure, but in reality they're basically the same. Unless you use the comment style Flow types, you will have to run your code through some stage to remove the types.

> TypeScript being a transpiler means what gets executed at runtime is not what you wrote but some other sources emitted by the TypeScript transpiler.

This is also true with Flow, if you want to be technical. What you write with Flow is not valid JavaScript (with the sole exception of comment style types) but some other sources emitted by another program like Babel.

If you haven't looked at TypeScript in 3-4 years, then you can't really make an informed opinion on the subject, because in that timeframe React has gone through 12 versions, Flow did not publicly exist, and TypeScript has changed significantly. It might be worth looking at TypeScript again and seeing how it compares to Flow in 2017.


You can use Babel to only remove the types, and not touch the code in any other way. And that's an important distinction: the code is exactly the same, just without types. I've been unable to use a Babel plugin at least once because of the way Typescript transpiled the code.


> Flow is not a transpiler, there is no concept of "emitting code", only of stripping away the annotations. In contrast, TypeScript is a transpiler.

TypeScript is a transpiler to the extent you want it to be a transpiler. You can use it to remove annotations only with '--target ESNext' - then it works the same as Flow does in your use case and does not add anything.

In the same vein, most people use Flow with babel. Then it's "transpiling" in the same way TypeScript is "transpiling".

You're either severely misinformed or opting to make your argument by misleading. I wonder how much you have actually used TypeScript.


> It is less intrusive. Flow's type system is built on annotations which are simply stripped away at runtime

> as opposed to writing in another - albeit similar - language that gets transpiled to JS

How is a nicely typed bit of flow-code different from the equivalent TS? If you make actual use of the type system in either of Flow or TS you should end up with code that looks a lot like Java or C#, with generic types and functions etc.

It's nice that you can do it gradually in flow for an existing codebase, but it's still no difference once properly applied in full.


the whole "MS is evil" thing is so played out.


Have you tried ScalaJs? Typescript seems like a better alternative to plain Js, but still seems pretty lacking. For example, the standard libraries are so much nicer than what TS or Javascript offer.


My suspicion is that the ease of porting an existing JS codebase to Typescript is an order of magnitude easier than rewriting it in Scala, even if the eventual benefit is higher.


I think scala.js is having better integration these days (due to typings etc.) But still not 100%.

But I would switch to all-scala if it ever had a dev-friendly 100% integration strategy.


What do you mean by that? It's had the ability for a while now to easily specify types for external js code and call js code.


I'll have to reexamine then. Last I saw the typings story wasn't well documented but would be beyond overjoyed to be wrong.


or Fable, or PureScript, or Kotlin... :)


Fable has such potential. F# is fantastic and I could totally get behind that as a TypeScript alternative under the right circumstances.


Hey Felix, was Dart ever in consideration? I use both TS & Dart (I'm on a TS project currently) but I find Dart so much cleaner but the JS code it generates is very hairy. Thoughts?


I personally haven't spent too much time looking at Dart, but I find it pretty suspicious that TypeScript is on Google's list of approved languages for projects, while Dart is interestingly missing. I'm sure there's upsides to Dart, but I would certainly need to spend more time with it to make a judgement call.

https://www.reddit.com/r/programming/comments/64e6x7/typescr...


Dart is doing fine inside Google. It is used by extremely important projects, like, for example Adwords. These teams are very happy with it and have no intention of changing.

Brad Green already posted a follow-up post on the omission of Dart on his slides: http://angularjs.blogspot.dk/2017/04/official-languages-at-g...

(I work on Dart.)


Even though I work with Typescript daily, Typescript feels like a stop-gap measure until ES6 /ES.Next take hold. Dart feels like the future - given Fuchsia + Flutter + Android apps in Chrome, etc. - if they can just work out some of the rough edges(e.g. isolates with Flutter) and make it more harmonious with JS/DOM - let's face it: We are stuck with the JS/HTML/CSS stack for the foreseeable future.


Thanks for the update, good to know!


The official list is a new process. TS was one of the first to go through that process. I wouldn't read too much into it.


There was a big discussion on Electron today here - https://news.ycombinator.com/item?id=14087381

One of the points was talking about React Native vs Electron. What are your thoughts? Why did you guys go with Electron?


Isn't Slack older than React Native for platforms outside of iOS?


It would be interesting to see examples of bugs you found.


Less engineering, more practical question: What's your setup? I see vscode screenshots, care to share your typescript config and preferences? :)


It does have a small additional own flavor of configuration, but basically, it's nearly identical to some of OSS project written in typescript, like RxJS (https://github.com/ReactiveX/rxjs/blob/master/tsconfig.json / https://github.com/ReactiveX/rxjs/blob/master/tslint.json) cause basically it just inherited those configurations. For VS code preferences, there isn't one unified one but just leave each individual picks configs based on own preferences.


Is the article's hero picture (the Seattle skyline) a hint that you'll be opening an office here soon?


Sorry, I just chose the image because TypeScript's official hero image is a Seattle skyline. I hope I didn't disappoint - I love Seattle though, I can't wait to be back this year for //build.


No worries, was mostly joking! I have a good friend at the SF office and hope to one day work with her again. That can only happen if your team opens some offices up here in the Emerald City :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: