CoffeeScript for warzone scripting.

For AI and campaign script related discussions and questions
User avatar
Duha
Trained
Trained
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

CoffeeScript for warzone scripting.

Post by Duha »

Hi,
CoffeeScript documentation wrote: CoffeeScript is a little language that compiles into JavaScript. Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

The golden rule of CoffeeScript is: "It's just JavaScript". The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable and pretty-printed, passes through JavaScript Lint without warnings, will work in every JavaScript runtime, and tends to run as fast or faster than the equivalent handwritten JavaScript.
http://jashkenas.github.com/coffee-script/


And some words from me:
+
it has good syntax. (to do same thing you need less code)
code is more readable.
code is more valid (you will never forget about var. You cant shoot you legs by using global variable in cycles)

-
You need to learn it. (I have experience in languages which influenced it syntax, I just read docks and start writing.)
Debugging is not good.

Here just two files in js and coffeescript for example:
coffescript
javascript

At current time there is no good way to load coffeescript directy in the game. But it is easy to add. To convert coffescript to javascript you just need js file.

Code: Select all

include('multiplay/skirmish/coffee-script.js')
CoffeeScript.eval('console "It works!"')
http://addons.wz2100.net/ developer
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: CoffeeScript for warzone scripting.

Post by aubergine »

Been there, done that, ran away screaming. After trying it for about 2 months, my reaction was that it didn't make code any easier to read or write, and it certainly didn't speed stuff up because lots of the more modern JS compiler optimisations don't get applied.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
Duha
Trained
Trained
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: CoffeeScript for warzone scripting.

Post by Duha »

aubergine wrote:Been there, done that, ran away screaming. After trying it for about 2 months, my reaction was that it didn't make code any easier to read or write
20 lines instead 10 is harder read and write?
You like brace-counting?
and it certainly didn't speed stuff up because lots of the more modern JS compiler optimisations don't get applied.
Propably you are only one here who knows about "modern JS compilers".
Coffee script converts to pure javascript. Why optimization does not work?

PS. I am coding python and ruby and CoffeeScript is just javascript with python-ruby syntax.
http://addons.wz2100.net/ developer
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: CoffeeScript for warzone scripting.

Post by milo christiansen »

Duha wrote:PS. I am coding python and ruby and CoffeeScript is just javascript with python-ruby syntax.
Which are two examples of horible syntax. Python is my all time least favorite language, largly because of its indentation sensitve nature, but also because of all sorts of other little things.
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
Duha
Trained
Trained
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: CoffeeScript for warzone scripting.

Post by Duha »

milo christiansen wrote:
Duha wrote:PS. I am coding python and ruby and CoffeeScript is just javascript with python-ruby syntax.
Which are two examples of horible syntax.
Give me example of pretty syntax. (C-style, lisp, perl, brainfuck, whitespace?)
Python is my all time least favorite language, largly because of its indentation sensitve nature, but also because of all sorts of other little things.
tastes differ.

I like python for indentation, and other little things (OOP, functional, ducktyping, batteries, runtime debugging, etc.)
IMHO it is language for fast and easy development.

What is you first favorite?
http://addons.wz2100.net/ developer
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: CoffeeScript for warzone scripting.

Post by aubergine »

Javascript might have some rough edges, in fact it has lots of them. And it might not be the nicest thing to look at.

But, IMHO, it's the code equivalent of this tea bowl:

Image

http://en.wikipedia.org/wiki/Wabi-sabi

Coffee Script, on the other hand, is more like this:

Image

It was a good idea in theory, but in practice it's not somewhere I'd want to go.

http://en.wikipedia.org/wiki/Jay_Maynard
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
Andrie
Regular
Regular
Posts: 533
Joined: 20 Jun 2012, 14:11
Location: Suid Afrika

Re: CoffeeScript for warzone scripting.

Post by Andrie »

lol lol :lol2: :lol2: :wink: :lol2: :lol2: :wink:
"My IRC en multiplay naam is Andrie"

Groete Andrie
User avatar
Duha
Trained
Trained
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: CoffeeScript for warzone scripting.

Post by Duha »

aubergine wrote:Coffee Script, on the other hand, is more like this:
IMHO Jay is more cooler then old ugly cup.

And almost same proportion in ages (17 for javascript and 3 for coffescript.)
http://addons.wz2100.net/ developer
raycast
Trained
Trained
Posts: 131
Joined: 12 Sep 2012, 19:16

Re: CoffeeScript for warzone scripting.

Post by raycast »

JavaScript fan shirt:
Image

Javascript... WAT?!?
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: CoffeeScript for warzone scripting.

Post by aubergine »

I'd rather wear that masochism t-shirt than Jay's groin-exposing Tron leotard.

EDIT: Jay is actually a really cool bloke. But that tron leotard... eye rape!
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
Duha
Trained
Trained
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: CoffeeScript for warzone scripting.

Post by Duha »

aubergine wrote:I'd rather wear that masochism t-shirt than Jay's groin-exposing Tron leotard.

EDIT: Jay is actually a really cool bloke. But that tron leotard... eye rape!
I dont` like masochism (once I have deal with AutoIt).

If someone decide to use coffescript I will add here tutorial how to have fast development.
http://addons.wz2100.net/ developer
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: CoffeeScript for warzone scripting.

Post by aubergine »

Duha,

I think it's worth adding tutorial anyway - at the end of the day, if people want to use coffeescript and that results in more AIs or warzone mods, it's good for the community despite the ugly syntax :P
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
raycast
Trained
Trained
Posts: 131
Joined: 12 Sep 2012, 19:16

Re: CoffeeScript for warzone scripting.

Post by raycast »

On a side note: a benefit of CoffeScript may be that it will already catch a number of errors when compiling into JavaScript. While when you write JavaScript directly, most errors will only pop up once the script (or even: part of the script!) is actually used.

But I havn't used CoffeeScript, I don't know how good the CS-to-JS compiler is at catching errors. I have, however, used the Google Closure Compiler. It does a reasonable job at this, definitely better than debugging with the web browser...
iap
Trained
Trained
Posts: 244
Joined: 26 Sep 2009, 16:08

Re: CoffeeScript for warzone scripting.

Post by iap »

If you want to find a better language that compiles to JS, try haxe.
http://haxe.org/
User avatar
Duha
Trained
Trained
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: CoffeeScript for warzone scripting.

Post by Duha »

iap wrote:If you want to find a better language that compiles to JS, try haxe.
http://haxe.org/
It is language (Has more docs to read). Coffeescript is syntax for js.

It has some benefits for debuging but not in wz case.

It less readable. IMHO

CoffeeScript is the #11 most popular language on GitHub
HaXe is the #48 most popular language on GitHub
http://addons.wz2100.net/ developer
Post Reply