Boo, C# and JavaScript in Unity - Experiences and Opinions

I’ve been thinking about creating this thread for a little while. We have an incredible amount of C# vs. JavaScript threads going on whenever someone asks which is “the best programming language for Unity” (use the search to find those if you look for some heated discussions :wink: ). But I think what would be really helpful for people new to Unity would be an actual list of people’s experiences with the different languages they’re actively using.

For some people, Boo will be best, for some people C# will be best, and for some people JavaScript will be best (in alphabetical order). So instead of trying to find “the best” language, this should help everyone get a basic understanding of the differences between those languages to make an educated decision for themselves.

To best serve that purpose it would be nice if we could avoid discussions and instead just share the personal background - and experiences with the languages we actually use: Where are you coming from (programmer / new to programming, which languages have you used before using Unity etc.), which languages are you working with in Unity, what do you enjoy about using these languages in Unity, what do you find annoying?

Tips and tricks are also very welcome when they go beyond what’s already in the documentation and Wiki:

Unity Documentation:
Writing Scripts in C#
Script compilation (Advanced) [about script compilation order, very relevant if you mix different languages in one project]

Unify Community Wiki:
Common Scripting Pitfalls
JavaScript Quirks
Beginner’s Scripting Guide (a few tips in JavaScript)
Beginner’s Programming Tutorial for C# (and an older version for C#/JavaScript)

I think that one relevant aspect to this is also how much know-how is available for each language on the forums - that’s why I’ve added the poll. For some people, this will not play a role - but for others it may be important to know and currently we only have guesses. Note that this explicitely is about “how many active forum members use language X” - not about how many people use language X in general.

Actually, I wanted to post this into “Scripting” as it’s directly related to scripting - but I can’t create polls in Scripting so I posted to “Gossip” instead. Could someone move this, maybe?

EDIT: Unfortunately I didn’t think of putting the results into the thread every once in a while so that trends become obvious. But there’s wayback … so let’s check out the Web history:http://web.archive.org/web/*/http://forum.unity3d.com/threads/18507-Boo-C-and-JavaScript-in-Unity-Experiences-and-Opinions

The first capture in the archive was Oct 1st, 2010 - about 1 1/2 years after the poll originally was started. Here’s the results from back then (299 voters):

Boo only 4.35%
C# only 31.10%
JavaScript only 31.77%
Boo C# 2.68%
Boo JavaScript 0.33%
JavaScript C# 28.76%
Boo, C# and JavaScript 1.00%

So let’s move one year into the future - sample from Oct 11th, 2011 (453 voters):

Boo only 3.53%
C# only 33.55%
JavaScript only 30.24%
Boo C# 2.21%
Boo JavaScript 0.44%
JavaScript C# 28.70%
Boo, C# and JavaScript 1.32%

There’s a trend becoming obvious here: JavaScript is losing, C# is winning :wink:

Another year into the future - sample from August 31st, 2012 (so it’s not a full year - but that’s the data I have), 583 voters:

Boo only 3.26%
C# only 37.39%
JavaScript only 28.99%
Boo C# 2.06%
Boo JavaScript 0.51%
JavaScript C# 26.59%
Boo, C# and JavaScript 1.20%

So … that trend obviously continues. We also see that Boo is going down a bit - but people using Boo with JavaScript is going up a little bit.

So let’s move almost another year into the future - July 18th, 2013, 763 voters:

Boo only 3.28%
C# only 40.10%
JavaScript only 27.92%
Boo C# 1.97%
Boo JavaScript 0.52%
JavaScript C# 25.29%
Boo, C# and JavaScript 0.92%

So … C# is now used significantly more than JavaScript and the trend is that the difference will become more significant over time … Boo has stalled around 3.28%

Where are you coming from?

I’ve learned programming a long time ago, starting with Basic but really getting into it with Java. For a while, I’ve been doing most projects in Java but once .NET was there moved over to C# and the .NET environment. Currently I’m earning money primarily with Web development which involves a lot of C#, a lot of SQL and a little JavaScript. I also have a little experience in C++, ActionScript, Perl, Visual Basic and a few more languages I never really got into because I didn’t like them.

Which languages are you working with in Unity?

Coming from a strong C#/.NET background one of the reasons I chose Unity was because it supports C# and .NET - so that’s logically the language I’m using primarily. Since many of the examples, tutorials and documentation are based on JavaScript, I also “work” with JavaScript a little - however, that’s primarily taking a JavaScript file and converting it to C#. So, I’m using JavaScript mostly just for reading existing code … not so much for writing my own.

What do you enjoy about using these languages in Unity?

