Programming Language Cheat Sheets: General

Strings Mathematics [True/False] Operators and Symbols [ternary operator] General (Control Flow/Debugging) Dates Objects [Type/TypeFull] New Features Timelines Sections: Key Functions Error Handling (try/catch/finally, throw) Loops Keywords / Constants Function Definitions Assign/Declare Single Variables Assign/Declare Multiple Variables Multi-Line Strings File Extensions/Artwork Sleep/Tick Counts (benchmark tests) Concatenate Strings/Integers The Universal Function Library Project: Details 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. 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] Crystal: ___ [can use: a, b = b, a] [note: destructuring assignment] Excel: ___ Excel VBA: ___ Go: ___ [can use: a, b = b, a] [note: destructuring assignment] 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] R: ___ Ruby: ___ [can use: a, b = b, a] [note: destructuring assignment] Rust: ___ [can use: (a, b) = (b, a)] [note: destructuring assignment] Scala: ___ Swift: swap [e.g. swap(&a, &b)] [also: (a, b) = (b, a)] [note: destructuring assignment] UFL: Noop ['no operation', a function that does nothing] AutoHotkey: ___ [can use: {}] [note: in some contexts this creates an object] C++: ___ [can use: ;] C#: ___ [can use: ;] Crystal: ___ [can use: nil] Excel: ___ Excel VBA: ___ Go: ___ 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] R: ___ Ruby: ___ [can use: nil] Rust: ___ [can use: {} (typically with no semicolon)] Scala: ___ Swift: ___ UFL: PrintWithNewLine [or PrintLn][print string and a newline character] AutoHotkey: ___ [can use: OutputDebug/MsgBox/ToolTip/TrayTip] C++: std::println(vVar) [also: std::printf(vVar)] [note: std::println (C++23)] [also: std::cout << vVar << "\n"] [also: std::cout << vVar << std::endl] C#: Console.WriteLine(vVar) Crystal: p vVar [also: puts vVar] [also: print vVar, "\n"] [note: p keyword/p()/puts keyword/puts()] [note: p() prints strings as code (e.g. "a\"b"), rather than their appearance (e.g. a"b)] [note: puts() doesn't print arrays newline-separated (Ruby does)] Excel: ___ Excel VBA: Debug.Print vVar [note: text is printed to the Immediate Window] Go: fmt.Println(vVar) Java: System.out.println(vVar) JavaScript: console.log(vVar) [also: alert(vVar)] Kotlin: println(vVar) PHP: var_dump($vVar) [also: echo $vVar . "\n"] [also: echo $vVar . "<br>"] [note: var_dump() always prints a line break, print_r() prints a line break for objects but not values] Python: print(vVar) R: print(vVar) [also: cat(vVar, "\n")] [note: print() prints strings as code (e.g. "a\"b"), rather than their appearance (e.g. a"b)] [also: writeLines(), noquote(), paste(), paste0()] Ruby: p vVar [also: puts vVar] [also: print vVar, "\n"] [note: p keyword/p()/puts keyword/puts()] [WARNING: puts() prints arrays newline-separated] [note: p() prints strings as code (e.g. "a\"b"), rather than their appearance (e.g. a"b)] Rust: println!("{}", vVar) Scala: println(vVar) Swift: print(vVar) UFL: PrintWithoutNewLine [or PrintNoLn][print string without a line break (newline) character] AutoHotkey: ___ [can use: OutputDebug/MsgBox/ToolTip/TrayTip] C++: std::print(vVar) [note: std::print (C++23)] [also: std::cout << vVar] C#: Console.Write(vVar) Crystal: print [note: print keyword/print()] [note: print()/p()/puts() print arrays on one line (in Ruby puts() prints arrays newline-separated)] Excel: ___ Excel VBA: Debug.Print vVar; [note: use a semicolon to omit the line break] [note: text is printed to the Immediate Window] [also: set active cell value: ActiveCell.Value = vValue] [also: set value of cell below active cell: ActiveCell.Offset(1, 0).Value = vValue] Go: fmt.Print(vVar) Java: System.out.print(vVar) JavaScript: ___ Kotlin: print(vVar) PHP: echo $vVar [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] [MAJOR WARNING: echo/print/print_r print true/false/null as "1"/""/"" (var_dump()/var_export() print true/false/NULL)] Python: print(vVar, end="") R: cat [e.g. cat(vVar)] Ruby: print [note: print keyword/print()] [note: print() and p() print arrays on one line] Rust: print!("{}", vVar) Scala: print(vVar) Swift: print(vVar, terminator:"") UFL: PrintNewLine [or PrintBlankLine][print a line break (newline) character]['print a blank line' (if following a line break)] AutoHotkey: ___ [can use: OutputDebug/MsgBox/ToolTip/TrayTip] C++: std::cout << "\n" C#: Console.WriteLine() Crystal: puts [also: print "\n"] Excel: ___ Excel VBA: Debug.Print Go: fmt.Println() Java: System.out.println() JavaScript: console.log() Kotlin: println() PHP: echo "\n" [also: print "\n"] [also: print_r("\n")] Python: print() R: cat("\n") Ruby: puts [also: print "\n"] Rust: println!() [also: println!("")] [also: println!("{}", "")] Scala: println() Swift: print() UFL: (PrintCustom) [define a custom function/macro 'myprint' to print a string (and a line break)][all handle at least 0 and 1 params unless stated][see also: MakeFuncForEachDemoPrint] AutoHotkey: myprint := MsgBox [also (append to clipboard): myprint := (vVar:="") => A_Clipboard .= vVar "`r`n"] C++: template<typename T=char[]> void myprint(T const& vVar="") {std::cout << (vVar) << "\n";} [also (a custom macro, which doesn't handle 0 params): #define myprint(vVar) std::cout << (vVar) << "\n"] C#: public static void myprint<T>(T vVar) {Console.WriteLine(vVar);} public static void myprint() {Console.WriteLine();} [note: 1 custom function with 2 overloads] Crystal: def myprint(*oVar); oVar.size>0 ? p(oVar[0]?) : puts(); end Excel: ___ Excel VBA: Function myprint(Optional vVar = ""): Debug.Print vVar: End Function Go: myprint := fmt.Println Java: public static <T> void myprint(T vVar) {System.out.println(vVar);} public static void myprint() {System.out.println();} [note: 1 custom function with 2 overloads] JavaScript: myprint = console.log; Kotlin: fun myprint(vVar: Any?="") : Unit {println(vVar)} [also: val myprint: (Any?)->Unit = ::println] PHP: function myprint($vVar="") {func_num_args() && var_export($vVar); echo("\n");} Python: myprint = print R: myprint = \(vVar) if (nargs()>0) print(vVar) else cat("\n") Ruby: def myprint(*oVar); oVar.size>0 ? p(oVar[0]) : puts(); end Rust: macro_rules! myprint {($vVar:expr)=>{println!("{:?}", $vVar)};()=>{println!()}} [note: a custom macro] [e.g. usage: myprint!(vVar)] Scala: var myprint = (vValue:Any) => println(vValue) Swift: func myprint(_ vVar: Any="") -> () {print(vVar)} [also: can use 'Void' instead of '()'] UFL: Version [get the programming language version] AutoHotkey: A_AhkVersion C++: __cplusplus C#: ___ Crystal: Crystal::VERSION 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)] Go: runtime.Version() [requires: import "runtime"] Java: System.getProperty("java.version") [also: Runtime.version().version().get(0)] JavaScript: ___ Kotlin: KotlinVersion.CURRENT PHP: phpversion() Python: sys.version [requires: import sys] R: paste(version[c("version.string")]) [also: paste(getRversion())] [also: paste(version[c("major", "minor")], collapse=".")] [also (multiple properties): version] [also (multiple properties): R.Version()] Ruby: RUBY_VERSION Rust: ___ Scala: ___ [can use: util.Properties.versionNumberString] [WARNING: states 2.x, when the version is 3.x] Swift: ___ [e.g. #if swift(>=5.9)] UFL: OSVersion [get the operating system type/version (e.g. Windows 10)] AutoHotkey: A_OSVersion C++: ___ C#: Environment.OSVersion Crystal: ___ [can use: Crystal::DESCRIPTION] 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] Go: runtime.GOOS [requires: import "runtime"] 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] R: paste(version["platform"]) [also: version["arch"]/version["os"]/version["system"]] [also (multiple properties): version] [also (multiple properties): R.Version()] Ruby: RUBY_PLATFORM Rust: env::consts::OS [requires: use std::env] [also: env::consts::FAMILY, env::consts::ARCH] Scala: System.getProperty("os.name") [also: 'os.version'/'os.arch'] Swift: ProcessInfo().operatingSystemVersion UFL: Sleep [perhaps consider friendly format options e.g. 'm'/'s'] AutoHotkey: Sleep [e.g. 1 sec: Sleep(1000)] C++: std::this_thread::sleep_for [e.g. 1 sec: std::this_thread::sleep_for(std::chrono::milliseconds(1000))] [also: sleep/usleep/nanosleep] C#: System.Threading.Thread.Sleep [e.g. 1 sec: System.Threading.Thread.Sleep(1000)] Crystal: sleep [e.g. 1 sec: sleep 1] [also: sleep(1)] Excel: ___ Excel VBA: Application.Wait [e.g. Application.Wait (Now + TimeValue("0:00:01"))] [also: the Winapi (kernel32\Sleep)] Go: time.Sleep [e.g. 1 sec: time.Sleep(1 * time.Second)] [requires: import "time"] Java: Thread.sleep [e.g. 1 sec: Thread.sleep(1000)] [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 [e.g. 1 sec: Thread.sleep(1000)] [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)] R: Sys.sleep [e.g. 1 sec: Sys.sleep(1)] Ruby: sleep [e.g. 1 sec: sleep 1] [also: sleep(1)] Rust: thread::sleep [e.g. 1 sec: thread::sleep(time::Duration::from_millis(1000))] [requires: use std::{thread, time}] Scala: Thread.sleep [e.g. 1 sec: Thread.sleep(1000)] Swift: sleep [also: usleep] [e.g. 1 sec: sleep(1)] [e.g. 1 sec: usleep(1000000)] UFL: TickCount [get the current time (e.g. 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: A_TickCount [e.g. vMSec := A_TickCount] [note: A_TickCount, a built-in variable] [type: Integer] C++: std::chrono::system_clock::now [e.g. oTime = std::chrono::high_resolution_clock::now()] [also: the Winapi (kernel32\GetTickCount64)] [type (a time point): e.g. NSt3__26chrono10time_pointINS0_12steady_clockENS0_8durationIxNS_5ratioILx1ELx1000000000EEEEEEE] [requires: #include <chrono>] C#: DateTime.Now [e.g. oTime = DateTime.Now] [type: DateTime] Crystal: Time.local [e.g. oTime = Time.local] [also: Time.utc] [type (both): Time] 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 values] [type (NOW): 1 (Number)] [type (TEXT): 2 (Text)] Excel VBA: Timer [e.g. vSec = Timer] [note: seconds plus fractions of seconds] [type: Single] Go: time.Now() [e.g. oTime := time.Now()] [requires: import "time"] [type: time.Time] Java: System.currentTimeMillis [e.g. vMSec = System.currentTimeMillis()] [also: System.nanoTime] [type (both): long] JavaScript: performance.now [e.g. vMSec = performance.now()] [type: number] Kotlin: System.currentTimeMillis [e.g. vMSec = System.currentTimeMillis()] [also: System.nanoTime] [type: Long] PHP: microtime [e.g. $vSec = microtime(true)] [note: seconds plus fractions of seconds] [type: double] Python: time.time [e.g. vSec = time.time()] [note: seconds plus fractions of seconds] [type: float] R: Sys.time() [e.g. oTime = Sys.time()] [type: double (class: POSIXct POSIXt)] [type (difference of 2 times): double (class: difftime)] Ruby: Time.now [e.g. oTime = Time.now] [type: Time] Rust: time::SystemTime::now [e.g. oTime = time::SystemTime::now()] [requires: use std::time] [type: std::time::SystemTime] Scala: System.currentTimeMillis [e.g. vMSec = System.currentTimeMillis()] [also: System.nanoTime] [type (both): long] Swift: DispatchTime.now [e.g. vNSec = DispatchTime.now().uptimeNanoseconds] [requires: import Foundation] [type: UInt64] UFL: SetTimer [create a timer, e.g. to execute a function once at a specific time, or at regular intervals] AutoHotkey: SetTimer C++: ___ C#: System.Timers.Timer Crystal: Thread.new Excel: ___ Excel VBA: Application.OnTime Go: time.NewTimer [requires: import "time"] Java: java.util.Timer JavaScript: setInterval [also: setTimeout] Kotlin: java.util.Timer [also: android.os.Handler] PHP: ___ Python: threading.timer R: ___ Ruby: Thread.new Rust: ___ [can use: tokio::spawn] Scala: java.util.Timer [e.g. oTimer = new java.util.Timer()] Swift: Timer.scheduledTimer UFL: Assert [for testing: confirm that a value is equal to another value, else throw] AutoHotkey: ___ C++: assert [e.g. assert(vVar1 == vVar2)] [note: assert macro] [requires: #include <cassert>] C#: Debug.Assert [e.g. Debug.Assert(vVar1 == vVar2)] [also: Trace.Assert] [requires: using System.Diagnostics] [WARNING: may need to enable debug mode, and/or use listeners] Crystal: should [e.g. vVar1.should eq(vVar2)] [requires: require "spec"] Excel: ___ [can use: can simply type in expressions e.g. '=A1=A2'] [can use: IF] Excel VBA: Debug.Assert [e.g. Debug.Assert vVar1 = vVar2] Go: ___ Java: assert [e.g. assert vVar1 == vVar2] [e.g. assert vVar1 == vVar2 : "my error message"] [WARNING: -enableassertions (or -ea) switch must be on] [note: assert keyword] [can use: if (!vCond) throw new AssertionError()] JavaScript: ___ Kotlin: assert [e.g. assert(vVar1 == vVar2)] [also: assertEquals] [e.g. assertEquals(vVar1, vVar2)] [WARNING: assertEquals parameter order is 'expected' then 'actual'] [requires (assertEquals): import kotlin.test.assertEquals] PHP: assert [e.g. assert($vVar1 == $vVar2)] Python: assert [e.g. assert vVar1 == vVar2] [note: assert statement] R: stopifnot [e.g. stopifnot(vVar1 == vVar2)] [e.g. stopifnot("my error message" = vVar1 == vVar2)] Ruby: assert_equal [e.g. assert_equal(vVar1, vVar2)] [requires: require "test/unit/assertions"] [requires: include Test::Unit::Assertions] Rust: assert [e.g. assert!(vVar1==vVar2, "my error message")] [also: assert_eq!] [note: assert/assert_eq macros] Scala: assert [e.g. assert(2+2 == 4)] Swift: assert [e.g. assert(vVar1 == vVar2)] Section: Error Handling UFL: Try/Catch/Finally [note: are braces needed for branches] AutoHotkey: try/catch/finally C++: try/catch/___ C#: try/catch/finally Crystal: begin/rescue/ensure/end 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)] Go: ___/___/___ Java: try/catch/finally JavaScript: try/catch/finally Kotlin: try/catch/finally PHP: try/catch/finally Python: try/except/finally R: ___/___/___ [can use: tryCatch (with params: expr/error/finally, also warning)] Ruby: begin/rescue/ensure/end Rust: ___/___/___ Scala: try/catch/finally Swift: do/catch/___ [also: try] [also: defer] UFL: Throw [code to indicate that an error has occurred][typically 'throw' within a 'try' block leads to 'catch'/'finally' blocks being executed, and code outside a 'try' block ends the program] 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") Crystal: raise "my message" Excel: ___ Excel VBA: Err.Raise 1234, , "my message" Go: ___ [also: panic] 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") R: ___ [can use: stop("my message")] Ruby: raise "my message" Rust: ___ Scala: throw new Exception("my message") [also: Error()] 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)][create an object with information describing an error] 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 Crystal: Exception [e.g. raise Exception.new("my message")] Excel: ___ Excel VBA: ___ Go: ___ [also: panic] Java: Exception [also: Error()] JavaScript: Error Kotlin: Exception PHP: Exception [also: ErrorException(), Error()] Python: Exception R: ___ [also: tryCatch/stop] Ruby: StandardError [e.g. raise StandardError.new "my message"] Rust: ___ Scala: Exception [also: Error()] Swift: ___ [can use: NSError()] [also: fatalError()] [requires (NSError): import Foundation] UFL: FatalError [end program/script early, e.g. for testing/debugging][the exact behaviours differ across languages] 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] Crystal: abort Excel: ___ Excel VBA: Exit Sub [note: different from 'End Sub'] Go: ___ [also: panic] 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] R: ___ [also: stop] Ruby: abort [note: in some situations, 'rescue'/'ensure' blocks can still be executed] Rust: process::exit(1) [requires: use std::process] Scala: System.exit(0) Swift: fatalError() Section: Loops UFL: LoopCountIncDemo [(or LoopRangeIncDemo)][loop n times (loop from 1 to 10, both inclusive)][see also: Range.New] 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++) Crystal: (1..10).each do |i| [also: 1.upto(10) do |i|] Excel: ___ Excel VBA: For i = 1 To 10 [afterwards: Next] Go: for i := 1; i <= 10; i++ 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): R: for (i in 1:10) [also: for (i in seq(1, 10, 1))] [also: for (i in seq_len(10))] Ruby: for i in 1..10 [also: (1..10).each do |i|] [also: 1.upto(10) do |i|] Rust: for i in 1..=10 Scala: for(i <- 1 to 10) Swift: for i in 1...10 [also (if i is unused): for _ in 1...10] UFL: LoopCountIncExcDemo [(or (LoopRangeExcDemo)][loop n times (loop from 0 inclusive to 10 exclusive)][i.e. 0 to 9 inclusive] 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++) Crystal: (0...10).each do |i| Excel: ___ Excel VBA: For i = 0 To (10 - 1) [note: parentheses unnecessary, for clarity] [afterwards: Next] Go: for i := 0; i < 10; i++ [also: for i := range 10] 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): [WARNING: range uses exclusive end] R: for (i in 0:(10-1)) Ruby: for i in 0...10 Rust: for i in 0..10 [WARNING: .. uses exclusive end] Scala: for(i <- 0 until 10) Swift: for i in 0..<10 [also (if i is unused): for _ in 0..<10] UFL: LoopCountDecDemo [(or LoopRangeDecDemo)][loop n times (loop from 10 to 1, both inclusive)] AutoHotkey: ___ [can use: Loop 10] [note (value): 11-A_Index will give 10, 9, 8 etc] C++: for (int i=10; i>=1; i--) [note: --i may be preferable to i--] C#: for (int i=10; i>=1; i--) Crystal: (10).downto(1) do |i| Excel: ___ Excel VBA: For i = 10 To 1 Step -1 [afterwards: Next] Go: for i := 10; i >= 1; i-- Java: for (int i=10; i>=1; i--) JavaScript: for (let i=10; i>=1; i--) Kotlin: for (i in 10 downTo 1) PHP: for ($i=10; $i>=1; $i--) Python: for i in range(10, 1-1, -1): R: for (i in 10:1) [also: for (i in seq(10, 1, -1))] Ruby: for i in (10).downto(1) [also: (10).downto(1) do |i|] Rust: for i in (1..=10).rev() Scala: for(i <- 10 to 1 by -1) Swift: for i in stride(from:10, through:1, by:-1) [also: for i in (1...10).reversed()] [note: use 'to' instead of 'through' for exclusive end] [note: if i is unused, use _] UFL: LoopCountDecExcDemo [(or (LoopRangeDecExcDemo)][loop n times (loop from 10 exclusive to 0 inclusive)][i.e. 9 to 0 inclusive] AutoHotkey: ___ [can use: Loop 10] [note (value): 10-A_Index will give 9, 8, 7 etc] C++: for (int i=10-1; i>=0; i--) [note: --i may be preferable to i--] C#: for (int i=10-1; i>=0; i--) Crystal: (10-1).downto(0) do |i| Excel: ___ Excel VBA: For i = (10 - 1) To 0 Step -1 [afterwards: Next] Go: for i := 10 - 1; i >= 0; i-- Java: for (int i=10-1; i>=0; i--) JavaScript: for (let i=10-1; i>=0; i--) Kotlin: for (i in 10-1 downTo 0) PHP: for ($i=10-1; $i>=0; $i--) Python: for i in range(10-1, 0-1, -1): R: for (i in (10-1):0) [also: for (i in seq(10-1, 0, -1))] Ruby: for i in (10-1).downto(0) [also: (10-1).downto(0) do |i|] Rust: for i in (0..10).rev() Scala: for(i <- 10-1 to 0 by -1) Swift: for i in stride(from:10-1, through:0, by:-1) [also: for i in (0..<10).reversed()] [note: use 'to' instead of 'through' for exclusive end] [note: if i is unused, use _] 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++)] Crystal: loop do [also: while true] Excel: ___ Excel VBA: Do While True [afterwards: Loop] Go: for 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):] R: while (TRUE) Ruby: loop do [also: while true] Rust: loop [also: while true] Scala: while(true) Swift: while true [also: for i in 1...] [also (if i is unused): for _ in 1...] UFL: Break/Continue [break: end a loop (break out of a loop)][continue: end current loop iteration (skip to next iteration)] AutoHotkey: break/continue C++: break/continue C#: break/continue Crystal: break/next Excel: ___/___ Excel VBA: Exit For/___ Go: break/continue Java: break/continue JavaScript: break/continue Kotlin: break/continue PHP: break/continue Python: break/continue R: break/next Ruby: break/next Rust: break/continue Scala: ___/___ [can use: breakable and break] [requires (breakable): import scala.util.control.Breaks._] Swift: break/continue UFL: (BreakMult)/(ContinueMult) [break: break out of multiple levels of a loop][continue: continue applied to multiple levels of a loop] AutoHotkey: break MyLabel/continue MyLabel [also: e.g. 2 levels: break 2/continue 2] C++: ___/___ C#: ___/___ Crystal: ___/___ Excel: ___/___ Excel VBA: ___/___ Go: break MyLabel/continue MyLabel Java: break MyLabel/continue MyLabel JavaScript: break MyLabel/continue MyLabel Kotlin: break@MyLabel/continue@MyLabel PHP: ___/___ [also: e.g. 2 levels: break 2/continue 2] Python: ___/___ R: ___/___ Ruby: ___/___ Rust: break 'MyLabel/continue 'MyLabel Scala: ___/___ Swift: break MyLabel/continue MyLabel Section: Keywords / Constants UFL: IfKeywords [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] Crystal: if c / elsif c / else / end [note: parentheses *not* needed] 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] Go: if c / else if c / else [WARNING: c must be a bool] [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] R: if (c) / else if (c) / else [note: c must be a bool or numeric] [note: 'else if'/'else' must be preceded by '}' on the same line] Ruby: if c / elsif c / else / end [note: parentheses *not* needed] Rust: if c / else if c / else [WARNING: c must be a bool] [WARNING: requires braces for 1-line statements] [note: can be used in expressions] [note: parentheses *not* needed] Scala: if (c) / else if (c) / else [WARNING: c must be a bool] [note: can be used in expressions] Swift: if (c) / else if (c) / else [WARNING: c must be a bool] [WARNING: requires braces for 1-line statements] UFL: SwitchKeywords [switch statement] AutoHotkey: switch/case/default [note: no fall-through] C++: switch/case/default [note: uses fall-through] [WARNING: the input value cannot be a string] C#: switch/case/default [note: no fall-through] [WARNING: C# requires 'break' for *every* case/default (i.e. it looks like fall-through is possible, but it is not, the breaks cannot be removed)] Crystal: case/when/else/end [note: no fall-through] Excel: ___/___/___ Excel VBA: Select/Case/Case Else/End Select [note: no fall-through] Go: switch/case/default [note: no fall-through (unless use 'fallthrough' keyword one or more times)] Java: switch/case/default [note: uses fall-through] [also: switch expressions: also switch/case/default (but *no* fall-through)] JavaScript: switch/case/default [note: uses fall-through] Kotlin: when/(pattern)/else [note: no fall-through] PHP: switch/case/default [note: uses fall-through] Python: match/case/case _ [note: no fall-through] R: ___/___/___ [can use: switch() one-liners, equivalent to a map/dictionary key lookup, returns NULL if not found] [note: no fall-through] Ruby: case/when/else/end [note: no fall-through] Rust: match/(pattern)/_ [note: no fall-through] [note: must be exhaustive (i.e. all possible values must be covered) (workaround: add a default case)] Scala: match/case/case _ [note: no fall-through] [WARNING: throws if no match (workaround: add a default case)] Swift: switch/case/default [note: no fall-through] [note: must be exhaustive (i.e. all possible values must be covered) (workaround: add a default case)] 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] Crystal: nil 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 [note: also Empty/Null] [e.g. Set vVar = Nothing] [e.g. vVar = Empty] [e.g. vVar = Null] [e.g. obtain Empty: a variable that hasn't been used yet/ReDim an array then get a value/store the result of a function with no return value] Go: nil [e.g. var vNil []int = nil] Java: null [also (functions): void] JavaScript: null [also: undefined] [also (array values): 'elided'/'empty'] [also: void operator] Kotlin: null [also: Nothing e.g. vVar is Nothing?] [also (functions): Unit] [note: Void is a Java class (with no special meaning in Kotlin)] PHP: null [note: case-insensitive] [also (functions): void, never] Python: None [also: del statement] R: NULL [also: NA] [note: NA and NaN are different] Ruby: nil Rust: ___ [also (option objects): None] [e.g. vNone: Option<i32> = None] Scala: null [also (functions): Unit] Swift: nil [also (functions): Void] UFL: NullDemo [assign null to a variable] AutoHotkey: vVar := unset [note: Type(unset) throws] C++: auto vVar = nullptr [type: Dn] C#: string vVar = null [note: null.GetType().Name throws] Crystal: vVar = nil [type: Nil] Excel: #NULL! [type: 16 (error type: 1)] Excel VBA: Set vVar = Nothing [type: Nothing] [also: vVar = Null] [type: Null] [also: vVar = Empty] [type: Empty] Go: vVar interface{} = nil [type: <nil>] Java: Integer vVar = null [note: null.getClass().getSimpleName()) throws] JavaScript: vVar = null [type: object] [also: vVar = undefined] [type: undefined] Kotlin: vVar = null [note: null::class.simpleName throws] PHP: $vVar = null [type: Null] Python: vVar = None [type: NoneType] R: vVar = NULL [type (NULL): NULL] [also: vVar = NA] [type (NA): logical] Ruby: vVar = nil [type: NilClass] Rust: vVar: Option<i32> = None [type: core::option::Option<i32>] Scala: var vVar = null [note: null.getClass().getSimpleName()) throws] Swift: vVar: Int? = nil [type: e.g. Optional<Int>] UFL: IsNull [see also: Null/Array.KeyIsEmpty/FuncVoidType] AutoHotkey: vIsNull = !IsSet(vVar) C++: ___ [e.g. (std::string): vIsNull = (vVar == (std::string)NULL)] [WARNING: NULL is defined as 0, so for many types, e.g. int, comparing with null is actually comparing with 0] C#: vIsNull = (vVar == null) Crystal: vIsNull = vVar.nil? [also: vIsNull = (vVar == nil)] Excel: =ERROR.TYPE(A1)=1 Excel VBA: ___ [e.g. (TypeName(vVar) = "Nothing")] [e.g. (TypeName(vVar) = "Empty")] [e.g. (TypeName(vVar) = "Null")] [also (throws if vVar is not an object): vIsNull = vVar Is Nothing] [inverse: Not vVar Is Nothing] [also: IsNull(vVar)] [also: IsEmpty(vVar)] Go: vIsNull := (vVar == nil) Java: var vIsNull = (vVar == null) [e.g. optional object: !oOpt.isPresent()] JavaScript: vIsNull = (vVar === null) [also (is undefined): (vVar == undefined)] [also (is undefined): (typeof vVar == "undefined")] [WARNING: vVar == null returns true for null *and undefined*] Kotlin: vIsNull = (vVar == null) [also: vVar is Nothing?] [e.g. nullable object: (oOpt == null)] [inverse: vVar !is Nothing?] PHP: $vIsNull = is_null($vVar) [also: !isset($vVar)] [also: ($vVar == null)] Python: vIsNull = (vVar == None) [also: vVar is None] [inverse: vVar is not None] R: vIsNull = is.null(vVar) [also: is.na()/exists()/missing()] Ruby: vIsNull = vVar.nil? [also: vIsNull = (vVar == nil)] Rust: vIsNull = (vVar == None) [e.g. option object: (oOpt == None)] [also: oOpt.is_none()] [also: !oOpt.is_some()] Scala: var vIsNull = !Option(vVar).isDefined [also (doesn't work on ints): var vIsNull = (vVar == null)] Swift: vIsNull = (vVar == nil) [e.g. optional object: (oOpt == nil)] 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 Crystal: vVar = nil Excel: ___ Excel VBA: Set vVar = Nothing [note: doesn't work with all types] Go: vVar = nil 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] R: vVar = NULL Ruby: vVar = nil Rust: drop(vVar) Scala: vVar = null [note: doesn't work on ints] 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] Crystal: require [also: include/extend] Excel: ___ Excel VBA: ___ [can use: Workbooks.Open and Run] Go: import [e.g. import "fmt"] [note: the Go Playground auto-formats multiple imports into one] 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] R: library Ruby: require [also: include/extend] Rust: use [e.g. use std::time] Scala: import [e.g. import scala.math] [e.g. import scala.math._] Swift: import [e.g. import Foundation] Section: Function Definitions UFL: (IsCallable) [does a variable contain something function-like/method-like] AutoHotkey: HasMethod(vVar) C++: ___ C#: ___ Crystal: vVar.responds_to? :call Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ [can use: vVar instanceof Function] [also: typeof vVar == "function"] Kotlin: ___ PHP: is_callable($vVar) Python: callable(vVar) R: ___ [can use: class(vVar) == "function"] [also: typeof(vVar) == "closure"] Ruby: vVar.respond_to? :call Rust: ___ Scala: ___ [can use: vVar.getClass().getSimpleName().contains("Lambda")] Swift: ___ [note: can check if type contains ' -> ': String(describing:type(of:vVar))] UFL: (FuncAnonTypeDemo) [get type for 'MyAddAnon' examples in FuncDemoAdd (anonymous functions)] AutoHotkey: ___ [type: Func] C++: ___ [type: e.g. Z4mainE3$_0] C#: ___ [type: Func`3] Crystal: ___ [type: Proc(Int32, Int32, Int32)] Excel: ___ Excel VBA: ___ Go: ___ [type: func(int, int) int] Java: ___ [type: e.g. HelloWorld$$Lambda$1/0x0000000100060840] JavaScript: ___ [type: function] Kotlin: ___ [type: null] PHP: ___ [type: object] Python: ___ [type: function] R: ___ [type: closure (class: function)] Ruby: ___ [type: Proc] Rust: ___ [type: e.g. playground::main::MyAddAnon] Scala: ___ [type: e.g. Playground$$$Lambda$7748/0x00007f6c56502800] Swift: ___ [type: (Int, Int) -> Int] UFL: (FuncTypeDemo) [get type for 'MyAdd' examples in FuncDemoAdd (functions)] AutoHotkey: ___ [type: Func] C++: ___ [type: FiiiE] C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ [type: func(int, int) int] Java: ___ JavaScript: ___ [type: function] Kotlin: ___ PHP: ___ Python: ___ [type: function] R: ___ [type: closure (class: function)] Ruby: ___ Rust: ___ [type: e.g. playground::main::MyAdd] Scala: ___ [type: e.g. Playground$$$Lambda$7748/0x00007f6c56502800] Swift: ___ [type: (Int, Int) -> Int] UFL: FuncBelow [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 Crystal: yes Excel: ___ Excel VBA: yes Go: 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] R: no [WARNING: functions must be defined above where they are called] Ruby: no [WARNING: functions must be defined above where they are called] Rust: yes Scala: yes Swift: yes UFL: FuncMutable [function parameters are mutable][i.e. can a parameter variable be overwritten] AutoHotkey: yes C++: yes C#: yes Crystal: yes Excel: ___ Excel VBA: yes Go: 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 R: yes Ruby: yes Rust: no [WARNING: function parameter values (not object members) are read-only (they are not mutable) (workaround: do 'let mut vMyParamVar = vMyParamVar' to create a local copy)] Scala: no [WARNING: function parameter values (not object members) are read-only (they are not mutable)] 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: FuncVoidType [return type in function definition, for function with no return value] AutoHotkey: ___ C++: void C#: void Crystal: ___ [can use: Nil] [can use: Void] [note: types can be omitted] Excel: ___ Excel VBA: ___ Go: ___ Java: void JavaScript: ___ Kotlin: Unit PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ [can use: '()', the unit type] [note: '()' can be omitted] Scala: Unit Swift: () [also: Void] UFL: FuncOmitReturn ['return' *can* be omitted in standard function definitions][implicit return][e.g. last-line return] AutoHotkey: no C++: no C#: no Crystal: yes Excel: ___ Excel VBA: ___ [note: return value is set by assigning to the function name] Go: no Java: no JavaScript: no Kotlin: no [note: 'return' can be omitted in an expression body, but not a block body] PHP: no Python: no R: yes Ruby: yes Rust: yes Scala: yes Swift: yes UFL: FuncAnonOmitReturn ['return' *can* be omitted in anonymous function definitions][implicit return] AutoHotkey: yes C++: no [WARNING: 'return' can't be omitted in anonymous functions] C#: yes Crystal: yes Excel: ___ Excel VBA: ___ Go: no [WARNING: 'return' can't be omitted in anonymous functions] Java: yes JavaScript: yes Kotlin: yes PHP: yes Python: yes R: yes Ruby: yes Rust: yes Scala: yes Swift: yes UFL: FuncMultReturn [function can return multiple values][i.e. can specify multiple variables to receive multiple values][e.g. via tuples, e.g. via destructuring assignment] AutoHotkey: no [can use: VarRef parameters (AHK v1: ByRef parameters)] C++: yes [e.g. std::tie(a, b, c) = MyRetMult()] [e.g. use std::make_tuple and return a tuple] C#: yes [e.g. (a, b, c) = MyRetMult()] [also: can use 'out' parameters] Crystal: yes [e.g. a, b, c = MyRetMult.call()] Excel: ___ Excel VBA: no Go: yes [e.g. a, b, c := MyRetMult()] Java: no JavaScript: yes [e.g. [a, b, c] = MyRetMult()] Kotlin: yes [e.g. var (a, b, c) = MyRetMult()] [note: can use Pair/Triple, and destructuring declaration (but not destructuring assignment, i.e. can initialise variables, but not update variables)] PHP: no Python: yes [e.g. a, b, c = MyRetMult()] R: no Ruby: yes [e.g. a, b, c = MyRetMult.call()] Rust: yes [e.g. (a, b, c) = MyRetMult()] Scala: yes [e.g. var (a, b, c) = MyRetMult()] [note: can use Tuple, and destructuring declaration (but not destructuring assignment, i.e. can initialise variables, but not update variables)] Swift: yes [e.g. (a, b, c) = MyRetMult()] UFL: FuncAnonKeyword [keyword (if any) needed to call anonymous functions] AutoHotkey: ___ [deprecated: AHK v1: Call (AHK v2 onwards: none)] C++: ___ C#: ___ Crystal: call Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [e.g. accept/apply/get/test, applyAsDouble/applyAsInt/applyAsLong, getAsBoolean/getAsDouble/getAsInt/getAsLong] JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: call Rust: ___ Scala: ___ Swift: ___ UFL: FuncVarSupersede [can create a variable with the same name a standard function, and supersede it][e.g. an anonymous function can supersede/override/'overwrite' a standard function] AutoHotkey: no [can use: a function's behaviour can be changed via MyFunc.DefineProp("Call", {Call:MyFuncNew})] [note: AHK throws if attempt to assign to a variable with the same name as a function] C++: yes C#: yes Crystal: no [note: myFunc() and myFunc.call() would call different functions] [note: 'myFunc', not 'MyFunc', because function names can't start with a capital letter] Excel: no Excel VBA: no Go: yes Java: no [note: MyFunc() and MyFunc.apply() (or accept()/get()/test() etc) would call different functions] JavaScript: yes Kotlin: yes PHP: no [note: a variable name requires '$', $MyFunc won't override MyFunc] Python: yes R: yes Ruby: no [note: MyFunc() and MyFunc.call() would call different functions] Rust: yes Scala: no [note: a double definition error would occur (or a function overload occurs)] Swift: yes UFL: FuncOverload [can do function overloading?][e.g. same name, different param count (or different param types)] AutoHotkey: no C++: yes [note: C does not support function overloading] C#: yes Crystal: yes Excel: ___ Excel VBA: no Go: no Java: yes JavaScript: no Kotlin: yes PHP: no Python: no R: no Ruby: no Rust: no Scala: yes Swift: yes UFL: FuncDefineMult [can a standard function be defined more than once][i.e. anonymous functions don't count][see also: FuncBelow] AutoHotkey: no [note: can't have 2 functions with the same name] C++: yes (overloads) [note: function overloads are allowed, but can't have 2 functions with the same name/types/param counts] C#: yes (overloads) [note: function overloads are allowed, but can't have 2 functions with the same name/types/param counts] Crystal: yes (overloads) [MAJOR WARNING: function overloads are allowed, and *can* also have 2 functions with the same name/types/param counts, where the bottommost function takes precedence (it as though the earlier functions didn't exist)] [i.e. you can have multiple overloads, but some are silently discarded] Excel: ___ Excel VBA: no [note: can't have 2 functions with the same name] Go: no [note: can't have 2 functions with the same name] Java: yes (overloads) [note: function overloads are allowed, but can't have 2 functions with the same name/types/param counts] JavaScript: yes [WARNING: the bottommost function takes precedence, it as though the earlier functions didn't exist] Kotlin: yes (overloads) [note: function overloads are allowed, but can't have 2 functions with the same name/types/param counts] PHP: no [note: can't have 2 functions with the same name] Python: yes [note: the function called is the nearest function above where the call is made (i.e. the same logic as defining/calling anonymous functions)] R: yes [note: all functions are anonymous functions, assigned to variables] Ruby: yes [note: the function called is the nearest function above where the call is made (i.e. the same logic as defining/calling anonymous functions)] Rust: no [note: can't have 2 functions with the same name] Scala: yes (overloads) [note: function overloads are allowed, but can't have 2 functions with the same name/types/param counts] Swift: yes (overloads) [note: function overloads are allowed, but can't have 2 functions with the same name/types/param counts] UFL: FuncCallOmitLeading [can omit leading/middle params in function calls?][e.g. MyFunc(,2)][e.g. MyFunc(1,,3)] AutoHotkey: yes C++: no C#: no Crystal: no Excel: yes Excel VBA: yes Go: no Java: no JavaScript: no [can use (to omit a parameter): undefined] [e.g. MyFunc(undefined, 2)] Kotlin: no PHP: no Python: no R: yes Ruby: no Rust: no Scala: no Swift: no UFL: FuncStatic [functions can store local static variables?][note: there are usually short/short-ish workarounds e.g. closures][e.g. increment every time the function is used] AutoHotkey: yes C++: yes C#: no Crystal: no Excel: ___ Excel VBA: yes Go: no Java: no JavaScript: no [can use: add a property to the function] Kotlin: no PHP: yes Python: no [can use: add a property to the function] R: no Ruby: no Rust: yes [note: has to be within an 'unsafe' block] Scala: no Swift: no UFL: FuncPassName [use function by name as a function call parameter][e.g. pass a sort comparator function, e.g. pass a function to map/reduce/filter] AutoHotkey: MyFunc [note: AHK v1: "MyFunc", also: Func("MyFunc")] C++: ::MyFunc [also: MyFunc] [note: '::MyFunc' calls function if it exists, 'MyFunc' calls variable if it exists, else function if it exists] C#: MyFunc Crystal: &->MyFunc [e.g. &->MyFunc(Int32,Int32)] Excel: ___ Excel VBA: "MyFunc" [e.g. Application.Run("MyFunc")] [note: Application.Run works on custom, but not built-in functions] Go: MyFunc Java: MyClass::MyFunc JavaScript: MyFunc Kotlin: ::MyFunc PHP: "MyFunc" Python: MyFunc R: MyFunc Ruby: :MyFunc [e.g. method(:MyFunc)] Rust: MyFunc Scala: MyFunc Swift: MyFunc UFL: (FuncCopyBuiltInDemo) [copy (a reference to/or clone) a built-in function][see also: MakeFuncMapDemo/PrintCustom] AutoHotkey: oFunc := MsgBox [e.g. usage: oFunc(123)] C++: ___ C#: Func<int,int,int> oFunc = Math.Max [e.g. usage: oFunc(3,4)] [note: in C#, can't create an anonymous function with return type 'void'] Crystal: ___ Excel: ___ Excel VBA: ___ [note: Application.Run works on custom, but not built-in functions] [e.g. Application.Run("MyFunc")] Go: oFunc := fmt.Println [e.g. usage: oFunc(123)] Java: ___ JavaScript: oFunc = console.log [e.g. usage: oFunc(123)] Kotlin: val oFunc: (Any?)->Unit = ::println [e.g. usage: oFunc(123)] [WARNING: this example doesn't handle omitting the param] PHP: $oFunc = "var_dump" [e.g. usage: $oFunc(123)] Python: oFunc = print [e.g. usage: oFunc(123)] R: oFunc = print [e.g. usage: oFunc(123)] Ruby: oFunc = ::Kernel.instance_method(:p).bind(0) [e.g. usage: oFunc.call(123)] Rust: ___ Scala: ___ [e.g. MyPrint = println(_: Any)] [e.g. MyPrint0 = println(_: Unit)] [note: syntax for referring to a specific function overload] Swift: let oFunc: (_ vNum1: Int, _ vNum2: Int) -> Int = max [e.g. usage: oFunc(3,4)] UFL: FuncDefaultValue [function parameter default values][e.g. make param 2 optional in the MyAdd() examples below] AutoHotkey: MyAdd(vNum1, vNum2:=100) C++: int MyAdd(int vNum1, int vNum2=100) C#: public static int MyAdd(int vNum1, int vNum2=100) Crystal: def myAdd(vNum1, vNum2=100) Excel: ___ Excel VBA: Function MyAdd(vNum1, Optional vNum2 = 100) Go: ___ [MAJOR WARNING: Go lacks default function arguments, and it lacks function overloading, workaround: each function 'overload' needs a different name] Java: ___ [WARNING: Java lacks default function arguments, workaround: function overloading] JavaScript: function MyAdd(vNum1, vNum2=100) Kotlin: fun MyAdd(vNum1: Int, vNum2: Int=100) : Int PHP: function MyAdd($vNum1, $vNum2=100) Python: def MyAdd(vNum1, vNum2=100): R: MyAdd = function(vNum1, vNum2=100) Ruby: def MyAdd(vNum1, vNum2=100) Rust: ___ [MAJOR WARNING: Rust lacks default function arguments, and it lacks function overloading, and 'functions' via macros require using '!', workaround: each function 'overload' needs a different name] Scala: def Add(vNum1:Int, vNum2:Int=100) : Int = Swift: func MyAdd(_ vNum1: Int, _ vNum2: Int = 100) -> Int UFL: FuncBindDemo [or FuncPartialDemo][bind a parameter to a function e.g. 'multiply' becomes 'double' (by binding 2 as the 1st param)][create an anonymous function, by modifying an existing existing function, by pre-filling one or more arguments][see also: MakeFuncReduceDemoMul] AutoHotkey: MyDouble := MyMul.Bind(2) C++: auto MyDouble = std::bind(MyMul, 2, std::placeholders::_1) C#: ___ Crystal: MyDouble = MyMul.partial(2) Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: MyDouble = MyMul.bind(null, 2) Kotlin: ___ PHP: ___ Python: MyDouble = partial(MyMul, 2) R: ___ Ruby: MyDouble = MyMul.curry[2] Rust: ___ [also: impl: functions can be created by adding parameters to a function that uses impl] Scala: ___ Swift: ___ UFL: FuncCountArgs [count arguments passed to a normal (non-variadic) function][note: variadic functions usually provide an array with a 'length' property/method] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ [can use (if vVar is a Variant): vIsPassed = Not IsMissing(vVar)] Go: ___ Java: ___ JavaScript: arguments.length Kotlin: ___ PHP: func_num_args() Python: ___ R: nargs() Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: FuncParamPassed [or IsPassed/!IsOmitted/!IsMissing][check if a param was passed (to a normal (non-variadic) function) or whether it received the default value] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ [can use (if vVar is a Variant): vIsPassed = Not IsMissing(vVar)] Go: ___ Java: ___ JavaScript: ___ [can use: choose a default value that isn't 'undefined', compare against 'arguments[vIndex]'] [WARNING: this elided (empty) key check, works on arrays but not on 'arguments': (vKey in Array.prototype.slice.call(arguments))] Kotlin: ___ PHP: ___ [can use (0-based param index): array_key_exists($vIndex, func_get_args())] Python: ___ R: ___ [can use: vIsPassed = !missing(vVar)] Ruby: ___ [can use: MyFunc(a, b = c = "default")] [i.e. if b passed, c is nil, else both are 'default'] Rust: ___ Scala: ___ Swift: ___ UFL: (FuncCallDynamic) [call a function dynamically (based on string containing a function name)][workaround: store function references in an array/map][see also: Array.Get/Map.Get/Object.Get/VarGetDynamic] AutoHotkey: vRet := %vFuncName%(vArg1, vArg2) C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: vRet = Application.Run(vFuncName, vArg1, vArg2) Go: ___ Java: ___ JavaScript: vRet = new Function("return " + vFuncName)()(vArg1, vArg2) Kotlin: ___ PHP: $vRet = $vFuncName($vArg1, $vArg2) [also: call_user_func($vFuncName, $vArg1, $vArg2)] [also: call_user_func_array($vFuncName, [$vArg1, $vArg2])] Python: ___ [can use: vRet = globals()[vFuncName](vArg1, vArg2)] R: vRet = do.call(vFuncName, list(vArg1, vArg2)) Ruby: vRet = send(vFuncName, vArg1, vArg2) [also: vRet = oObj.send(vMtdName, vArg1, vArg2)] Rust: ___ Scala: ___ Swift: ___

