Programming Language Comparison: General

Strings Mathematics Operators and Symbols [ternary operator] General (Control Flow/Debugging) Dates Objects [Type/TypeFull] New Features Timelines Note: UFL: Universal Function Library, a set of around 100-300 standard functions for all programming languages. Languages do not have to implement anything exactly to the UFL specification, it is a guide. See lower down for further details. Sections: Key Functions Error Handling (try/catch/finally, throw) Loops Keywords / Constants Function Definitions Assign/Declare Multiple Variables Multi-Line Strings File Extensions Sleep/Tick Counts (benchmark tests) Concatenate Strings/Integers The Universal Function Library Project: Details Section: Key Functions UFL: Swap [consider 'Swap(&a, &b)' or 'Swap(a, b)' or a swap statement 'swap a b'][destructuring assignment is unclear when longer variable names are used] AutoHotkey: ___ C++: swap [e.g. std::swap(a, b)] C#: ___ [can use: '(a, b) = (b, a)'][note: destructuring assignment] Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ [can use: '[a, b] = [b, a]'][note: destructuring assignment] Kotlin: ___ PHP: ___ [can use: '[$a, $b] = [$b, $a]'][also: 'list($a, $b) = [$b, $a]'][note: destructuring assignment] Python: ___ [can use: 'a, b = b, a'][note: destructuring assignment] Swift: swap [e.g. swap(&a, &b)][also: can use: '(a, b) = (b, a)'][note: destructuring assignment] UFL: Noop AutoHotkey: ___ [can use: {}][note: in some contexts this creates an object] C++: ___ [can use: ;] C#: ___ [can use: ;] Excel: ___ Excel VBA: ___ Java: ___ [can use: ;] JavaScript: ___ [can use: {} (typically with no semicolon)][note: in some contexts this creates an object] Kotlin: ___ PHP: ___ [can use: ;] Python: ___ [can use: pass] Swift: ___ UFL: PrintLn [print string and a newline character] AutoHotkey: ___ [can use: OutputDebug/MsgBox/ToolTip/TrayTip] C++: std::println(vText) [also: std::printf(vText)][note: std::println (C++23)][also: std::cout << vText << "\n"][also: std::cout << vText << std::endl][note: a custom 'myprint(x)' macro: #define myprint(x) std::cout << (x) << "\n"] C#: Console.WriteLine(vText) Excel: ___ Excel VBA: Debug.Print vText [note: text is printed to the Immediate Window] Java: System.out.println(vText) JavaScript: console.log(vText) [also: alert(vText)] Kotlin: println(vText) PHP: var_dump(vText) [also: echo vText . "\n"][also: echo vText . "<br>"][note: var_dump() always prints a line break, print_r() prints a line break for objects but not values] Python: print(vText) Swift: print(vText) UFL: Print [(or PrintNoLn) print string without a line break (newline) character] AutoHotkey: ___ [can use: OutputDebug/MsgBox/ToolTip/TrayTip] C++: std::print(vText) [note: std::print (C++23)][also: std::cout << vText] C#: Console.Write(vText) Excel: ___ Excel VBA: Debug.Print vText; [note: use a semicolon to omit the line break][note: text is printed to the Immediate Window] Java: System.out.print(vText) JavaScript: ___ Kotlin: print(vText) PHP: echo vText [note: echo keyword/echo()/print keyword/print()/var_export() never print a line break, print_r() prints a line break for objects but not values][WARNING: echo/print/print_r print true/false/null as "1"/""/"" (var_dump()/var_export() print true/false/NULL)] Python: print(vText, end="") Swift: print(vText, terminator: "") UFL: Version AutoHotkey: A_AhkVersion C++: __cplusplus C#: ___ Excel: INFO("release") Excel VBA: ___ [e.g. #If VBA6 Then][e.g. constants: VBA7/VBA6, Win64/Win32/Mac][also: Application.Version (for the Excel version number)] Java: System.getProperty("java.version") [also: Runtime.version().version().get(0)] JavaScript: ___ Kotlin: KotlinVersion.CURRENT PHP: phpversion() Python: sys.version Swift: ___ [e.g. #if swift(>=5.9)] UFL: OSVersion AutoHotkey: A_OSVersion C++: ___ C#: Environment.OSVersion Excel: INFO("osversion") [e.g. 'Windows (32-bit) NT 6.02'][also: INFO("system") (e.g. 'pcdos')] Excel VBA: Application.OperatingSystem [e.g. 'Windows (32-bit) NT 6.02'][e.g. #If Win64 Then][e.g. constants: Win64/Win32/Mac] Java: System.getProperty("os.name") [also: 'os.version'/'os.arch'] JavaScript: navigator.userAgent [also: navigator.platform] Kotlin: System.getProperty("os.name") [also: 'os.version'/'os.arch'] PHP: php_uname() Python: platform.platform() [also: platform.system()/platform.release()/platform.version()/sys.platform/os.name] Swift: ProcessInfo().operatingSystemVersion UFL: Sleep [perhaps consider friendly format options e.g. 'm'/'s'] AutoHotkey: Sleep C++: std::this_thread::sleep_for [also: sleep/usleep/nanosleep] C#: System.Threading.Thread.Sleep Excel: ___ Excel VBA: Application.Wait [e.g. Application.Wait (Now + TimeValue("0:00:01"))][also: the Winapi (kernel32\Sleep)] Java: Thread.sleep [also: TimeUnit.SECONDS.sleep][note: both require a try/catch block] JavaScript: ___ [can use: 'while' and 'new Date()'][can use (inside an async function): await new Promise(r => setTimeout(r, 1000))] Kotlin: Thread.sleep [also: TimeUnit.SECONDS.sleep] PHP: sleep [also: usleep][e.g. 1 sec: sleep(1)][e.g. 1 sec: usleep(1000000)] Python: time.sleep [e.g. 1 sec: sleep(1)][note: sleep accepts fractions of seconds, e.g. 0.5 sec: sleep(0.5)] Swift: sleep [also: usleep][e.g. 1 sec: sleep(1)][e.g. 1 sec: usleep(1000000)] UFL: TickCount [get the current time in milliseconds (typically centisecond accuracy, or a higher resolution if possible), take the difference of 2 timestamps to get the time elapsed][e.g. milliseconds since program started, milliseconds since PC switched on] AutoHotkey: ___ [can use: vMSec := A_TickCount (a built-in variable)] C++: std::chrono::system_clock::now [can use: the Winapi (kernel32\GetTickCount64)] C#: DateTime.Now Excel: NOW [e.g. milliseconds: TEXT(NOW()*86400000,"0")][also: TEXT(NOW(),"hh:mm:ss.000")][note: NOW() returns days plus fractions of days][note: Copy, Paste Special..., Values, to lock the date] Excel VBA: Timer [e.g. vSec = Timer][note: seconds plus fractions of seconds] Java: System.currentTimeMillis [also: System.nanoTime] JavaScript: performance.now [e.g. vMSec = performance.now()] Kotlin: System.currentTimeMillis [e.g. vMSec = System.currentTimeMillis()][also: System.nanoTime] PHP: microtime [e.g. vSec = microtime(true)][note: seconds plus fractions of seconds] Python: time.time [e.g. vSec = time.time][note: seconds plus fractions of seconds] Swift: DispatchTime.now [e.g. vNSec = DispatchTime.now().uptimeNanoseconds][requires: import Foundation] UFL: SetTimer AutoHotkey: SetTimer C++: ___ C#: System.Timers.Timer Excel: ___ Excel VBA: Application.OnTime Java: java.util.Timer JavaScript: setInterval [also: setTimeout] Kotlin: java.util.Timer [also: android.os.Handler] PHP: ___ Python: threading.timer Swift: Timer.scheduledTimer UFL: Assert AutoHotkey: ___ C++: ___ [can use: assert macro] C#: Debug.Assert [also: Trace.Assert] Excel: ___ [can use: can simply type in expressions e.g. '=1=1'][can use: IF] Excel VBA: Debug.Assert Java: ___ [can use: assert keyword] JavaScript: ___ Kotlin: assert [also: assertEquals][WARNING: assertEquals parameter order is expected then actual] PHP: assert Python: ___ [can use: assert statement] Swift: assert Section: Error Handling UFL: Try/Catch/Finally [note: are braces needed for branches] AutoHotkey: try/catch/finally C++: try/catch/___ C#: try/catch/finally Excel: ___/___/___ Excel VBA: ___/___/___ [can use: 'On Error Resume Next' (disables error reporting, but the Err object is still updated), 'On Error Goto MyLabel:' (e.g. can be used as a catch block workaround), 'On Error Goto 0' (default, enables error reporting)] Java: try/catch/finally JavaScript: try/catch/finally Kotlin: try/catch/finally PHP: try/catch/finally Python: try/except/finally Swift: do/catch/___ [also: try][also: defer] UFL: Throw AutoHotkey: throw Error("my message") C++: throw std::runtime_error("my message") [note: various classes derive from std::exception][can use (with catch, but not throw): std::exception] C#: throw new Exception("my message") Excel: ___ Excel VBA: Err.Raise 1234, , "my message" Java: throw new Exception("my message") [also: Error()] JavaScript: throw new Error("my message") Kotlin: throw Exception("my message") PHP: throw new Exception("my message") Python: raise Exception("my message") Swift: ___ [can use: throw NSError(domain:"my message", code:1234)][WARNING: lacks a convenient message field, workaround: use domain field][also: fatalError("my message")][requires (NSError): import Foundation] UFL: Error [(or Exception)] AutoHotkey: Error [note: Exception in AHK v1] C++: std::runtime_error [note: various classes derive from std::exception][can use (with catch, but not throw): std::exception] C#: Exception Excel: ___ Excel VBA: ___ Java: Exception [also: Error()] JavaScript: Error Kotlin: Exception PHP: Exception [also: ErrorException(), Error()] Python: Exception Swift: ___ [can use: NSError()][also: fatalError()][requires (NSError): import Foundation] UFL: FatalError [end program/script early, e.g. for testing/debugging] AutoHotkey: ExitApp() C++: exit(1) [e.g. 0 for success, non-zero for failure] C#: throw new Exception() [WARNING: this would be caught if within a try block] Excel: ___ Excel VBA: Exit Sub [note: different from 'End Sub'] Java: System.exit(0) JavaScript: throw "" [WARNING: this would be caught if within a try block] Kotlin: exitProcess(0) [note: import kotlin.system.exitProcess][also (to just throw an exception): throw Exception()] PHP: die Python: raise SystemExit [also: sys.exit()][WARNING: if the current thread is not the main thread, code may still execute] Swift: fatalError() Section: Loops UFL: LoopCountInc [(or LoopRangeIncDemo)][loop n times (loop from 1 to 10, both inclusive)] AutoHotkey: Loop 10 [note (value): A_Index will contain 1, 2, 3 etc] C++: for (int i=1; i<=10; i++) [note: ++i may be preferable to i++] C#: for (int i=1; i<=10; i++) Excel: ___ Excel VBA: For i = 1 To 10 [afterwards: Next] Java: for (int i=1; i<=10; i++) JavaScript: for (let i=1; i<=10; i++) Kotlin: for (i in 1..10) [note: *doesn't work*: for (i in 1 to 10)][also: for (i in 1.rangeTo(10))] PHP: for ($i=1; $i<=10; $i++) Python: for i in range(1, 10+1): Swift: for i in 1...10 [also (if i is unused): for _ in 1...10] UFL: LoopCountIncExc [(or (LoopRangeExcDemo)][loop n times (loop from 0 inclusive to 10 exclusive)] AutoHotkey: ___ [can use: Loop 10][note (value): A_Index-1] C++: for (int i=0; i<10; i++) [note: ++i may be preferable to i++] C#: for (int i=0; i<10; i++) Excel: ___ Excel VBA: For i = 0 To 9 [afterwards: Next] Java: for (int i=0; i<10; i++) JavaScript: for (let i=0; i<10; i++) Kotlin: for (i in 0..<10) [also: for (i in 0 until 10)][also: for (i in 0.rangeUntil(10))] PHP: for ($i=0; $i<10; $i++) Python: for i in range(0, 10): Swift: for i in 0..<10 [also (if i is unused): for _ in 0..<10] UFL: LoopInfinite [infinite loop (e.g. loop 1 to infinity, infinite range) (an alternative: 0 to infinity)] AutoHotkey: Loop [also: while True][note (value): A_Index will contain 1, 2, 3 etc] C++: for(;;) [also: while(1)][also: for (int i=1;; i++)] C#: for(;;) [also: while(true)][also: for (int i=1;; i++)] Excel: ___ Excel VBA: Do While True [afterwards: Loop] Java: for(;;) [also: while(true)][also: for (int i=1;; i++)] JavaScript: for(;;) [also: while(1)][also: for (let i=1;; i++)] Kotlin: while(true) [also: for (i in generateSequence(1){it+1})] PHP: also: for(;;) [also: while(1)][also: for ($i=1;; $i++)] Python: while True: [also: for i in itertools.count(start=1):] Swift: while true [also: for i in 1...][also (if i is unused): for _ in 1...] Section: Keywords / Constants UFL: if-statement [note: state if bool/parentheses/braces needed] AutoHotkey: if c / else if c / else [note: parentheses *not* needed] C++: if (c) / else if (c) / else C#: if (c) / else if (c) / else [WARNING: c must be a bool] Excel: IF(c,x,y) [note: c must be a bool or numeric] Excel VBA: If c Then / ElseIf c Then / Else / End If [note: c must be a bool or numeric][note: parentheses *not* needed] Java: if (c) / else if (c) / else [WARNING: c must be a bool] JavaScript: if (c) / else if (c) / else Kotlin: if (c) / else if (c) / else [WARNING: c must be a bool][note: can be used in expressions] PHP: if (c) / else if (c) / else Python: if c: / elif c: / else: [note: parentheses *not* needed] Swift: if (c) / else if (c) / else [WARNING: c must be a bool][WARNING: requires braces for 1-line statements] UFL: switch statement AutoHotkey: switch/case/default (no fall-through) C++: switch/case/default (uses fall-through) [WARNING: the input value cannot be a string] C#: switch/case/default (no fall-through) Excel: ___/___/___ Excel VBA: select/case/case else (no fall-through) Java: switch/case/default (uses fall-through) [note: switch expressions: also switch/case/default (but *no* fall-through)] JavaScript: switch/case/default (uses fall-through) Kotlin: when/(pattern)/else (no fall-through) PHP: switch/case/default (uses fall-through) Python: match/case/case _ (no fall-through) Swift: switch/case/default (no fall-through) UFL: True/False AutoHotkey: true/false [note: case insensitive] C++: true/false C#: true/false Excel: TRUE/FALSE [note: gets case-corrected by Excel] Excel VBA: True/False [note: gets case-corrected by Excel VBA editor] Java: true/false JavaScript: true/false Kotlin: true/false PHP: true/false [note: case insensitive] Python: True/False Swift: true/false UFL: Null [note: to delete a variable, see VarDelete/ObjectDelRef] AutoHotkey: unset [note: case insensitive] C++: nullptr [note: NULL macro expands to 0][also (functions): void] C#: null [also (functions): void] Excel: #NULL! [e.g. type '#NULL!' or '=A1 A2' or '=SUM(A1 A2)' into a cell][note: use ERROR.TYPE() to get the error type] Excel VBA: Nothing [also (e.g. redim array/store result of function with no return value): Empty][also: Null] Java: null [also (functions): void] JavaScript: null [also: undefined][also (array values): 'elided'/'empty'][also: void operator] Kotlin: null [also: Nothing][also (functions): Unit][note: Void is a Java class (with no special meaning in Kotlin)] PHP: null [note: case insensitive] Python: None [also: del statement] Swift: nil [also (functions): Void] UFL: function with no return value AutoHotkey: ___ C++: void C#: void Excel: ___ Excel VBA: ___ Java: void JavaScript: ___ Kotlin: Unit PHP: ___ Python: ___ Swift: Void UFL: VarDelete [see also: ObjectDelRef][note: typically: deleting an object instance deletes 1 reference, and only when the last reference is deleted, is the object deleted] AutoHotkey: vVar := unset [note: in AHK v1: 'vVar := ""' and 'vVar := 0' were common] C++: delete vVar [also: delete[] vVar][note: 'delete'/'delete[]' must be used for variables created with 'new'][note: 'free' must be used for variables created with 'malloc'] C#: vVar = null Excel: ___ Excel VBA: Set vVar = Nothing [note: doesn't work with all types] Java: vVar = null JavaScript: vVar = null [also: vVar = undefined][also: void operator] Kotlin: vVar = null PHP: unset($vVar) [also: $vVar = null][note: unset() sets contents to null] Python: del vVar [also: vVar = None] Swift: vVar = nil UFL: Import [(or Include)] AutoHotkey: #Include [also: #IncludeAgain] C++: #include [e.g. #include <iostream>][e.g. #include <string>][e.g. #include <map>] C#: using [e.g. using System][e.g. using System.Linq][e.g. using System.Collections.Generic] Excel: ___ Excel VBA: ___ [can use: Workbooks.Open and Run] Java: import [e.g. import java.util.*][e.g. import java.util.stream.*] JavaScript: import [also: <script src="MyFile.js"></script>] Kotlin: import PHP: include [also: require/include_once/require_once] Python: import [e.g. import sys][e.g. from functools import reduce] Swift: import [e.g. import Foundation] Section: Function Definitions UFL: functions can be defined below where they are called AutoHotkey: yes C++: yes [note: functions must be defined above where they are called (workaround: *declare* the function above where it is called)] C#: yes Excel: yes Excel VBA: yes Java: yes JavaScript: yes Kotlin: no [WARNING: functions must be defined above where they are called] PHP: yes Python: no [WARNING: functions must be defined above where they are called] Swift: yes UFL: function parameters are mutable AutoHotkey: yes C++: yes C#: yes Excel: yes Excel VBA: yes Java: yes JavaScript: yes Kotlin: no [WARNING: function parameter values (not object members) are read-only (they are not mutable) (workaround: do 'var vMyParamVar = vMyParamVar' to create a local copy, but it leaves a warning)] PHP: yes Python: yes Swift: yes [WARNING: function parameter values (not object members) are read-only (they are not mutable) (workaround: do 'var vMyParamVar = vMyParamVar' to create a local copy)]