With C#, I get very clear and expressive code - by looking at a piece of code I immediately know which variables have which types, which methods can be used as CoRoutines, when are new objects created and so on. That’s an integral part of the way the language is designed and thus I don’t need naming conventions which artifically add this information.

Also, C# in itself is a very well-specified, standardized and documented language so when there’s some construct that I don’t understand it’s very easy for me to find the relevant specification and read up on it.

Furthermore, many of the “typical programming errors” (misspelled a variable, anyone) are caught during compile time and don’t bug me during runtime where they are more difficult to debug. Actually, most of those errors are now caught during “coding-time” which leads to …

… finally, there are a lot of very advanced tools for developing C# code. So I primarily use Visual Studio 2008 (see Setting up Visual Studio for Unity for information on how to use Visual Studio with Unity when using a Mac, and One click Unity Visual Studio integration for more tips on how to set this up) for coding and Altova UModel for doing software-design for more complex tasks (using Unified Modelling Language (UML)).

With Visual Studio, I particularly like Intellisense which gives me “intelligent code completion”, very advanced and convenient tools for refactoring as well as API documentation available directly as tooltips in the IDE.

What do you find annoying?

Using C# with Unity, there’s a few things that are painfully missing:

Namespaces. While Unity does use Mono and you can use namespaces for “plain old C# classes”, MonoBehaviours cannot be put into namespaces which makes organizing your code into packages very difficult. There’s some workarounds that were discussed here in the forums (search “namespaces” and you should find them) but I found none of them convenient enough for me to use.

[EDIT: Also, the Unity API is only split in two namespaces (UnityEngine and UnityEditor) so be prepared for a lot of scrolling and searching when working with the scripting reference. Furthermore, the Unity API uses some “standard object names” which also exist in commonly used .NET/Mono namespaces which gives you naming conflicts when using those (easily resolved by using the fully qualified class-name but that’s simply not nice).]

Proper use of generics in the API. The Unity API is not really built with generics in mind, so there’s some “old-school” ways of doing things that are “less-than-ideal”, like the all-famous:

MyScript myScript = (MyScript) GetComponent(typeof(MyScript));

Using generics, this would look like:

MyScript myScript = GetComponent<MyScript>();

EDIT: As of Unity 2.6, this is no longer an issue. You can now use the second way of writing this in Unity without any extra effort. No more useless typecasting.

WARNING: If you’re using Unity iPhone, there’s currently no proper solution to this because Unity iPhone does not support generics at all (/me is hoping for an update on this :wink: ).

Properties and their names. Coming from Java and C#, I’m very used to using codestyle guidelines, one of which is that properties are written PascalCase in C#. Unfortunately, the Unity API doesn’t follow this, which makes most properties look like member variables which in reality they are not (which, among other things can give you performance penalties where you wouldn’t expect them).

