Search Unity

What you’re objectively missing when using UnityScript instead than C#

Discussion in 'General Discussion' started by Demigiant, Oct 18, 2012.

Thread Status:
Not open for further replies.
  1. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @Ippokratis: I couldn't agree more. Actually, it would be interesting if we could all do a Yalta pact (hoping no one will want to play Germany :p) and try to broaden the scope of these posts. It would actually be cool to also have a list of the additional features of UnityScript (the automatic Coroutine implementation is probably the one that looks most useful to me, and it's rather cool), and do a "what you're objectively missing when using C# instead than UnityScript" thing.

    @alexzzzz: about the point I just mentioned above, I'm not sure about what you mean with "implicit implementation of classes derived from MonoBehaviour"? And by the way, I'm not sure about this: does every class that you create in US automatically derive from MonoBehaviour? Is that what you meant?
     
  2. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    In UnityScript if you write just

    Code (csharp):
    1. var Health: float;
    it means

    Code (csharp):
    1.  
    2. import UnityEngine;
    3.  
    4. public class ScriptFileNameHere extends MonoBehaviour
    5. {
    6.     public var Health: float;
    7. }
    8.  
     
  3. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    I see. So every class derives from MonoBehaviour and all variables are public by default? Or you can also create a class as in your second piece of code (this would be cool, since it would probably mean that UnityScript will support namespaces)?
     
  4. Redbeer

    Redbeer

    Joined:
    Nov 1, 2009
    Posts:
    402
    Well here's my objective two cents...

    I use Boo.
    I'm probably one of a few.
    ~A Unity Programming Dr. Seuss Tribute.

    Objectively, I do this for the following reasons:
    1) I started teaching a computer programming class using Python, and have become more familiar with the syntax.
    2) What I quickly realized about the syntax was that it's significantly less typing, and not having to type all the curly braces and semicolons is really nice and the indentation is not an issue, as I was in the habit of doing that already for readability, with all the various things I've written code in (C++, C#, etc.)
    3) I prefer static typing, so Boo seems to me to be somewhat of a hybrid of C# and Unityscript, because if I'm going to static type, there's really no reason for me to use Unityscript. I like the ability to duck type too.
    4) While there may not be any jobs using Boo, there are Python jobs, and honestly I'm not looking to become someones code writing, slave bitch anyway.
    Regardless, unlike Unityscript, I can download Boo and use it to write and compile programs, including standard .NET stuff, completely independent of Unity, as I can with C#.
    5) Syntactic macros are pretty sweet. The Pascal case requirement doesn't bug me because I learned that first in college 18 years ago, and I'm not one that quibbles about switching between one way of typing stuff or another as I typically can adjust pretty fluently in an hour or less.
     
  5. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Code (csharp):
    1. var Health: float;
    2. private var a: int;
    3. protected var b: int;
    4. internal var c: int;
    5. protected internal var d: int;
    6.  
    7. function A(){}
    8. private function B(){}
    9. protected function C(){}
    10. internal function D(){}
    11. protected internal function E(){}
    12.  
    13. class TestClass
    14. {
    15.     var x: int;
    16. }
    17.  
    18. class TestStruct extends System.ValueType
    19. {
    20.     var x: int;
    21. }
    compiles into

    Code (csharp):
    1. [Serializable]
    2. public class USTest : MonoBehaviour
    3. {
    4.     // Fields
    5.     public float Health;
    6.     private int a;
    7.     protected int b;
    8.     internal int c;
    9.     protected int d;
    10.  
    11.     // Methods
    12.     public USTest() {}
    13.     private void A() {}
    14.     protected override void B() {}
    15.     internal override void C() {}
    16.     protected internal override void D() {}
    17.     public override void Main() {}
    18. }
    19.  
    20. [Serializable]
    21. public class TestClass
    22. {
    23.     // Fields
    24.     public int x;
    25. }
    26.  
    27. [Serializable, StructLayout(LayoutKind.Sequential)]
    28. public struct TestStruct
    29. {
    30.     public int x;
    31.     public TestStruct()
    32.     {
    33.     }
    34. }
    Notice, "protected internal" field d became just "protected". And there's also a suspicious Main method (it behaves like the Start method, and is called automatically right after it.)

    All the members are public by default, all the methods are virtual by default (I don't know if there is a way to make them non-virtual other than making them private), all the classes are public and serializable by default.

    If you want a class not derived from MonoBehaviour, you should declare it explicitly.

    UnityScript also supports structs, but the syntax is not obvious.

    US can declare interfaces, but I don't remember the correct syntax. There's a funny thing actually about this language - it doesn't have a language reference. There's no such a place you would go to if you wanted to learn the syntax.

    PS
    Here is an interface declaration. Doesn't differ much from C# except optional semicolons.
    Code (csharp):
    1. interface TestInterface
    2. {
    3.     function X()
    4.     function Y()
    5. }
     
    Last edited: Oct 20, 2012
  6. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    Interesting. You're entire campaign of 'freedom of choice' is nothing more than a sham.

    So you're wrong? If so how?

    So, freedom of choice is important [as long as the choice is US], but freedom of expression not so?

    I must be pretty big and scary to be able to do that.

    Interesting - you're emotionally involved in a discussion between programming languages.

    Oooh 'cyber mobbing' can I get me some of that? Does it come in a can?

    And here you are telling me there are no JS users in this thread. Turns out they just share a differ view of things.
     
    Last edited: Oct 21, 2012
  7. Jingle-Fett

    Jingle-Fett

    Joined:
    Oct 18, 2009
    Posts:
    614
    @ npsf3000

    Just to go back to the list<T>() stuff for a second, doesn't ArrayList() in UnityScript do the exact same thing?
    With ArrayList() in US you can put in whatever you want and it automatically resizes the array, and you don't have to specify the ArrayList type. If you want to see it in the inspector you can convert it via ToArray() and the array in the inspector will automatically re-size itself (obviously if you convert it, the inspector array needs a specific type).You don't have to do import System.Collections.Generic either.

    Example working code in js:
    Code (csharp):
    1.  
    2. #pragma strict
    3. var objectArray = ArrayList();
    4. var objectArrayInspector: int[];
    5.  
    6. function Start(){
    7.      objectArray = new ArrayList();
    8.    
    9.      objectArray.Add(1);
    10.      objectArray.Add(4);
    11.      objectArray.Add(7);
    12.      objectArray.Add(3);
    13.      objectArray.Add(8);
    14. }
    15.  
    16. function Update(){
    17.      objectArrayInspector = objectArray.ToArray(int);
    18. }
    19.  
    20. //add objects, remove object, whatever code here
    21.  
    22.  
    Are you talking about something like that or am I thinking of something different?
     
  8. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    An arraylist is not the same, because an ArrayList is a list of object types. A List<T> is a generic list, and any specific instance can only contain the type of object for which it is declared. When you use an ArrayList, the object stored in it has to be dynamically cast back to the correct type on use.
    While I prefer C#, and believe it is stronger, safer, faster, and easier to use, I do believe you can use List<T> in UnityScript also (from UnityAnswers):

    var listOfTransform : List.<Transform> = new List.<Transform>();
     
  9. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    Both ArrayList and List<T> can be used in both C# and UnityScript. The whole List thing is in reference to the fact that in UnityScript you can't implement IList<T> (or any other generic interface), not that you can't use it.
     
  10. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    That's basically the following:

    Code (csharp):
    1. List<Object>()
    And used a similar example in my code snippets see "ObjectPool". It has a couple problems though... for a start you are completely correct: You can put in whatever you want.

    Code (csharp):
    1.  
    2. void Start(){
    3.      intArray = new ArrayList();
    4.      intArray.Add(1);
    5.      intArray.Add(gameObject);  //oops?
    6.      intArray.Add(transform);
    7.      intArray.Add(new Rect(10,10,10,10));
    8.      intArray.Add("This is interesting");
    9. }
    Which raises the following problems:

    1. What types are we dealing with? You can't know without casting.
    2. What happens if the wrong type is put in the Array? Exception?
    3. Structs are being boxed to objects... why? This is inefficient.

    What people have to remember is that C# did not come with generics - take a look at System.Collections - no generics in sight. This is where 'ArrayList' comes from, the 'special' US version is actually Array! What happened is they realized this was crappy situation with people either excessive casting, or 'manually' typing out strongly typed classes [one for every type you wish to use] - so they decided to add Generics into version 2 of C#.

    And as Jaimi superpig has pointed out, you can *consume* generics you just can't implement 'em. Which means you are either limited to what other people have done... or you're stuck with non generic collections functions - you never have the choice to make your own.
     
    Last edited: Oct 21, 2012
  11. Jingle-Fett

    Jingle-Fett

    Joined:
    Oct 18, 2009
    Posts:
    614
    I see, thanks for clearing that up, I didn't really understand the differences. In a practical scenario it sounded like they more or less did the same thing but I see there are big differences.

    Gotcha, I think that might have been one of the other main things throwing me off. I saw on the wiki page that you could use List<T> so that's why it didn't make sense to me
     
    Last edited: Oct 21, 2012
  12. Grafos

    Grafos

    Joined:
    Aug 30, 2011
    Posts:
    231
    I have not used C#, thus I don't even know what most of the stuff you mention US is missing mean. I am pretty sure I don't even use all the features of US. But, I am very comfortable using what I know to efficiently create everything I need with US, so unless I hit a brick wall in the future, I don't see any reason investing time on rewriting reusable code/getting accustomed to a different workflow.

    Who knows, maybe some day I'll look back at the way I am doing things now and think "Wow, I was really taking the long way there and didn't even know it".
     
  13. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    Perfectly reasonable approach - there is a cost for the transition and depending on your needs the benefits might not be sufficient to warrant it for now.

    My advice is to do a bit light reading on the feature differences - and try some light coding in Visual Studio. That way, you should be able to better identify areas where you're potentially being inefficient without having to jump ship.
     
  14. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    No, Mister "i twist the facts until it fits my needs", it is not. Use it. Use whatever you want. I don`t have a problem with that. Which is the difference between us two. You start to cry because i use JS, and not C#. You want the whole world to use C#. So use F# when you want, and best of luck with it.

    F# is nevertheless not supported. The three supported languages in Unity are JS, BOO and C#

    No. You are wrong when you want to declare my personal playground to a bazar where somebody else can tell me what i have to do. Like "could you agree with this and that bit and handle it that way then? No? Then what about this bit? No?"

    My area is my property where i alone decide what to do. It is no bazar, no trading market.

    The freedom of expresssion ends where you put a gun onto my head to convince me to follow your path. Which you did and do. See "make JS deprecated" and every hijacked thread where you and your followers sing the C# song and shoot everybody down that has another opinion.

    Your other C# folks even tell lies like that JS will not longer be supported by Unity. That`s your kind of freedom of expression. I definitely don`t share this kind of expression.

    And again, i am not a JS fanboy, i don`t have anything against C# or their users. And don`t want to convince anybody to JS. Everybody should use what he wants, what fits his needs best. I have something against missionars though. I have something against people that wants to take me away what i prefer to use.

    No. I am emotionally involved into a moron that cannot stop to poke me even when i am not in the thread. Which shows how emotionally you are involved. No weapon is too dirty for you. Grow up, get a living. There is more than C#. And more than this nonsense here.

    So you still don`t see what you did here. Didn´t expect something else.

    What about i start the same? Start laughing about you in every thread where i post something, even when you are not in the thread? Would you still laugh then? Hey, it`s surely funny to do that. "Sssh, or i call nsfp, haha". Then it could be funny for your boss to know that you are an alcoholic, funny for your girlfriend to know that you have another girl, funny for ... . And when you really want i could even send you a can then.

    No, that`s not me. I would never do that. But you did, you did the first step here.

    No i do not. I tell you that this thread has become a "why i use C#" thread meanwhile again. As usual. And as usual when you run out of arguments you start to twist facts. We have reached the polemic chapter of the discussion again.

    And now i am surprised. Where does this 180 degree turn come from? Can it be that you were able to learn? Or did we really misunderstand each other so much before? Because that is exactly what i always say. Try it by yourself, then decide what fits. And is what i did first.

    That`s by the way freedom of choice. When you make JS deprecated, when you hijack every thread to tell the kids to start with C# and Unity really decides to skip the support for JS, then there is no choice anymore.
     
    Last edited: Oct 21, 2012
  15. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,869
    Can you two please take this to private messaging?
     
  16. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    I would. But nsfp prefers to do this publically. He has called for me in this thread. I did not join the discussion at a voluntary base.
     
  17. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,869
    A: You didn't have to respond.
    B: You're still fully capable of taking it to PM.
     
  18. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Sorry when it looks like i didn`t read your answers. I did. It`s just so much points here were again to answer. Your answers and my possible answers to that were at a lower place at my priority list. I´m not so multitasking anymore, i usually concentrate at one issue. Which was in this case somebody pissing at my leg, and the usual "C# is king" debate. And then most of the times the time is gone to give a useful answer. I do care about what others have to say. And as told, i see and understand your intention. Maybe now that the main part of the usual debate is done you can go on with your initial intention. I try not to disturb anymore. I´ve wasted two days here now. That`s enough.

    I still have the opinion though that the languages are simply not comparable. JS and BOO were made for Unity. C# not. JS and C# are at the one hand very similar. So similar that you don`t have bigger problems to switch from C# to JS and vice versa when you really want. An Unity admin has put it this way once: think of JS as C# with Javascript syntax. But then again so different because C# comes from outside, has lots of extra things that you don`t really need inside Unity (even when nice to have). And isn`t made for Unity in the first place.

    And this is simply something that your list does not reflect. Somebody who has no clue about the languages will have a look at the list, see that C# has so much more features, will put More equal Better, and will probably miss that he would be easier and faster done with JS for his pong clone. I just have to think at the usual advices of how to start with C#: grab a book, learn C#, then come back after a year to do your game. To be fair: this advice isn`t really good anyways. You can immediately jump into Unity, and learn there, no matter with which language. But is unfortunately common.
     
  19. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    When i get publically attacked then i answer publically.

    Yes. When i want to.
     
  20. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @alexzzzz: Very interesting, thanks for sharing. I also edited the namespaces thingie on my blog, saying that namespaces will probably be supported by UnityScript too. Do you think I can remove the "probably" and state that as simply true?

    @Redbeer: All good reasons to use Boo, and being able to type the word "duck" while coding is for me already reason enough to use a language ;) One day I will definitely have to learn Boo.

    @Tiles: ok, peace. But in the future please don't say I ignored you when instead you were just keeping me at a low priority ;) I changed my blog post again, adding the disclaimer n.2 and a different final recap which includes what you said.
     
  21. Aurore

    Aurore

    Director of Real-Time Learning

    Joined:
    Aug 1, 2012
    Posts:
    3,106
    Alright guys that's enough. The arena is now closed.
     
Thread Status:
Not open for further replies.