UFL: FuncDemoAdd/FuncDemoSum [custom 'MyAdd' and 'MySum' functions][and 'MyAddAnon' anonymous function][and print example values][see also: OpSpreadReceiveDemo]

[AutoHotkey]

MyAdd(vNum1, vNum2)
{
	return vNum1 + vNum2
}
;MyAddAnon := (vNum1, vNum2) => vNum1 + vNum2
;MsgBox(MyAdd(1,2))
;MsgBox(MyAddAnon(1,2))

MySum(oParams*)
{
	vSum := 0
	for _, vValue in oParams
		vSum += vValue
	return vSum
}

[C++]

int MyAdd(int vNum1, int vNum2)
{
	return vNum1 + vNum2;
}
//auto MyAddAnon = [](int vNum1, int vNum2) {return vNum1+vNum2;};
//std::cout << MyAdd(1,2) << "\n";
//std::cout << MyAddAnon(1,2) << "\n";

//WARNING: C++ doesn't have variadic functions, so accept a vector instead:
int MySum(std::vector<int> oVec)
{
	int vSum = 0;
	for (const auto& vValue : oVec)
		vSum += vValue;
	return vSum;
}

[C#]

public static int MyAdd(int vNum1, int vNum2)
{
	return vNum1 + vNum2;
}
//Func<int,int,int> MyAddAnon = (vNum1, vNum2) => vNum1 + vNum2;
//Console.WriteLine(MyAdd(1,2));
//Console.WriteLine(MyAddAnon(1,2));

public static int MySum(params int[] oParams)
{
	int vSum = 0;
	for (var i=0; i<oParams.Length; i++)
		vSum += oParams[i];
	return vSum;
}

[Crystal]

#MAJOR WARNING: Crystal forces function names (method names) to start with a lower-case letter:
#WARNING: if try to define a function whose name starts with an upper-case letter, the error message is: 'Error: unexpected token: "("'

def myAdd(vNum1, vNum2)
	return vNum1 + vNum2
end
#MyAddAnon = ->(vNum1: Int32,vNum2: Int32) {vNum1+vNum2}
#p myAdd(1,2)
#p MyAddAnon.call(1,2)

def mySum(*oParams)
	vSum = 0
	oParams.each do |vValue|
		vSum += vValue
	end
	return vSum
end

[Excel]

'note: this can be used in sheet formulae (it accepts 2 parameters):
'e.g. =MyAdd(A1,A2)
Function MyAdd(vNum1, vNum2)
	MyAdd = vNum1 + vNum2
End Function

'note: this can be used in sheet formulae (it accepts 1 parameter, which can be a range) (it does not use ParamArray):
'e.g. =MySum(A1:A10)
Function MySum(oParams)
	vSum = 0
	For Each vValue In oParams
		vSum = vSum + vValue
	Next
	MySum = vSum
End Function

[Excel VBA]

Function MyAdd(vNum1, vNum2)
	MyAdd = vNum1 + vNum2
End Function
'Debug.Print MyAdd(1,2)

Function MySum(ParamArray oParams())
	vSum = 0
	For Each vValue In oParams
		vSum = vSum + vValue
	Next
	MySum = vSum
End Function

[Go]

// MAJOR WARNING: the Go Playground demands K&R style indentation:
// WARNING: the Go Playground may add whitespace before and after '//':

func MyAdd(vNum1 int, vNum2 int) int {
	return vNum1 + vNum2
}
//MyAddAnon := func(vNum1, vNum2 int) int { return vNum1 + vNum2 }
//fmt.Println(MyAdd(1,2))
//fmt.Println(MyAddAnon(1,2))

func MySum(oParams ...int) int {
	vSum := 0
	for _, vValue := range oParams {
		vSum += vValue
	}
	return vSum
}

[Java]

static int MyAdd(int vNum1, int vNum2)
{
	return vNum1 + vNum2;
}
//import java.util.function.*;
//BinaryOperator<Integer> MyAddAnon = (vNum1, vNum2) -> vNum1 + vNum2;
//System.out.println(MyAdd(1,2));
//System.out.println(MyAddAnon.apply(1,2));

static int MySum(int... oParams)
{
	int vSum = 0;
	for (var i=0; i<oParams.length; i++)
		vSum += oParams[i];
	return vSum;
}

[JavaScript]

function MyAdd(vNum1, vNum2)
{
	return vNum1 + vNum2;
}
//MyAddAnon = (vNum1, vNum2) => vNum1 + vNum2;
//console.log(MyAdd(1,2));
//console.log(MyAddAnon(1,2));

function MySum(...oParams)
{
	vSum = 0;
	for (var i=0; i<oParams.length; i++)
		vSum += oParams[i];
	return vSum;
}

[Kotlin]

fun MyAdd(vNum1: Int, vNum2: Int) : Int
{
	return vNum1 + vNum2
}
//var MyAddAnon = {vNum1:Int, vNum2:Int -> vNum1+vNum2}
//println(MyAdd(1,2))
//println(MyAddAnon(1,2))

fun MySum(vararg oParams: Int) : Int
{
	var vSum = 0
	for (i in 0 until oParams.size)
		vSum += oParams[i]
	return vSum
}

[PHP]

function MyAdd($vNum1, $vNum2)
{
	return $vNum1 + $vNum2;
}
//$MyAddAnon = fn($vNum1, $vNum2) => $vNum1 + $vNum2;
//var_dump(MyAdd(1,2));
//var_dump($MyAddAnon(1,2));

function MySum(...$oParams)
{
	$vSum = 0;
	foreach($oParams as $vValue)
		$vSum += $vValue;
	return $vSum;
}

[Python]

def MyAdd(vNum1, vNum2):
	return vNum1 + vNum2
#MyAddAnon = lambda vNum1, vNum2 : vNum1 + vNum2
#print(MyAdd(1,2))
#print(MyAddAnon(1,2))

def MySum(*oParams):
	vSum = 0
	for vValue in oParams:
		vSum += vValue
	return vSum

[R]

#note: this is creating an anonymous function, storing it as a variable:
#note: both approaches are doing this, 'function' and '\':
#note: in R, '<-' is often used for assignment, this website consistently uses '=':

MyAdd = function(vNum1, vNum2)
{
	return (vNum1 + vNum2)
}
#MyAddAnon = \(vNum1,vNum2) vNum1+vNum2
#print(MyAdd(1,2))
#print(MyAddAnon(1,2))

MySum = function(...)
{
	oParams = list(...)
	vSum = 0
	for (vValue in oParams)
		vSum = vSum + vValue
	return (vSum)
}

[Ruby]

def MyAdd(vNum1, vNum2)
	return vNum1 + vNum2
end
#MyAddAnon = ->(vNum1,vNum2) {vNum1+vNum2}
#p MyAdd(1,2)
#p MyAddAnon.call(1,2)

def MySum(*oParams)
	vSum = 0
	for vValue in oParams
		vSum += vValue
	end
	return vSum
end

[Rust]

fn MyAdd(vNum1: i32, vNum2: i32) -> i32
{
	return vNum1 + vNum2;
}
//fn MyAddAnon (vNum1:i32, vNum2:i32) -> i32{vNum1+vNum2}
//println!("{}", MyAdd(1,2));
//println!("{}", MyAddAnon(1,2));

//note: using implicit return syntax:
//'The final expression in the function will be used as [the] return value.'
fn MyAddAlt(vNum1: i32, vNum2: i32) -> i32
{
	vNum1 + vNum2
}

//WARNING: Rust doesn't have variadic functions, so accept a vector instead:
fn MySum(oVec: Vec<i32>) -> i32
{
	let mut vSum = 0;
	for vValue in oVec
	{
		vSum += vValue
	}
	return vSum;
}

[Scala]

def MyAdd(vNum1:Int, vNum2:Int) : Int =
{
	return vNum1 + vNum2
}
//def MyAddAnon(vNum1:Int, vNum2:Int): Int = vNum1 + vNum2
//println(MyAdd(1,2))
//println(MyAddAnon(1,2))

def MySum(oParams: Int*) : Int =
{
	var vSum = 0
	for(vValue <- oParams)
		vSum += vValue
	return vSum
}

[Swift]

func MyAdd(_ vNum1: Int, _ vNum2: Int) -> Int
{
	return vNum1 + vNum2
}
//var MyAddAnon: (_ vNum1:Int, _ vNum2:Int) -> Int = {vNum1,vNum2 in vNum1+vNum2}
//print(MyAdd(1,2))
//print(MyAddAnon(1,2))

func MySum(_ oParams: Int...) -> Int
{
	var vSum = 0
	for vValue in oParams
	{
		vSum += vValue
	}
	return vSum
}

Section: Assign/Declare Single Variables UFL: VarDecl [declare a variable, without assigning a value] AutoHotkey: ___ [e.g. (within a function): local a] C++: int a; C#: int a; Crystal: a: Int32 Excel: ___ Excel VBA: Dim a As Integer Go: var a int Java: int a; JavaScript: var a; Kotlin: var a: Int PHP: ___ Python: ___ R: ___ [can use: vText = character()] [also: vNum = numeric()] [also (equivalent to numeric()): vNum = double()] Ruby: ___ Rust: let mut a: i32; Scala: var a: Int = _ [note: using '_' assigns to the default value for that type] Swift: var a: Int UFL: VarDeclSetAuto [or VarDeclAssignAuto][assign variable (infer type)] AutoHotkey: vText := "abc" C++: auto vText = "abc" C#: var vText = "abc" Crystal: vText = "abc" Excel: ___ Excel VBA: vText = "abc" Go: vText := "abc" [also: var vText = "abc"] [MAJOR WARNING: if 'myvar declared and not used' then 'Go build failed.' (workaround: _ = myvar)] Java: var vText = "abc" JavaScript: vText = "abc" Kotlin: var vText = "abc" PHP: $vText = "abc" Python: vText = "abc" R: vText = "abc" Ruby: vText = "abc" Rust: let vText = "abc" [also: let mut vText = "abc"] Scala: var vText = "abc" Swift: var vText = "abc" UFL: VarDeclSet [or VarDeclAssign][assign variable (specify type)][or specify type hints/type annotations] AutoHotkey: ___ C++: std::string vText = "abc" C#: string vText = "abc" [note: 'String' also works] Crystal: vText: String = "abc" Excel: ___ Excel VBA: ___ [note: declaration/assignment keywords: Dim/ReDim/Set] Go: var vText string = "abc" Java: String vText = "abc" JavaScript: ___ Kotlin: var vText: String = "abc" PHP: ___ Python: vText: str = "abc" R: ___ Ruby: ___ Rust: let mut vText: String = "abc".to_string() [e.g. let vNum: i32 = 123] Scala: var vText = "abc" [also: val] Swift: var vText: String = "abc" UFL: VarSet [or VarAssign][assign a variable (update value)] AutoHotkey: a := 1 C++: a = 1; C#: a = 1; Crystal: a = 1 Excel: ___ Excel VBA: a = 1 Go: a = 1 Java: a = 1; JavaScript: a = 1; Kotlin: a = 1 PHP: $a = 1; Python: a = 1 R: a = 1 Ruby: a = 1 Rust: a = 1; Scala: a = 1 Swift: a = 1 UFL: (VarGetDynamic) [retrieve the value of a variable dynamically][workaround: use an array/map][see also: Array.Get/Map.Get/Object.Get/FuncCallDynamic] AutoHotkey: vValue := %vVarName% [also: vValue := %vVarNamePart1%%vVarNamePart2%] C++: ___ C#: ___ Crystal: ___ Excel: ___ [can use (specify a cell address dynamically): e.g. INDIRECT("A1")] [e.g. INDIRECT("A"&ROW())] Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ [can use: vValue = window[vVarName]] [also: vValue = window[vVarNamePart1 + vVarNamePart2]] Kotlin: ___ PHP: $vValue = $$vVarName [also: $vValue = ${$vVarNamePart1 . $vVarNamePart2}] Python: ___ [can use: vValue = globals()[vVarName]] [also: vValue = globals()[vVarNamePart1 + vVarNamePart2]] R: vValue = get(vVarName) [also: vValue = get(paste0(vVarNamePart1, vVarNamePart2))] Ruby: ___ Rust: ___ Scala: ___ Swift: ___ UFL: (VarSetDynamic) [set the value of a variable dynamically][workaround: use an array/map][see also: Array.Set/Map.Set/Object.Set/FuncCallDynamic] AutoHotkey: %vVarName% := vValue [also: %vVarNamePart1%%vVarNamePart2% := vValue] C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ [can use: window[vVarName] = vValue] [also: window[vVarNamePart1 + vVarNamePart2] = vValue] Kotlin: ___ PHP: $$vVarName = $vValue [also: ${$vVarNamePart1 . $vVarNamePart2} = $vValue] Python: ___ [can use: globals()[vVarName] = vValue] [also: globals()[vVarNamePart1 + vVarNamePart2] = vValue] R: assign(vVarName, vValue) [also: assign(paste0(vVarNamePart1, vVarNamePart2), vValue)] Ruby: ___ Rust: ___ Scala: ___ Swift: ___ Section: Assign/Declare Multiple Variables UFL: VarDeclMult [declare multiple variables, without assigning values] AutoHotkey: ___ [e.g. (within a function): local a, b, c] C++: int a, b, c; C#: int a, b, c; Crystal: a: Int32; b: Int32; c: Int32 Excel: ___ Excel VBA: Dim a, b, c As Integer Go: var a, b, c int Java: int a, b, c; JavaScript: var a, b, c; Kotlin: var a:Int; var b:Int; var c:Int PHP: ___ Python: ___ R: ___ [can use: a = b = c = character()] [also: a = b = c = numeric()] [also (equivalent to numeric()): a = b = c = double()] Ruby: ___ Rust: let (mut a, mut b, mut c): (i32, i32, i32); Scala: var a, b, c: Int = _ [note: using '_' assigns to the default value for that type] Swift: var a, b, c: Int UFL: VarDeclSetMult [or VarDeclAssignMult][declare and assign multiple variables] AutoHotkey: ___ [e.g. (within a function): 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);] Crystal: a: Int32 = 1; b: Int32 = 2; c: Int32 = 3 Excel: ___ Excel VBA: ___ Go: var a, b, c int = 1, 2, 3 [also (type omitted): var a, b, c = 1, 2, 3] [note: destructuring assignment] 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: var a:Int=1; var b:Int=2; var c:Int=3] [also (destructuring assignment) (destructuring declaration): var (a, b, c) = arrayOf(1, 2, 3)] [also: var (a:Int, b:Int, c:Int) = arrayOf(1, 2, 3)] PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: let (mut a, mut b, mut c): (i32, i32, i32) = (1, 2, 3); Scala: var (a, b, c) = (1, 2, 3) Swift: var a=1, b=2, c=3 [also: var a:Int=1, b:Int=2, c:Int=3] [also (destructuring assignment): var (a, b, c) = (1, 2, 3)] UFL: VarSetMult [or VarAssignMult][assign multiple variables] 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);] Crystal: a=1; b=2; c=3 [also (destructuring assignment): a, b, c = 1, 2, 3] Excel: ___ Excel VBA: a = 1: b = 2: c = 3 Go: a, b, c = 1, 2, 3 [note: destructuring assignment] 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] R: a=1; b=2; c=3 Ruby: a=1; b=2; c=3 [also (destructuring assignment): a, b, c = 1, 2, 3] Rust: a=1; b=2; c=3; [also (destructuring assignment): (a, b, c) = (1, 2, 3);] Scala: a=1; b=2; c=3 Swift: a=1; b=2; c=3 [also (destructuring assignment): (a, b, c) = (1, 2, 3)] UFL: VarDeclSetMultSame [or VarDeclAssignMultSame][declare and assign multiple variables, to the same value] AutoHotkey: ___ [WARNING (only creates static variable 'a'): static a := b := c := 123] C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ [can use: var a, b, c int = 123, 123, 123] [also (type omitted): var a, b, c = 123, 123, 123] [note: destructuring assignment] 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)] [also: var (a:Int, b:Int, c:Int) = IntArray(3){123}] [also: var (a:Int, b:Int, c:Int) = arrayOf(123, 123, 123)] PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: let [mut a, mut b, mut c] = [123; 3]; [note: destructuring assignment] Scala: var a, b, c = 123 Swift: ___ [can use: var (a, b, c) = (123, 123, 123)] [note: destructuring assignment] UFL: VarSetMultSame [or VarAssignMultSame][assign multiple variables, to the same value] AutoHotkey: a := b := c := 123 C++: a = b = c = 123; C#: a = b = c = 123; Crystal: a = b = c = 123 [also (destructuring assignment): a, b, c = Array.new(3, 123)] Excel: ___ Excel VBA: ___ Go: ___ [can use: a, b, c = 123, 123, 123] [note: destructuring assignment] 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] R: a = b = c = 123 Ruby: a = b = c = 123 [also (destructuring assignment): a, b, c = Array.new(3, 123)] Rust: [a, b, c] = [123; 3]; [note: destructuring assignment] Scala: ___ Swift: ___ [can use: (a, b, c) = (123, 123, 123)] [note: destructuring assignment] Section: Multi-Line Strings

UFL: StrMultiLine [multi-line strings][WARNING: some approaches crop whitespace (e.g. all whitespace, e.g. some whitespace based on indentation)]

C: concatenate operator
J: join method/function
X: other

[AutoHotkey]

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

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

vTextX1 := " ;continuation section
(
LINE 1
LINE 2
LINE 3
)"

vTextX2 := " ;continuation section
(Join`r`n
LINE 1
LINE 2
LINE 3
)"

MsgBox(vTextC1)
MsgBox(vTextC2)
MsgBox(vTextX1)
MsgBox(vTextX2)

[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 vTextX1 = "LINE 1\n\
LINE 2\n\
LINE 3";

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

std::cout << vTextC1 << "\n";
std::cout << vTextX1 << "\n";
std::cout << vTextX2 << "\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 vTextX1 = @"LINE 1
LINE 2
LINE 3";

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

[Crystal]

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

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

vTextX1 = "LINE 1
LINE 2
LINE 3"

vTextX2 = "LINE 1\n\
LINE 2\n\
LINE 3"

vTextX3 = "LINE 1\n" \
"LINE 2\n" \
"LINE 3"

vTextX4 = <<-MYTEXT
LINE 1
LINE 2
LINE 3
MYTEXT

vTextX5 = %q(LINE 1
LINE 2
LINE 3
)

puts vTextC1
puts vTextJ1
puts vTextX1
puts vTextX2
puts vTextX3
puts vTextX4
puts vTextX5

[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

[Go]

	//WARNING: Golang online compiler auto-indents code:
	//WARNING: Golang online compiler sometimes enforces a space after the comment symbol ('//'):

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

	vTextJ1 := strings.Join([]string{"LINE 1",
		"LINE 2",
		"LINE 3"},
		"\n")

	//WARNING: preserves leading whitespace:
	vTextX1 := `LINE 1
LINE 2
LINE 3
`

	fmt.Println(vTextC1)
	fmt.Println(vTextJ1)
	fmt.Println(vTextX1)

[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 vTextX1 = """
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(vTextX1);

[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")

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

vTextX2 = `LINE 1
LINE 2
LINE 3`;

console.log(vTextC1);
console.log(vTextC2);
console.log(vTextJ1);
console.log(vTextJ2);
console.log(vTextX1);
console.log(vTextX2);

[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 vTextX1 = """LINE 1
LINE 2
LINE 3"""

println(vTextC1)
println(vTextC2)
println(vTextJ1)
println(vTextJ2)
println(vTextX1)

[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"
]);

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

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

echo $vTextC1 . "\n";
echo $vTextC2 . "\n";
echo $vTextJ1 . "\n";
echo $vTextJ2 . "\n";
echo $vTextX1 . "\n";
echo $vTextX2 . "\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"
])

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

vTextX2 = """LINE 1
LINE 2
LINE 3"""

print(vTextC1)
print(vTextC2)
print(vTextJ1)
print(vTextJ2)
print(vTextX1)
print(vTextX2)

[R]

vTextJ1 = paste("LINE 1"
, "LINE 2"
, "LINE 3"
, sep="\n")

vTextJ2 = paste("LINE 1",
"LINE 2",
"LINE 3",
sep="\n")

vTextX1 = "LINE 1
LINE 2
LINE 3"

cat(vTextJ1); cat("\n")
cat(vTextJ2); cat("\n")
cat(vTextX1); cat("\n")

[Ruby]

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

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

vTextX1 = "LINE 1
LINE 2
LINE 3"

vTextX2 = "LINE 1\n\
LINE 2\n\
LINE 3"

vTextX3 = "LINE 1\n" \
"LINE 2\n" \
"LINE 3"

vTextX4 = <<-MYTEXT
LINE 1
LINE 2
LINE 3
MYTEXT

vTextX5 = <<~MYTEXT
LINE 1
LINE 2
LINE 3
MYTEXT

vTextX6 = %q(LINE 1
LINE 2
LINE 3
)

puts vTextC1
puts vTextJ1
puts vTextX1
puts vTextX2
puts vTextX3
puts vTextX4
puts vTextX5
puts vTextX6

[Rust]

let vTextX1 = "LINE 1
LINE 2
LINE 3";

let vTextX2 = "LINE 1\n\
LINE 2\n\
LINE 3";

let vTextX3 = concat!("LINE 1\n"
, "LINE 2\n"
, "LINE 3"
);

println!("{}", vTextX1);
println!("{}", vTextX2);
println!("{}", vTextX3);

[Scala]

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

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

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

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

var vTextX1 = """
LINE 1
LINE 2
LINE 3"""

println(vTextC1)
println(vTextC2)
println(vTextJ1)
println(vTextJ2)
println(vTextX1)

[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 vTextX1 = """
LINE 1
LINE 2
LINE 3
"""

print(vTextC1)
print(vTextC2)
print(vTextJ1)
print(vTextJ2)
print(vTextX1)

Section: File Extensions

UFL: FileExtension [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] Go: go Java: java JavaScript: js [also (related extensions): htm/html/css] Kotlin: kt PHP: php Python: py R: r Ruby: rb Rust: rs Scala: scala, sc Swift: swift UFL: (ArtworkLogo) [programming language logo] AutoHotkey: white 'H', green background C++: white 'C++', blue hexagon C#: white 'C#', purple hexagon Crystal: black hexagon, white equilateral triangle Excel: white 'X', green background Excel VBA: 4 boxes, orange/blue/yellow/purple (VBA logo) Go: light blue 'GO', with light blue speed marks on left Java: blue cup of coffee, orange steam JavaScript: black 'JS', yellow background Kotlin: stylised purple 'K' [note: previous logo: stylised K with blue/purple, and orange(/magenta) stripe] PHP: black 'php', purple background (purple oval) Python: blue snake, yellow snake R: blue 'R', grey unfilled oval Ruby: red ruby (shape is similar to (not necessarily identical to) an octagon diamond) Rust: black 'R' inside a cog Scala: red spiral staircase, 3 tiers (based on staircase at the EPFL, Lausanne, Switzerland) Swift: white bird facing bottom-right corner, orange background UFL: (ArtworkMascot) [programming language mascot] AutoHotkey: ___ C++: ___ [note: not Keith (brown with lighter bits, rat)] C#: ___ [note: formerly Andy (human, C-shaped tie, '#' pocket)] [also: DotNet Bot (purple, spherical, robot)] Crystal: crow (black) Excel: ___ Excel VBA: ___ Go: Go Gopher (light blue) Java: Duke (black head/arms, white body, round red nose, shaped like an upside-down tooth) JavaScript: ___ Kotlin: Kodee (purple, robot, cat-like, screen-like) PHP: ElePHPant (purple, elephant) Python: ___ R: ___ Ruby: ___ Rust: Ferris (red/orange, crab) Scala: ___ Swift: ___ Section: Sleep/Tick Counts (benchmark tests)

UFL: BenchmarkTest [benchmark test][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");

[Crystal]

oTick1 = Time.monotonic
sleep 123/1000
oTick2 = Time.monotonic
vDurationMSec = (oTick2-oTick1).total_milliseconds
puts vDurationMSec.to_s + " 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")

[Go]

//requires: import "time"
//requires: import "strconv"

oTime1 := time.Now()
time.Sleep(123 * time.Millisecond)
oTime2 := time.Now()
vDurationMSec := oTime2.Sub(oTime1).Milliseconds()
fmt.Println(strconv.Itoa(int(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")

[R]

oTime1 = Sys.time()
Sys.sleep(123/1000)
oTime2 = Sys.time()
vDurationMSec = as.numeric(oTime2-oTime1) * 1000
print(sprintf("%0.4f msec", vDurationMSec))
#print(paste(vDurationMSec, "msec")) #for more decimal places

[Ruby]

oTick1 = Time.now
sleep 123/1000.0
oTick2 = Time.now
vDurationMSec = (oTick2-oTick1) * 1000
puts vDurationMSec.to_s + " msec"

[Rust]

use std::{thread, time};

let oDate1 = time::SystemTime::now();
thread::sleep(time::Duration::from_millis(123));
let oDate2 = time::SystemTime::now();
let vDurationMSec = oDate2.duration_since(oDate1).unwrap().as_millis();
println!("{}{}", vDurationMSec, " msec");

[Scala]

var vTick1 = System.currentTimeMillis()
Thread.sleep(123)
var vTick2 = System.currentTimeMillis()
var vDurationMSec = vTick2 - vTick1
println(s"$vDurationMSec msec")
//println(s"${vDurationMSec} msec") //equivalent to line above

[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: StrIntConcat [can concatenate string and int directly?] AutoHotkey: yes [e.g. vText vNum] [e.g. vNum vText] [also: vText . vNum] [also: 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] Crystal: no [can use: vText + vNum.to_s] [also: vNum.to_s + vText] Excel: yes [e.g. =A1&B1][=B1&A1] Excel VBA: yes [e.g. vText & vNum] [e.g. vNum & vText] Go: no [can use: vText + strconv.Itoa(vNum)] [also: strconv.Itoa(vNum) + vText] [requires: import "strconv"] 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] R: yes [e.g. paste0(vText, vNum)] [e.g. paste0(vNum, vText)] Ruby: no [can use: vText + vNum.to_s] [also: vNum.to_s + vText] Rust: no [can use: format!("{}{}", vText, vNum)] [can use: format!("{}{}", vNum, vText)] Scala: yes [e.g. vText + vNum] [e.g. s"$vNum$vText"] [e.g. s"${vNum}${vText}"] [deprecated: vNum + vText] Swift: no [can use: vText + String(vNum)] [can use: String(vNum) + vText] UFL: PrintKeyValueConcat [or PrintConcat][note: will work for (at least) strings and ints][see also: StrIntConcat/Array.PrintWithIndex/Map.Print] AutoHotkey: MsgBox(vKey ": " vValue) C++: std::cout << vKey << ": " << vValue << "\n" [WARNING: std::to_string fails on std::string itself] C#: Console.WriteLine(vKey + ": " + vValue) [also: Console.WriteLine(oEntry.Key + ": " + oEntry.Value)] Crystal: p vKey.to_s + ": " + vValue.to_s Excel: =A1&": "&B1 Excel VBA: Debug.Print vKey & ": " & vValue Go: fmt.Printf("%v: %v\n", vKey, vValue) Java: System.out.println(vKey + ": " + vValue) [also: System.out.println(oEntry.getKey() + ": " + oEntry.getValue())] JavaScript: console.log(vKey + ": " + vValue) Kotlin: println("" + vKey + ": " + vValue) PHP: var_dump($vKey . ": " . $vValue) Python: print(str(vKey) + ": " + str(vValue)) R: print(paste(vKey, vValue, sep=": ")) [also: print(paste(vKey, oMap[[vKey]], sep=": "))] Ruby: p vKey.to_s + ": " + vValue.to_s Rust: println!("{}: {}", vKey, vValue) Scala: println(s"$vKey: $vValue") [also: println(s"${vKey}: ${vValue}")] Swift: print(String(vKey) + ": " + String(vValue)) [also: print(String(describing:vKey) + ": " + String(describing:vValue))] UFL: PrintKeyValueAsPair [or PrintAsPair/PrintAsTuple][note: will work for (at least) strings and ints][see also: StrIntConcat/Array.PrintWithIndex/Map.Print/Tuple.New/MakeFuncForEachWithIndexDemoPrintIntStr] AutoHotkey: ___ [can use: MsgBox(vKey ": " vValue)] C++: std::apply([](auto&&... oArgs) {((std::cout << oArgs << ", "), ...);}, std::make_pair(vKey, vValue)) [note: prints trailing separator] [afterwards: std::cout << "\n"] [also: can replace 'std::make_pair' with 'std::make_tuple'] [requires (pair): #include <utility>] [requires (tuple): #include <tuple>] C#: Console.WriteLine((vKey, vValue)) [also: Console.WriteLine(new KeyValuePair<string,int>(vKey, vValue))] [requires (KeyValuePair): using System.Collections.Generic] Crystal: p ({vKey, vValue}) Excel: ___ [can use: =A1&": "&B1] Excel VBA: ___ [can use: Debug.Print vKey & ": " & vValue] Go: fmt.Println([...]interface{}{vKey, vValue}) Java: System.out.println(Map.entry(vKey, vValue)) [also: System.out.println(new AbstractMap.SimpleEntry<>(vKey, vValue))] [requires (both): import java.util.*] JavaScript: console.log([vKey, vValue]) Kotlin: println(Pair(vKey, vValue)) PHP: var_dump([$vKey, $vValue]) Python: print((vKey, vValue)) [also: print([vKey, vValue])] R: print(list(vKey, vValue)) [also: print(c(vKey, vValue))] [also: print(unlist(list(vKey, vValue)))] Ruby: p [vKey, vValue] Rust: println!("{:?}", (vKey, vValue)) Scala: println((vKey, vValue)) Swift: print((vKey, vValue)) UFL: PrintMultDemo [or PrintWithNewLineMultDemo][print multiple values of different types on one line] AutoHotkey: ___ [can use: MsgBox(Format("{} {} {}", "a", 1, 1.1))] C++: ___ [can use: std::apply([](auto&&... oArgs) {((std::cout << oArgs << ", "), ...);}, std::make_tuple("a", 1, 1.1))] [note: prints trailing separator] [afterwards: std::cout << "\n"] [requires (tuple): #include <tuple>] C#: Console.WriteLine(("a", 1, 1.1)) Crystal: p ({"a", 1, 1.1}) [also (prints each on a separate line): p "a", 1, 1.1] Excel: ___ Excel VBA: Debug.Print Join(Array("a", 1, 1.1), " ") Go: fmt.Println("a", 1, 1.1) Java: System.out.println(List.of("a", 1, 1.1)) [requires: import java.util.*] JavaScript: console.log("a", 1, 1.1) Kotlin: println(listOf("a", 1, 1.1)) PHP: var_dump(implode(" ", ["a", 1, 1.1])) [also (prints each on a separate line): var_dump("a", 1, 1.1)] Python: print("a", 1, 1.1) R: print(c("a", 1, 1.1)) [also: print(unlist(list("a", 1, 1.1)))] [also (prints across multiple lines, preserves types): print(list("a", 1, 1.1))] Ruby: p ["a", 1, 1.1] [also (prints each on a separate line): p "a", 1, 1.1] Rust: println!("{:?}", ("a", 1, 1.1)) [also: println!("{} {} {}", "a", 1, 1.1)] Scala: println(("a", 1, 1.1)) Swift: print("a", 1, 1.1) The Universal Function Library Project: Details Note: UFL: Universal Function Library, a set of around 100-300 standard functions for all programming languages. UFL notes: 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 notes: 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 notes: Sleep [perhaps consider friendly format options e.g. 'm'/'s'] UFL notes: 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 notes: 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 notes: 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 notes: SetTimer recommendation: it may be worth having 3 options: delay before first occurrence, gap in-between occurrences, number of occurrences UFL notes: Type UFL notes: Error UFL notes: 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)