[UFL] add function

[AutoHotkey]

Add(vNum1, vNum2)
{
	return vNum1 + vNum2
}

[C++]

int Add(int vNum1, int vNum2)
{
	return vNum1 + vNum2;
}

[C#]

public static int Add(int vNum1, int vNum2)
{
	return vNum1 + vNum2;
}

[Excel]

[Excel VBA]

Function Add(vNum1, vNum2)
	Add = vNum1 + vNum2
End Function

[Java]

static int Add(int vNum1, int vNum2)
{
	return vNum1 + vNum2;
}

[JavaScript]

function Add(vNum1, vNum2)
{
	return vNum1 + vNum2;
}

[Kotlin]

fun Add(vNum1: Int, vNum2: Int) : Int
{
	return vNum1 + vNum2
}

[PHP]

function Add($vNum1, $vNum2)
{
	return $vNum1 + $vNum2;
}

[Python]

def Add(vNum1, vNum2):
	return vNum1 + vNum2

[Swift]

func Add(_ vNum1: Int, _ vNum2: Int) -> Int
{
	return vNum1 + vNum2
}

Section: Assign/Declare Multiple Variables UFL: multiple declare AutoHotkey: ___ [e.g. local a, b, c] C++: int a, b, c; C#: int a, b, c; Excel: ___ Excel VBA: Dim a, b, c As Integer Java: int a, b, c; JavaScript: var a, b, c; Kotlin: var a:Int; var b:Int; var c:Int PHP: ___ Python: ___ Swift: var a, b, c : Int UFL: multiple declare and assign AutoHotkey: ___ [e.g. local a:=1, b:=2, c:=3] C++: int a=1, b=2, c=3; C#: int a=1, b=2, c=3; [also (destructuring assignment): var (a, b, c) = (1, 2, 3);] Excel: ___ Excel VBA: ___ Java: int a=1, b=2, c=3; JavaScript: var a=1, b=2, c=3; [also (destructuring assignment): var [a, b, c] = [1, 2, 3];] Kotlin: var a=1; var b=2; var c=3 [also (destructuring assignment): var (a, b, c) = (1, 2, 3)] PHP: ___ Python: ___ Swift: var a=1, b=2, c=3 [also (destructuring assignment): var (a, b, c) = (1, 2, 3)] UFL: multiple assign AutoHotkey: a:=1, b:=2, c:=3 C++: a=1; b=2; c=3; [also: a=1, b=2, c=3;] C#: a=1; b=2; c=3; [also (destructuring assignment): (a, b, c) = (1, 2, 3);] Excel: ___ Excel VBA: a = 1: b = 2: c = 3 Java: a=1; b=2; c=3; JavaScript: a=1; b=2; c=3; [also: a=1, b=2, c=3;][also (destructuring assignment): [a, b, c] = [1, 2, 3];] Kotlin: a=1; b=2; c=3 PHP: $a=1; $b=2; $c=3; [also (destructuring assignment): [$a, $b, $c] = [1, 2, 3];] Python: a=1; b=2; c=3 [also (destructuring assignment): a, b, c = 1, 2, 3] Swift: a=1; b=2; c=3 [also (destructuring assignment): (a, b, c) = (1, 2, 3)] UFL: multiple declare and assign to the same value AutoHotkey: ___ [WARNING (only creates static variable 'a'): static a := b := c := 123] C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: var a = b = c = 123; [also (destructuring assignment): var [a, b, c] = Array(3).fill(123);] Kotlin: var (a, b, c) = IntArray(3){123} [also: var (a, b, c) = (123, 123, 123)][note (both): destructuring assignment (destructuring declaration)] PHP: ___ Python: ___ Swift: var (a, b, c) = (123, 123, 123) UFL: multiple assign to the same value AutoHotkey: a := b := c := 123 C++: a = b = c = 123; C#: a = b = c = 123; Excel: ___ Excel VBA: ___ Java: a = b = c = 123; JavaScript: a = b = c = 123; [also (destructuring assignment): [a, b, c] = Array(3).fill(123);] Kotlin: ___ [note: can do destructuring declaration, but not destructuring assignment] PHP: $a = $b = $c = 123; [also (destructuring assignment): [$a, $b, $c] = array_fill(0, 3, 123);] Python: a = b = c = 123 [also (destructuring assignment): a, b, c = [123] * 3] Swift: (a, b, c) = (123, 123, 123) Section: Multi-Line Strings

[UFL] multi-line strings

C: concat
J: join

[AutoHotkey]

vTextC1 := "Line 1`n"
. "Line 2`n"
. "Line 3"

vTextC2 := "Line 1`n" .
"Line 2`n" .
"Line 3"

vText1 := " ;continuation section
(
Line 1
Line 2
Line 3
)"

vText2 := " ;continuation section
(Join`r`n
Line 1
Line 2
Line 3
)"

MsgBox(vTextC1)
MsgBox(vTextC2)
MsgBox(vText1)
MsgBox(vText2)

[C++]

//doesn't work:
//std::string vTextC1 = "LINE 1\n"
//+ "LINE 2\n"
//+ "LINE 3";

//doesn't work:
//std::string vTextC2 = "LINE 1\n" +
//"LINE 2\n" +
//"LINE 3";

//string literal concatenation (no operators needed):
std::string vTextC1 = "LINE 1\n"
"LINE 2\n"
"LINE 3";

std::string vText1 = "LINE 1\n\
LINE 2\n\
LINE 3";

std::string vText2 = R"(LINE 1
LINE 2
LINE 3)";

