Game Development Community

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!

Page«First 1 2 3 Next»
#41
08/09/2013 (1:41 pm)
IagreeIhardlyeverusewhitespaceorpunctuationanywayweshouldjustremovethemfromthelanguagealtogether
#42
08/09/2013 (4:03 pm)
Quote: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.
Care to elaborate? I used to think the same thing but after using Python, CoffeeScript and Haskell for a while, I've basically found it makes no difference to my coding, aside from looking nicer and using less keystrokes. What I do dislike is languages that have keywords for dividers, like Ruby's 'end'.

Quote:What is actually so awful about TS?
It's not about heavy lifting, at least for me - you're right, constant updates and complex logic should be done in source not in script. It's about how fast you can make things in it, how flexible it is and how readily it supports your ideas.

For me, this is made most evident in the way it treats everything as a string, requiring global functions to operate on simple data. Like all the vector functions. Why can we not do %vec.x to get the x coordinate? T2D devs wondered that and added it to the engine, but it's nonsensical. It works for all strings, so you can ask for "do re mi".x and not even realise that "do re mi" is not a vector.

Only if I do something really egregious like VectorAdd("do re mi", 5) will the language complain.

I will concede that JavaScript does have a major problem in not being able to use overloaded operators - so we still couldn't do x+y where x and y are not integers. Python is better in that regard. Or C#, I imagine.

Quote:Here's another question, why isnt it easier to fix some of the issues with TS
That's a really good question. I don't know myself. I would hazard that it's because the console code is a bit of a mess, and hooked into almost every part of the engine.

I've often thought of making improvements - for example, I wanted to add JavaScript-style object literals (without the colons, just using the standard TS object declaration interior). Not sure how helpful it would have been (without garbage collection!), but I wanted to see if I could do it just for fun. The grammar was such that I couldn't get it to recognise that object literals were not the same as opening a new scope after an if statement.

