Comparison of Programming Languages

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
Line 203: Line 203:
 
| {{wikitable-td}} <boo>(type)</boo>
 
| {{wikitable-td}} <boo>(type)</boo>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">type[size]</syntaxhighlight>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">type[size]</syntaxhighlight>
| {{wikitable-td}} <syntaxhighlight lang="javascript">type[size]</javascript>
+
| {{wikitable-td}} <syntaxhighlight lang="javascript">type[size]</syntaxhighlight>
 
|-
 
|-
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Array#Multi-dimensional_array multi-dimensional] fixed size array
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Array#Multi-dimensional_array multi-dimensional] fixed size array
Line 210: Line 210:
 
or
 
or
 
<syntaxhighlight lang="csharp">type[size1][size2]...</syntaxhighlight>
 
<syntaxhighlight lang="csharp">type[size1][size2]...</syntaxhighlight>
| {{wikitable-td}} <syntaxhighlight lang="javascript">type[size1, size2,...]</javascript>
+
| {{wikitable-td}} <syntaxhighlight lang="javascript">type[size1, size2,...]</syntaxhighlight>
 
(note: currently these types of arrays can be created implicitly and used, but cannot be created explicitly)
 
(note: currently these types of arrays can be created implicitly and used, but cannot be created explicitly)
 
|-
 
|-
Line 222: Line 222:
 
or
 
or
 
<syntaxhighlight lang="csharp">System.Collections.Generic.List<type></syntaxhighlight>
 
<syntaxhighlight lang="csharp">System.Collections.Generic.List<type></syntaxhighlight>
| {{wikitable-td}} <syntaxhighlight lang="javascript">Array</javascript>
+
| {{wikitable-td}} <syntaxhighlight lang="javascript">Array</syntaxhighlight>
 
or
 
or
<syntaxhighlight lang="javascript">System.Collections.ArrayList</javascript>
+
<syntaxhighlight lang="javascript">System.Collections.ArrayList</syntaxhighlight>
 
|-
 
|-
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Array#Multi-dimensional_array multi-dimensional] dynamic size array
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Array#Multi-dimensional_array multi-dimensional] dynamic size array
Line 244: Line 244:
 
| {{wikitable-?}}
 
| {{wikitable-?}}
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">struct name { type name; ... }</syntaxhighlight>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">struct name { type name; ... }</syntaxhighlight>
| {{wikitable-td}} via objects: <syntaxhighlight lang="javascript">class name { type name; ... }</javascript>
+
| {{wikitable-td}} via objects: <syntaxhighlight lang="javascript">class name { type name; ... }</syntaxhighlight>
 
|-
 
|-
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Enumerated_type Enumeration] Simple Composite Types
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Enumerated_type Enumeration] Simple Composite Types
Line 252: Line 252:
 
⇥ …»</boo>
 
⇥ …»</boo>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">enum name «: integral-type» { name «= value», ... }</syntaxhighlight>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">enum name «: integral-type» { name «= value», ... }</syntaxhighlight>
| {{wikitable-td}} <syntaxhighlight lang="javascript">enum type { name, ... }</javascript>
+
| {{wikitable-td}} <syntaxhighlight lang="javascript">enum type { name, ... }</syntaxhighlight>
 
|}
 
|}
  
Line 267: Line 267:
 
| {{wikitable-?}}
 
| {{wikitable-?}}
 
| {{wikitable-?}}
 
| {{wikitable-?}}
| {{wikitable-td}} <syntaxhighlight lang="javascript">Array</javascript>
+
| {{wikitable-td}} <syntaxhighlight lang="javascript">Array</syntaxhighlight>
 
|}
 
|}
  
Line 283: Line 283:
 
| {{wikitable-td}} <boo>name = initial_value</boo>
 
| {{wikitable-td}} <boo>name = initial_value</boo>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">type name «= initial_value»;</syntaxhighlight>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">type name «= initial_value»;</syntaxhighlight>
| {{wikitable-td}} <syntaxhighlight lang="javascript">var name «= initial_value»;</javascript>
+
| {{wikitable-td}} <syntaxhighlight lang="javascript">var name «= initial_value»;</syntaxhighlight>
 
|-
 
|-
 
! {{wikitable-th}} constant
 
! {{wikitable-th}} constant
 
| {{wikitable-td}} <boo>final name = initial_value</boo>
 
| {{wikitable-td}} <boo>final name = initial_value</boo>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">const type name = value;</syntaxhighlight>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">const type name = value;</syntaxhighlight>
| {{wikitable-td}} <syntaxhighlight lang="javascript">N/A</javascript>
+
| {{wikitable-td}} <syntaxhighlight lang="javascript">N/A</syntaxhighlight>
 
|-
 
|-
 
! {{wikitable-th}} type synonym
 
! {{wikitable-th}} type synonym
Line 315: Line 315:
 
«else { instructions; }»</syntaxhighlight>
 
«else { instructions; }»</syntaxhighlight>
 
| {{wikitable-td}} <syntaxhighlight lang="javascript">if (condition) { instructions; }
 
| {{wikitable-td}} <syntaxhighlight lang="javascript">if (condition) { instructions; }
«else { instructions; }»</javascript>
+
«else { instructions; }»</syntaxhighlight>
 
|-
 
|-
 
! {{wikitable-th}} else if
 
! {{wikitable-th}} else if
Line 329: Line 329:
 
else if (condition) { instructions; }
 
else if (condition) { instructions; }
 
...
 
...
«else { instructions; }»</javascript>
+
«else { instructions; }»</syntaxhighlight>
 
|-
 
|-
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Switch_statement select case]
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Switch_statement select case]
Line 342: Line 342:
 