std::cout << vTextC1 << "\n";
std::cout << vText1 << "\n";
std::cout << vText2 << "\n";

[C#]

string vTextC1 = "LINE 1\n"
+ "LINE 2\n"
+ "LINE 3";

string vTextC2 = "LINE 1\n" +
"LINE 2\n" +
"LINE 3";

string vTextJ1 = String.Join("\n"
, "LINE 1"
, "LINE 2"
, "LINE 3"
);

string vTextJ2 = String.Join("\n",
"LINE 1",
"LINE 2",
"LINE 3"
);

string vText1 = @"LINE 1
LINE 2
LINE 3";

Console.WriteLine(vTextC1);
Console.WriteLine(vTextC2);
Console.WriteLine(vTextJ1);
Console.WriteLine(vTextJ2);
Console.WriteLine(vText1);

[Excel]

[Excel VBA]

vTextC1 = "LINE 1" & vbLf & _
"LINE 2" & vbLf & _
"LINE 3"

vTextC2 = "LINE 1" & vbLf _
& "LINE 2" & vbLf _
& "LINE 3"

Debug.Print vTextC1
Debug.Print vTextC2

[Java]

String vTextC1 = "LINE 1\n"
+ "LINE 2\n"
+ "LINE 3";

String vTextC2 = "LINE 1\n" +
"LINE 2\n" +
"LINE 3";

String vTextJ1 = String.join("\n"
, "LINE 1"
, "LINE 2"
, "LINE 3"
);

String vTextJ2 = String.join("\n",
"LINE 1",
"LINE 2",
"LINE 3"
);

String vText1 = """
LINE 1
LINE 2
LINE 3""";

System.out.println(vTextC1);
System.out.println(vTextC2);
System.out.println(vTextJ1);
System.out.println(vTextJ2);
System.out.println(vText1);

[JavaScript]

vTextC1 = "LINE 1\n"
+ "LINE 2\n"
+ "LINE 3";

vTextC2 = "LINE 1\n" +
"LINE 2\n" +
"LINE 3";

vTextJ1 = ["LINE 1"
, "LINE 2"
, "LINE 3"
].join("\n")

vTextJ2 = [
"LINE 1",
"LINE 2",
"LINE 3"
].join("\n")

vText1 = "LINE 1\n\
LINE 2\n\
LINE 3";

vText2 = `LINE 1
LINE 2
LINE 3`;

console.log(vTextC1);
console.log(vTextC2);
console.log(vTextJ1);
console.log(vTextJ2);
console.log(vText1);
console.log(vText2);

[Kotlin]

//doesn't work:
//vTextC1 = "LINE 1\n"
//+ "LINE 2\n"
//+ "LINE 3"

var vTextC1 = ("LINE 1\n"
+ "LINE 2\n"
+ "LINE 3")

var vTextC2 = "LINE 1\n" +
"LINE 2\n" +
"LINE 3"

var vTextJ1 = arrayOf("LINE 1"
, "LINE 2"
, "LINE 3"
).joinToString("\n")

var vTextJ2 = arrayOf(
"LINE 1",
"LINE 2",
"LINE 3"
).joinToString("\n")

var vText1 = """LINE 1
LINE 2
LINE 3"""

println(vTextC1)
println(vTextC2)
println(vTextJ1)
println(vTextJ2)
println(vText1)

[PHP]

$vTextC1 = "LINE 1\n"
. "LINE 2\n"
. "LINE 3";

$vTextC2 = "LINE 1\n" .
"LINE 2\n" .
"LINE 3";

$vTextJ1 = implode("\n", ["LINE 1"
, "LINE 2"
, "LINE 3"
]);

$vTextJ2 = implode("\n", [
"LINE 1",
"LINE 2",
"LINE 3"
]);

$vText1 = "LINE 1
LINE 2
LINE 3";
$vText1 = str_replace("\r", "", $vText1);

//e.g. Nowdoc string:
$vText2 = <<<'END'
LINE 1
LINE 2
LINE 3
END;

echo $vTextC1 . "\n";
echo $vTextC2 . "\n";
echo $vTextJ1 . "\n";
echo $vTextJ2 . "\n";
echo $vText1 . "\n";
echo $vText2 . "\n";

[Python]

#doesn't work:
#vTextC1 = "LINE 1\n"
#+ "LINE 2\n"
#+ "LINE 3"

#doesn't work:
#vTextC2 = "LINE 1\n" +
#"LINE 2\n" +
#"LINE 3"

vTextC1 = ("LINE 1\n"
+ "LINE 2\n"
+ "LINE 3")

vTextC2 = ("LINE 1\n" +
"LINE 2\n" +
"LINE 3")

vTextJ1 = "\n".join(["LINE 1"
, "LINE 2"
, "LINE 3"
])

vTextJ2 = "\n".join([
"LINE 1",
"LINE 2",
"LINE 3"
])

vText1 = "LINE 1\n" \
+ "LINE 2\n" \
+ "LINE 3"

vText2 = """LINE 1
LINE 2
LINE 3"""

print(vTextC1)
print(vTextC2)
print(vTextJ1)
print(vTextJ2)
print(vText1)
print(vText2)

[Swift]

var vTextC1 = "LINE 1\n"
+ "LINE 2\n"
+ "LINE 3"

var vTextC2 = "LINE 1\n" +
"LINE 2\n" +
"LINE 3"

var vTextJ1 = ["LINE 1"
, "LINE 2"
, "LINE 3"
].joined(separator:"\n")

var vTextJ2 = [
"LINE 1",
"LINE 2",
"LINE 3"
].joined(separator:"\n")

var vText1 = """
LINE 1
LINE 2
LINE 3
"""

print(vTextC1)
print(vTextC2)
print(vTextJ1)
print(vTextJ2)
print(vText1)

Section: File Extensions

UFL: file extension AutoHotkey: ahk C++: cpp [also: c/cxx/cc][also (header files): h/hpp/hxx/hh] C#: cs Crystal: cr Excel: xlsx [also (older Excel versions): xls] Excel VBA: xlsm [also (older Excel versions): xls] Java: java JavaScript: js [also (related extensions): htm/html/css] Kotlin: kt PHP: php Python: py Ruby: rb Rust: rs Swift: swift Section: Sleep/Tick Counts (benchmark tests)

UFL: sleep and compare tick counts

[AutoHotkey]

vTick1 := A_TickCount
Sleep(123)
vTick2 := A_TickCount
vDurationMSec := vTick2 - vTick1
MsgBox(vDurationMSec . " msec")

[C++]

#include <iostream>
#include <chrono>
#include <thread>

auto vTick1 = std::chrono::high_resolution_clock::now();
std::this_thread::sleep_for(std::chrono::milliseconds(123));
auto vTick2 = std::chrono::high_resolution_clock::now();
auto vDurationMSec = std::chrono::duration_cast<std::chrono::milliseconds>(vTick2-vTick1).count();
std::cout << std::to_string(vDurationMSec) + " msec" << "\n";

[C#]

var vTick1 = DateTime.Now;
System.Threading.Thread.Sleep(123);
var vTick2 = DateTime.Now;
var vDurationMSec = (vTick2-vTick1).TotalMilliseconds;
Console.WriteLine(vDurationMSec + " msec");

[Excel]

[Excel VBA]

#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If

vTick1 = Timer
'Application.Wait (Now + TimeValue("0:00:01"))
Sleep (123) 'Winapi function kernel32\Sleep, more accurate than Application.Wait
vTick2 = Timer
vDurationMSec = Int((vTick2 - vTick1) * 1000)
Debug.Print (vDurationMSec & " msec")

[Java]

var vTick1 = System.currentTimeMillis();
try
{
	Thread.sleep(123);
}
catch (Exception e)
{
}
var vTick2 = System.currentTimeMillis();
var vDurationMSec = vTick2 - vTick1;
System.out.println(vDurationMSec + " msec");

[JavaScript]

vTick1 = performance.now();
var vDate = 123 + new Date().getTime();
while (new Date() < vDate)
	{} //noop
vTick2 = performance.now();
vDurationMSec = vTick2 - vTick1;
console.log(vDurationMSec + " msec");

[Kotlin]

var vTick1 = System.currentTimeMillis()
Thread.sleep(123)
var vTick2 = System.currentTimeMillis()
var vDurationMSec = vTick2 - vTick1
println("" + vDurationMSec + " msec")

[PHP]

$vTick1 = microtime(true);
usleep(123*1000); //note: usleep uses microseconds (1000 microseconds = 1 millisecond)
$vTick2 = microtime(true);
$vDurationMSec = intval(($vTick2-$vTick1)*1000);
var_export($vDurationMSec . " msec");

[Python]

import time

vTick1 = time.time()
time.sleep(123/1000)
vTick2 = time.time()
vDurationMSec = int((vTick2-vTick1)*1000)
print(str(vDurationMSec) + " msec")

[Swift]

import Foundation

var oTick1 = DispatchTime.now()
usleep(123*1000)
var oTick2 = DispatchTime.now()
var vDurationNSec = oTick2.uptimeNanoseconds - oTick1.uptimeNanoseconds
var vDurationMSec = vDurationNSec / 1000000
print(String(vDurationMSec) + " msec")

Section: Concatenate Strings/Integers UFL: can concatenate string and int? AutoHotkey: yes [e.g. vText . vNum][e.g. vNum . vText] C++: no [can use: vText + std::to_string(vNum)][can use: std::to_string(vNum) + vText] C#: yes [e.g. vText + vNum][e.g. vNum + vText] Excel: yes [e.g. =A1&B1][=B1&A1] Excel VBA: yes [e.g. vText & vNum][e.g. vNum & vText] Java: yes [e.g. vText + vNum][e.g. vNum + vText] JavaScript: yes [e.g. vText + vNum][e.g. vNum + vText] Kotlin: depends on order [e.g. vText + vNum][can use: "" + vNum + vText] PHP: yes [e.g. vText . vNum][e.g. vNum . vText] Python: no [can use: vText + str(vNum)][also: str(vNum) + vText] Swift: no [can use: vText + String(vNum)][can use: String(vNum) + vText] The Universal Function Library Project: Details Note: UFL: Universal Function Library, a set of around 100-300 standard functions for all programming languages. UFL: Tern ['c ? x : y' is preferable since it's clear/concise/common, else use alternative symbols like Raku ('c ?? x !! y')][a ternary function is a lesser option since it can't do short-circuit Boolean evaluation] recommendation: 'c ? x : y' is extremely clear and concise and very well known, if you create a programming language, you should implement it just like that, and if your programming language for whatever failed to do that (and even if has some alternative syntax ...), choose alternative symbols (e.g. Raku: 'c ?? x !! y') author's note: unlike with 'c ? x : y', where either x or y are not executed, depending on c, for the function 'Tern(c, x, y)', x and y will both be executed) UFL: Swap [consider 'Swap(&a, &b)' or 'Swap(a, b)' or a swap statement 'swap a b'][destructuring assignment is unclear when longer variable names are used] author's note: (all of the options aside from 'Swap(&a, &b)' and 'swap a b' are poor) author's note: a function is a fine option, if the language supports functions with ByRef variables: 'Swap(&a, &b)' (or possibly 'Swap(a, b)') author's note: 'swap a b' is a good option for any programming language author's note: 't = a, a = b, b = t', is verbose (e.g. a 3-liner, plus blank lines, plus a comment to say 'swap', plus longer variable names), can easily result in bugs (especially when code is updated and variables are renamed), and it doesn't make the intention clear, a user can't simply search 'swap' to find any swaps in the code author's note: destructuring assignment only looks clear when the variable name ares are unusually short author's note: if all languages implemented 'swap a b' or 'Swap(&a, &b)', this would make it easy to migrate code between programming languages, otherwise simply swapping variables will be a recurring headache author's note: there are huge numbers of views on Stack Overflow etc, on threads re. swapping variables author's note: the only argument against a swap statement/function, is that swapping is relatively uncommon, however, it is relatively verbose, and relatively unsafe author's note: in general, well-known operations should be doable at the level the user thinks of them ('I'm swapping variables a and b', not, 'I'm creating a temporary variable and using it to swap a and b') author's note: in general, well-known operations should be doable in as safe a way as possible, having to name each variable twice, and name a temporary variable twice, and 3 assignments where something may be ordered incorrectly, are chances for more bugs, and reasonably often exactly these bugs do occur author's note: many approaches have the side effect of introducing a temporary variable author's note: oArray.Swap(Key1, Key2) and oMap.Swap(Key1, Key2) are also useful, add a swap statement/function, and then you can easily find variable and object key swaps by searching for 'swap' author's note: a swap statement/function is easier to find, understand and debug than the alternatives author's note: if it can be written badly, it will be written badly, a swap statement/function is very hard to get wrong UFL: Sleep [perhaps consider friendly format options e.g. 'm'/'s'] UFL: Noop recommendation: the string 'noop' is uncommon, so it is easier to search for than 'nop' and 'pass', which are relatively common substrings of words recommendation: either a noop statement or function is fine recommendation: a noop statement, that can't be overridden, may be useful as it enables the language to be sure it can replace the statement with a noop, no other checks are required recommendation: people use makeshift noops, a built-in noop, makes it easier to find any noops, for later removal recommendation: noops are useful as a line for adding breakpoints recommendation: some versions of noops can be confusing, e.g. '{}', because the programmer must remember not to add a trailing semicolon UFL: PrintLn [print string and a newline character] recommendation: a 'PrintLn' that always appends a line break, is more useful than a 'Print' that doesn't, if only one can be picked recommendation: since 'Print' with line break is wanted 99%+ of the time, it is fine for 'Print' to print a line break by default, with an option or separate function to print without a line break UFL: TickCount [get the current time in milliseconds (typically centisecond accuracy, or a higher resolution if possible), take the difference of 2 timestamps to get the time elapsed] UFL: SetTimer recommendation: it may be worth having 3 options: delay before first occurrence, gap in-between occurrences, number of occurrences UFL: Type UFL: Error UFL: Assert recommendation: it may be worth having variants of this function, e.g. assert that an error would occur if it were run, e.g. instead of 1 param that is a bool, perhaps 2 params (actual value, expected value), perhaps 3 params (function, parameters as an array, expected value)