
JavaScript for squares: The incredible rise of TypeScript - ohjeez
http://www.infoworld.com/article/3209652/application-development/javascript-for-squares-the-incredible-rise-of-typescript.html
======
nonsince
> As Tom Dale, a senior software engineer at LinkedIn and a JavaScript
> luminary, more colorfully described it to me, “JavaScript is like the hippie
> parents who let you have premarital sex and smoke weed.” That sounds great,
> he notes, even liberating, but “eventually you resent that you didn’t have
> any structure and now you’re 32 and living in their basement.”

I don't mean to imply anything about this man's outlook on life from these
quotes, but that's a mormon-worthy stereotyping of premarital sex and weed.

~~~
allover
Or, you know ... just a joke?

------
draw_down
I came to JS after spending years in C# and Java, and so I liked the
dynamically-typed nature of the language. It feels a lot freer, to me. Of
course I understand why people think static typing is important, but going
back to that way of denoting what everything is just seems so onerous.

But even regardless of that, what I really hate is how these typed JS variants
introduce so much extra syntax and -- sorry for my phraseology -- _crap_ into
the language.

Here is an example of Flow:

    
    
        declare function isMap(m: mixed): boolean %checks(m instanceof Map);
    

You can call that whatever you want, but JavaScript it ain't.

~~~
shakna
Type deduction isn't a terrible hardship, and should make the code look
dynamic.

A simple debugging output can attach the types visibly.

So... My question is why these statically typed JSs add such verbose syntax?

Even C++ has had auto to avoid irritating boilerplate.

~~~
girvo
Flow doesn't require you to write what's above at all for the most part, and
it's type inference and flow analysis is amazing. Your applications code will
have few type hints if that's what you want, and your core libraries can have
the extremely specific types as what's show in the parent post. I dunno, I
like TS and Flow, and gradual typing with excellent inference means it rarely
gets in my way, even when calling out to JS libraries that are as dynamic and
loose as you can get.

------
mcappleton
The thing I like most about TS is interfaces. I use a single "options"
parameter for functions whenever there are a bunch of parameters, and having
autocomplete for it makes life so much easier.

------
valuearb
I spend most of my time writing in Swift, The rest of the time I'm JavaScript,
talk about a schism. I greatly prefer Swift, which is why I'm installing
Typescript this week. Maybe because I'm less experienced with JS, but I make
too many silly mistakes in it.

I know a lot of people love the freedom of JavaScript, but I also know lots of
people write crappy code.

~~~
nojvek
Swift and Typescript go really well together. Typescript made me get into
swift and now into my first app in appstore.

------
nailer
I'm not a 'Typing is Safety' person - languages I use tend to be strongly,
dynamically typed. At least one study has shown more errors come from other
issues other than type mismatches and that's also my own experience.

That said: as my ES2017 app gets more complex, a little type safety could be
useful. I _think_ it might catch more stuff - eg, earlier this week I tried to
use a Promise (because I forgot an 'await') and then got a bunch of NaNs on
invoices (the unit tests had the await, so passed, the route didn't).

Renaming something to .ts and adding a quick compilation step doesn't seem
like a big deal and would catch that error. Typescript also has a MASSIVE
amount of community support around it. So yeah: still don't believe 'typing is
safety' but will likely end up using TypeScript by the end of the year.

~~~
slackingoff2017
IMO the static analysis that becomes possible from using types is more useful
than types themselves.

My favorite JS gotcha is the number of special values a variable can take on.
NaN, Undefined, null, Infinity, -Infinity, maybe more? Also the fact that
arrays and objects are always truthy. Honorable mention for the seemingly
random results of concatenating strings. I'm tired of getting burned by these
design flaws and if it takes strong typing to be protected from them than so
be it.

------
brylie
> incremental typechecking sounds small but isn’t. It pays huge dividends in
> developer productivity. As Dale notes, “Refactors that used to take weeks
> take days, sometimes less..."

Just out of curiosity, what is the basis of claims like that? What types of
bugs does static typing prevent, and how pervasive are those bugs otherwise?

~~~
badlucklottery
From a refactoring perspective, typechecking makes the answer to the question
"What is this change going to break?" _much_ more obvious.

Combine that with Typescript's IDE support and a lot of the usual dumb
refactoring mistakes just don't happen so you can focus on the actual
algorithmic problems emerging.

~~~
Chyzwar
Your tests would catch breaking changes as well. In many typescript codebases
(angular4) strict null checks is disabled befits are really minuscule.

I am now doing an angular4 project and I do not feel any safer. If you want to
have real static typing use Elm, Reason, BuckleScript.

I do not trust MS. Tooling is already bad on anything other than VS Code.
TypeScript development is slowing down from 2017.

~~~
earcaraxe
Look at mister test driven development over here. Hey everyone this guy writes
unit tests.

I'm joking here but I think that a lot of people ignore basics like writing
unit tests, and that statically typed languages will break a lot more quickly
and predictably for people who are lazier, since it enforces structure.

However, I agree with you. Also I think that the people who really push for
static typing are the kinds of people who already would write unit tests.

~~~
Chyzwar
We do. Most of our projects have 80%+ unit test coverage and decent amount
e2e/acceptance tests.

The problem with TypeScript is that in most codebases you will need to disable
useful type-checks. Without strict null checking, you will only catch trivial
errors. Additionally, you will interface with a lot of JS code that do not
provide typings.

------
brian_herman
javascript... i like it because it is the wrong way to do it and it feels so
good.

~~~
slackingoff2017
Like turning left on a red when nobody's around

~~~
zumu
Legal in Oregon if it's on to a one way

~~~
Waterluvian
Legal in Canada too. I just assumed it's legal everywhere because logically
it's a safe operation.

My favourite is a one way /one way intersection in my town where I will turn
left from the far left lane into the far left lane. It feels very British.

Oh no this is really far off topic. I'm a JS developer in robotics and I keep
getting tempted by the allure of TS. The only reason I don't take the plunge
is that I'm the only developer and mitigate most typing issues because I'm so
intimate with the code. I suspect as a team grows I'll regret not going TS :)

