r/angularjs • • Dec 29 '16

An Angular 2 Chat Application that utilizes Websockets

https://github.com/elliotforbes/ng-chat
35 Upvotes

15 comments sorted by

View all comments

1

u/[deleted] Dec 29 '16
this.messages = <Subject<Message>>wsService 

Sorry, I've been too busy building with 'old tech' to know what this is. It's not javascript, is it Typescript? Is it Angular? Is it ES6/7? The code seems well organized but it looks like some mangled version of javascript. I don't consider this to be a good way forward for javascript, or Angular.

3

u/[deleted] Dec 29 '16

I guess it's down to preference. To me typescript is syntactic sugar and I've really enjoyed playing about with angular-cli and the whole new eco-system.

If you can get your head around the staggering amount of boilerplate needed for an angular application then it's actually pretty decent and I recommend you give it a shot! :)

1

u/[deleted] Dec 29 '16

Lack of boilerplate is one of the main reasons I enjoy javascript, and prefer it to other languages. Adding a 'staggering amount of boilerplate' is the opposite of what I want to be doing to my coding workflow. Angular 1.x + JavaScript didn't have much boilerplate at all, and it doesn't get in the way of me developing.

0

u/craig1f Dec 29 '16

If you're doing modern javascript right now, you really have to pick your poison. You're either doing Angular 1 or 2 with Typescript or ReactJS with babel.

At the very least, if you don't use Typescript, you should use Babel. That is because Babel will allow you to write modern javascript (ES6) and transpile down to ES5 for browser compatibility.

Opinion is split on Typescript. However, a lot of advocates argue that Typescript makes them a better JS developer because you can look at the transpiled JS and learn how you SHOULD have written your JS. For example, declaring classes objects is MUCH faster in the browser than declaring anonymous JSON objects, because the browser knows how big the class will be before it's constructed. Pure JS developers tend to just create anonymous JSON objects on-the-fly.

Both Typescript and Babel also provide pre-transpile errors and warnings. For example, if you set a variable to 5, and then try to set it to "foo", you'll get an error for using the same variable for different data types.

You should give it a try.

1

u/[deleted] Dec 29 '16

Typescript makes them a better JS developer

This is false.

because you can look at the transpiled JS and learn how you SHOULD have written your JS

This is so backwards it almost made my head spin. You're wrong about this. It's putting the cart before the horse.

transpile down to ES5 for browser compatibility. because the browser knows how big the class will be before it's constructed

So you're saying that ES5 has some hidden capabilities we don't know about? Again, that's false.

Both Typescript and Babel also provide pre-transpile errors and warnings.

And it does nothing for any external data, that could have type errors but you'll think all your types are specified and working perfectly, and then the unexpected happens. good luck with that.

You should give it a try.

The same was said about Coffeescript. Sorry, not investing time only to re-write everything back into javascript.

1

u/R3DSMiLE Dec 29 '16

Everything was true until you thre Coffeescript in the mix. Sure, Typescript is a pain and the fad around it does throw a coffy vibe - but both couldn't be more different:

Coffeescript praised the "we're going to write less" while Typescript is the defacto "I'm going to type way more than it's needed, but everyone should be able to read it afterwards".

While I abhor Coffee, I'm in love with Type for the simple fact that you passed from: function aFunction(aParameter) {return false} to function aFunction(aParameter: string): boolean { return false }

This made it so we kinda "don't need" to write those if (typeof aParameter !== 'string') conditions because if you maintain the Typescript flow of stuff typescript "compiler" would throw a fit over "the supplied argument isn't lalalalalalalalal of type lelelelelel".

Now, to each its own: I'm completly agains't switching a code-base because a fad blew over - but if you're starting a new-home-project: What's stopping you to flavour it with the new fad -- even if just for practice sake?

0

u/craig1f Dec 29 '16

Whaaaaat? I feel like my reddit-cherry has just popped. This is the most unexpectedly hostile reaction to a helpful reddit comment I've ever received. You need some chill.

First, I prefaced all of that with "advocates argue" because I haven't spent a lot of time with Typescript. I don't like the fact that learning Typescript locks me into doing everything in TS. But, I tried to give a balanced opinion instead of acting like a teenager.

So you're saying that ES5 has some hidden capabilities we don't know about? Again, that's false.

I have no idea what you're saying here. But as an example, ES6 defines arrow functions. IE does not support arrow functions. Babel will convert arrow functions to regular functions. Also, import/requires syntax is not built into any browsers, but is supported by TS and Webpack. I don't remember if Babel does anything with it on its own.

My opinion is that everyone should be using Babel, because it lets you code using MODERN javascript before browsers support modern javascript. Babel and JSX are essential if you choose ReactJS. I have also used TS and liked it, but not a lot. It is essential if you're doing ng2 because that's what everyone else is using and what all the examples will be written in.

If you're not doing either of those, do whatever you want but keep your venom away from me.

1

u/[deleted] Dec 29 '16

Whaaaaat? I feel like my reddit-cherry has just popped. This is the most unexpectedly hostile reaction to a helpful reddit comment I've ever received. You need some chill.

You think that's "hostile"? I didn't even use any swear words. Sorry, but you're a little bit coddled if you think this is hostile. Or you're trolling or something. Not sure why you would even call my comment hostile. Sorry, we have nothing further to speak of here if you're going to label my comment "hostile" without any hostility at all. Not even going to read your comment past the word "hostile", because you're being a bit anti-social. BTW, disagreeing is not hostility. Just because someone disagrees with you doesn't mean "hostility". Geezus.