To my knowledge, thus far, I have thought that C# is and has always been a compiled language. I have recently started studying Unity3d and noticed that they give C# as an option for scripting and interacting with game objects through their API (along with JavaScript and a couple of other alternatives).

How is this done? Is C# actually being executed or is this an abstraction that is being converted to a different scripting language under the covers? It seems to me that there is some sort of interpretation going on for this functionality.

  • 2
    \$\begingroup\$ What are scripting languages? \$\endgroup\$ – jcora Mar 19 '13 at 20:18
  • \$\begingroup\$ en.wikipedia.org/wiki/Category:Scripting_languages languages interpreted at runtime rather than compile time. \$\endgroup\$ – Brandon Clapp Mar 19 '13 at 20:20
  • 2
    \$\begingroup\$ But JavaScript is compiled before being executed 99% of the time, and some Python implementations too. C(++) can be interpreted. I think that the terminology is flawed, as you're not talking about a property of the language, but the way you use it. But it seems that's not really important for the question... \$\endgroup\$ – jcora Mar 19 '13 at 20:25
  • \$\begingroup\$ "compiled" or "scripted" is not the property of programming language. When you are implementing the language specification, you can decide whether you want to "compile" it or "interpret" it. \$\endgroup\$ – Ivan Kuckir Mar 19 '13 at 20:26
  • 1
    \$\begingroup\$ That being said, what I have always interpreted as a "scripting language" is the basis of this definition. Perhaps the vocab should have been "interpreted" but I have always seen them one in the same. webopedia.com/TERM/S/scripting_language.html \$\endgroup\$ – Brandon Clapp Mar 19 '13 at 21:59

Unity is using Mono behind the scenes. Every time you make a change to your C#/UnityScript scripts it recompiles the code almost instantly.

If you look in the data directory of a standalone unity player, you can see it has compiled all the scripts into Assembly-CSharp.dll, or similar.

So yes, the C# is being compiled.

  • \$\begingroup\$ Ah I see the .dll now in the data directory. This clears things up. \$\endgroup\$ – Brandon Clapp Mar 19 '13 at 20:22
  • 5
    \$\begingroup\$ +1 for actually answering the question and not turning it into a pompous semantic arm-wrestling match \$\endgroup\$ – HumanCatfood Mar 20 '13 at 10:35
  • 1
    \$\begingroup\$ @BrandonClapp if this answer solved your question, please mark it as correct. \$\endgroup\$ – petervaz Mar 20 '13 at 18:12
  • 1
    \$\begingroup\$ Sorry for reviving this, but how does Unity handle the loading and unloading of the compiled DLL in the editor? Or should I start a new question? \$\endgroup\$ – Jeff Sep 4 '14 at 15:51

First, scripting languages are not necessarily interpreted languages. Some scripting languages such as Lua and Python can be either JIT-compiled or interpreted.

And, as for the question itself: because C# is a scripting language, but Microsoft does a good job on making it not look as such.

C# has everything a scripting language needs: dynamic typing, JIT-compiling rather than static compiling, runs in a virtual machine...


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.