Typescript VS Javascript
What is TypeScript ?
On the 27th of April 2017, you wake to begin your morning routine, It’s 4:05 AM, so you don’t see it yet. No screen time till 6:00 am. Personal policy. You meditate. You work out, you make breakfast. This time you decide to slide in the book reading routine for a little while in there. You surely haven’t done that in a while.
It’s 8:00 am you have managed to not have checked that phone screen. Your mind is fixed on getting to the office first. And again you don’t see it. Finally, the morning meetings are over and you have your sanity back for what? An hour? Half an hour maybe before another meeting.
Then you pick up your phone to check for what you believe is a Twitter notification. That’s when your eyes catch it.
Announcing TypeScript 2.3 For those who aren’t familiar, TypeScript is a superset of JavaScript that brings users optional static types and solid tooling. Using TypeScript can help avoid painful bugs people commonly run into when writing JavaScript by type-checking your code. TypeScript can actually report issues without you even saving your file, and leverage the type system to help you write code even faster. This leads to a truly awesome editing experience, giving you time to think about and test the things that really matter.
You wonder, what in Gods name is this? You had just gone through hell with React/Redux, you are still grappling at Vue.js. Somehow you have figured Angular out. Well okay let’s say you did not really have a choice, you were learning on the job. No results meant your job would suffer. And so you learned Angular.
You think of the stress you have to go through to learn this shiny new thing. You check up the usage of this strict syntactical superset of JavaScript, a few days later and you find out it has an army of developers behind it. Do people love this thing? Now as a smart developer you know you have no other job but to keep up with the market as Chad Fowler mentioned in his still very relevant book The Passionate Programmer. I understand perfectly the way you feel. But I personally feel like TypeScript has come to stay.
But What Exactly Is This JavaScript ?
JavaScript the very dynamic programming language that everyone was drawn to because it didn’t “house them in” like C++ did. Its untyped nature and its unique prototypal inheritance was perfect bait. To justify my gut feeling about this just days after TypeScript was released by Microsoft, Angular picked it up and abandoned the plain ES6 that was another available option. Initially, their idea was to go with actionScript, a javascript scripting language that extended Typescript and got published by Google’s AngularJS team exactly two years after the forerunner TypeScript. In fact, it was going to run on the TypeScript of course as an extension.
With all that being said since then a decorator proposal has appeared for ES and it seems to be quite close to what original actionScript did. But before we jump the gun here really. What is this decorator proposal ES utilizes ?
A Decorator is:
- An expression
- That evaluates to a function
- That takes the target, name, and decorator descriptor as arguments
- And optionally returns a decorator descriptor to install on the target object
Read more here. But if you don’t want to branch out into another page until you are done with this article, a decorator is basically a high order function? An high order function ‘takes in’ another function and when it runs, it extends the behavior of the latter function without explicitly modifying it.
So if our function myFunction(as a higher function) here takes in a function it won’t necessarily modify that function, though the output will turn out differently.
One of the first things that put me off with decorators was the ‘@’ sign. It immediately felt like I was reading another language other than JavaScript. I am sure this was the experience for a lot of other people too. Either ways the ‘@` tells the parser that everything (in that block of code) after that sign is a decorator. Sounds easy now? It is simply just talking to the computer directly what is about to happen which is that a function will be decorated by another function and the results will be passed back up.
And the computer says; ‘Got it! Fine, go on’ . The computer then treats that block of code as a different kind of function, kind of like how a parent would treat a favourite child and as a result of this special attention from the ‘parent’, it becomes a function that can do cool things like memoization, authentication, logging and so on. Again I won’t go deeply into the details of this for now but when you think of decorators think of them as this:
…Instead of this train wreck.
Imagine you have a couple of functions you want to wrap around themselves. It would be a nightmare to code and maintain such program. All said and done about ES6, of course, you would still have to deal with typing somehow in ES. And TypeScript is a natural fit there(when it comes to typing). You can complement ES with a solution like Flow to get gradual typing after all. Maybe we’ll see two bigger camps. One for ES (Babel guys) and one for TS.
What is Static vs Dynamic Typing ?
Typing has always been about the variables in the program. If I create a static typing language I don’t have to immediately tell the compiler that this particular integer and will always be an integer. It will be exactly what I stored in the program even If I forget while coding and changed its value by passing it to another class or something. A number of good language examples are C, C++, Java. Dynamic typing, on the other hand, is the direct opposite of what the above is about. Ruby, Perl and of course our poster boy: JavaScript. This doesn’t mean any one of these languages is inherently weak or bad. And that should be the focus.
Example of Java (Static and Strongly Typed)
There is no way the system can go wrong in evaluating the value of ‘foo’, ever.
Example of Javascript (Dynamic and Strongly Typed)
As opposed to Java or C++, which are both strongly typed languages, Javascript is intelligent enough to know/interpret what variable type you want to use. but because of the laxness that this creates or can create in code quality it is also called a weakly typed language. But we know better. Especially if you follow best practices.
Example of PHP (Static and Weakly Typed)
Between the two up there they are just paradigm ways of coding, it doesn’t mean Static typing is bad or Dynamic typing is good. The devil that should be your sole attention should be weak and strong type languages. Here is what you lose by overlooking a scripting language that is focused on improving the life its users.
- Generic functions & Polymorphism
- Higher order functions
- Object composition
Again. Dynamic types DOES NOT =/ No type checks. on that topic check out this article that Dynamic Typing is NOT Weak Typing Taking a step back what if we combined both sides of the coin, meaning we take what made C++ be C++ and introduced that into Javascript?
- Speed: Static languages are generally faster
- Efficiency/Effective Static languages make the programmer more accountable. Dynamic programming sometimes creates a moral hazard and encourages bad programming habits
Here is JavaScript Dynamically typed
Here is Javascript Strongly Typed
And that is TypeScript!
If this article makes Typescript sound interesting, you can delve more into Typescript and see if it’s something you want to invest time and energy into. This is just a very brief article talking about these tools in a very peripheral manner.
Micheline Quentin
I like the valuable info you provide for your articles.
I will bookmark your weblog and take a look at once more right here
frequently. I’m rather certain I’ll be informed plenty of new stuff right right
here! Good luck for the next!
Raymond Gordon
whoah this blog is fantastic i love reading your articles.
Keep up the good work! You understand, lots of persons are searching
round for this information, you could help them greatly.
Hung Marcum
Excellent post. Keep posting such kind of information on your
site. Im really impressed by it.
Hey there, You’ve done an incredible job. I’ll certainly digg it and in my view suggest to my friends.
I’m sure they will be benefited from this site.
Iesha Kentish
I have read so many articles or reviews concerning the blogger lovers but this piece of
writing is in fact a fastidious article, keep it up.
Mellissa Lymburner
This is my first time go to see at here and i am actually impressed to read everthing at single place.
Gennie Ridgeway
WOW just what I was searching for. Came here by searching
for viagra cialis online
Marie Colosimo
you are really a excellent webmaster. The website loading velocity is amazing.
It kind of feels that you are doing any distinctive trick.
Furthermore, The contents are masterpiece. you have performed a wonderful job
on this topic!
Rogelio Fifer
Hi there, You’ve done a great job. I will definitely digg it
and personally suggest to my friends. I am sure they will be
benefited from this website.
Del Oldham
I have been exploring for a bit for any high-quality articles
or weblog posts in this sort of space . Exploring in Yahoo
I ultimately stumbled upon this website. Studying this info So i’m
satisfied to exhibit that I have a very good uncanny feeling I discovered exactly what
I needed. I such a lot undoubtedly will make sure to don?t disregard this website and give
it a glance regularly.
Etta Everett
This is my first time go to see at here and i am
really pleassant to read everthing at one place.
Marian Rintel
It’s awesome to visit this site and reading the views of all friends regarding this paragraph, while I
am also keen of getting experience.
Rae Neitenstein
Wow, that’s what I was exploring for, what a data!
existing here at this weblog, thanks admin of this
site.
Candy Parris
I know this if off topic but I’m looking into starting my own blog and
was wondering what all is required to get set up?
I’m assuming having a blog like yours would cost a pretty penny?
I’m not very web smart so I’m not 100% sure.
Any suggestions or advice would be greatly appreciated.
Appreciate it
Kam Coolidge
What’s up to every body, it’s my first pay a quick visit of this weblog; this
website carries remarkable and in fact fine material in favor of readers.
Angelia Vale
Keep this going please, great job!
August Spedding
Definitely believe that that you said. Your favourite reason seemed to be
on the web the easiest factor to keep in mind of.
I say to you, I certainly get annoyed whilst people consider worries that they plainly do not know about.
You managed to hit the nail upon the top as well as defined
out the whole thing without having side effect , folks could take
a signal. Will likely be again to get more. Thank you
Elida Meiners
Your style is so unique in comparison to other people I have read stuff from.
Thank you for posting when you have the opportunity, Guess I’ll just bookmark this page.
Lin Crumley
I have to thank you for the efforts you have put in writing this website.
I really hope to see the same high-grade content from you later on as well.
In fact, your creative writing abilities has encouraged me to get my own, personal website now 😉
Ethel Mulvany
What’s Taking place i am new to this, I stumbled upon this
I’ve found It positively useful and it has helped me out loads.
I hope to give a contribution & help different users like its helped me.
Good job.
Susana Willcock
Hey there! Do you use Twitter? I’d like to follow you if that would
be ok. I’m absolutely enjoying your blog and look forward to new posts.
Candida Molinari
Hello would you mind letting me know which hosting company you’re working with?
I’ve loaded your blog in 3 different web browsers and I
must say this blog loads a lot faster then most.
Can you recommend a good internet hosting provider at a honest price?
Kudos, I appreciate it!
Solomon Sayre
At this time I am going to do my breakfast, afterward having my breakfast coming again to read additional news.
Selene Yamada
Hi there! This post couldn’t be written much better! Looking at this post reminds me of my previous roommate!
He always kept preaching about this. I’ll forward this information to him.
Pretty sure he will have a very good read. Thanks for sharing!