With JavaScript, which I primarily used when learning the Unity API, I found it very annoying that most of the time variable types are not written explicitely in the code but instead are inferenced from the return types of various methods / properties and so on. So in the beginning, I had a pretty hard time finding out what’s going on and looking it up in Unity’s API reference because the information was simply not available in the code. However, that issue soon dissolved once I got more comfortable with the Unity API (for which converting the examples from JavaScript to C# was actually quite a good exercise).

I’m still quite new to unity and am coding in Javascript because the majority of tutorials and samples seem to be in Javascript. I would be interested in learning C# especially if it had an advantage, but whilst I’m trying to get the things I need to get done done, I’ll stick to Javascript.

My other programming langauges I’ve had experience with are mainly: php, lsl, actionscript, lingo

I experimented a bit with basic as kid, at college I did some pascal and delphi, but java was the first language I really got into in more depth. Later I thought I would study some game programming. I bought a book of C++ and DirectX, but never got excited about it very much. Later I moved to C# mainly because the company I worked for changed to it. Java still remains my favourite language of choice and Eclipse the favourite IDE.

C# and Javascript.

I am quite new to Unity. I started in Javascript because most examples seemed to be written in it. First I experimented a little scripting in C# but found that many things like using yield was so much more straight forward in Javascript.

Now I am writing my own libraries in C# (I use Eclipse with Emonic) and I compile them and use Javascript to interact with my libraries. This way I can use the strengths of both worlds.

I recently realized that this approach has it’s disadvantages, but I haven’t found enough reason to change it yet.

I am not annoyed by anything really. I adapt pretty well. I wish there was better C# and Javascript editors for Mac, but I can manage. Emonic does not work very well on mac, but I still prefer it over MonoDevelop. Don’t ask me why. For Javascript I use Unitron. I am so used to it now, I don’t miss code completion anymore.

edit: Emonic, not Memonic

Only Javascript here…no surprise that, eh? :wink: Every time I say “OK, C# can’t be all that bad” and give it another try, I end up irritated at all the hoops I have to jump through, and with what I consider (never having been into languages like C++ or Java) to be backwards syntax. I like that Javascript is more direct and easier for me to read, without wading through a lot of excess verbosity. Type inference is great (although you don’t have to use it)…C# has that in 3.0, but that’s not used in Unity yet. Being able to use dynamic typing is a big time-saver so I can quickly prototype scripts, and then (but only if it’s speed-critical) I can switch on “#pragma strict” and get rid of it. Being able to use eval() is nice, but with great power comes great responsibility, so I’ve only used it a couple of times (also it has the speed penalty of having to be compiled at run-time).

Annoying things about Javascript: the “unused variable” warning disappeared in 2.1 for some reason. You can define variables without using “var,” which can lead to mistakes through carelessness. Can make use of multi-dimensional built-in arrays (as returned by functions such as GetHeights), but can’t define them for some reason. Can’t pass values to functions as references without using ugly workarounds. Makes iPhone builds a bit bigger than C# because of having to use extra libraries. It’s not Javascript, and should be called Unityscript. :wink:

–Eric

Definitely agreeing on the UnityScript name, but no surprise there either I’d expect. Just like my favouring of C#.

To me, it is primarily a question of habit - coming from a C++ background which leads me to hugely dislike how JavaScript/UnityScript in its less-verbose-force also can lead the developer to believe that he is doing something quite cheap, single operation stuff while JavaScript/UnityScript really is doing a lot of operations behind the scenes based on that syntactically one operation.

I think the documentation argument is less of an issue as I see the two languages as being more or less equal here. We’re all coding against both the .net and the unity libraries here anyway and while one offers examples in C#, the other offers them in UnityScript.

One could argue that perhaps C# would make more sense since you could use the same syntax in applications outside unity, but then if you’re doing applications outside unity or planning to, learning a new language for that shouldn’t be an issue.

New to programming? I’d recommend UnityScript.

Experienced? I shouldn’t have do advice you on the issue - you should be able to make that decision on your own.

Edit
Ok I probably completely misunderstood the intend of this thread as I’m honestly too lazy to fully read a lot of your posts, Jashan :wink:

Anyway: Where are you coming from?
Learned C from a book, writing programs in my grade-school note books. Didn’t have a computer with a compiler, but I really wanted to make computers obay my every whim. OK I wanted to make games!

Had some kind of idea that the only way to program on the mac was to get a license of CodeWarrior which at the time was more expensive than a PC, so I got a PC. My PC pusher told me that the way to go was to learn QuickBasic, so that’s what I did. Wasted a lot of time on that, but it was fun.

Then I got windows on the sucker and went through C++ and Pascal (Delphi). Got a taste for the internets so I did some CGI programming in C++ interfaced with my lovely HTML skills and animated GIFs. Stumbled over Java, PHP, JavaScript and a lot of other trash. Did some funky work in there - got a notion of database use via the PHP/MySQL coupling.

Somehow I got access to a game engine and soon after got hired as game programmer where I went through various engines with their individual mix of their own scripting and C++.

Ack. stopping here. This post is nearing Jashan-size ™

Boo Resources:
Official Homepage: http://boo.codehaus.org/
→ Boo Primer (http://boo.codehaus.org/Boo+Primer)
→ Language Guide (http://boo.codehaus.org/Language+Guide)
Those two links contain almost everything that you could possibly want to know (the rest is .net).

Boo mailing list: http://groups.google.com/group/boolang
For special cases where the documentation doesn’t help.

Where are you coming from?

I’ve first programmed Basic on my TI-89 during boring classes but really started learning programming with PHP, creating homepages and smaller scripts. I then moved on to some Java for non-browser-bound interfaces and portability. I’ve since worked with Python, Ruby and Objective-C. I don’t remember working with Java/Objective-C too fondly because you need to type so much more code for the same functionality than with PHP, Pyhton or Ruby. Especially Ruby was a very pleasing experience which thought me how much fun an elegant language can be (need to work with hashes and cross-reference-jumble-something? You can probably do it with one line of elegant Ruby code :wink:).

Which languages are you working with in Unity?

I’ve worked with JavaScript, touched C# but stayed with Boo. The three languages are very interchangeable in Unity and I have converted some simple scripts between languages in a matter of minutes.
That’s great because it means that it doesn’t really matter what language an example or code is in - I can just quickly convert it in my head.

What do you enjoy about using these languages in Unity?

People with a background in C-style languages usually have problems with Python/Boo where whitespace matters. Sure, with IDEs and some training you can set brackets with ease but once you let go, it’s a relieve to simply create a block with indentation.

A classical case is when you first write a short if statement:

if (condition)
    return;

and then want to add debugging information before the return, forcing you to set brackets which I always thought was a pain, especially when debugging. In Boo, you simply add another line:

if condition:
    Debug.Log("blah")
    return

Also, no semicolons you forget. All basics that are easily learned by rote but you don’t know what you miss until you let it go. :slight_smile:

There are also things like event handlers, closures and callables (delegates) that are so effortlessly handled in Boo.

# I really like writing
return unless FunctionThatCheckesSometing()
// instead of
if (!FunctionThatChecksSomething())
    return;

# Or have function like
def FindWithCallback(center as Vector3, radius as single, callback as callable)
# That can be used like
FindWithCallback(transform.position, 5, {go | return (go.GetComponent(MyScript) != null})

What do you find annoying?

There are some quirks with OO-programming in Unity that I banged my head against. It’s not so much that I really needed them but they do make some things easier and with the strong programming language support in Unity you expect it to handle those cases until you learn that it doesn’t (like overriding properties or namespaces).

Apart from that there is nothing that pops to my ming right now that I find annoying.

Had to vote for C# but not because I actually like it.

Where are you coming from?

20+ years of programming everything from assembler against raw silicone, c, c++, vb, object pascal, php, java, python bla bla bla. Looked at ruby once
but found it also crufty, hard to look at another scripting language once
you know python.

Which languages are you working with in Unity?

C# but only because boo is not working on unity iphone.

What do you enjoy about using these languages in Unity?

I don’t enjoy it, not one bit I hate crufty languages. I am fully comfortable
writing in C#, Java, C etc but it is no where near as productive as python, boo etc.

What do you find annoying?

That I have to resort to using a crufty less productive language because boo is broken on the iphone.

I guess I am kind of spoiled now by programmer efficient languages like python, boo etc. I am fully comfortable writing in java, C# etc but I really
get annoyed by all the extra cruft. If boo was working on the iphone it is close enough to python to make me happy, since it is not I am pretty much forced
to do everything in C# just so I can have portable code.

Where are you coming from?

I’ve only been programming for the past 5 years, senior year of high school to end of senior year in college (which is now.) The first language I worked in was Java and I still like it a lot. Then I learned Scheme, C++, C#, Javascript, Processing, and Arduino. (Well, the last two aren’t really full-blown programming languages but they sound cool :smile:)

Which languages are you working with in Unity?

I started using unity about 4 months ago and the first language I used was Javascript. It seemed easier to get into for some reason, probably because there were more Javascript examples posted on the Unify Wiki and most people seemed to know how to code in JS. Only recently (like, two weeks ago) I’ve switched to C#. The main reason was that I wanted to use the power of inheritance and singletons and it seemed less ambiguous in C# than in JS. I definitely like the strictly defined variables of C# over JS. I’m sure the other case has its uses but not so much in Unity.

What do you enjoy about using these languages in Unity?

Before Unity I was using the C4 Engine, which required you to go into the Source code to add Controllers to make things work. In Unity, it’s much simpler. You want some custom functionality? Script it in JS, C#, or Boo and then attach it to the Game Object you want to control. Bam! No re-building of the source code.

What do you find annoying?

Having to type this:

AttachedScript scr = obj.GetComponent(typeof(AttachedScript)) as AttachedScript;

All that “typeof” and “as blabla” stuff is just starting to get on my nerves :?

well 1st my background in programing is PHP and Actionscript 3.0 I like the best :slight_smile:

so the jump to javaScript was really fast and I was happy it seems like I can do everything I need to do but one day I tried to make my own class an I could not do it in javascript well I can somewhat but its not the same as like in AS3.0 but c# is

Us AS3.0 people look at c# and say what the hell is that… but you need to take a longer look at it
and you will see its the same it’s just fliped… for example

//javaScript
function myfunc() : void{
//something gos here//
}

//c#
//this is function just spell it out void now you know its not going to return anything

void myfunc(){
//something gos here//
}

Now if you going to return something just flip it around
string myfunc(){
//something gos here//
return;
}

//javaScript 
function myfunc() : String{
//something gos here//
return;
}

//variables and data typing 

//c#
float mynumber  = 10F;

//javaScript  
var mynumber : float = 10;

See how things are kind of fliped
But now if you really play with c# you will find out c# is more like as3.0 in allot of ways like how classes work and how you use them feel the same.

In this way I feel c# could be more powerful

Plus I use SmartFox Server pro and it seems you have to use c# to use there frame work anyway its good to know both javaScript and c#

I really Think javaScript it easier to read and more organized but that’s just me…

I hope this makes sents to you I feel sleepy im going to bed…

I don’t like to learn and use proprietary languages that aren’t useable for anything other than the product they are made for. So UnityScript is out of the question for me.

I prefer Boo because I like its python inspired syntax. It’s a more productive language than C# but unfortunately it isn’t supported for iPhone development. I hope this will change now that the Boo creator works for UT.

stig - that was cool. probably one of the best comparisons i’ve seen yet. cheers!

double post on purpose!

hey amy… why don’t you post the same stuff stig did but in boo? i’d be interested in that context.

just a thought…

Here you go…

// JavaScript 
function myfunc() : void { 
    //something gos here// 
} 

// C# 
void myfunc() { 
    //something gos here// 
} 

# Boo
def myfunc():
    # something goes here and without pinky-killing semicolons!
    # also note no end-function keyword
    # ....

Now if you going to return something just flip it around 

// javaScript 
function myfunc() : String { 
    //something gos here// 
    return; 
} 

// C#
string myfunc(){ 
    //something gos here// 
    return; 
} 

# Boo (explicit return type)
def myfunc() as string:
    # 'as' is the casting/type keyword in Boo so basically sayiing
    # this function is of type 'string'
    # note this is optional and only needed if return type is not clear
    return "hello world"

# Boo (less typing version: ie, implicit return type)
def myfunc():
    return "hello, world"

//variables and data typing 

//c# 
float mynumber  = 10F; 

//javaScript  
var mynumber : float = 10; 

# Boo
mynumber = 10

In summary, if you care about your fingers, you use Boo. If you get paid by keyboard manufacturers you can use the others :wink:

Most of those Javascript examples could be shortened quite a bit, though, without losing anything; Javascript and Boo are actually fairly similar in verbosity and share some of the same things (including the author, so that’s not a surprise…). e.g., “mynumber = 10” is valid Javascript if you add a semicolon. :wink: (That will be an integer though…you need “mynumber = 10.0” if you want a float.)

–Eroc

As of Unity 2.6 this is finally history. You can now type instead:

AttachedScript scr = obj.GetComponent<AttachedScript>();

Finally, the Unity API is using generics where it makes sense - yeeeha!!!

Where are you coming from?
I started with Microsoft Basic on the little-known Dragon 32 (!) and later a bit of AmigaBasic. My first programming job was with legacy ThinkPascal code, C/C++ and a bit of Perl. A subsequent job involved web server scripting with PHP/MySQL and a fair bit of stuff in RealBasic and Flash/ActionScript. I’ve also had an interest in Lua and I think array languages like APL and R have great untapped potential. I guess I’m a bit of a language whore, really - I’ll do anything with any available language.

Which languages are you working with in Unity?
For preference C#, but I do some JS for examples, etc. I’m willing to use Boo, but somehow it has never come up…

What do you enjoy about using these languages in Unity?
C# just feels like the latest and greatest development in the familiar C family. Also, the standardisation and the fact you can easily use the same language for non-Unity stuff with Mono. I’m still faintly hoping UT will do a souped-up, game-centric derivative of C sometime in the future.

What do you find annoying?
MyPlayerController player = (MyPlayerController) playerObject.GetComponent(“MyPlayerController”);
(But see previous post…)

Who do you serve and who do you trust?
The Vorlons, obviously :wink:

All three languages aren’t anywhere near perfect for various reasons (better languages already around, poor documenation, better integration needed, …), same like quite some of the Unity commands.

They do work but aren’t enjoyable to use.

Where are you coming from?

Learned Basic on an Apple II a long time ago. Have since used Applescript, c, c++, c#, actionscript, javascript, GML (gamemaker scripting language), and python. Python spoiled me, I have a hard time programming in anything else now!

Which languages are you working with in Unity?

Javascript, but only because BOO isn’t supported on the iPhone. If Iron Python support is added, I’ll switch to that and never look back…

What do you enjoy about using these languages in Unity?

I enjoy not having to learn objective c to make an iPhone game. I enjoy being able to test my code immediately, without having to create a build every time.

What do you find annoying?

Brackets and semi-colons, I think it makes for ugly code. And how painful nested arrays and hashtables are on the iPhone.

I’m also frustrated at how long it’s taking me to master Unity in general. :wink:

Thats Supper Cool I like to play with Boo too, I really love programming its creative just like being and artist :smile: