Typescript and Angular

For discussions about game development that does not fit in any of the other topics.
Post Reply
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Typescript and Angular

Post by hallsofvallhalla »

How in world is it considered better to go from a project with say 3 files to 30 files? Create a project with node, add typescript then angular and do a simple hello world. You are at at least 50 files in your project by now! Makes no sense how this is considered more organized. I can do the same thing with 1 file.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Typescript and Angular

Post by Jackolantern »

One file is difficult to manage and maintain long term.

If you only have one class per file, it makes it much easier to find things if you have a good folder structure (and the Angular CLI gets you on the right path). It cuts down on leakage into the global namespace which was a huge problem for one-file, attached-to-HTML Javascript applications. It makes files easier to manage in an IDE or code editor since you can have the names of each class on each tab rather than just "game.js". It makes code much easier to merge if you are working with a team using a code versioning system since one file will cause many more merge conflicts. It is one of the main methods of encapsulation in ES2015 modules (although TS uses its own module system with explicit access levels so it doesn't suffer as much from this problem). It also makes your code more unit and integration testable and enables you to use things such as code coverage and other analysis tools to better maintain a very large codebase.

I could literally go on and on :D

EDIT: And to the point of the Angular CLI, Angular sets up a staggering amount of JS ecosystem tools such as linters, minification, bundling, TS transpilation, hot code reloading, Webpack task runners, etc., and also gives you a standard place to put polyfills and do other similar things. It downloads a massive number of npm packages to manage all aspects of your codebase and to give a huge number of tools and options to the developer. Basically Angular has tried to anticipate the needs of pretty much anything you would want to do in an enterprise web app.

I often compare Angular to .NET since this, to a large degree is what .NET does for you as well. But .NET has the benefit of being able to hide a lot of this stuff in metadata which Angular can't do.

If the massive number of files bothers you it is always an option to set up Angular yourself and only set up stuff as you need it. At its minimum it is fairly lean. Angular CLI did not debut with Angular 2+ so there are a lot of seed app repos out there ranging from the most basic Hello World all the way up to what the CLI gives you and beyond. They may just need a small bit of tweaking to make them work with the latest Angular since most of them were for < Angular 4, as the vast majority of devs have migrated to the CLI.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Typescript and Angular

Post by hallsofvallhalla »

Yeah i get the point of everything broken out but did not expect 30-50 files for a simple hello world. I guess comparing it to .net makes sense as it is 10-15 just for a hello world. I also expect the web to be less, less space and less files. It just seems the more we advance the more we rely on fast internet and growing hard drives.
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Typescript and Angular

Post by hallsofvallhalla »

I must say it is absolutely sickening what they have done with the web and the languages and libraries that surround it. The elegance of the web 10 years ago was the simplicity. Now they have turned everything into a garbled mess of files and libraries. Getting a angular app setup on VS is beyond stupid. It reminds me of the old days of trying to setup a java app. Granted I have it all working but the biggest question is why? The object of this was to make things easier and more elegant. They have basically built the Taj Mahal and smeared turds all over it.
/Rant off
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Typescript and Angular

Post by Jackolantern »

Keep in mind that an Angular CLI started project is not designed for a "Hello World" project. Yes, it would be overkill for such a thing but you are really only going to make one Hello World app and then hopefully dozens of large, real applications.

I am honestly surprised you are having problems with it. Coming from a project where I had to set up Gulp with minifacation, bundling and many other tasks, LESS preprocessing, ES2015 transpiling, hot reloading, etc., Angular CLI was a breath of fresh air. If you want all of those things (and pretty much every major front-end project today should have them), you will still end up with 30+ files just to get a Hello World running. But at least this way it is standardized by the CLI. If you need any help others will know exactly what you have and where everything should be. The transpiler is tuned perfectly so that you simply write Typescript and save your file and the browser reloads with your changes. Probably if you had set up a lot of this stuff repeatedly for yourself it would be more visible how awesome it is that all of this is done for you.

And the web 10 years ago did not have 100,000+ lines-of-code front-end codebases. That is what these types of frameworks are here to support. A tight front-end workflow. Trying to make large front-end SPAs in jQuery often ends up with thousand+ lines-of-code files filled with the brim with hundreds of jQuery event handlers. Maintaining those types of apps is a nightmare. I've had to do it before and I have also had to recommend completely rewriting an app because it had become too brittle due to tons of events being fired and the state of the app being completely out of control and unmanageable.

I think if you really stick it out and read up a bit on Angular, you will eventually come around and see how beautiful and clean a front-end codebase can be :D
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Typescript and Angular

Post by hallsofvallhalla »

I get where you are coming from and you are right, I have not spent a lot of time in a large development group working on one single project. I am use to one or two people max so i am probably not getting all the utilization out of it. I am gonna stick with it and I am sure one day I will be like "WOW I love Angular!" hehe
I remember when I hated all things Jquery but now I use it often.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Typescript and Angular

Post by Jackolantern »

It can take time. I remember it took me a while to really see the effectiveness of MVC server-side frameworks. Now it is second-nature and I can't imagine living without them.

That said, there are definitely things I think that Angular 2+ could have done better. Angular 2 was already underway when React started to blow up and they already had made their templating engine. It is a whooole lot like Angular 1. I am kind of envious over React's JSX where you can write HTML in your JS and use regular JS logic on it. I think taking that system and using that for Angular 5's templates would be the perfect framework for me. But outside of that, I really enjoy Angular 5 and think that it is an incredible feet of engineering. I am honestly still learning it myself. I have been working on tutorials and poking around with it for about 8 or 9 months on-and-off. I am hoping to start a large scale project with it soon although it may be a little while to get everything ready and to kind of finish up learning about Angular.

As you may have already seen, Angular has a large learning curve. But that is in the same way as .NET or Java EE have a large learning curve: they contain a gigantic amount of everything you will ever need (not 100% everything you will need but a gigantic amount of it). So naturally that is going to take a long time to learn. My main strategy has been to sample, sample, sample. Try to at least know what all the pieces do and have good resources lined-up for when I inevitably need them because I know I will never be able to remember everything. I want to get to the point where I at least know what piece or pattern is used to solve each kind of problem so I know where to start. I feel like I am pretty close to that now but am still learning 8-)
The indelible lord of tl;dr
Post Reply

Return to “General Development”