Comparison of Programming Languages
Daniel Moore (Talk | contribs) (Removed Boo comparison as it is no longer supported by Unity) |
Isaiah Kelly (Talk | contribs) m (added UnityScript notice and updated brief description) |
||
Line 1: | Line 1: | ||
− | + | {{UnityScript Notice}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | This is a comparison of the features and instructions of the three high-level programming languages offered by Unity: UnityScript/JavaScript, [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], and [http://en.wikipedia.org/wiki/Boo_(programming_language) Boo]. '''Update:''' As of version 2018.2, Unity now only officially supports the C# programming language. | ||
== Conventions of This Article == | == Conventions of This Article == | ||
Line 14: | Line 8: | ||
The following tables compare code differences of the Unity programming languages. See also the [[Comparison of Programming Languages]] for general information. | The following tables compare code differences of the Unity programming languages. See also the [[Comparison of Programming Languages]] for general information. | ||
− | |||
− | |||
== Features == | == Features == | ||
Line 520: | Line 512: | ||
[[Programming|Programming Index]] | [[Programming|Programming Index]] | ||
+ | |||
+ | [[Category: Legacy]] | ||
+ | [[Category: Boo]] | ||
+ | [[Category: JavaScript]] |
Latest revision as of 01:39, 22 November 2018
End of support for UnityScript Starting with Unity 2018.2, support for UnityScript (Unity's version of JavaScript) has ended. C# is now the only supported language going forward. You can learn more about the reasons for this change here. There is an official UnityScript-to-C# Automatic Conversion tool to help those wanting to transition their UnityScript projects over to C#. |
This is a comparison of the features and instructions of the three high-level programming languages offered by Unity: UnityScript/JavaScript, C#, and Boo. Update: As of version 2018.2, Unity now only officially supports the C# programming language.
Contents |
[edit] Conventions of This Article
The bold is the literal code. The non-bold is interpreted by the reader. Statements in guillemets (« … ») are optional. “⇥ ” indicates a necessary indent.
The following tables compare code differences of the Unity programming languages. See also the Comparison of Programming Languages for general information.
[edit] Features
The following tables compares major features of the Unity programming languages.
Language | C# | UnityScript/JavaScript |
---|---|---|
Paradigm(s) | ||
Standardized Variation? | Yes, ECMA, ISO ECMA-334; ISO/IEC 23270:2006 | No |
Type Strength | strong | strong1, duck |
Type Safety | safe | safe |
Expression of Types | explicit | implicit with optional explicit typing |
Compatibility Among Composite Types | name-based | ? |
Type Checking | static with optional dynamic typing | static with optional dynamic typing |
1 Normally Javascript in Unity uses type inference to statically type all variables when possible, in cases where the type is not explicitly stated. Dynamic typing can be forced if desired, and, in certain circumstances, dynamic typing is used unless forced otherwise. Use of the "#pragma strict" directive disables all dynamic typing.
[edit] Type Identifiers
[edit] Integer
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
8-bit (byte) Signed | sbyte | sbyte | sbyte |
8-bit (byte) Unsigned | byte | byte | byte |
16-bit (short integer) Signed | short | short | short |
16-bit (short integer) Unsigned | ushort | ushort | ushort |
32-bit Signed | int | int | int |
32-bit Unsigned | uint | uint | uint |
64-bit (long integer) Signed | long | long | long |
64-bit long integer) Unsigned | ulong | ulong | ulong |
[edit] Floating Point
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
Single Precision | single | float | float |
Double Precision | double | double | double |
Arbitrarily Precise (bignum) | decimal | decimal | ? |
[edit] Other Types
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
Text Character | N/A | char | char |
Text String | string | string | String |
Boolean) | bool | bool | boolean |
Object/Universal) | object | object | Object |
[edit] Derived Types
[edit] Array
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
one-dimensional fixed size array | (type) |
type[size] |
type[size] |
multi-dimensional fixed size array | array(type, size1, size2, ...) or (type, ndims) |
type[size1, size2,...] or type[size1][size2]... |
type[size1, size2,...] (note: currently these types of arrays can be created implicitly and used, but cannot be created explicitly) |
one-dimensional dynamic size array | myList = [item1, item2, ...] or List or System.Collections.Generic.List[type] or System.Collections.ArrayList |
System.Collections.ArrayList or System.Collections.Generic.List<type> |
Array or System.Collections.ArrayList or System.Collections.Generic.List.<type> |
multi-dimensional dynamic size array | ? | System.Collections.Generic.List<System.Collections.Generic.List<...>> |
System.Collections.Generic.List.<System.Collections.Generic.List.<...>> |
[edit] Other Types
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
Record Simple Composite Types | struct name: ⇥ name as type ⇥ ... |
struct name { type name; ... } |
via objects: class name { type name; ... } |
Enumeration Simple Composite Types | enum condition:
⇥ item1
⇥ item2
⇥ ... |
enum name «: integral-type» { name «= value», ... } |
enum type { name, ... } |
[edit] Basic Unity-Specific Types
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
array | Boo.Lang.List |
? | Array |
[edit] Declarations
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
variable | name = initial_value |
type name «= initial_value»; |
var name «= initial_value»; |
constant | final name = initial_value |
const type name = value; |
N/A |
type synonym | synonym = typeof(type) |
using synonym = type; |
? |
[edit] Flow of Control
[edit] Conditional Statements
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
if | if (condition): instructions else: instructions |
if (condition) { instructions; } «else { instructions; }» |
if (condition) { instructions; } «else { instructions; }» |
else if | if (condition): instructions elif: instructions |
if (condition) { instructions; } else if (condition) { instructions; } ... «else { instructions; }» |
if (condition) { instructions; } else if (condition) { instructions; } ... «else { instructions; }» |
select case | (none) | switch (variable) { case case1: instructions; jump-statement; ... «default: instructions; jump-statement;» } |
switch (variable) { case case1: instructions; jump-statement; ... «default: instructions; jump-statement;» } |
conditional expression (ternary) | valueIfTrue if condition else valueIfFalse |
condition ? valueIfTrue : valueIfFalse; |
condition ? valueIfTrue : valueIfFalse; |
[edit] Loop Statements
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
while | while (condition): instructions |
while (condition) { instructions; } |
while (condition) { instructions; } |
do-while | ? | do { instructions; } while(condition); |
? |
for | for i in range(first, last): instructions |
for («initializer»; «condition»; «modifier») { instructions; } |
? |
foreach | ? | foreach (type name in collection) { instructions; } |
? |
[edit] Exceptions
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
throw | ? | throw new exceptionType(«arguments»); or throw exceptionVariable; or throw; // re-throws an exception; can only be used inside a catch block |
? |
handler | ? | try { instructions; } «catch(exceptionType «variable») { «instructions;» }» ... catch«(exceptionType «variable»)» { «instructions;» } or try { instructions; } finally { instructions; } or try { instructions; } «catch(exceptionType «variable») { «instructions;» }» ... catch«(exceptionType «variable»)» { «instructions;» } finally { instructions; } |
? |
assertion | ? | System.Diagnostics.Debug.Assert(condition «, message «, detailsMessage»»); |
? |
[edit] Other Flow of Control Statements
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
exit block(break) | break |
break; |
? |
continue | continue |
continue; |
? |
label | ? | labelName: |
? |
branch (goto) | ? | goto labelName; or goto case caseValue; // can only be used in a switch block |
? |
return value from generator | ? | ? | ? |
[edit] Functions
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
calling a function | ? | functionName(arg1, arg2, ...); |
? |
basic/void function | ? | void functionName(type param1, type param2, ...) { instructions; } |
? |
value-returning function | ? | type functionName(type param1, type param2, ...) { instructions; return valueOfFunctionType; } |
? |
[edit] Type Conversions
Language | Boo | C# | UnityScript/JavaScript |
---|---|---|---|
basic type to basic type | ? | (type) name |
? |
string to basic type | ? | type.Parse(name) /* THIS IS HIGHLY DEPENDENT UPON THE BASIC TYPE */ |
? |
basic type to string | ? | name.ToString() |
? |
complex type to string | ? | name.ToString() |
? |
complex type to complex type | ? | (type) name or name as type |
name as type |