This is why I want JavaScript in Torque
by Daniel Buckmaster · in General Discussion · 08/07/2013 (5:23 am) · 52 replies
altjs.org
See that? It's like an extend family of technologies that all work off JavaScript. Languages that compile to JS are the current big thing as far as I can tell. Adding the V8 engine to the core of T3D would not only provide support for writing in JavaScript itself, which as a language has many tradeoffs. It would enable writing your game in any of the fantastic languages that compile to JS, as well as taking advantage of new stuff that targets the V8 engine without being JS at all (Ruby, for example).
Or even insane things like Emscripten which goes from LLVM bytecode to JavaScript. Which is... insane. That means you can write C++, compile it to JavaScript and run it in a browser - or in this case, in Torque3D. Or Lua.
I just thought I'd post this because I found the site and was very impressed. I wish I were able to dedicate some time to actually making this happen; it'd be a massive amount of work, but work that I think would be extremely valuable.
Basically, T3D needs a modern scripting language. The popularity of the internet and browsers as the only universally available interpreting environment means that engines like V8 aren't going away soon, and will continue to receive a lot of attention to both ends (back and front). That's why I recommend JavaScript.
About the author
Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!
#22
See? This is why I want TorqueScript in Java!
As I've always said, I'm all for diversity and flexibility. I've also always been impressed with Frank's language projects, too.
08/07/2013 (10:34 pm)
lol -See? This is why I want TorqueScript in Java!
As I've always said, I'm all for diversity and flexibility. I've also always been impressed with Frank's language projects, too.
#23
08/08/2013 (4:03 am)
Hehe, seems like I'm the only one who would want C# as the main scripting language. I guess it's not as high level as Python, Lua or such.. but it's so beautiful!
#24
if you guys are wanting to use C# or some other .Net langauge instead of TS, go chk out DotNetTorque.
https://www.winterleafentertainment.com/Products/DotNetTorque.aspx
08/08/2013 (5:34 am)
@Edward and Stefan:if you guys are wanting to use C# or some other .Net langauge instead of TS, go chk out DotNetTorque.
https://www.winterleafentertainment.com/Products/DotNetTorque.aspx
#25
08/08/2013 (8:41 am)
I'm well aware of the pack and I think it's great. :)
#26
A while back I found out Haxe can compile from ActionScript to JavaScript. As well as many other targets including Neko VM. It would be interesting in the sense that you could actually program in ActionScript potentially if the VM were JS. That is what got me really interested in compilers.
The idea that you could compile from TS to another scripting language really removes a major barrier. Because of this I was trying to come up with a way to get ScriptT3D to allow script commands to be imported natively in V8 running inside Python. That way if V8 were to replace the VM then the previously developed JS code would not have to be changed.
So if that abstraction were to be developed for V8 in Python using ScriptT3D you could literally have most of the TS to JS code ported before V8 was even natively put into T3D. A similar thing could be done for LUA as there is a LUA module for Python. The PyV8 module is much more mature though. I know, it starts to get really exciting when you start looking at different things you can connect. It is like programming with Legos.
08/08/2013 (12:30 pm)
@dB,A while back I found out Haxe can compile from ActionScript to JavaScript. As well as many other targets including Neko VM. It would be interesting in the sense that you could actually program in ActionScript potentially if the VM were JS. That is what got me really interested in compilers.
The idea that you could compile from TS to another scripting language really removes a major barrier. Because of this I was trying to come up with a way to get ScriptT3D to allow script commands to be imported natively in V8 running inside Python. That way if V8 were to replace the VM then the previously developed JS code would not have to be changed.
So if that abstraction were to be developed for V8 in Python using ScriptT3D you could literally have most of the TS to JS code ported before V8 was even natively put into T3D. A similar thing could be done for LUA as there is a LUA module for Python. The PyV8 module is much more mature though. I know, it starts to get really exciting when you start looking at different things you can connect. It is like programming with Legos.
#27
" I'm the only one who would want C# as the main scripting language."
not only u.i also on the same boat(but mono c#).
i belief manyone have same intention.
but not much of them have enough time/knowledge to implement that.
in case of c#,i want to go for slightly different approach.
my plan is to use TS or JS for fast development and testing.
when testing done i want to move my js/ts code to c# for better performance.
is it possible to make python/js a compiled language like c# ?
about python:
i belief stock python VM is bit of slow to consider it for real time game programming.is there any customized version of python for game development?
or possible to make a customized one?
08/08/2013 (5:12 pm)
(c#+TS+JS+python)" I'm the only one who would want C# as the main scripting language."
not only u.i also on the same boat(but mono c#).
i belief manyone have same intention.
but not much of them have enough time/knowledge to implement that.
in case of c#,i want to go for slightly different approach.
my plan is to use TS or JS for fast development and testing.
when testing done i want to move my js/ts code to c# for better performance.
is it possible to make python/js a compiled language like c# ?
about python:
i belief stock python VM is bit of slow to consider it for real time game programming.is there any customized version of python for game development?
or possible to make a customized one?
#28
Python runs on .NET as IronPython using the same VM as C#. Which also does JIT compile to machine code.
Python has a separate JIT called PyPy, but it is a subset of the main Python language and most compiled libraries do NOT work with it.
If you are NOT using Python correctly it will be slow. You cannot program Python like you would C++ and expect it to be fast. Part of the philosophies of Python is to build the app and then if necessary speed up the sections of the code that are the bottleneck. This way you leverage the time of the programmer (the most expensive part of programming) and leverage compiled language speed by implementing Python libraries to do the critical code sections. This is also how TS is designed to operate BTW. Prototype, find slow sections, move code to C++ as needed.
Python will take some effort to learn how to use effectively even without moving slow code to a compiled language. Much of Python internals are implemented in C and using those effectively you can move much of the processing in C just by understanding how to use the internals. I would suggest going this route with Python, C, C++ (or any language you want to use):
projecteuler.net/
The problems in that challenge are really good to force yourself to grow as a programmer in general. It would also force you to learn how to make any language you use work the way that language was intended.
Also search for how to use Python more effectively. There are tons of articles on switching your mindset to work with the tools available in Python. Python is not C++, Java, JS, etc.
To give you some perspective I wrote a daemon process for Linux using Python. The process was designed to be fed data from an email. The email could be plain text or html. I took this data and processed it through and XML library called lxml. I used the library to fix the structure of the document. For html based emails I would convert to XML, parse all the CSS (including downloading and decompressing if necessary), combine the CSS into one group, prepend the CSS to use a unique namespace to that document, prepend the CSS tags in the HTML code to use this namepace as well, and spit out a well formed X/HTML document. I could feed this daemon over 5000 documents in a 5 minute period when doing stress tests. Oh, given the time to develop this code I could have created a C++ solution and it would have been faster potentially. But it would have taken 3x as long. As an indie developer it is more important to leverage the time of the single or small group developers working on a project and actually finishing. I can always speed up critical sections of code at a later time if I designed my code in a smart manner. However, I cannot replace the time if it takes 3x as long to code. This has been my experience so YMMV. There are a number of articles where C/C++ programmers find they can be significantly more effective programming in Python. These are not college students observing this, but seasoned pros.
08/08/2013 (6:29 pm)
V8 and other JS VMs are doing JIT compile to machine code.Python runs on .NET as IronPython using the same VM as C#. Which also does JIT compile to machine code.
Python has a separate JIT called PyPy, but it is a subset of the main Python language and most compiled libraries do NOT work with it.
If you are NOT using Python correctly it will be slow. You cannot program Python like you would C++ and expect it to be fast. Part of the philosophies of Python is to build the app and then if necessary speed up the sections of the code that are the bottleneck. This way you leverage the time of the programmer (the most expensive part of programming) and leverage compiled language speed by implementing Python libraries to do the critical code sections. This is also how TS is designed to operate BTW. Prototype, find slow sections, move code to C++ as needed.
Python will take some effort to learn how to use effectively even without moving slow code to a compiled language. Much of Python internals are implemented in C and using those effectively you can move much of the processing in C just by understanding how to use the internals. I would suggest going this route with Python, C, C++ (or any language you want to use):
projecteuler.net/
The problems in that challenge are really good to force yourself to grow as a programmer in general. It would also force you to learn how to make any language you use work the way that language was intended.
Also search for how to use Python more effectively. There are tons of articles on switching your mindset to work with the tools available in Python. Python is not C++, Java, JS, etc.
To give you some perspective I wrote a daemon process for Linux using Python. The process was designed to be fed data from an email. The email could be plain text or html. I took this data and processed it through and XML library called lxml. I used the library to fix the structure of the document. For html based emails I would convert to XML, parse all the CSS (including downloading and decompressing if necessary), combine the CSS into one group, prepend the CSS to use a unique namespace to that document, prepend the CSS tags in the HTML code to use this namepace as well, and spit out a well formed X/HTML document. I could feed this daemon over 5000 documents in a 5 minute period when doing stress tests. Oh, given the time to develop this code I could have created a C++ solution and it would have been faster potentially. But it would have taken 3x as long. As an indie developer it is more important to leverage the time of the single or small group developers working on a project and actually finishing. I can always speed up critical sections of code at a later time if I designed my code in a smart manner. However, I cannot replace the time if it takes 3x as long to code. This has been my experience so YMMV. There are a number of articles where C/C++ programmers find they can be significantly more effective programming in Python. These are not college students observing this, but seasoned pros.
#29
how a man can write down that much,so quickly!
ya.that is what i am feeling now(actually just noticed after reading your short article).after several months tries to concentrate on joomla,recently i have switched into django and found out some amazing books which actually was changing(improving) my coding style(just noticed).
django made me fall in love with web development.after t3d this is something i actually loving to work with.
thanks for the answer.very much encouraging.
edit:
how much time u took to think & type that answer ?
08/08/2013 (6:55 pm)
oye!is that an answer or an article!how a man can write down that much,so quickly!
Quote:The problems in that challenge are really good to force yourself to grow as a programmer in general. It would also force you to learn how to make any language you use work the way that language was intended.
ya.that is what i am feeling now(actually just noticed after reading your short article).after several months tries to concentrate on joomla,recently i have switched into django and found out some amazing books which actually was changing(improving) my coding style(just noticed).
django made me fall in love with web development.after t3d this is something i actually loving to work with.
Quote: I would suggest going this route with Python, C, C++so far it was only python and some c/c++ libraries.no other language.
Quote:Python has a separate JIT called PyPy, but it is a subset of the main Python language and most compiled libraries do NOT work with it.got the point.i will try that out after "using Python correctly".
thanks for the answer.very much encouraging.
edit:
how much time u took to think & type that answer ?
#30
BTW, the Panda game engine uses Python for scripting. I forget about that.
@dB,
altJS is a really cool resource! I love how they have the AST there. I have not looked at it real close. Do you know if they have used the compilers to work with V8? I know V8 has WAY more that it can do than what is in the browsers. There are huge language extensions in there that are not used because the browser does not support it. Thanks for posting this resource. It is bookmarked! (yeah, it only took me a couple of days to finally reread the OP... ;)) I think it is part of being human and being fallible...
Edit:
Can JIT in V8 be disabled? That way it could still run cross platform on non x86 platforms? If this is possible there is no reason to not use V8 in the core of the engine. This would also encourage people to tweak the JIT to work with non-x86 architectures.
08/08/2013 (7:16 pm)
Quote:how much time u took to think & type that answer ?I dunno, 10 minutes?
BTW, the Panda game engine uses Python for scripting. I forget about that.
@dB,
altJS is a really cool resource! I love how they have the AST there. I have not looked at it real close. Do you know if they have used the compilers to work with V8? I know V8 has WAY more that it can do than what is in the browsers. There are huge language extensions in there that are not used because the browser does not support it. Thanks for posting this resource. It is bookmarked! (yeah, it only took me a couple of days to finally reread the OP... ;)) I think it is part of being human and being fallible...
Edit:
Can JIT in V8 be disabled? That way it could still run cross platform on non x86 platforms? If this is possible there is no reason to not use V8 in the core of the engine. This would also encourage people to tweak the JIT to work with non-x86 architectures.
#31
IMO speed isn't the number one factor. Probably number two. Number one, for me, is the quality of the language itself. How expressive is it? How easy is it to learn?
With regards to disabling JIT, apparently it wasn't possible in 2009, but who knows how that's changed since then.
08/09/2013 (1:11 am)
I've never found much to be interested in about C#, but I'm open to finding out more about it - lots of people have recommended it to me, but I don't understand the fuss. It seems like Java-ish C from the small knowledge I have of it... and we don't exactly need more Java-ish or C-ish languages.IMO speed isn't the number one factor. Probably number two. Number one, for me, is the quality of the language itself. How expressive is it? How easy is it to learn?
With regards to disabling JIT, apparently it wasn't possible in 2009, but who knows how that's changed since then.
#32
I guess you could call it Java-ish, yeah. I like it because it reminds me somewhat of C++, but I don't have to care about memory management and some of the mistakes one usually does in C++. I think I recall their standard library being quite extensive too.
But JavaScript, I just can't see it when it comes to object oriented scripting languages. Not Lua either, though I realize it's very popular.
08/09/2013 (2:48 am)
Stackless Python can be a little bit faster (EVE Online uses it) if you're using threads.Quote:
I've never found much to be interested in about C#, but I'm open to finding out more about it - lots of people have recommended it to me, but I don't understand the fuss. It seems like Java-ish C from the small knowledge I have of it... and we don't exactly need more Java-ish or C-ish languages.
I guess you could call it Java-ish, yeah. I like it because it reminds me somewhat of C++, but I don't have to care about memory management and some of the mistakes one usually does in C++. I think I recall their standard library being quite extensive too.
But JavaScript, I just can't see it when it comes to object oriented scripting languages. Not Lua either, though I realize it's very popular.
#33
08/09/2013 (5:29 am)
One thing that stands out about V8 is it is inherently designed to be sandboxed. Which makes it a great language for client side scripting. Python is a horrible language for sandboxing. There is so much introspection in Python that it is not safe for client side scripting. That is one major reason I am interested in PyV8. I can create multiple contexts, and each context is unaware of the other. So putting V8 in Torque and making sure you can have separate contexts gives you a powerful scripting platform that can also do safe client side scripting.
#34
Honestly, perhaps we should look at C++ compile-on-demand. It is possible to create an environment where you can edit the game's C++ source in the in-game editor, recompile it and switch to the new output on the fly. I was fiddling with the idea back in 1999 but I still don't have the skill to implement it myself - others already have, though - pay attention at right around the 10 minute mark.
08/09/2013 (6:59 am)
To me, C# feels like C++ without as much opportunity to shoot yourself in the foot and Java without the handcuffs.Honestly, perhaps we should look at C++ compile-on-demand. It is possible to create an environment where you can edit the game's C++ source in the in-game editor, recompile it and switch to the new output on the fly. I was fiddling with the idea back in 1999 but I still don't have the skill to implement it myself - others already have, though - pay attention at right around the 10 minute mark.
#35
There is another issue with V8 there is no equivalent of a DSO. V8 optimizes for the processor available and may recompile more than once on critical code. If there is the ability of TS to target V8 then there may be a way to have a DSO like intermediate. Not sure though.
08/09/2013 (11:45 am)
I guess you could have TS and JS used with #defines. So non-x86 platforms could use TS. The TS in general could be compiled to target the V8 VM (or another VM) that way the main code base can be used in tact.There is another issue with V8 there is no equivalent of a DSO. V8 optimizes for the processor available and may recompile more than once on critical code. If there is the ability of TS to target V8 then there may be a way to have a DSO like intermediate. Not sure though.
#36
08/09/2013 (12:06 pm)
Demo, it shouldn't be too hard to dump compiled bytecode to a file, eh?
#37
ok, thats got that off my chest...
Now, speaking as somebody who doesn't fully understand the ins and outs of half of this stuff, i have a few questions as well as an observation or two.
What is actually so awful about TS? I was always under the impression that if you needed some heavy lifting done, you code it in the engine not in script.
Since there are 1001 different damn scripting languages, seems to me that ripping out one to add a different one is just a waste of time, now if you want to add a feature that allows everyone to use their own favourite language then i guess that's a different beast.
if you add another language are you not then adding yet another dependency that will demand to be upgraded every so often, arent you also placing yourself at the mercy of the people who run the projects for these other languages. who fixes the bugs in a closed source, or incompatible source licensed product?
Here's another question, why isnt it easier to fix some of the issues with TS, since 100% of the source for it is available and there for all to fix.
I refuse to accept the argument that 'nobody knows TS' as a good reason for replacing it, language syntax is pretty fast to understand even for non programmers, most of the hard work is remembering what engine functions do what and that changes for every engine you use, language choice isn't really a factor there.
08/09/2013 (12:17 pm)
Anything that uses whitespace as an important syntax divider needs to be dragged down a dark alley and shot, along with anybody who thinks the concept is a good idea.ok, thats got that off my chest...
Now, speaking as somebody who doesn't fully understand the ins and outs of half of this stuff, i have a few questions as well as an observation or two.
What is actually so awful about TS? I was always under the impression that if you needed some heavy lifting done, you code it in the engine not in script.
Since there are 1001 different damn scripting languages, seems to me that ripping out one to add a different one is just a waste of time, now if you want to add a feature that allows everyone to use their own favourite language then i guess that's a different beast.
if you add another language are you not then adding yet another dependency that will demand to be upgraded every so often, arent you also placing yourself at the mercy of the people who run the projects for these other languages. who fixes the bugs in a closed source, or incompatible source licensed product?
Here's another question, why isnt it easier to fix some of the issues with TS, since 100% of the source for it is available and there for all to fix.
I refuse to accept the argument that 'nobody knows TS' as a good reason for replacing it, language syntax is pretty fast to understand even for non programmers, most of the hard work is remembering what engine functions do what and that changes for every engine you use, language choice isn't really a factor there.
#38
08/09/2013 (12:42 pm)
Demo, it shouldn't be too hard to dump compiled bytecode to a file, eh?V8 is not designed to produce bytecode. It produces compiled code on the fly. The description I got on how it works excludes a bytecode stage.
Quote:What is actually so awful about TS?It uses white space as an important syntax divider:
// notice space in between new and SimObject new SimObject();Now commence walking into a dark alley for defending TS. ;)
#39
Hey, I want English instead of TorqueScript!
08/09/2013 (1:16 pm)
Hey, Python uses whitespace as an "important syntax divider" too! And so does English, for that matter....Hey, I want English instead of TorqueScript!
#40
Whatthefudgedoyouneedwhitespacefor?
08/09/2013 (1:23 pm)
Quote:Python uses whitespace as an "important syntax divider" too!I plead the 5th!
Whatthefudgedoyouneedwhitespacefor?
Torque Owner Edward Smith
Silencersoft
But of course I think we need to be looking at speed at runtime number 1 if we want to replace TS, unless we can't make TS much closer in speed?
I know some are saying also Lua, I would really like it to remain as a C syntax script language. Surely it makes sense the engine is in C++.
JS with the V8 engine is a great choice in my opinion, though some limitations when it comes to running on non x86 platforms.
There is a lot of talk for a replacement of TS, I think we need a poll on the topic and it needs to make most people happy for it to be adopted.
What are the factors that make TS slow?