Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

What makes C# so appealing?

Discussion in 'General Discussion' started by Mr-GamingWatch, Mar 15, 2015.

Thread Status:
Not open for further replies.
  1. Mr-GamingWatch

    Mr-GamingWatch

    Joined:
    Jan 17, 2015
    Posts:
    29
    Hey everyone

    I've been thinking recently about the language my scripts are in, and I was wondering why is it so common for developers to write in C#?

    Personally, I prefer Javascript in Unity, but it's evidently few people share that preference.

    Why do so many people choose C# over other languages?
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,143
    One of the big disadvantages of UnityScript is that it isn't actual JavaScript. It may resemble it to a large degree but there are enough differences that it is effectively a separate language. If someone were to write a US script that made no references to Unity's API, it would still largely fail to run within a normal JavaScript environment.

    Contrast this with Unity's C# which is identical to other implementations of C#. Code snippets that do not rely on Unity's API will function outside of Unity with no changes. The inverse is going to be equally true and this is where C# really shines.

    Resources aimed at JavaScript, learning or otherwise, will be far less valuable than those for C#.
     
    the_motionblur, Socrates, ZJP and 3 others like this.
  3. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    To echo what @Ryiah has just stated a lot of people, myself included, use C# outside of Unity for everything from a web backend to enterprise applications with Xamarin really sweetening the deal allowing publishing of iOS and Android applications written in C#. So being able to take that knowledge already in place and use it within Unity is just the icing on the cake.
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Bunch of thoughts, in no order.

    Documentation. It's pretty much what other users have said. On MSDN I can look up every standard class and see code examples. Impossible in JavaScript.

    Community support. Google something like "sort a list c#" and you'll get a SO question with a bunch of answers. Not so for JavaScript.

    Control. C# doesn't do fancy synantic sugar stuff. No pretend dynamic typing. No implicit class declarations. The language straight out does what you tell it too. It would be okay if all of the JavaScript stuff was properly documented, but see above.

    Support. Almost all tutorials these days are written with C# in mind. There is more support for it in the forums too.

    And what does JavaScript offer for losing all of this? It saves you a couple of lines of typing. Hardly worth the trade off.
     
  5. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    personally i use C# because i use C#
    if i used something else then i'd use that
     
    chingwa and Kiwasi like this.
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I'm glad the human brain is not subject to freezes on encountering infinite loops the same way Unity is.
     
    Gigiwoo, Spoken_OS, Tomnnn and 5 others like this.
  7. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    what better reason other than UnityScript is a pretend language do you need?

    In other words, you can only code in US in Unity. It has zero use outside of that. Even boo has use outside of Unity.
     
    Kiwasi likes this.
  8. nosyrbllewe

    nosyrbllewe

    Joined:
    Oct 18, 2012
    Posts:
    182
    Also, UnityScript often has problems in Visual Studio.
     
  9. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,796
    - C# is a very well documented language, and can be used not only in Unity, but in many other career paths
    - It works well with Visual Studio, and even more importantly, it works well with Resharper, which makes coding 10x easier and more efficient.
    - It takes care of all the plumbing for you and allows you to focus on coding logic, not worrying about memory and all the other things that would come with a language such as C++

    * I'm not going to say anything about UnityScript. Because we all know what happens after that..
     
    Last edited: Mar 16, 2015
    Ryiah likes this.
  10. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    I first learned c, then c++ and then c# so it was a just natural evolution for me. Not having to manage memory, the events and delegates etc
     
  11. Socrates

    Socrates

    Joined:
    Mar 29, 2011
    Posts:
    787
    What happens? Unity knocks on your door and demands their mustache back? :)
     
    Gigiwoo likes this.
  12. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Tomnnn and Ryiah like this.
  13. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,796
    Kiwasi likes this.
  14. Waz

    Waz

    Joined:
    May 1, 2010
    Posts:
    287
    Problems ... like not really being any use at all. Using VS with UScript is pointless - you get more (eg. debugging) by sticking with MonoDevelop if using UScript. ... with all the pain that comes along with MonoDevelop.
     
  15. RichardKain

    RichardKain

    Joined:
    Oct 1, 2012
    Posts:
    1,261
    C# has strict typing, which is usually considered better for debugging purposes. Javascript is a lot more free and loose when it comes to declaring and using variables, but this flexibility can make it a nightmare to debug. As usual with most programming languages, there are trade-offs no matter which option you decide to go for.

    I always use C#, but it was one of the first serious programming languages I learned, so I'm quite familiar and comfortable with it. Using the language you are most comfortable with is often better, as it tends to improve your productivity.
     
  16. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,516
    To me this is the main one, and it works both ways.

    For starters it means that C# code written for Unity can often be used elsewhere (as long as you follow standard software dev practices like keeping your data, UI and functionality separate), and code written elsewhere can often be used in Unity. This opens up the possibility of loads of 3rd party libraries, tools, etc. being integrated with Unity with relatively little effort, not to mention existing legacy code. A lot of my work involves working with simulation developers who work in C#.

    Secondly, when looking to build a team there are plenty of professionals with prior C# experience, and anyone using C# professionally can probably transfer that skill directly into another job in the future. Neither of those things are true of US.

    Documentation has already been covered, so no need to go over that again.

    Aside from that, I think the rest is personal preference.
     
  17. RichardKain

    RichardKain

    Joined:
    Oct 1, 2012
    Posts:
    1,261
    It's true that C# has better documentation. But I wouldn't dismiss Javascript as a possible career in other industries. Thanks to the continuing growth in HTML5, there is actually quite a demand for capable Javascript developers now. Of course, this is for the web industry primarily, and not games. Javascript is still finding its footing a little when it comes to game development, even on the web.
     
  18. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,143
    If only Unity had actual JavaScript. :p
     
    Socrates likes this.
  19. Socrates

    Socrates

    Joined:
    Mar 29, 2011
    Posts:
    787
    I doubt I missed it; more like avoided it like the plague. I'm still recovering from the Down With Egyptian Brackets War of 1991.
     
    superpig and Kiwasi like this.
  20. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    This is true if you do actual JavaScript. UnityScript is not the same thing.
     
    angrypenguin likes this.
  21. RichardKain

    RichardKain

    Joined:
    Oct 1, 2012
    Posts:
    1,261
    A fair point. UnityScript is not exactly the same as Javascript. But UnityScript is based on Javascript, and has numerous structural similarities. A solid understanding of UnityScript could serve as a decent introduction to more advanced Javascript development. And a prior grasp of Javascripting definitely helps you better understand UnityScript out of the gate.

    Those who start off learning UnityScript aren't necessarily setting themselves up for a dead technology. There is some room for them to transition their skills into other applications, applications that have merit in other industries.

    That said, the opportunities for C# coders to transition to other industries are quite a bit more numerous. C#, in the form of ASP.NET and server coding is a pretty widely applied technology.
     
  22. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Try to use C# in Unreal, then let's talk again about zero use outside of Unity ;)

    To point me to things outside of Unity is pointless. Because fact is we all use Unity here. Most likely for a game, since Unity is a game engine. And not some imaginary engine for an imaginary project where we could have a imaginary need for " insert favourite language here ".

    Important is what is available in your current environment. And then it's the simple decision what does the better job for your needs. Which is something that just you can decide. Not some self called missionars who thinks they knows best for the rest of the world.

    Unity JS has definitely its place. For quite a few people it is easier to understand and to use, while doing the job just fine. Which is a no brainer then.

    The available language is just a tool. It changes as fast as you change the engine anyways. I've gone through quite a few engines and languages in the past. I had and have not a single need for C# outside of Unity. When i would work outside of Unity then most likely in Unreal. And Unreal uses Blueprints/C++. Or Godot maybe. That's a Python dialect. Currently i have a closer look at Fabric Engine. That's a completely proprietary language called KL.

    Don't nail it at the language. Nail it at the engine. I don't write code with C# or JS. I develop a game with Unity. That's a big difference.
     
    crag and KellyThomas like this.
  23. KellyThomas

    KellyThomas

    Joined:
    Jul 1, 2012
    Posts:
    39
    UnityScript is more alike to ActionScript with implied classes than JavaScript as it is typically used.

    I don't think experience with Unity will help people with this:

    Code (JavaScript):
    1.     (function($) {
    2.         $(document).ready(function() {
    3.             $('form#tablename_form :input:visible:enabled:first').focus()
    4.         });
    5.     })(django.jQuery);
    Conversely people with experience with JavaScript will have a lot of work getting used to the nuances of UnityScript syntax.
     
  24. 3agle

    3agle

    Joined:
    Jul 9, 2012
    Posts:
    508
    Of course, you could actually do this. :D
    https://mono-ue.github.io/
     
  25. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Yeah, you could. When Unreal wouldn't have forbidden it by its eula :)

    They have added a clause that language bindings have to be free. And Xamarin wants money. The whole thing is at halt now. The download seems to be broken from what i heard.

    My guess is that they wanted to prevent to end in the same licensing dilemma as Unity is now. A stone old Mono version, a stone old Monodevelop ...
     
  26. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,793
    I came from 9+ years of various flavors of AS. It took me zero hours to start developing in US. I can take all my tricks and reconvert them back into ECMA styled scripting. The only resources I need are the scripting API when developing in Unity.
     
    crag likes this.
  27. 3agle

    3agle

    Joined:
    Jul 9, 2012
    Posts:
    508
    That's a shame, as Xamarin would undoubtedly be the best people to provide such functionality, however there are other projects in the works (supposedly one not far off), to get open C# support. I won't link to the thread as this is going in a direction I didn't intend it to, but you can find it on their forums in the Mono C# Bindings thread.
     
  28. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Does anyone actually use javascript? I think in my IT202 class it was used for like a week, then we switched to JQuery and AngularJS. I know they're both javascript, but does anyone use javascript without something like that?
     
  29. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Yeah, there are plans. But there is no C# for Unreal yet.

    My point wasn't Unreal anyways. My point was that it is not very likely that you can really use C# in your next engine.
     
  30. XGundam05

    XGundam05

    Joined:
    Mar 29, 2012
    Posts:
    473
    Yup, I do. jQuery is both super bloated and a crutch. Crutch may be too loaded a word, but I run into too many developers who write js that leaks all over the place because of too much reliance on jQuery.

    Another note as to the difference between US and JS: US uses traditional classes and inheritance, JS is a prototypal (prototypical) language.
     
  31. RichardKain

    RichardKain

    Joined:
    Oct 1, 2012
    Posts:
    1,261
    Not often, no. But then, not many people use C++ just as it is, they normally throw in some OpenGL. And most people don't just use C# as it is, they throw in some extra libraries so that they don't have to re-invent the wheel every time. The same is true for jQuery and Angular. Even if you use those libraries, it's still a good idea to learn the basics of Javascript itself. If nothing else it would help you to understand how those libraries operate. (and alter them if necessary)

    And the same holds true for Unity. Learning the basics of the scripting language you are using is always a good idea. Just trying to leap directly to results without appreciating some of the underlying structure is never wise. Sure, it's great to be able to throw something together quickly. But at some point it is best to step back and make certain everything is working correctly. Relying too much on copy/paste of other people's work is a shortcut to bug-central.
     
  32. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,143
    Chances are pretty good they would be equally bad without it.
     
    Tomnnn and XGundam05 like this.
  33. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,887
    If you're a neat freak like me, you should find C# cleaner and easier to read. It has a nicer syntax and everything is strongly typed (you can even still use "var" if you want).
     
  34. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Leaks in a scripting language? What? Oh no, that poor single thread :p

    Lol probably. I don't mind the bloat, web pages... they aren't quite as demanding as nearly every other thing we can do with our computers. Unity WebGL applications will probably be the most intense activity our browsers do, no?

    @RichardKain I see. I'm taking a class on reinventing the wheel. Last week the program due was to remake strlen in ARM. When spring break is over, the next program due is to remake strcpy in ARM lol. I like jquery for the syntax so far.

    $("#idname") is more interesting so far than searching the document. I also like the really simple ajax calling.

    On the topic of C#... it's amusing that you have to call it unsafe when you want to use pointers. But it's impressive that they still exist in C#. My high school called C# "Microsoft's Java". Maybe the new minecraft will be written in C# and use mono to keep it cross platform :O
     
  35. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    I think one of the biggest factors of why C# is so liked is its clear and easy to understand syntax and powerful standard library. It really helps that creators of Object Pascal language (a.k.a. language used in Delphi) worked on C# and so for anyone who previously worked with Object Pascal, C# will be easy.

    It's also, due to it's clear syntax, great to pick up by complete programing noobs who never wrote a line of code in their life.

    Don't get me wrong - things like Playmaker or Blueprints are great. Visual programming in general is great. Heck, two of gamedev programs I'm using are based mostly or entirely on visual programing (those programs are GDevelop and RPG Maker).

    But some things, like AI, physics and stuff that deals with complex data manipulation (such as sorting an array, for example), are better to be written in regular programing language. Unfortunately, no one wrote visual programing language that is clear when complex code is involved, and that include stuff like Playmaker or Blueprints. And that's where C# comes in.

    C# is also, coincidentally, the only thing Microsoft ever did right and only because creators of Object Pascal/Delphi were involved.

    //edit:
    Hate to break it to you, but it already is. It's called Manic Digger, though development is kinda stopped - but sources are available.
     
  36. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Pretty much completely irrelevant to the point I was making.
     
  37. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    Because it represents evolution. C. C++. C#. Although I do miss direct memory management and real pointers to a degree overall this managed model is better. I've used it at my job for many years. Basically I see it as a sort of candified version of C++. Not that you can eat it but I mean it represents the trend to do more for you so you have less real understanding of what is going on. Write one line of code and produce 100 or more behind the scenes. That sort of "progressive" thinking. ;)

    Also as others have stated. Using C# gets you experience that is useful outside of Unity. That comes in handy for anyone wanting to get a job as a programmer even as a business app developer, data mining and so forth. Overall, it is a nice little language.
     
  38. christinanorwood

    christinanorwood

    Joined:
    Aug 9, 2013
    Posts:
    402
    I wonder if the OP is stating a preference (Java/Unit script) over C# or is wondering if it's worth learning C#. If the latter I can only say that knowing only one language is always limiting, and learning a second (or third...) shouldn't be seen as being a big deal.
     
    GarBenjamin and Kiwasi like this.
  39. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,143
    Whether or not we all use Unity is irrelevant to the point he was making. Some of us are not strictly game developers and some of us are not strictly using Unity to do so. You can still develop applications and games outside of Unity using C#.

    UnityScript though, as the name very much implies, is strictly developed for Unity. While you can still be a competent developer, as proven by @ippdev, it is still limited solely to Unity development.

    Learning C# has the advantage that you're only having to master one language.
     
    Last edited: Mar 16, 2015
  40. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    What if someone wrote a US -> JS parser / interpreter / translator? Unity has a decent sized audience, I'm sure it would be useful. If DogeScript is a thing, US->JS should definitely be a thing.
     
  41. bigdaddy

    bigdaddy

    Joined:
    May 24, 2011
    Posts:
    153
    Sure, I code servers in node.js (and meteor).
     
  42. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    Pretty sure that's called IL2CPP (plus the actual JS conversion part). Turns out Unity is kind of working on it.
     
    Tomnnn likes this.
  43. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    IL2CPP could make US useful outside of Unity? That's interesting

    That's kinda what I was referring to though :p I guess most JS web people will be using node.js, meteor, angular.js, jquery, etc.
     
  44. knr_

    knr_

    Joined:
    Nov 17, 2012
    Posts:
    258
    Running backend code on a server using node.js is incredibly useful. Client-side and server-side Javascript are building the Internet of Things, which is considered by many to be the next major industry, so yes, Javascript is definitely being used - and in particular being used by people who want their own piece of what will be a huge pie in the not too distant future.

    But I wouldn't use Javascript for a game client when you have better alternatives.
     
  45. Zeblote

    Zeblote

    Joined:
    Feb 8, 2013
    Posts:
    1,102
    Unityscript is not javascript though
     
  46. knr_

    knr_

    Joined:
    Nov 17, 2012
    Posts:
    258
    I didn't say it was.
     
  47. Zeblote

    Zeblote

    Joined:
    Feb 8, 2013
    Posts:
    1,102
    Then what does JS have to do with this?
     
  48. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    There's better alternatives for web games? :eek:

    I usually run desktop software on the server if I can. I'm not really knowledgeable in web stuff though.
     
    AndrewGrayGames and knr_ like this.
  49. knr_

    knr_

    Joined:
    Nov 17, 2012
    Posts:
    258
    LOLOLOLOLOL that... was hilarious. Well played good sir.

    Wow, that's an interesting setup. Does it work well for you?

    I'm a big fan of using JSON so I just use LitJson in my projects to serialize game data out and, since Javascript natively understands (J)ava(S)cript (O)bject (N)otation using node.js on the server(s). It seems like a perfect marriage for how I architect the saving and retrieval of data from client to server (and back).

    The irony of this all is that I'm actually using PHP for the current project. Go figure.
     
    bigdaddy likes this.
  50. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    What? I was sincere, are there better web options besides plugins? I really don't know much web stuff. @Asvarduil see? I just can't be serious. I'm cursed.

    It was more like having some unfounded hatred for scripting languages that cannot truly do multithreading. But ultimately it worked out because the big data application we were working on to sort useful information from noise on twitter did end up taking advantage of the computer having multiple cores.

    I enjoy programming, so I tend to invent a way to serialize and deserialize data to best suit each application. It seems like JSON could be handy in the future, I'm finally getting some exposure to it by passing JSON data back and forth through ajax calls with jquery.

    I don't always reinvent the wheel, but when I do, strings are involved.
     
Thread Status:
Not open for further replies.