...
 
...
 
«default: instructions; jump-statement;»
 
«default: instructions; jump-statement;»
}</javascript>
+
}</syntaxhighlight>
 
|-
 
|-
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Conditional_(programming)#If_expressions conditional expression (ternary)]
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Conditional_(programming)#If_expressions conditional expression (ternary)]
 
| {{wikitable-n/a}}
 
| {{wikitable-n/a}}
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">condition ? valueIfTrue : valueIfFalse;</syntaxhighlight>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">condition ? valueIfTrue : valueIfFalse;</syntaxhighlight>
| {{wikitable-td}} <syntaxhighlight lang="javascript">condition ? valueIfTrue : valueIfFalse;</javascript>
+
| {{wikitable-td}} <syntaxhighlight lang="javascript">condition ? valueIfTrue : valueIfFalse;</syntaxhighlight>
 
|}
 
|}
  
Line 363: Line 363:
 
     instructions</boo>
 
     instructions</boo>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">while (condition) { instructions; }</syntaxhighlight>
 
| {{wikitable-td}} <syntaxhighlight lang="csharp">while (condition) { instructions; }</syntaxhighlight>
| {{wikitable-td}} <syntaxhighlight lang="javascript">while (condition) { instructions; }</javascript>
+
| {{wikitable-td}} <syntaxhighlight lang="javascript">while (condition) { instructions; }</syntaxhighlight>
 
|-
 
|-
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Do_while_loop do-while]
 
! {{wikitable-th}} [http://en.wikipedia.org/wiki/Do_while_loop do-while]
Line 519: Line 519:
 
or
 
or
 
<syntaxhighlight lang="csharp">name as type</syntaxhighlight>
 
<syntaxhighlight lang="csharp">name as type</syntaxhighlight>
| {{wikitable-td}} <syntaxhighlight lang="javascript">name as type</javascript>
+
| {{wikitable-td}} <syntaxhighlight lang="javascript">name as type</syntaxhighlight>
 
|}
 
|}
  

Revision as of 20:52, 10 January 2012


This is a comparison of the features and instructions of the three high-level programming languages offered by Unity: JavaScript, C#, and Boo.


Contents

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.


Features

The following tables compares major features of the Unity programming languages.

Language Boo C# UnityScript/JavaScript
Paradigm(s)
Standardized Variation? Yes Yes, ECMA, ISO ECMA-334; ISO/IEC 23270:2006 No
Type Strength strong, duck strong strong1, duck
Type Safety safe safe safe
Expression of Types implicit with optional explicit typing explicit implicit with optional explicit typing
Compatibility Among Composite Types ? name-based ?
Type Checking static with optional dynamic typing 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.

Type Identifiers

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

Floating Point

Language Boo C# UnityScript/JavaScript
Single Precision single float float
Double Precision double double double
Arbitrarily Precise (bignum) decimal decimal ?

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


Derived Types

Array

Language Boo C# UnityScript/JavaScript
one-dimensional fixed size array <boo>(type)</boo>
type[size]
type[size]
multi-dimensional fixed size array ?
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 <boo>List</boo>

or <boo>System.Collections.Generic.List[type]</boo> or <boo>System.Collections.ArrayList</boo>

System.Collections.ArrayList

or

System.Collections.Generic.List<type>
Array

or

System.Collections.ArrayList
multi-dimensional dynamic size array ?
System.Collections.Generic.List<System.Collections.Generic.List<...>>
?

Other Types

Language Boo C# UnityScript/JavaScript
Record Simple Composite Types ?
struct name { type name; ... }
via objects:
class name { type name; ... }
Enumeration Simple Composite Types <boo>enum condition:

⇥ item1 ⇥ «item2 ⇥ …»</boo>

enum name «: integral-type» { name «= value», ... }
enum type { name, ... }

Basic Unity-Specific Types

Language Boo C# UnityScript/JavaScript
array ? ?
Array


Declarations

Language Boo C# UnityScript/JavaScript
variable <boo>name = initial_value</boo>
type name «= initial_value»;
var name «= initial_value»;
constant <boo>final name = initial_value</boo>
const type name = value;
N/A
type synonym <boo>synonym = typeof(type)</boo>
using synonym = type;
?

Flow of Control

Conditional Statements

Language Boo C# UnityScript/JavaScript
if <boo>if (condition):
   instructions

else:

   instructions</boo>
if (condition) { instructions; }
«else { instructions; }»
if (condition) { instructions; }
«else { instructions; }»
else if <boo>if (condition):

instructions elif: instructions</boo>

if (condition) { instructions; }
else if (condition) { instructions; }
...
«else { instructions; }»
if (condition) { instructions; }
else if (condition) { instructions; }
...
«else { instructions; }»
select case ?
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) N/A
condition ? valueIfTrue : valueIfFalse;
condition ? valueIfTrue : valueIfFalse;

Loop Statements

Language Boo C# UnityScript/JavaScript
while <boo>while (condition):
   instructions</boo>
while (condition) { instructions; }
while (condition) { instructions; }
do-while ?
do { instructions; } while(condition);
?
for <boo>for i in range(first, last):
   instructions</boo>
for («initializer»; «condition»; «modifier») { instructions; }
?
foreach ?
foreach (type name in collection) { instructions; }
?

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»»);
?

Other Flow of Control Statements

Language Boo C# UnityScript/JavaScript
exit block(break) <boo>break</boo>
break;
?
continue <boo>continue</boo>
continue;
?
label ?
labelName:
?
branch (goto) ?
goto labelName;

or

goto case caseValue; // can only be used in a switch block
?
return value from generator ? ? ?

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; }
?

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



Programming Index

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox