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

Discussion in 'Unity Gossip' started by jashan, Feb 27, 2009.

?

Which Unity languages are you currently using?

  1. Boo only

    2.9%
  2. C# only

    53.0%
  3. JavaScript only

    20.9%
  4. Boo & C#

    1.7%
  5. Boo & JavaScript

    0.4%
  6. JavaScript & C#

    20.3%
  7. Boo, C# and JavaScript

    0.7%
  1. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,499
    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 ;-) ). 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):

    [TABLE="width: 500"]
    [TR]
    [TD]Boo only[/TD]
    [TD="align: right"]4.35%[/TD]
    [/TR]
    [TR]
    [TD]C# only[/TD]
    [TD="align: right"]31.10%[/TD]
    [/TR]
    [TR]
    [TD]JavaScript only[/TD]
    [TD="align: right"]31.77%[/TD]
    [/TR]
    [TR]
    [TD]Boo C#[/TD]
    [TD="align: right"]2.68%[/TD]
    [/TR]
    [TR]
    [TD]Boo JavaScript[/TD]
    [TD="align: right"]0.33%[/TD]
    [/TR]
    [TR]
    [TD]JavaScript C#[/TD]
    [TD="align: right"]28.76%[/TD]
    [/TR]
    [TR]
    [TD]Boo, C# and JavaScript[/TD]
    [TD="align: right"]1.00%[/TD]
    [/TR]
    [/TABLE]


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

    [TABLE="width: 500"]
    [TR]
    [TD]Boo only[/TD]
    [TD="align: right"]3.53%[/TD]
    [/TR]
    [TR]
    [TD]C# only[/TD]
    [TD="align: right"]33.55%[/TD]
    [/TR]
    [TR]
    [TD]JavaScript only[/TD]
    [TD="align: right"]30.24%[/TD]
    [/TR]
    [TR]
    [TD]Boo C#[/TD]
    [TD="align: right"]2.21%[/TD]
    [/TR]
    [TR]
    [TD]Boo JavaScript[/TD]
    [TD="align: right"]0.44%[/TD]
    [/TR]
    [TR]
    [TD]JavaScript C#[/TD]
    [TD="align: right"]28.70%[/TD]
    [/TR]
    [TR]
    [TD]Boo, C# and JavaScript[/TD]
    [TD="align: right"]1.32%[/TD]
    [/TR]
    [/TABLE]

    There's a trend becoming obvious here: JavaScript is losing, C# is winning ;-)


    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:

    [TABLE="width: 500"]
    [TR]
    [TD]Boo only[/TD]
    [TD="align: right"]3.26%[/TD]
    [/TR]
    [TR]
    [TD]C# only[/TD]
    [TD="align: right"]37.39%[/TD]
    [/TR]
    [TR]
    [TD]JavaScript only[/TD]
    [TD="align: right"]28.99%[/TD]
    [/TR]
    [TR]
    [TD]Boo C#[/TD]
    [TD="align: right"]2.06%[/TD]
    [/TR]
    [TR]
    [TD]Boo JavaScript[/TD]
    [TD="align: right"]0.51%[/TD]
    [/TR]
    [TR]
    [TD]JavaScript C#[/TD]
    [TD="align: right"]26.59%[/TD]
    [/TR]
    [TR]
    [TD]Boo, C# and JavaScript[/TD]
    [TD="align: right"]1.20%[/TD]
    [/TR]
    [/TABLE]

    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:

    [TABLE="width: 500"]
    [TR]
    [TD]Boo only[/TD]
    [TD="align: right"]3.28%[/TD]
    [/TR]
    [TR]
    [TD]C# only[/TD]
    [TD="align: right"]40.10%[/TD]
    [/TR]
    [TR]
    [TD]JavaScript only[/TD]
    [TD="align: right"]27.92%[/TD]
    [/TR]
    [TR]
    [TD]Boo C#[/TD]
    [TD="align: right"]1.97%[/TD]
    [/TR]
    [TR]
    [TD]Boo JavaScript[/TD]
    [TD="align: right"]0.52%[/TD]
    [/TR]
    [TR]
    [TD]JavaScript C#[/TD]
    [TD="align: right"]25.29%[/TD]
    [/TR]
    [TR]
    [TD]Boo, C# and JavaScript[/TD]
    [TD="align: right"]0.92%[/TD]
    [/TR]
    [/TABLE]

    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%
    Last edited: Jul 18, 2013
  2. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,499
    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:
    Code (csharp):
    1. MyScript myScript = (MyScript) GetComponent(typeof(MyScript));
    Using generics, this would look like:
    Code (csharp):
    1. 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 ;-) ).



    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).
  3. degeneration

    degeneration

    New Member

    Joined:
    Apr 3, 2008
    Messages:
    115
    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
  4. Cu3e

    Cu3e

    New Member

    Joined:
    Oct 27, 2008
    Messages:
    63
    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
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    25,574
    Only Javascript here...no surprise that, eh? ;) 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. ;)

    --Eric
  6. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Messages:
    2,948
    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 (tm)
  7. Adrian

    Adrian

    Member

    Joined:
    Apr 5, 2008
    Messages:
    290
    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:
    Code (csharp):
    1. if (condition)
    2.     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:
    Code (csharp):
    1. if condition:
    2.     Debug.Log("blah")
    3.     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. :)

    There are also things like event handlers, closures and callables (delegates) that are so effortlessly handled in Boo.
    Code (csharp):
    1. # I really like writing
    2. return unless FunctionThatCheckesSometing()
    3. // instead of
    4. if (!FunctionThatChecksSomething())
    5.     return;
    6.  
    7. # Or have function like
    8. def FindWithCallback(center as Vector3, radius as single, callback as callable)
    9. # That can be used like
    10. 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.
  8. codepunk1

    codepunk1

    New Member

    Joined:
    Jan 31, 2009
    Messages:
    19
    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.
  9. VoxelBoy

    VoxelBoy

    Member

    Joined:
    Nov 7, 2008
    Messages:
    201
    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 :D)

    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:
    Code (csharp):
    1. AttachedScript scr = obj.GetComponent(typeof(AttachedScript)) as AttachedScript;
    All that "typeof" and "as blabla" stuff is just starting to get on my nerves :?
  10. Stig_The_Ghost

    Stig_The_Ghost

    New Member

    Joined:
    Sep 4, 2009
    Messages:
    12
    well 1st my background in programing is PHP and Actionscript 3.0 I like the best :)

    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
    Code (csharp):
    1. //javaScript
    2. function myfunc() : void{
    3. //something gos here//
    4. }
    5.  
    6. //c#
    7. //this is function just spell it out void now you know its not going to return anything
    8.  
    9. void myfunc(){
    10. //something gos here//
    11. }
    12.  
    13. Now if you going to return something just flip it around
    14. string myfunc(){
    15. //something gos here//
    16. return;
    17. }
    18.  
    19. //javaScript
    20. function myfunc() : String{
    21. //something gos here//
    22. return;
    23. }
    24.  
    25. //variables and data typing
    26.  
    27. //c#
    28. float mynumber  = 10F;
    29.  
    30. //javaScript  
    31. var mynumber : float = 10;
    32.  
    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..
  11. amy

    amy

    New Member

    Joined:
    Apr 8, 2009
    Messages:
    58
    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.
  12. pete

    pete

    New Member

    Joined:
    Jul 21, 2005
    Messages:
    1,640
    stig - that was cool. probably one of the best comparisons i've seen yet. cheers!
  13. pete

    pete

    New Member

    Joined:
    Jul 21, 2005
    Messages:
    1,640
    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...
  14. Timmer

    Timmer

    New Member

    Joined:
    Jul 28, 2008
    Messages:
    330
    Here you go....
    Code (csharp):
    1. // JavaScript
    2. function myfunc() : void {
    3.     //something gos here//
    4. }
    5.  
    6. // C#
    7. void myfunc() {
    8.     //something gos here//
    9. }
    10.  
    11. # Boo
    12. def myfunc():
    13.     # something goes here and without pinky-killing semicolons!
    14.     # also note no end-function keyword
    15.     # ....
    16.  
    17. Now if you going to return something just flip it around
    18.  
    19. // javaScript
    20. function myfunc() : String {
    21.     //something gos here//
    22.     return;
    23. }
    24.  
    25. // C#
    26. string myfunc(){
    27.     //something gos here//
    28.     return;
    29. }
    30.  
    31. # Boo (explicit return type)
    32. def myfunc() as string:
    33.     # 'as' is the casting/type keyword in Boo so basically sayiing
    34.     # this function is of type 'string'
    35.     # note this is optional and only needed if return type is not clear
    36.     return "hello world"
    37.  
    38. # Boo (less typing version: ie, implicit return type)
    39. def myfunc():
    40.     return "hello, world"
    41.  
    42. //variables and data typing
    43.  
    44. //c#
    45. float mynumber  = 10F;
    46.  
    47. //javaScript  
    48. var mynumber : float = 10;
    49.  
    50. # Boo
    51. mynumber = 10
    52.  
    In summary, if you care about your fingers, you use Boo. If you get paid by keyboard manufacturers you can use the others ;)
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    25,574
    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. ;) (That will be an integer though...you need "mynumber = 10.0" if you want a float.)

    --Eroc
  16. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,499
    As of Unity 2.6 this is finally history. You can now type instead:

    Code (csharp):
    1. AttachedScript scr = obj.GetComponent<AttachedScript>();
    Finally, the Unity API is using generics where it makes sense - yeeeha!!!
  17. andeeeee

    andeeeee

    Unity Technologies

    Joined:
    Jul 19, 2005
    Messages:
    8,729
    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 ;-)
  18. taumel

    taumel

    New Member

    Joined:
    Jun 9, 2005
    Messages:
    5,283
    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.
  19. tonyd

    tonyd

    New Member

    Joined:
    Jun 2, 2009
    Messages:
    1,224
    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:
  20. Stig_The_Ghost

    Stig_The_Ghost

    New Member

    Joined:
    Sep 4, 2009
    Messages:
    12
    Thats Supper Cool I like to play with Boo too, I really love programming its creative just like being and artist :D
  21. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,499
    I just thought I'd post some regular expressions to convert from the "old ugly verbose style" of GetComponent to the new one. Use these regular expressions at your own risk!!! I did this in my project in the 3 steps below and it worked pretty smoothly (using global search and replace with regular expressions activated):

    Code (csharp):
    1. Step 1: Find what:
    2. \({:a+}\){.*}GetComponent\(typeof\(\1\)\)
    3.  
    4. Replace with:
    5. \2GetComponent<\1>()
    6.  
    7.  
    8. Step 2: Find what:
    9. { [A-Za-z0-9\.]+}GetComponent\(typeof\({:a+}\)\) as \2
    10.  
    11. Replace with:
    12. \1GetComponent<\2>()
    13.  
    14.  
    15. Step 3: Find what:
    16. GetComponent\(typeof\({:a+}\)\)
    17.  
    18. Replace with:
    19. GetComponent<\1>()
    If you're not using Asset Server or another version control system and have checked everything in before doing this - be sure to make a backup!
  22. Godheval

    Godheval

    New Member

    Joined:
    Nov 29, 2009
    Messages:
    7
    Sorry not to be able to weigh in on this conversation just yet, but...

    If you are completely new to programming (not counting HTML or CSS - I know, laugh at me), and you want to use Unity3D, which would you recommend between C# and JS?

    I'm hearing a lot of conflicting opinions in this thread alone, and it seems people have reasons for their preferences, but...specifically for a new programmer, which would be easiest to get into?

    What're the limitations, if any, of either language?

    Thanks!

    (Edit: I noticed that all of the Unity documentation and the one book on Unity development all use JS. Is there a reason for this?)
  23. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,499
    I think it really depends on what you like: JavaScript and UnityScript is somewhat less strict which may appear easier to use (and less to type in some cases). It implicitely does a few things for you where C# would throw a compilation error and ask you to tell it exactly what you want. Some people consider this an advantage of JavaScript compared to C# - others (like myself) consider it a disadvantage.

    The reason why I consider it a disadvantage is that when learning programming (or a programming language, or an API - like the one provided by Unity), I want to get all the "relevant" information by just reading the code. I don't want to have to "know" things to fully understand what's going on there - I want to have it written in the code. One reason why I prefer it that way is that it gives me "hooks" which I can follow to look things up. My experience with UnityScript (which is more or less a synonym to JavaScript on these forums) is that especially when learning, those hooks were missing which made it much harder for me. I ended up converting many of the examples from UnityScript to C# - the difficult part in that was "adding the missing information" - the syntax isn't *that* different after all; and then I had examples that I could actually immediately understand when reading them.

    With C#, on the other hand, you may get a few more compiler errors in the beginning - but in my experience you'll get less runtime errors in the long run. "Compiler errors" are those you get without even starting the game - compared to "runtime errors" which only happen when the game executes the code. Compiler errors are always much easier to fix than runtime errors.

    Another reason why I'd always recommend learning C# to a "programming novice" is because C# is a well-specified language with lots of tutorials available. And all of those tutorials refer to the same C# (well, there's different versions, 1.0, 1.1, 2.0 and 3.5 - but those are chronological, Unity is currently at 2.0; 3.5 to be "available" somewhere in the not-so-distant-future).

    If while working with the language you don't understand something and want to know "now what exactly does this mean"? You can always look into the specification and will find the description.

    With JavaScript, on the other hand, when you look for tutorials and learning resources, most of what you will get are tutorials referring to ECMAScript or the JavaScript dialects implemented in browsers. So most of what you get is related to Web development; and significant parts of that are not relevant to using UnityScript aka JavaScript in Unity (which is "very much like JavaScript - but not exactly JavaScript").
  24. Godheval

    Godheval

    New Member

    Joined:
    Nov 29, 2009
    Messages:
    7
    So you're saying that C# makes for cleaner code? Analogous to the difference between using XHTML strict vs. transitional?

    And does it also mean that where I make a mistake in C#, it'll be easier to identify? One of the reasons I've dreaded programming, why I've never gotten into it before, was because I did not want to have to search a hundred pages of code for a single syntax error. Maybe that's just a myth, but...I want to avoid that like the plague.
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    25,574
    Yes, that's a myth...when you get a syntax error, it tells you what line it's on. In any language.

    --Eric
  26. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,499
    Yeah, I think the difference between XHTML strict vs. transitional is a nice analogy. In my opinion, C# enforces cleaner code, while you can also write clean code in JavaScript - but it's just not enforced. Keep in mind, though, that "clean" is in the eye of the beholder ;-)

    I'd say that in general in fact mistakes in C# are easier to identify.

    Modern compilers spit out the line numbers of where they find the problems - so usually, you'll just click on the error message and will be immediately taken to where the problem is (that applies to any language you could use with Unity, though - so that's not something specific to C#).
  27. Godheval

    Godheval

    New Member

    Joined:
    Nov 29, 2009
    Messages:
    7
    Alright, so I'm being swayed towards C#. A little more work in the short-term to save frustrations in the long-term sounds good to me.

    And what's this about intellisense not being available for JS? I might've read something obsolete.
  28. jtbentley

    jtbentley

    Member

    Joined:
    Jun 30, 2009
    Messages:
    1,365
    I know this a pointless post, but I lost it when I saw that.
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    25,574
    I did find your claim about always asking yourself "Does this add anything?" before posting to be suspiciously unlikely. ;)

    --Eruc
  30. Jessy

    Jessy

    Member

    Joined:
    Jun 7, 2007
    Messages:
    7,173
  31. jtbentley

    jtbentley

    Member

    Joined:
    Jun 30, 2009
    Messages:
    1,365
    By bringing it to peoples attention, I was hoping to add something :)

    Oh, and I use Javascript because I find its syntax the easiest :)
  32. Godheval

    Godheval

    New Member

    Joined:
    Nov 29, 2009
    Messages:
    7
    One other thing...

    Does the language matter with regards to whether you'll be using a Mac or a PC? Because isn't C# specific to Microsoft?
  33. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,499
    No, not at all.

    While C# has been developed by Microsoft, it's also available in Mono which is cross-platform. Personally, I really enjoy using Visual Studio (in VMWare, on my Mac) but there's also MonoDevelop which supports C# and is cross-plattform.
  34. Tapgames

    Tapgames

    Member

    Joined:
    Dec 1, 2009
    Messages:
    161
    Hi All,

    I am a Maya user and just want to focus on one language. What I know is that Maya can read Python script so is Boo the language for me to learn?

    Unity Website:
    Unity supports three scripting languages: JavaScript, C#, and a dialect of Python called Boo. All three are equally fast and interoperate. All three can use the underlying .NET libraries which support databases, regular expressions, XML, file access and networking.

    Roy
  35. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    Boo is not exactly python but has similarities, so if you want to focus on one and maya only offers python then it would be boo to learn. But be aware that you can not use Unity iPhone then
  36. Godheval

    Godheval

    New Member

    Joined:
    Nov 29, 2009
    Messages:
    7
    All this stuff about Mono totally confuses me. Is Mono a compiler? And speaking of compilers, can I learn all I need to learn of C# to use Unity with Visual C# Studio Express? Or do I need the full version?

    (By the way, I'm using a PC now, but within a few months I intend to buy a new iMac).
  37. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    Mono is an alternative .NET framework
    You can learn C# up to a given point in VS, but you would need to have VC# 2003 to be on an equal language feature level as you are with unity, so keep in mind that you will likely see things that don't exist in mono 1.2.5

    Generally you can skip the following topics as you can't use them:

    1. The whole window forms stuff
    2. namespaces
    3. no Microsoft.xxx stuff
  38. rouhee

    rouhee

    New Member

    Joined:
    Dec 23, 2008
    Messages:
    194
    C# all the way (and yes, I am little disapointed that all the Help Examples are in Javascript).

    I've never used Boo and I am not going to learn another syntax just for fun.

    And what comes to Javascript, although I can write code with it (I use it mostly for web programming), I find it little too poor for my needs.
  39. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,499
    I've just posted a pretty extensive answer to that question to Unity Answers: What is Mono? Is it a compiler? A language? Or what?

    Btw: C# in Unity is "about" what you get with Visual Studio 2005, which uses .NET 2.0. Mono 1.2.5 is "about" what .NET 2.0 provides. Visual Studio 2003 used .NET 1.1 which is "about" what Unity iPhone provides (in particular: no generics). The current version of Visual Studio (2008) uses .NET 3.5 (or 2.0 if you wish - you can set it in the project settings). 3.5 is "way above" what Unity currently provides ... but 2.0 is just fine ;-)

    Express, Pro or whatever other edition of Visual Studio has no effect regarding the language features (it's more a thing about IDE features, in simpler terms "editor features" ;-) ). So, for most needs, Visual Studio Express should just be fine.
  40. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    d'oooohhh!
    (yes 2003 was VERY LONG ago ... or no wait, I'm just old)
  41. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,499
    Don't you remind me of that! ;-) ... Seriously: Don't tell anybody! The truth is: We were just doing some time travelling to the stone age of computer-technology ... you know? For educational purposes, kk? We were born 2012, weren't we? Don't you remember?
  42. rouhee

    rouhee

    New Member

    Joined:
    Dec 23, 2008
    Messages:
    194
    Oh, the good'old'days ... :D

    When i started bang my head against the wall, the VS6 was out and DirectX was in version 5. :wink:
  43. WinningGuy

    WinningGuy

    New Member

    Joined:
    Aug 10, 2009
    Messages:
    886
    What is it about Boo that keeps it from working on iPhone?

    I thought all 3 languages compiled to pretty much the same code.
  44. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    If I had to guess then the fact that Unity iPhone has no .NET 2.0 only .NET 1.1
  45. aaron parr

    aaron parr

    New Member

    Joined:
    Apr 22, 2007
    Messages:
    577
    Isn't the language restriction on the iphone due to which frameworks they wished to pack into the app?
  46. asterix

    asterix

    New Member

    Joined:
    Aug 1, 2009
    Messages:
    245
    As kid I played a little with Basic, then at school Logo :D, later at high school, more logo. But the teacher make us create a game, it was fun. I din't took any other class on programmation, even if I liked it. I try a little VB, din't like it. Then I decide let's make game. Did a little of Dark Basic, was a waste of time. 3D rad was nice, but limited. Blender game engine, ok, let's skip this one. Then I arrived here. Wow, easy to learn, boo, JavaScript what ever. My first question was: ok what is easy. Here is what I found.

    Some where saying: JS, it is like but it is not like JS. Ok what it is, I still ask myselve. Some said they read or took courses on JS and din't see any link with UnityScript.

    Alot of programmer (doing that as job/ already studied programmation) would say wow it is so easy, C# is perfect, and JS is garbage. OK.

    Also there I read that a guy read a whole book on C# and din't find it usefull.

    Boo, I din't eard of it.

    I start learning JS, then C# to use with Unity. well I really liked C#, but in some place, people can't help you out, cause they only know JS. Or you go in doc and all example are in JS. So if you are a C# programmer YOU ARE SUPPOSED TO KNOW EVERYTHING, and be able to see the C# in through the examples.

    I start to understand all those . . . everywhere, comming from BASIC it is, wow what is that for.
    It look like people get disouraged with Unity or they come from Actionscript (Flash) or another game engine and know where they are going. I believe Unity is for initiated and it should be mentionned in the description of the product, it is called be profesionnal. Like C4 they mention: prior knowledge C++, that is clear, if you don't know it, just not waste your time here. XNA is clear too on that http://www.xnadevelopment.com/tutor...opment/GettingStartedWithXNADevelopment.shtml

    Unity is cool but often frustrating, but have a long run to learn what easy mean. Easy mean, you give that to someone that have not much knowledge and with tutorials you can do alot. Right now Unity is for initiated programmer and people that migrate from another game engine.
  47. zibba

    zibba

    New Member

    Joined:
    Mar 13, 2009
    Messages:
    165
    I use C# because it's easy for me. Easy because I have a C, C++, assembler background and C# is easy compared to C++. Though I would love to see a Unity Pro+ which let me use C++ and forget about the Mono virtual machine :D

    I think all the documentation and tutorials are in UnityScript because the bloke who wrote the manual knew it.

    Unity is "easy" because I don't have to spend 2 years writing the engine, physics, art importers, audio, level editor and so on. It's still programming though. It's not a point and click game maker.
  48. jedy

    jedy

    Member

    Joined:
    Aug 1, 2010
    Messages:
    568
    Javascript is cake. This is why it is so awesome - easy but fully functional.

    Anyways I tend to use C#. Mainly because it is faster. After some Java and C++ development, C# isn't a problem at all.
  49. Kokumo

    Kokumo

    Member

    Joined:
    Jul 23, 2010
    Messages:
    405
    Almost ten years of programming, which includes (not in order):
    - Visual basic
    - Asp
    - Php
    - Pascal
    - Basic
    - Action Script
    - Java
    - .NET

    The last 4 years, working with Action Script, Java and Visual Basic.


    I use C# because of the designs patterns and documentation available; making singletones, interfaces or abstract class are really easy comming from Java, which is quite similar to C.
    If i found a code in Unity Script, i translate it to C# (of course, trying to improve it).

    jashan said everything.


    Nothing in fact... :D
  50. Vimalakirti

    Vimalakirti

    Member

    Joined:
    Oct 12, 2009
    Messages:
    752
    Back around 1980 I used a TRS-80 Model 2 and then my dad got the new product called the "IBM Personal Computer" that had a whopping 64K of RAM and was Soooo Excited! I did a lot of programming in BASIC.

    After that I went to art school, adventured around the world, and built myself a cabin in the mountains of New Mexico with no running water, solar electric, and wood heat for 18 years, so I was far far away from computers and everything about them.

    When I finally came down off the mountain 3 years ago to re-join society I was blown away by what computers had become! I got into making 3d art, first in SecondLife then (after being very inspired by 6 months of complete immersion in World of Warcraft) 3ds Max. I wanted to be part of this exciting new world of computers and virtual worlds!

    I began to learn programming about a year ago. I started with some C++. Eight months ago I started working with Unity and used Javascript because that's what all the tutorials and other resources used. With the help of these forums I can say that now I am a competent JS programmer and can make Unity do most anything I want it to!

    As I wrote, I've been working with JS but have finally been making the switch to C# during the last month because it seems like a more rigorous language and is more widely used, so C# will continue to be an asset no matter what engine/task I am working on. And C# is object oriented so it is a better gateway into the wider world of programming languages. Nowhere in JS have I seen the word "class". I'm not sure if JS can even be called object oriented, but I'm new at all this.

    Since I'm so new to programming, I just love that when I use these languages in Unity I see results. I'm a building contractor by trade so I'm used to looking back at the end of the day and seeing something there that wasn't there that morning. In Unity that happens. I spend a day programming and at the end of the day my program does stuff that it didn't that morning. Cool stuff! Stuff that includes AI, movement, lighting, graphics... It's immediate gratification and who doesn't like that? Of course some days I bang my fingers against the keyboard and nothing happens...

    After taking the last 2 days to translate all my scripts in my latest Unity project from JS to C# what I find annoying is a lack of C# resources. Maybe I'm missing something, but it is hard to dig up examples of code in C#. The syntax is just different enough to be really very frustrating. I would love to see a forum for C# Scripting specifically.