Jump to content

Is it worth using TypeScript?


Martiny
 Share

Recommended Posts

I'm a little bit worried about code organization in my next game, and by talking to my brother, he suggested that I started using TypeScript, saying that it offers better tools to organize my code (the class system, basically). 

 

And I just don't know if the class system is awesome or my knowledge of prototypal inheritance is not good enought, but here's what I wanted to do:

 

Suppose I have a lot of elements that my enemies share. They damage on contact, they walk towards the player and they can be killed.

 

I could create a class Enemies that have all those properties/methods, and then if I want to create a new kind of enemy that has unique features (suppose it shoots you with a gun and it poisons you when you touch it), I could do something like this:

 

newEnemy extends Enemies.

 

Right?

 

I'm not totally sure if that's the best way of doing, but it's the only way I can think of now. I don't have a clue of how to do this "extends" with prototypal inheritance.

 

My question is: is it a good idea to use TypeScript or is it better to learn to use prototypes better?

 

Link to comment
Share on other sites

Other than classical Object oriented mania I don't really find any useful reason to do so. I have 120 thousand lines worth of AI code which I manage everyday written under FreeBASIC ignoring the classes full (ignoring all advice of c++ and prolog groups). Yet code is fast and efficient too. It understands a very basic subset of Sanskrit language and try to learn from experience and reading in a small virtual world. Basically to study machine learning.

 

My another program Royal BASIC is a compiler written in C, again huge (well above 120k), no classes.

 

I don't think any HTML5 mobile game at current stage or in near would be more complex. Classical object oriented system don't give solutions itself. I fail to see how it even save you from anything . Then JavaScript is a beautiful new experience   :D

Link to comment
Share on other sites

Only use TypeScript if you are comfortable using Visual Studio. Support for it outside of VS is mediocre at best and you tend to lose most of the core benefits of using TS in the first place. However it's easy enough to get started with TS, so why not just try building something basic in it and see how it 'feels' to you?

 

Also remember though, there is NOTHING that TS can do that you can't already do using normal JavaScript, because it IS normal JavaScript under the hood :)

Link to comment
Share on other sites

Other than classical Object oriented mania I don't really find any useful reason to do so. I have 120 thousand lines worth of AI code which I manage everyday written under FreeBASIC ignoring the classes full (ignoring all advice of c++ and prolog groups). Yet code is fast and efficient too. It understands a very basic subset of Sanskrit language and try to learn from experience and reading in a small virtual world. Basically to study machine learning.

 

My another program Royal BASIC is a compiler written in C, again huge (well above 120k), no classes.

 

I don't think any HTML5 mobile game at current stage or in near would be more complex. Classical object oriented system don't give solutions itself. I fail to see how it even save you from anything . Then JavaScript is a beautiful new experience   :D

 

it is not about how many lines of code, but about code structure and maintenability.

when you are the only developer/maintainer of code, you can do everything in the language you want and using the paradigm you are confortable with ... you can even write code without any comment if you are sure to be able to maintain it later.

what POO solve (or at least try to solve) is the problem of code structure, and tasks sharing.

even on small game project if you work with 3 developers it's better to have a structured code so one developer work on game logic, another one on rendering and the third one on AI.

that's easy with POO, but very complex with linear code.

there is also other approaches that try to solve POO problems, for example entity systems that I dicuss in the following thread : http://www.html5gamedevs.com/topic/1171-entity-systems-have-you-used-them-in-html5-game-dev/  (Unity3D Game engine is base on Entity Systems btw).

 

Link to comment
Share on other sites

If you're just looking to mimic the behavior of TypeScript's "extends" keyword in JavaScript, you can use the Object.create() function.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain

 

I'll take a look on that, thank you.

 

Only use TypeScript if you are comfortable using Visual Studio. Support for it outside of VS is mediocre at best and you tend to lose most of the core benefits of using TS in the first place. However it's easy enough to get started with TS, so why not just try building something basic in it and see how it 'feels' to you?

 

Also remember though, there is NOTHING that TS can do that you can't already do using normal JavaScript, because it IS normal JavaScript under the hood :)

 

I'm quite familiar with Sublime Text and got TypeScript running in it. Is it a bad idea to continue using Sublime if I aim to code with TypeScript?

 

TypeScript felt a little bit better to code, but I fear that it its just my lack of experience with Javascript prototype. I don't know any of these approaches that well, but I worry that one is better than the other in the long run when it comes to code organization. If I were to code an Harvest Moon game for example, what would be the best way to organize all the crops? With classes or prototypes?

 

I guess there's no real answer to that question, since it depends on the style of the programmer.  

 

Being honest, I know nothing about this topic yet. I just don't get prototypical inheritance! The code of the game I'm making is just getting messier and messier, and I'm getting worried that I'm getting into a bad habit. If anyone has an advice or any material about this topic, I'll be glad to know/read!

 

Thanks for the attention (:

Link to comment
Share on other sites

it is not about how many lines of code, but about code structure and maintenability.

when you are the only developer/maintainer of code, you can do everything in the language you want and using the paradigm you are confortable with ... you can even write code without any comment if you are sure to be able to maintain it later.

what POO solve (or at least try to solve) is the problem of code structure, and tasks sharing.

even on small game project if you work with 3 developers it's better to have a structured code so one developer work on game logic, another one on rendering and the third one on AI.

that's easy with POO, but very complex with linear code.

there is also other approaches that try to solve POO problems, for example entity systems that I dicuss in the following thread : http://www.html5gamedevs.com/topic/1171-entity-systems-have-you-used-them-in-html5-game-dev/  (Unity3D Game engine is base on Entity Systems btw).

Linux Kernel is one of largest collaboration  project in the history of programming which uses C  in organized object like mode though. FreeBSD kernel is none smaller project, again in C. Quake games again in C. Classical OO is just an hype.

 

What stop many people on working different thing in non classical OO language(s)? Each programmer can work on its own files(s) and  one on master file and then all would be put together and compiled.

Whenever I see pro Classical OO points, never see justification of the claim. Just like all fancy claimed merits of encapsulation I have seen... none looks true. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...