Quote:who fixes the bugs in a closed source, or incompatible source licensed product?
Two answers to this question:
  • Google. They're pretty invested in this JavaScript thing since it's what runs the internet, and will do so increasingly as people start to embrace thin servers and thick clients (which means more JavaScript, and more incentive to optimise JS engines). Replace 'Google' with any of the other large browser vendors with open-source JS engines (like Mozilla's SpiderMonkey).
  • Not us. Probably the more important answer. We as a community don't need to deal with maintaining and improving the script engine. Which is only a good thing as far as I can tell. We don't have the expertise or manpower for that, at least right now. So we hand that job off to someone who wants to do it and who has proven to be very good at doing it, like Google, or whoever maintains Lua, or Python.
Quote:language syntax is pretty fast to understand even for non programmers
That's a very good point. Every time I say that we should use a mainstream language I wait for someone to point out that your first programming language is the hardest - after that it's just a matter of learning slightly different syntax.

But I still believe people would rather use a game engine with a language they're familiar with than a proprietary language. It will remove a barrier to entry for people to work with Torque - not even a difficulty barrier, because TS isn't all that difficult - but a mental barrier that might stop them choosing the engine in the first place.

Quote:But JavaScript, I just can't see it when it comes to object oriented scripting languages.
That's because, unfortunately, it really isn't - though that doesn't stop you from using OO paradigms. I think its features everywhere else (first-class functions and closures, in particular) make up for its lack of OO structure. And things like CoffeeScript add proper OO in. Because the underlying language can support emulating that structure, even if it doesn't have the syntax sugar for it.

Quote:Java without the handcuffs.
Put that way it sounds a whole lot more attractive :P. I guess I never felt a need for a language like that. Probably because I don't do this as a job! If I'm writing stuff, it's for Torque (C++), uni classes (C, Java or Python), my own edification (Haskell), or for web (JavaScript baby! Or CoffeeScript if I can get away with it).
#43
08/10/2013 (1:00 am)
Quote:V8 implements ECMAScript as specified in ECMA-262, 5th edition, and runs on Windows (XP or newer), Mac OS X (10.5 or newer), and Linux systems that use IA-32, x64, or ARM processors.
Ooh, V8 supports ARM! I think a lot of Android runs on ARM. I also saw there may be support by 3rd parties for MIPS.

What do Apple iPhones run?
#44
08/10/2013 (6:44 am)
iOS? Or do you mean which processor?

We can discuss this until the cows come home (when we'll have a barbeque) but what it comes down to for me is a discussion of personal taste. No matter what language you replace TS with someone will insist that another language is superior for a laundry-list of valid (or perhaps invalid) reasons.

Quote:
Quote: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.

Care to elaborate? I used to think the same thing but after using Python, CoffeeScript and Haskell for a while, I've basically found it makes no difference to my coding, aside from looking nicer and using less keystrokes. What I do dislike is languages that have keywords for dividers, like Ruby's 'end'.

My opinion on this is that if every line of each block must start with a certain number of tab characters (and not 3 or 4 or however many spaces specifically) then you have to use a tool for writing your code that somehow points out when you're doing it wrong. It's not possible to look at a source file in most editors and tell if that ' ' whitespace is 4 spaces or a tab and if it's wrong your code won't compile. If you've ever seen any of my code you'll immediately see that simple coding conventions can achieve the same "cleanliness" as a compiler-enforced need to be able to differentiate between different "invisible" characters....
#45
08/10/2013 (7:06 am)
I use Torque Script therefore I am.

Cheers! Pass me the peanuts.

I second Ranft's post.









#46
08/10/2013 (1:17 pm)
Tabs and spaces, we are complaining about tabs and spaces?
"Get out of your parent's basement! Hey you, have you EVER kissed a girl?"

www.everymac.com/systems/apple/iphone/iphone-faq/iphone-processor-types.html
Apparently the iPhone is an ARM platform. So V8 could run there too, theoretically.

@dB,
Makes the best arguments for replacing TS with JS. It will neither be perfect, nor will it be what everyone wants. It will however be one of the best VMs in existence (Google hired the top VM designers on the planet). It is maintained by a multi-billion software company for one of its most publicly visible projecsts: Chrome. Like dB says, we won't have to maintain the VM itself anymore. Just the interfaces.

However, before this can happen there needs to be a solution for code conversion. Without that we will segment the scripting community within T3D. I am sure many of the veteran TS programmers here have libraries and solutions built around TS. So either we need a conversion tool or a tool to run existing TS in parallel or that calls the JS functions directly.

No, it won't be easy, but it will force us to cleanup the console interface and make it more modular. This is a good thing for the engine. It shuts down the argument of not being able to run other scripting languages for good. You would literally be able to point to the interface and say: go read up how to add a different language. No more biotching about Lua or LUA or Python or 'TS is too slow' or 'my dog hates C#' or 'my cat is a Scheme junky' ...

@dB,
When you are ready to do this you have my email.

#47
08/10/2013 (1:45 pm)
JS/V8 does support inheritance through prototype inheritance:
developers.google.com/v8/embed#inherit

It can have both instances of and prototypes of objects. Though this is quite a bit different than classical OOP.
#48
08/10/2013 (9:09 pm)
OMG! WTH!
numba.pydata.org/
It uses freaking decorators to JIT compile a function! It is designed to speed up numpy arrays for scientific computing. I wonder if it will work on the fractal code?! This is crazy stuff.

This is JS, so I am sorry, but this is really cool!
#49
08/10/2013 (10:22 pm)
Demo: cheers for the support - I'll definitely let you know ;). For now, I think I'm going to focus on what you're doing with Python - I'm very happy with that as a scripting language, I just prefer JS for more abstract reasons.

Code conversion is probably a good idea, you're right. My programmer-centric nature kind of jumps to the T2D approach - when it went OS, it did so with a very minimal script codebase. I imagined something similar could happen with a new language. But that's not exactly attractive for people who don't enjoy coding for its own sake :P.

Decorators are so cool... I need to research them more. A fella in one of my classes wrote a decorator to automatically memoise calls in a mahcine learning assignment he was doing :P. Do you reckon we could use them for more easily defining Python callbacks to/from T3D?

Richard: you're right, I doubt there'll be a choice that makes everyone happy. I've never really run into the tabs/spaces issue, except doing silly things like trying to edit my code in vim but run it from IDLE... and then making little tweaks in IDLE, which doesn't have any sensible tabbing options... I should just find a good Python plugin for vim :P.
#50
08/10/2013 (10:44 pm)
@dB,
Yes, I think you could. I just didn't go through the effort of doing so. You can also decorate an entire class. I looked into it for functions, but kind of got lost as I only wanted to run the decorator the first time it was called. So I just did in the __init__ function and called it good. I am not sure I was all there at the time... ;)

I think your efforts with minimizing the code base could be a starting point. The core vs game codebase division has always confused me. So a more minimalist approach would help. I have been trying to run it through my head how I would convert the code base to Python and I get lost pretty quick. So I am attempting a graft to get things to work. One shift is the difference between Python and TS compiles. The game compiles TS when it needs stuff. Python compiles everything and then calls what it needs. So I have to think around how those two paradigms will work when I only want client code on the client and server code on the server sides. I have just decided for now I will use callbacks to do this. Then I have to make sure I only expose those functions that are needed by each type of mode the program is running in. I think this would affect JS as well if it was in the core.
#51
08/11/2013 (9:03 am)
Quote:Tabs and spaces, we are complaining about tabs and spaces?
"Get out of your parent's basement! Hey you, have you EVER kissed a girl?"

I'm not "complaining," I'm saying that I am not a fan of what amounts to invisible code. I was always under the impression that high level languages were supposed to be "human readable." ;p
#52
08/11/2013 (12:55 pm)
I had a big response to all this whitespace is bad talk. However, I don't think it will help anyone. It is fairly obvious that those against it for delimiting code blocks have never used a language for any significant amount of time that does use it for that purpose. To me this is a very minor feature of the language anyway. Heck I started programming in Pascal with begin and end statements.

I will say this though. One of the things that Python strives to achieve through its design is "human readable" code. Perhaps there is more to their choice of white space than is apparent at first glance?

Self introspection moment:
I have noticed that as a community we (myself include) tend to pounce on and nit pick things we don't agree with. I, shamefully, have participated in this as well. This will kill a community. It may have already pushed people away. So for my personal growth I am going to work on only providing positive input on topics, and not being goaded into reactive comments. This should be a time saver as well.
Page«First 1 2 3 Next»