top | item 12609785

TypeScript Seals My Penchant for JavaScript

79 points| labrador | 9 years ago |cycligent.com | reply

130 comments

order
[+] edem|9 years ago|reply
I simply don't understand how can someone like javascript (or anything derived from it) when there are so many much better languages around. Can someone state some advantages for web development for example compared to ruby, python, or clojure? All I see is a slow tangled mess of dependencies and broken libraries with a package manager which lets you change already released modules and a language which is even more poorly designed than PHP. Is it just because of node.js and the promise that you can use javascript from database to frontend?
[+] ceronman|9 years ago|reply
I am a Python fan and I'm not a huge fan of JavaScript, but I do understand why many people love using JavaScript/TypeScript:

1. It's available in the Browser which opens a lot of possibilities. Yes, there are transpilers for other languages but it's not the same.

2. On the server side is really fast. In fact JavaScript is one of the fastest dynamic languages out there. Much better performance than Python (even with PyPy), Ruby or Perl.

3. With TypeScript you get amazing IDE support. Which is something that you just don't have with Ruby, Python or Perl. Yes, I'm aware of PyCharm, but it's not up to the things that you can do with VS and TypeScript.

4. I know the language has some design mistakes, especially around operators and other few things. But in the end the language is small enough and simple enough that it's easy to learn. And it's also easy to learn how to avoid the pitfalls of the language as well. So in the end that's not much of a problem. Besides that, even when the language is simple, it's still quite powerful because of its dynamicity, closures and prototype oriented programming. In the end you can be as concise as you are with Ruby, Python or Perl.

[+] izolate|9 years ago|reply
Best thing about JavaScript is the speed of development. Once you master it, all other languages & ecosystems feel verbose, archaic.

Modern JS (ES2015+) combined with a code style (Standard, Airbnb) is beautiful, sometimes more so than Python.

Bad modules isn't a problem inherent to JS. NPM has its faults, but the JS community is the largest, and the fastest moving of all. Everything you need already exists, and it's probably actively maintained, if not accessible for you to submit a PR.

PHP? Lol, no. JS > PHP.

[+] danneu|9 years ago|reply
I used Clojure for three years before realizing that all of the dynamically typed languages you listed still have the same hard problems: making large code changes and reasoning about existing code. I also realized that in the real world, technical superiority is overrated, and the difference between these languages is overestimated.

Javascript is ubiquitous, runs in the browser + server, everyone I meet in the wild has to know it, and it has static typing options. It's not easy to shove those aspects under the rug to justify another language. It takes something else, mostly depending on just who I'm working with and then on what we're building.

[+] tomca32|9 years ago|reply
For me, it's first class function support. Of course, there are other "real functional languages" like Scala, Haskel or whatever, but they very uncommon. JS is the only commonly (Clojure is very uncommon) used language with real first class functions and not some silly hack like Ruby/Python lamdas, procs, or blocks.

To be fair, it seems that Java 8 has first class functions. I can't say much about it since I didn't get a chance to play with it yet.

[+] chriswwweb|9 years ago|reply
Being able to reuse the code you wrote for the server in your client code and vice versa, is in my opinion not just a small feature, it can save you a lot of time and money.

I joined a company where the backend was written in PHP and the frontend in javascript. There was a ton of duplicate code, just because the backend and the frontend had been written in different languages. By using UMD modules and switching our backend from PHP to nodejs by building a custom isomorphic framework saved us a lot of time. We now don't have two development teams but just one, it's really great having everyone write (speak) the same language and makes hiring, sharing knowledge and training much more efficient.

Yeah javascript is not perfect, but I disagree that is totally bad and that you can't write good code with it.

We also use typescript because it is not just about types it does much more for us. For example allows us to write our code in ES6/ES7 (with core-js) and transpiles it on the fly (on save file) to ES5 UMD modules. Visual Studio and the nodejs tools make it easy to debug our backend code.

[+] emodendroket|9 years ago|reply
Well, the fact that it's a VM that is installed on practically everything is really cool but beyond that I can't see why you'd prefer to use it.
[+] seanwilson|9 years ago|reply
Well you don't have much choice for frontend for one. Typescript offers much stronger typing than Ruby, Python, Clojure and PHP as well.
[+] qudat|9 years ago|reply
When you compare pip to npm, it's a no brainer, npm wins that battle. Pip is getting better but so is npm.

Js code looks a lot like python to me now as well, especially when referencing generators.

The speed of development is it's strongest advantage. However I do think that from an architecture point of view something like golang could be considered more sound.

[+] talmand|9 years ago|reply
>> All I see is a slow tangled mess of dependencies and broken libraries with a package manager which lets you change already released modules...

Ah yes, let's blame the tool for the bad things people do with the tool.

