Search Unity

C# vs. Java Script

Discussion in 'Community Learning & Teaching' started by lewaP, Feb 21, 2011.

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

    lewaP

    Joined:
    Feb 21, 2011
    Posts:
    3
    Hello everyone I'm Pawel and complete new to Unity and Programming. Haven't even started to properly learn programming and that's exactly why I made this thread.

    What would you recommend to learn first, Is oone of the above (c# or JS) easier to learn for beginners. Does it make a difference in the long run what I learn?

    Maybe you could help me with answering some of these questions. Thank you for your time

    kind regards Pawel
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    In my opinion, you should learn JavaScript (its actually UnityScript but thats not important) first because it is a simpler language. With C#, you have a bit more functionality, but because you are a beginner I doubt you would get into those aspects.

    Once you are fluent in JavaScript, (Or any language for that matter) it is far easier to learn another language such as C#.

    My suggestion: JavaScript.
     
  3. WinningGuy

    WinningGuy

    Joined:
    Aug 10, 2009
    Posts:
    884
    I'd suggest C#.

    You'll find far more resources for C# that you'd be able to learn with, and then use what you've learned in Unity.

    With Javascript, most of the 3rd party learning resources you'll find focus on programming for websites, not game development. So you'll pretty much be stuck with Unity specific tutorials.

    Unity specific Javascript/Unityscript tutorials aren't bad. But they're not going to teach you general programming concepts as well as a book that focuses on general programming. And for resources about general programming, C# beats Unityscript by a mile.
     
    tanwarrohit825 likes this.
  4. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    821
    I highly suggest C#

    Three main reasons:

    1) The Syntax really isn't any harder, just different - and the more advanced features available certainly aren't required right out of the gate.
    2) There is much better documentation available (since C# under Unity is pretty much identical to C# anywhere else).
    3) UnityScript will let you get away with a lot of sloppy coding that, down the line, will form bad habits you wish you never had.

    C# is more strict than JS/US - but that translates into cleaner code, a better understanding of what you are actually writing, and better performance.
     
    tanwarrohit825 likes this.
  5. LFLFM

    LFLFM

    Joined:
    Feb 28, 2011
    Posts:
    5
    C# by a long shot; for the same reasons already stated, but to me, the major reason is:
    --> C# is (much) more strict

    Some people see this as a disadvantage; but my guess is that these people never worked with larger projects. You cannot work on assumptions and you cannot work with autodeclared variables... Seriously, who invented autodeclaration of variables?!?? one letter that you mistype and BAM, you have a new variable and your code is broken!
    tihs is a vairable autodlared <-- THAT is the main reason autodeclare shouldn't exist. ;-)

    Basically, what I'm saying to you is... the more strict the language you are working with is, the more solid the final code will be and honestly... because you'll run into less bugs, the development process will also be faster. Just make sure you use a good IDE such as visual studio 2010 express (no need to buy the pro, its a little more convenient, but much more expensive; not worth it for Unity programming).
     
  6. LucasDaltro

    LucasDaltro

    Joined:
    Oct 31, 2010
    Posts:
    236
    I think js is better because is more easy,more simple and most of unity tutorials are in js.The guys prefer c# because they are already programmers and most of programmers are comfortable with c# or java or even c++(these languges seems c# syntax).But I can only say this:Start in js.
    Somebody already thinks that nobody codes in boo?
     
  7. Diana_Diana89

    Diana_Diana89

    Joined:
    Oct 17, 2011
    Posts:
    4
    i studied c# language and i actually liked it . yes , it was a bit hard at the beginning but i think it was worth it . .c# is more strict than javascript but you have a clear idea of what you are doing and if you make any mistakes in your programme.
     
  8. inEarth

    inEarth

    Joined:
    Nov 27, 2011
    Posts:
    7
    If you're a programmer, or want to get into serious programming, pick C#... I actually started with c/c++ and as a result there is a lot of knowledge about writing good and fast code that I take for granted that you'll never know if you do JS..

    If you want to eventually get into writing games in Unity with more advanced data structures and making things run at 60 fps.. you'll need to understand concepts like data localization and cache friendly coding, which C# at least gives you a better handle on.

    While you can learn the language, you'll not be coding C# the way it should be. You will use bad programming practices when you move from JS to C#... These rules are critical if you want to do any kind of serious programming with games.
     
    Last edited: Nov 28, 2011
  9. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Besides these features, what other things that C# can do only?
     
  10. Diviner

    Diviner

    Joined:
    May 8, 2010
    Posts:
    677
    At the time of the writing of this post, Unityscript cannot handle true delegation, reference parameters and output parameters (may be more it's missing but I haven't encountered them yet).

    To combat the true delegation issue, Unityscript offers "Function type" pseudo-delegation but it's severely limited and in many cases it's completely insufficient (such as designing events for RPGs/MMORPGs). You are forced to bloat your event functions leading to non-optimized spaghetti code.

    Reference and output parameters are completely out of the question in Unityscript, forcing you to create multiple one-time-use classes to return more than a single value, making your code even more bloated with a serious hit on RAM usage.

    If you want to make simple puzzle games and platformers, choose whatever you fancy. If you want to make a serious game with depth and sophistication, Unityscript is completely out of the question. Stick to C#, you can use it for more than just Unity.
     
    Last edited: Nov 29, 2011
  11. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Another vote for C# .... it's a much more structured language that will ingrain good programming habits from the beginning.
     
  12. inEarth

    inEarth

    Joined:
    Nov 27, 2011
    Posts:
    7
    There's a lot of bad slow things that you can do in Unity, and honestly most of those things wouldn't even enter into my head because I know they're slow simply by the nature of it...

    GameObject.Find?... I've seen people use this in loops... Honestly, any programmer will instantly know why this is bad, because they know how they would implement a Find function and things like this aren't apparent in JS.

    Even when you call unity functions, I instinctively know why that might be bad.
    Two words: CACHE MISS.

    In my opinion, I'd say look at Unity as a tool to make development faster, but it is no substitute for real programming knowledge. Live and breathe this stuff... Learn as much programming as you can. Please don't think that just because Unity came along suddenly anyone can make fast complex games. Nope.

    And in my opinion UnityScript/JS will only occlude these bad behaviors...

    But if you want to make simple puzzle games, Diviner is right, you can pick any language.

    If you want to make more complex games:

    Learn how cache and memory works. Learn math!!! difference between using magnitude and magnitudeSqr for example... Learn how data localization works, storing data in contiguous buckets of memory for fast pointer math under the hood and fast access of data (avoiding cache misses)...

    Sorry to break it to you, but just because c/c++ isn't used here, doesn't mean that a lot of those principles don't apply.

    But yes, you could probably get this same performance by doing these good programming practices in UnityScript, just that still requires a good understanding that you start to really get once use a more strict programming language.
     
    Last edited: Nov 30, 2011
  13. Nomad72

    Nomad72

    Joined:
    Oct 25, 2011
    Posts:
    117
    This thread has made me decide to go the C# route, despite the fact that the tutorials I'm currently working through are done in JavaScript (the Walker Brothers course). I have used C# before in a web development context, so the syntax is familiar to me. However, web development and game development are quite different (duh!) so a lot of the things mentioned here, especially by inEarth, are completely new to me. There is clearly a world of difference between knowing a language's syntax and good programming.

    Can anyone recommend a decent book/resource for learning the "important stuff" about game programming in C#? There are tons of books/websites out there, but I have no way of knowing which ones will actually deal with the kind of issues used as reasons to choose C# over UnityScript.
     
    Last edited: Nov 30, 2011
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    There is a good "Getting Started" tutorial for C# that can be found in my .sig, but it sounds like you are looking more for theory than basic "Getting Started" details, no?

    Speaking of which, Welcome to the Unity Community, Nomad72. If you have any have any difficulty finding what you need, drop me a line - and take note of the Custom Search Engine in my .sig as well, as this can help find answers to questions in a number of different pages and places.

    [edit]

    I have updated my .sig from having a direct link to the tutorial to making it a link to a sticky thread that includes resources for both C# UnityScript(JS).

    The direct link is:
    http://www.csharp-station.com/Tutorials.aspx
     
  15. Nomad72

    Nomad72

    Joined:
    Oct 25, 2011
    Posts:
    117
    Little Angel, thanks for the welcome! I am using the "Getting started" link in your sig (really good tutorials!) in conjunction with the Unity Scripting Reference as I attempt to translate the Walker Brother's script into C#, just to make sure I'm doing things correctly!

    I guess what I was getting at in my post above is this: it's all well and good to say to beginners "use C# rather than UnityScript because it has a bunch of stuff you will need to know in order to do serious programming." However, actually learning that "stuff" so that you can do serious programming is another thing entirely. That does require more than just syntax knowledge, but a deeper understanding of what good practises are, and why they are good practises.

    At this stage, I supose it doesn't matter much since I'm still getting to grips the basics of game development. Still, if there are in fact good books/resources that deal with issues like "data localization, storing data in contiguous buckets of memory" etc. etc. , this would be nice to know for future reference.
     
  16. Endgame

    Endgame

    Joined:
    Dec 9, 2011
    Posts:
    61
    I am pretty new to Unity myself, with some Java programming under my belt, and a little knowledge of C from using matlab. Since you stated that you are new, both to programming and Unity, I would suggest follow a few of the smaller tutorials that are easily found on the unity site or google, to get a feel for programming in Unity before you get into the longer more indepth tutorials.
    As far as I can tell, most of the tutorials that i found helpful were done in JS. After playing around with unity for awhile now, I have finally started working on my own game, in JS. I chose JS due to the availability of the example code that would work for me. I initially tried to code it in C# but i just couldn't bring it together, and decided since my game was simple 2D that JS would not be too bulky. My preference may come from my prior experience. The only way to know for sure what will work for you is to dive in and get your hands dirty. Do some of both. A lot of new Unity users that post on this site seem to talk about hot 3d graphics, RPG's, FPS etc. ie complex games. This is where C# will be of benefit. But if you are new, this is a long ways off.

    this quote might explain the problem i am currently stuck on. Everything went swimmingly till I couldn't figure out how to pass outputs. I may be converting to c#.
     
  17. Diviner

    Diviner

    Joined:
    May 8, 2010
    Posts:
    677
    I just encountered another limitation of Unityscript. You can't create namespaces (namespace keyword is not supported in Unityscript). You can import existing ones, just not create new ones.

    Add this to my list above.
     
    Last edited: Dec 13, 2011
  18. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Performancewise and featurewise there is no difference between C# and Javascript in Unity. You will miss nothing with either the one choice nor the other. And also bad programming habits are not limited to one language. That`s nonsense.

    Unity`s Javascript is easier to pick up by non programmers though. And you need less code to write the same content. And most of Unity tutorials are for Unity`s Javascript.

    It`s in the end more a thing of faith and personal flavour. And if you have eventually used C# or Javascript before.
     
  19. Wekthor

    Wekthor

    Joined:
    Apr 30, 2011
    Posts:
    165
    Definitely javascript. Period.

    C# is out of question, if you are beginner. All comments that were made on regards of C# performance and functionality are valid, but these things shouldnt be of any concern to you right now. You need to learn basics, so you should start with basic language. I am telling you this of my own experience i started with C# and was learning it for half of an year, i learned all the concepts and basics, but i wasnt able to write the game with that knowledge. It was nightmare even with all the knowledge i was able to gather in that time, to code my own projects. You dont become coder by learning syntax, but by actual coding and you wont be able to do that for a long time in C#, i learned javascript well in two months and with all availabe resources i was easily able to code pretty much anything. And right now after some time and few bigger projects behind me with javascript i am again exploring C# and also started looking into C++.

    Start easy and work your way up to more difficult things. There are definitely some bad habits you can create if you will start only with javascript, so looking into C# basics is good idea, but for actual first coding experiences you can definitely use javascript. There are tons of games written in javascript and if you do it right, performance can be also great, so its not like we are talking about day and night difference, C# is just better, but you can make great games even with javascript and thats all that matters at the end of the day.
     
  20. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,997
    I found javascript to be easier for me. Just try both and pick your favorite! :)
     
  21. vaskess

    vaskess

    Joined:
    Nov 23, 2016
    Posts:
    1
  22. Kalladystine

    Kalladystine

    Joined:
    Jan 12, 2015
    Posts:
    227
    Just to clear it out - the question has been beaten to death numerous times.
    General consensus, against this particular thread, is C# is the way to go. Or even that the question should be reversed to "is UnityScript still a viable language?" with an answer of "No, it isn't.".

    This doesn't mean that you can't do a project in UnityScript (note - it's not actual JavaScript), it's just that if you're starting, UnityScript is a dead end.

    As a sidenote - features of C#7 are not really that relevant, as Unity is behind actual .Net/C# curve by a mile (but slowly catching up). Same for JS, as UnityScript is not JavaScript, it just has similar syntax and semantics.
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Please do not resurrect dead posts.

    I am closing this thread.
     
Thread Status:
Not open for further replies.