iPhone, mono and scripting performance

Hi all, I’m going to begin developing in Unity3d, both for the Weband the iPhone.
When I was reading the mono web page I saw that the embedded javascript interpreter is written with C#, so: does it create performance problems?

According to your experience what’s the best language to use for iPhone development with unity3d?

hi,
Jareth

Hi,
on Unity iPhone all scripts are compiled to native code, so script performance is comparable to C code performance.

I personally like to use C# because on iPhone, everything must be strictly typed, which is the only possible way in C#, whereas Javascript can be either way (which is nice normally). Plus, I’m a C++ guy so I’m just more comfortable with C#. Oh, and with C# you can use Microsoft’s excellent MSDN docs to answer most questions you may have about syntax, classes, etc, which is nice.

the docs side is of course nice with C#. Regarding the strict typing side one can just write
#pragma strict
in a js file so then it moans if one doesn´t use strict typing and then one can use JS for iphone dev fine, too.

I’ve been using static typing with JavaScript for a while, now. I don’t like the verbosity of C#, but I like the clarity and efficiency that static typing offers. So, except for the keyword “var”, which is useless to me, I like JavaScript alright.

My favorite language so far has been Objective-C; I wonder how well that would work with Unity.

Not on the iPhone…it has to be statically typed, no dynamic allowed.

Javascript in Unity almost always uses static typing; it’s generally not something you choose to do, except in those rare circumstances where dynamic typing can kick in. Something like ‘var myString = “blah”;’ isn’t dynamic typing…it’s statically typed as a string, because of type inference. 99% of the time you don’t have to explicitly write out the type. If you have 'myVar = Vector3.zero" it’s obvious that it’s a Vector3, so I don’t think doing so helps with clarity either…writing “Vector3” twice just adds noise. The exception being ints and floats where it’s not necessarily obvious.

You don’t actually need that, except when defining public variables; otherwise it’s assumed when a variable is used the first time. Although I wouldn’t call it useless, and would recommend using it, because it’s helpful for avoiding bugs…trying to use “var x = 0” in the same function twice will generate an error, whereas saying “x = 0” twice won’t generate any errors, but might not have the results you intended (if you forgot you already used that variable name, for example).

–Eric

Yes, I know. That’s why I said I liked to use C#, because then I didn’t have to worry about remembering to use #pragma strict. With Javascript, to be safe on iPhone, you have to use #pragma strict or else you can get annoyed.

This isn’t entirely true. Unity iPhone disables dynamic typing altogether. It’s as if every script has a hidden #pragma strict at the top of every file). You don’t have to add it; you’ll get compiler errors as if it were set.

However, it is true that if you’re porting a project to iPhone it helps to have already been using #pragma strict, since you won’t get a bunch of errors that weren’t there before as you soon as you open the project with the iPhone Unity.

Agreed on the noise. However, how are we supposed to know what the 1% is?

If you get an error message. :slight_smile: Other than that, one case is with Objects, such as what’s returned by Instantiate:

var bar : GameObject;
function Start () {
	var foo : GameObject = Instantiate(bar);
	foo.transform.position = Vector3.zero;
}

That’s fine with dynamic typing, as foo will get cast to GameObject on the fly, but you need to specify “var foo : GameObject = Instantiate(bar);” if you’re using #pragma strict or iPhone Unity, since transform isn’t part of Object.

–Eric