[+] smegel|9 years ago|reply
The most underrated feature of TypeScript is not the language itself, but the transpiler. With the flick of a switch you can support ES3, ES5 and in future ES6 and beyond - without changing your code (not entirely true, but it is possible to write code that transpiles well to all JS standards).

Decoupling your development from the shifting sands of JS support - across multiple browsers and platforms - is a dream come true, and a good enough reason alone to use TS.

[+] labrador|9 years ago|reply
Totally agree. After doing a bunch of code with TypeScript (transpiling to ES5 and ES3), I decided to give Babel a try. It took me awhile to set it up properly with the right presets and plugins. It did a fine job transpiling, but I wondered why people just don't use TypeScript. It's so much easier to use.
[+] wtbob|9 years ago|reply
But if you're going to transpile, why not transpile from a real language, not a Turing tarpit?
[+] gjolund|9 years ago|reply
Just a warning, people said the same thing about coffeescript.

I love TS, and am finding more and more ways to inject it into old codebases. However I remember what happened with coffeescript and am sure to always clearly document my build pipeline in case someone needs to move away from TS in 5 years.

[+] caub|9 years ago|reply
I love JS/ES2016 how it is, I seriosuly don't see the advantage of typescript except maybe for a gigantic application
[+] WayneBro|9 years ago|reply
> seriosuly

Well, if English were statically typed, the compiler would have caught your spelling mistake before you submitted your comment.

Types are valuable for any size application. They bring order to a chaotic world.

If you don't do static typing, you have to do a lot more unit testing. You also have to type out a lot of code to convert your function arguments into the types that you actually wanted. So, you're spending your time either way. Specifying types up front takes way less time than writing unit tests or converting arguments.

[+] gjolund|9 years ago|reply
I have had a lot of trouble explaining the benefits of static analysis, type interfaces, generic types, etc. to my js dev colleagues.

I think that what it breaks down to is that a chunk of your education is missing, and you won't "get it" until you catch up.

There are gigantic advantages to leveraging the compiler while developing. It makes refactoring a breeze, testing intuitive, and it gives you an additional safety net before deploying code.

Sure, there are benefits to writing vanilla js. I still do it from time to time while prototyping. However if you are writing javascript in a professional context on an application that needs to be stable, testable, and maintainable by a potentially distributed team, then Typescript is a no brainer (for front-end, back-end the debate rages).

[+] leshow|9 years ago|reply
I think even in large applications its not well suited because the type system has an 'escape hatch' in the form of any and null/undefined. IMO Elm is probably a better candidate, or Flow if you like the more imperative syntax.
[+] tkubacki|9 years ago|reply
Since TS is superset of JS it has all it's flaws - we need different lang compiled to JS (like Dart) not a mockup.
[+] Klathmon|9 years ago|reply
Just because a language has a feature does not mean you need to use it.

We use JavaScript, but in 90%+ of our codebase we use it without 'this', without prototypes, without classes, and without other ugly parts.

[+] cies|9 years ago|reply
See PureScript and Elm. Dart is surely more concise, but not very innovative.
[+] xntrk|9 years ago|reply
I took a look at Facebook's Flow type checker for Javascript seems like it would really help with a lot of the authors complaints but would still get to right mostly plain JS.
[+] tribby|9 years ago|reply
to save readers the time I've just wasted, here are the two sentences about typescript in this sales pitch for cycligent.js:

"I am able to keep the freedom and expressiveness of JavaScript to which I have become so accustomed while getting enterprise-level type checking and refactoring capabilities. Declaration of objects and interfaces is a dream."

[+] labrador|9 years ago|reply
I think these reports from the field are worthwhile. The guy is an experienced programmer. I thought it was interesting that he was a hard core Java/C# and hated JavaScript when he had to use it. Then after a couple of years of JavaScript, he fell in love with the expressiveness and ease of coding and chaffed at the restrictions of Java/C#. Then he had to do a large app in JavaScript and hit the point where he it was really painful to refactor and he missed the tools he had in Java and C#. Finding TypeScript was, as Goldilocks said "just right." The tagline of TypeScript is "JavaScript that Scales" for exactly this reason. His journey mirrors mine and probably a lot of others.

I got there from thier other article "Does Electron live up to the hype?"

https://www.cycligent.com/blog/does-electron-live-up-to-the-...

tl;dr - It does

I am not associated with the company. I download and tried Cycligent to see how their Elecron app turned out (I'm a big fan of Electron.) It looks like a decent git client, although it feels like a web app with the dialogs that slide in. I could get used to it. Screen shot:

http://imgur.com/a/y5F5A

[+] ilurkedhere|9 years ago|reply
What on Earth is "enterprise-level type checking"?
[+] boubiyeah|9 years ago|reply
thank you, I went and checked the article anyway and yes, it's not very useful or educated.
[+] JackMorgan|9 years ago|reply
"Between Java and Typescript, Typescript is my favorite."

Aka

"Of the two languages I know, Typescript is my favorite."