Switch to C# - worth it?

Hi all,

We are just about to start coding for two new projects. Up until this point we have been using Javascript exclusively but are now considering switching to C#. The main reason would be that it is closer to C++ / Objective C which would be helpful when implementing native functionality and in the (hopefully unlikely) event Unity is forced to go with plan B for iOS development.

I have used C++/C extensively in the past but will probably need a day or so before it becomes comfortable. Also, C# is a little less rapid than Javascript iMHO, although the increased strictness of C# is helpful at times.

Anyway, I would be very thankful for your thoughts on the matter? How did you decide on which language to go with?

Thanks in advance!
Dan

I’m no programmer, but I’ve noticed javascript tends to get a lot more love (scripts free/purchased, tutorials, help, examples etc.) than C# when it comes to Unity. But if you’re already well versed in it, then that likely isn’t going to make a difference.

I suppose go with what works best for you. There probably is a performance difference between the two, but I’ve not noticed myself.

Sorry I can’t be more help.

Edit: hmm, I didn’t read your post properly. You’re talking about converting to C++/Objective C, which is a different situation, although I don’t believe it changes my conclusion at all. I’ll therefore leave in my original response (please replace the word ‘to’ by ‘from’ where applicable :P):

In my opinion, the differences between JS and C# are very superficial. JS has some features that allow you to save you a few lines of code in commonly used expressions, whereas C# offers a few Mono features that that are not available in JS (the most important one, generics, being added to JS in 3.0).

My guess is that when converting code from C++, the bulk of your time will be spent in translating C++ specific features to their Mono counterparts (like changing algorithms and classes to not rely on pointers, multiple inheritance and other specific C++ features). While it will sure not be fun, I can’t imagine converting all the variable and function declarations to JS notation will be a very large part of the task (unless we’re talking about really small pieces of code here). In other words, I don’t think it takes that much longer to convert C++ to JS than converting C++ to C#.

Anyway, what I mean to say is that I wouldn’t base my choice of language on which is closer to C++, but rather on which language I’d prefer to use normally.

Well, not really. I am talking about coding in Javascript vs. C# and whether it is worth it to switch from Javascript (which we are very used to by now) to C# for the benefit of doing all of it in a C variant (main code in C#, native stuff in objective/C++). “Worth it” in the sense of enduring the (small) overhead C# adds to unity and the adjustment period.

I guess I failed to express that in my OP. :slight_smile:
Cheers,
Dan

I guess I imagined ‘converting’ into your post, because I do not see the relation between the languages your game code is in and using native code. The two things are separate and cannot be in the same language, so I fail to see how picking, for example, JS would affect programming your native code. But perhaps I’m missing some JS limitations with native code, due to my limited knowledge of using Objective C in Unity. If there’s no JS limitations and if you’re used to and comfortable with JS, I don’t see a reason to switch, native code or not.

If you’re considering it, try taking a week and just hammer out some C#. Visual Studio integration is awesome and the benefits of C#, in my opinion, far far outweigh saving you a few lines of UnityScript code.

Plus you’ll start stepping into the world of .NET which is pretty expansive. :smile:

My personal experience as someone who tried to switch to C# - it’s not worth it.

Javascript support in Unity is great, and Javascript is the easier language to script in.

I’ve also grown to dislike C# a ton. It’s one of those languages where you NEED a development environment (an IDE) or you have nothing but trouble.

Unless you are creating a game with very few and very simple scripts, I’d bet that you’d have nothing but trouble if you didn’t use an IDE. (and why are IDEs a bad thing again?)

With U3 all languages get the same kind of documentations.

For tutorials and scripts it makes kind of sense as UnityScript is the “noob language” (in the good and the bad sense), so also the better market to sell of trivialities that any programmer can write himself in an hour

In your humble, unbiased opinion :roll:

I put my vote in for C# for a few reasons.

  1. Javascript lacks .NET functionality/Undocumented functionalities. It is not an official .NET language but a custom Unity format, and therefore doesn’t support everything (can’t initialize a Char with single quotes, can’t use Generics, no Properties/screwy syntax for properties, etc…).

  2. C# has the entire MSDN resource with sample code. While it may lack Unity specific code samples, it has an unbelievable amount of samples, documentation, and how-tos out there on the web for doing any manner of functionlity. And due to point 1 these are not always easily convertible into Javascript code.

  3. While not having strict typing seems like a benefit when initially writing code, it can be a massive detriment, especially working in groups. It’s much harder to debug things when you don’t even know what type they are. When you have to hunt through someone else’s complex function to hopefully see a yield in there to be able to determine if it runs as a coroutine or whether it is just a regular function. When you see variable names but have to hunting up and down the code to determine when they were first instantiated, it’s a pain to debug. It’s somewhat achievable when it’s your own code and a small code base, but once you start working in teams it becomes needlessly complex. Yes, you can enforce strict typing, but that kind of removes the benefit Javascript in Unity being less lines to type.

That being said, if you are comfortable and functional in one, I still wouldn’t suggest switching unless you desperately need a specific functionality from the other.

I second that.

Edit: Nvm, misread what you wrote (had just woken up).

To be honest, I too have seen more UnityScript than C#. But I also notice that most of those scripts are crap. And if you know how to read both C# and UnityScript syntax, porting or using one sample over another is trivial. (save for how much more difficult it is to read/understand someone else’s UnityScript for the reasons Ntero already pointed out)

Isn’t Boo or something also supported? I gotta admit I have rarely if ever seen anyone using that with Unity (hadn’t even heard of it before I started using Unity, lol).

Boo is a .NET form of Python iirc(but don’t quote me on it).

It’s very uncommon I think I’ve only seen 1 or 2 people on the forums using it.

Interestingly enough though, Unity Javascript gets put through the Boo compiler from what I understand. Because Unityscript is not a direct .NET language it gets translated into Boo and then compiled through the Boo compiler.(once again don’t quote me, I’m not 100% sure)

Although it’s not really common, and lacks pretty much any documentation at all (no MSDN or Unity Docs) so it get avoided as if you use it no-one can really help you.

Yeah, besides the thread Mac vs Win here we go with another religious war. As for my opinion, like someone wrote once on this forum, choose whatever language that you can do refactor and has code complete, which for Unity 2.6 is C#, so use C#.

After the release of the new U3, in my (biased)opinion, keep the C# way :twisted:

Nah, I doubt this thread will get nasty like Mac vs Windows threads (everyone knows Windows is better :P)

If I had a preference, I’d probably say Javascript, simply cause it’s so much easier to get into from scratch that C# is, at least it is for me. But if what dreamora says is true, then it wont really matter at all after U3 is released. They’re all as confusing as each other anyway, lol.

Pull up a chair and enjoy the show! I’ve got plenty of popcorn to share, but only brought enough beer for me.

Please keep on topic? I couldn’t care much less about Boo or which language is better. The question is whether C# or Javascript has a significant advantage in Unity and whether it is worth switching to C#.

Thanks to all of those who replied on topic. The rest of you…get your own thread! :wink: