13 ms·
TypeScript Seals My Penchant for JavaScript
- smegel 10y agoThe 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 10y agoTotally 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.
- marcus_holmes 10y agobecause I enjoy writing pure JS. Typescript feels like Coffeescript, which always felt like a hack to make Rubyists more comfortable. Similarly TS feels like a hack to make C#'ers more comfortable. Ultimately, if you're going to program in JS then get comfortable in JS, rather than trying to make JS more like your favourite language.
- labrador 10y agoSome people like types, other people don't. Some people like indenting with 4 spaces, other like 2. I was a die hard 4 space guy until today, when I was debugging a bunch of 2 space code and decided I like it better.
- wiredearp 10y agoI have a solution for hardcoded spaces that is sure to blow your mind.
- labrador 10y ago8 charwidth tabs in Go are a sight to behold - what decade is this?
- wiredearp 10y agoYour editor will however default to 4 charwidth tabs, but you can change this whenever you feel like it and that's the point. It's just a setting, so we can all have our own and then we don't have to argue about it. This morning you like 2 spaces of indent because you can see more code; but this evening you like 8 spaces because the beer makes the code hard to see. It's true that the code appears locked to 8 spaces when you view it in a browser on GitHub (and that's basically why a majority of developers use spaces still in this decade) but you can also change this whenever you feel like it by placing an ".editorconfig" file in the root of your GitHub project, little known fact. In your case, you would simply change the tab width to 2 and then you don't have to commit all your files again and ruin it for everyone who prefers 4. Serious answer.
- addicted 10y agoYou can type absolutely pure JavaScript, change the file extension to .ts and still get some of the benefits of the typescript compiler for absolutely free. That's probably why a lot of people are excited about typescript. It basically is JavaScript, but optionally annotated JavaScript. It's not a new language.
- cies 10y agoNot when using the billion-dollar-mistake-fixing `--strictNullChecks` flag. :)
- wtbob 10y agoBut if you're going to transpile, why not transpile from a real language, not a Turing tarpit?
- smegel 10y agoWell Google already did that with Java and GWT, but it never caught on. I guess TS being a superset of JS itself might be an advantage...otherwise it is still a new language designed for web browser programming unlike Java. I suppose it is a fair question why they didn't just use C#.
- aikah 10y ago> Well Google already did that with Java and GWT, but it never caught on. Actually it did catch on in the enterprise world, just like Typescript. Will Microsoft be as "dedicated" as Google regarding its language? wait and see.
- Cthulhu_ 10y agoThere's also Scala.js, which takes it even further than GWT. And of course Dart.
- _pmf_ 10y ago> Well Google already did that with Java and GWT, but it never caught on. ClojureScript uses the Closure(sic) compiler from GWT to compile Clojure/Java to JavaScript (not that I defend this technological train wreck). > I suppose it is a fair question why they didn't just use C#. This would have been superb, but I think Microsoft wanted to show that they "get" web developers; just mentioning C# causes the JS pundit get jittery because someone wants to limit the amount of write-only code he is able to spit out.
- PretzelFisch 10y agoThere were already open source projects that tried to do this some paid projects, but they never gained traction. Microsoft also had the hind sight of DART and GWT to help point them in the TypeScript direction.
- gjolund 10y agoJust 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.
- tribby 10y agoto 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 10y agoI 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-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 http://imgur.com/a/y5F5A
- mixedCase 10y ago>I got there from thier other article "Does Electron live up to the hype?" tl;dr - It does It creates applications that require at the very least three times as many resources as Qt, which is also a cross-platform tool-kit that allows you a lot of freedom (specially with QML) as well as native OS widgets using a single codebase (although probably compromising on the HIGs' patterns for each OS). I fail to see how Electron lives up to its hype as a holy grail for cross-platform application development, unless my impression of the hype behind it is wrong.
- colinmegill 10y agoGoing ahead and linking to the website linked to in this post about web development: https://www.cycligent.com/ https://www.cycligent.com/ That is all.
- edem 10y agoI 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?
- seanwilson 10y agoWell you don't have much choice for frontend for one. Typescript offers much stronger typing than Ruby, Python, Clojure and PHP as well.
- winter_blue 10y agoIf I were to start a new project today, I would use Elm[1] for the front-end. It's a very well-designed language (reminiscent of Haskell), specifically designed with HTML and DOM manipulation in mind. [1] http://elm-lang.org/ http://elm-lang.org/
- chriswwweb 10y agoIs using elm really worth it? I have not yet tried elm, but I wonder if it's advantages really justify the increased costs that this choice might bring? Isn't elm a little bit too young? I mean is the time you and your coworkers will need to learn it, the increased difficulty to hire skilled elm developers, the increased difficulty to find good training courses for new junior developers you hire, the increased difficulty to debug the code compared to js, the lack of third party libraries ... really worth it?
- winter_blue 10y ago> the increased difficulty to debug the code compared to js Elm has an amazing time-traveling debugging system: http://debug.elm-lang.org/ http://debug.elm-lang.org/ This is a cut above pretty much every other front-end JS framework, and languages that transpile to JS. > the lack of third party libraries It has JavaScript interop that's based around message-passing. The JS library is treated sort of like a service, and thus the Elm code is kept isolated from it: https://guide.elm-lang.org/interop/javascript.html https://guide.elm-lang.org/interop/javascript.html > the increased difficulty to find good training courses for new junior developers you hire The official docs are pretty good. A good programmer shouldn't have a trouble picking it up. The architectural benefits of using Elm (that lead to a high-quality, almost zero bugs website) is IMO worth it.
- wwho 10y agowow who gives a shit
- tkubacki 10y agoSince TS is superset of JS it has all it's flaws - we need different lang compiled to JS (like Dart) not a mockup.
- Klathmon 10y agoJust 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.
- aljones 10y agoYou also don't use integers!
- talmand 10y ago?
- omni 10y agoJavaScript does not have an Integer primitive, it only has Number which is floating point. http://www.w3schools.com/js/js_numbers.asp http://www.w3schools.com/js/js_numbers.asp
- talmand 10y agoWhy the downvotes? It answer the question. As I'm not a deep coder, what are the advantages of having an integer type versus a float type in the case of Javascript? Memory? Not having to use Math.floor, Math.ceil, or Math.round in case of funky divisions? I've used Javascript for years now without worrying over that particular detail.
- cies 10y agoSee PureScript and Elm. Dart is surely more concise, but not very innovative.
- caub 10y agoI love JS/ES2016 how it is, I seriosuly don't see the advantage of typescript except maybe for a gigantic application
- retox 10y agoAm I missing something? None of the major browsers even support ES2016 yet do they? https://en.wikipedia.org/wiki/ECMAScript#Implementations https://en.wikipedia.org/wiki/ECMAScript#Implementations
- exception_e 10y agoMost people use Babel to write ES2015/ES7 code that turns into ES5 compatible code: http://babeljs.io/ http://babeljs.io/
- caub 10y agoyea, babel, as exception replied
- WayneBro 10y ago> 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.
- koolba 10y ago> Well, if English were statically typed, the compiler would have caught your spelling mistake before you submitted your comment. Ha! I love seeing things like this on HN and think it's a perfect example to illustrate the power of static typing. Kudos!
- 10y ago
- xntrk 10y agoI 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.