Programming Language Comparison: Operators and Symbols

Strings Mathematics Operators and Symbols General (Control Flow/Debugging) Dates Objects 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.

Introduction

Note: most of these symbols are operators, but some are not e.g. comment symbols. Operators are typically comprised of characters from what I call, the 'classic 32': !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ Start with ASCII chars 33-126 (94 chars), remove A-Za-z0-9 (62 chars), that gives 32 chars. 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.

By Role

UFL: spread (splat) (for variadic function definitions/calls) AutoHotkey: * [e.g. MyFunc(oArray*)] C++: ... [note: ... (fold expressions) for function definitions *only*, no special syntax for function calls][also: macros: ... and __VA_ARGS__][also: va_list/va_start/va_arg/va_end (WARNING: this approach requires that a param, e.g. the first param, indicate how many params were passed)] C#: .. and params [e.g. MyFunc(..oArray)][note: 'params' keyword for function definitions, .. (2 dots) (spread operator) for function calls] Excel: [none] Excel VBA: ParamArray [note: ParamArray for function definitions, no special syntax for function calls] Java: ... [note: ... (varargs feature) for function definitions *only*, no special syntax for function calls][WARNING: 'varargs' (with 's') is name, '...' is syntax] JavaScript: ... [e.g. MyFunc(...oArray)][note: spread syntax] Kotlin: * and vararg [e.g. MyFunc(*oArray)][note: 'vararg' keyword for function definitions, * (spread operator) for function calls][WARNING: 'vararg' (no 's') is syntax] PHP: ... [e.g. MyFunc(...oArray)] Python: * [e.g. MyFunc(*oArray)][note: splat] Swift: ... [note: ... for function definitions *only*, no special syntax for function calls][note: ... is also for closed ranges] UFL: ternary operator ['c ? x : y' is preferable since it's clear/concise/common, else use alternative symbols like Raku ('c ?? x !! y')][a ternary function (e.g. 'Tern') is a lesser option since it can't do short-circuit Boolean evaluation][note: state if bool/parentheses needed] AutoHotkey: c ? x : y C++: c ? x : y C#: c ? x : y [WARNING: c must be a bool] Excel: IF(c,x,y) [note: c must be a bool or numeric] Excel VBA: IIf(c, x, y) [note: c must be a bool or numeric] Java: c ? x : y [WARNING: c must be a bool] JavaScript: c ? x : y Kotlin: if (c) x else y [WARNING: unusual operators][WARNING: c must be a bool][note: can be used in expressions][note: parentheses *are* needed] PHP: c ? x : y [note: can't chain ternary operator, unless use parentheses, e.g. a ? b : (c ? d : e)] Python: x if c else y [WARNING: unusual operators][note: can be used in expressions] Swift: c ? x : y [WARNING: c must be a bool] UFL: short-ternary operator [x ?: y][equivalent to x ? x : y][e.g. (x != 0) ? x : y][e.g. (x != "") ? x : y] AutoHotkey: || [note: AHK v2 onwards] C++: [none] C#: [none] Excel: [none] Excel VBA: [none] Java: [none] JavaScript: || Kotlin: [none] PHP: ?: Python: or Swift: [none] UFL: null-coalescing operator [x ?? y][equivalent to (x != null) ? x : y] AutoHotkey: [none] C++: [none] C#: ?? Excel: [none] Excel VBA: [none] Java: [none] [can use: oOptional.orElse(vDefault)] JavaScript: ?? [note: nullish coalescing operator] Kotlin: ?: [WARNING: '?:' is a null-coalescing operator, not a short-ternary operator: e.g. '0 ?: 123' returns 0, since 0 is non-null] PHP: ?? Python: [none] Swift: ?? [note: nil-coalescing operator] UFL: statement separator (multiple statements on 1 line) AutoHotkey: , C++: ; [note: statements must end with ;] C#: ; [note: statements must end with ;] Excel: [none] Excel VBA: : [note: colon] Java: ; [note: statements must end with ;] JavaScript: ; Kotlin: ; PHP: ; [note: statements must end with ;] Python: ; Swift: ; UFL: string escape character AutoHotkey: ` [`a `b `f `n `r `s `t `v `` `' `" `;][note: AHK v1 used dual quoting for "] C++: \ [\a \b \f \n \r \t \v \' \" \\ \?][also (with further chars): \0 \N \u \U \x][also: \c] C#: \ [\a \b \f \n \r \t \v \' \" \\ \0][also (with further chars): \u \U \x][WARNING: \x can handle 1-4 hex digits, but it is safer to always use 4 (to avoid later chars being accidentally interpreted as part of the sequence)] Excel: [none] [note: uses dual quoting: e.g. "a""b"] Excel VBA: [none] [note: uses dual quoting: e.g. "a""b"] Java: \ [\b \f \n \r \t \' \" \\] JavaScript: \ [\b \f \n \r \t \v \' \" \\ \0][also (with further chars): \u \x][note: \ followed by line break gives a blank string] Kotlin: \ [\b \n \r \t \' \" \\ \$][also (with further chars): \u] PHP: \ [\e \f \n \r \t \v \' \" \\ \$][also (with further chars): \0 \1 \2 \3 \4 \5 \6 \7 \u \x] Python: \ [\b \f \n \r \t \' \" \\][also (with further chars): \o \x] Swift: \ [\n \r \t \0 \' \" \\][also (with further chars): \u] UFL: string interpolation AutoHotkey: [none] [can use: Format("Hello, {}!", name)] C++: [none] [can use: std::format("Hello, {}!", name)][requires: #include <format>] C#: $"Hello, {name}!" Excel: [none] Excel VBA: [none] Java: [none] [can use: String.format("Hello, %s!", name)] JavaScript: `Hello, ${name}!` Kotlin: "Hello, ${name}!" [also: "Hello, $name!"][WARNING: $ is a special character in string literals] PHP: "Hello, ${name}!" [also: "Hello, $name!"][WARNING: $ is a special character in string literals] Python: f"Hello, {name}!" [also: f'Hello, {name}!'] Swift: "Hello, \(name)!" UFL: power (exponent) AutoHotkey: ** C++: [none] C#: [none] Excel: ^ Excel VBA: ^ Java: [none] JavaScript: ** Kotlin: [none] PHP: ** Python: ** Swift: [none] UFL: comment AutoHotkey: ; C++: // C#: // Excel: [none] [can use: N("my comment") returns 0, T(N("my comment")) returns "", LET()] Excel VBA: ' Java: // JavaScript: // Kotlin: // PHP: // Python: # Swift: // UFL: concatenate AutoHotkey: . [also: string literal concatenation (and other types) (auto-concat) (e.g. '"abc" "def" 123' is equivalent to '"abcdef123"')] C++: + [WARNING: + for addition and concatenation][also: string literal concatenation (e.g. '"abc" "def"' is equivalent to '"abcdef"')] C#: + [WARNING: + for addition and concatenation] Excel: & Excel VBA: & [also: +][WARNING: + for addition and concatenation] Java: + [WARNING: + for addition and concatenation] JavaScript: + [WARNING: + for addition and concatenation] Kotlin: + [WARNING: + for addition and concatenation] PHP: . Python: + [WARNING: + for addition and concatenation][also: string literal concatenation (e.g. '"abc" "def"' is equivalent to '"abcdef"')] Swift: + [WARNING: + for addition and concatenation] UFL: string comparison (less than) AutoHotkey: [none] [can use: StrCompare()] C++: < [e.g. ((std::string)"abc" < (std::string)"def")][also (for char arrays): strcmp()] C#: [none] [can use: String.Compare()] Excel: < Excel VBA: < Java: [none] [can use: compareTo()] JavaScript: < Kotlin: < PHP: < Python: < Swift: < UFL: string comparison (equality) AutoHotkey: == [case insensitive: =] C++: == [e.g. ((std::string)"abc" == (std::string)"def")][also (for char arrays): strcmp()] C#: == Excel: = Excel VBA: = Java: == JavaScript: == Kotlin: == PHP: == Python: == Swift: == UFL: increment AutoHotkey: i++ ++i i+=1 C++: i++ ++i i+=1 C#: i++ ++i i+=1 Excel: [none] Excel VBA: [none] [can use: i = i + 1] Java: i++ ++i i+=1 JavaScript: i++ ++i i+=1 Kotlin: i++ ++i i+=1 PHP: $i++ ++$i $i+=1 Python: i+=1 Swift: i+=1

By Symbol

(symbol): / (applied to integers) [C-style integer division: divide then round towards zero (truncate)] AutoHotkey: true division C++: C-style integer division [WARNING: not true division] C#: C-style integer division [WARNING: not true division] Excel: true division Excel VBA: true division Java: C-style integer division [WARNING: not true division] JavaScript: true division Kotlin: C-style integer division [WARNING: not true division] PHP: true division Python: true division [note: Python 1/2: floor division] Swift: C-style integer division [WARNING: not true division] (symbol): / (applied to floats) AutoHotkey: true division C++: true division C#: true division Excel: true division Excel VBA: true division Java: true division JavaScript: true division Kotlin: true division PHP: true division Python: true division Swift: true division (symbol): // AutoHotkey: C-style integer division [note: in AHK v1: sometimes floor division] C++: comment C#: comment Excel: ___ Excel VBA: ___ Java: comment JavaScript: comment Kotlin: comment PHP: comment Python: floor division Swift: comment (symbol): % AutoHotkey: ___ [can use: the Mod function (C-style modulo)] C++: C-style modulo C#: C-style modulo Excel: ___ [can use: the MOD function (floor modulo)][WARNING: Excel/Excel VBA differ] Excel VBA: ___ [can use: the 'Mod' operator (C-style modulo)][WARNING: Excel/Excel VBA differ] Java: C-style modulo JavaScript: C-style modulo Kotlin: C-style modulo PHP: C-style modulo Python: floor modulo [WARNING: % as floor modulo is uncommon][WARNING: % is also the string formatting operator] Swift: C-style modulo (symbol): ' AutoHotkey: literal strings C++: characters C#: characters Excel: ___ Excel VBA: comments Java: characters JavaScript: literal strings Kotlin: characters PHP: literal strings [note: unlike double quotes, only \' and \\ are escaped] Python: literal strings Swift: ___ (symbol): || (whether it returns a bool or an operand) (i.e. whether it's equivalent to a short-ternary operator) [note: examples are equivalent to JavaScript's: a || b || c] AutoHotkey: 0 || 123 [returns: 123][note: AHK v1: returns 1 (i.e. True)] C++: 0 || 123 [returns: 1 (i.e. True)][can use: a?a : b?b : c] C#: 0!=0 || 123!=0 [returns: True][can use: (a!=0) ? a : (b!=0) ? b : c] Excel: OR(0,123) [returns: TRUE] Excel VBA: 0 Or 123 [returns: 123] Java: 0!=0 || 123!=0 [returns: true][can use: (a!=0) ? a : (b!=0) ? b : c] JavaScript: 0 || 123 [returns: 123] Kotlin: 0!=0 || 123!=0 [returns: true][WARNING: '?:' is a null-coalescing operator, not a short-ternary operator: e.g. '0 ?: 123' returns 0, since 0 is non-null][can use: if (a!=0) a else if (b!=0) b else c] PHP: 0 || 123 [returns: 1 (i.e. True)][note: '0 ?: 123' returns 123] Python: 0 or 123 [returns: 123] Swift: 0 != 0 || 123 != 0 [returns: true][note: '0 || 123' is invalid][can use: (a != 0) ? a : (b != 0) ? b : c] (symbol): = AutoHotkey: equals [note: *case-insensitive* when comparing strings] C++: assign C#: assign Excel: equals [note: *case-insensitive* when comparing strings] Excel VBA: assign [also: comparison (case-sensitive when comparing strings)] Java: assign JavaScript: assign Kotlin: assign PHP: assign Python: assign Swift: assign (symbol): == AutoHotkey: equals [note: case-sensitive when comparing strings] C++: equals C#: equals Excel: ___ Excel VBA: ___ Java: equals JavaScript: equals Kotlin: equals PHP: equal after type juggling Python: equals Swift: equals (symbol): === AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: strict equal [note: operands are equal and of the same type] Kotlin: referential equality [note: true iff point to same object] PHP: equal and of the same type Python: ___ Swift: ___ (symbol): != AutoHotkey: not equal [note: *case-insensitive* when comparing strings] C++: not equal C#: not equal Excel: ___ Excel VBA: ___ Java: not equal JavaScript: not equal Kotlin: not equal PHP: not equal after type juggling Python: not equal Swift: not equal (symbol): !== AutoHotkey: not equal [note: case-sensitive when comparing strings] C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: strict not equal [note: operands are of the same type but not equal, or are of different type] Kotlin: referential equality negated counterpart PHP: not equal or not of the same type Python: ___ Swift: ___ (symbol): <> AutoHotkey: ___ [deprecated: was available in AHK v1 (*case-insensitive* when comparing strings)] C++: ___ C#: ___ Excel: not equal [note: *case-insensitive* when comparing strings] Excel VBA: not equal [note: case-sensitive when comparing strings] Java: ___ JavaScript: ___ Kotlin: ___ PHP: not equal after type juggling Python: ___ [deprecated: was available in Python v2] Swift: ___

Operators Across Multiple Languages

role: common operators in many languages: + [add][sometimes concatenate] - [subtract] * [multiply][sometimes dereference (indirection), sometimes splat/spread][Python: WARNING: repeat string] / [divide] ** [power][note: not in C++][sometimes double splat] ~ & | ^ [bitwise: not/and/or/xor][^ is sometimes power][Visual Basic: & is concatenate][C++: & is also address-of] ! && || [logical: not/and/or][logical not (logical negation)] ? : [ternary operator] << >> >>> [bitshift: left/right (signed)/right (logical/unsigned/zero-fill)][C++: << and >> can mean output/input] == [equals] != <> [not equal (inequality)] < > [less than/greater than][sometimes used as angle brackets (e.g. HTML)][Python: comparison operators can be chained e.g. x < y < z] <= >= [less than or equal to/greater than or equal to] % [modulo (modulus)][note: in Excel, % is equivalent to '/100'] role: assignment operators: = [assign][can be used for function parameter default values] := [assign][walrus operator][can be used for function parameter default values] ++ [increment] -- [decrement] role: operators (augmented assignment versions): += -= *= /= **= &= |= ^= >>= <<= >>>= .= %= ??= //= ~/= \= role: operators further: ~/ [C-style integer division (e.g. Dart)][corkscrew operator (author's name proposal)] // [floor division (e.g. Python)][often a comment symbol] %% [floormod (floor modulo) (e.g. R)] role: operators further: <=> [comparison][spaceship operator][e.g. C++/Perl/PHP/Ruby] !== [not equal (type safe)] === [equals (type safe)] => [fat-arrow function][PHP: key-value pair definitions] -> [C++: member access (structure pointer operator)][Kotlin: lambda expression, declaring function types][PHP: property access] ?: [Elvis operator][note: checks true/false, sometimes non-null/null][note: sometimes || is equivalent] ?? [null coalescing operator][note: non-null/null] ... [spread/splat][note: Swift: also for closed ranges] .. [range][e.g. Haskell/Kotlin/Pascal/Perl/Ruby (inclusive end), e.g. C#/Rust (WARNING: exclusive end)] ..< [range][e.g. Kotlin: range until, Swift: half-open range] . [member access][AutoHotkey/Perl/PHP: concatenate] ~= [AutoHotkey: RegExMatch] =~ [Ruby: RegEx match] !~ [Ruby: RegEx not match] :: [C++: scope qualifier][AutoHotkey: hotkey/hotstring][Kotlin: reference] # [directives] role: comments: // [single-line comments] ; [single-line comments][e.g. AutoHotkey/FASM] # [single-line comments][e.g. Perl/PHP/Python/Ruby (PHP also uses //)] ' [single-line comments][e.g. Visual Basic] /* */ [multi-line comments (and single-line comments)][CSS comments] <!-- --> [HTML comments] :: [single-line comments][e.g. batch files] ''' [(3 apostrophes) bare string literals can be used as comments][e.g. Python] """ [bare string literals can be used as comments][e.g. Python] role: further symbols/operators: and [logical AND] or [logical OR] not [logical NOT] new [create object: create new instance of class] mod [modulo][Visual Basic has 'Mod' operator] in [is item in object] !in [is item not in object][e.g. Kotlin] , [separate statements] ; [separate statements] [ ] [get object value (aka subscript)] { } [scope][define object][noop][string interpolation] ( ) [group][note: '(mytype)' can be used for casting] @ [email addresses] _ [often used as a variable name, during loops, for a variable that needs a name but isn't used][numeric literal separator][Swift: unnamed parameter/label] : [object property assignment e.g. {"myprop": 123}] ?. [optional chaining operator] " " [literal string][string literal concatenation e.g. AutoHotkey/C/C++/Python/Ruby] ' ' [literal string][C++: char][string literal concatenation e.g. AutoHotkey/Python/Ruby] \ [string escape character][Visual Basic: integer division] ` [JavaScript: template literals][AutoHotkey: string escape character] $ [string interpolation (inside literal strings)] role: RegEx: \.*?+[{|()^$ [12 characters that need escaping in RegEx generally] ^-]\ [4 characters that need escaping in a RegEx character class] $()*+-.?[\]^{| [14 characters listed above (^ and \ appear twice)] !"#%&',/:;<=>@_`}~ [18 characters not listed above from the 'classic 32'] $ [sometimes needs escaping when doing a RegEx replace] [note: PHP: preg_quote escapes the 14, and also these 7: '!#:<=>}'] [note: Python: re.escape escapes the 14, and also these 4: '#&}~'] [note: C#: Regex.Escape escapes the 12, and also this 1: '#'] [note: Kotlin: Regex.escape uses '\Q...\E' to escape, and correctly handles literal '\E']

Operators and Symbols Listed in: The C Programming Language (1978)

Listed in Appendix A's Syntax Summary (pp. 214-219): unary: * & - ! ~ ++ -- binary: * / % + - >> << < > <= >= == != & ^ | && || ? : assignment: = += -= *= /= %= >>= <<= &= ^= |= also (scattered throughout Syntax Summary): ( ) , [ ] . -> ; { } : " " < > # (note: ':' in structs, '< >' with #include) not in Syntax Summary (but are in Appendix A): /* */ ' ' \ (note: '/* */' for comments, '' '' for characters, '\' for escape characters) (note: '//' was *not* available as a comment character until C99 (1999)) (note: when C++ was first released in 1985, it had both comment styles: '/* */' and '//')

The Universal Function Library Project: Details

a blueprint for ideal operators: + += [addition, *NOT* concatenation (safer to restrict '+' to numbers only)] - -= [subtraction] * *= [multiplication and spread operator (for function calls and definitions)] / /= [true division (i.e. int/int=float)] ~/ ~/= [C-style integer division (e.g. Dart)] ~~/ ~~/= [floor division (author's proposal), least worst option so far] ** **= [exponentiation] . .= [concatenation, and member access] ~ & | ^ &= |= ^= [bitwise: not/and/or/xor] ! && || [logical: not/and/or][where && and || return an operand, not necessarily a bool] << >> >>> >>= <<= >>>= [bitshift: left/right (signed)/right (unsigned)] % %= [C-style modulo] %% %%= [floor modulo (e.g. R)] ?? ??= [PERHAPS][null coalescing operator] ?. [PERHAPS][optional chaining operator] a blueprint for ideal operators (further): ? : [ternary operator]['c ? x : y', where c can be any value, not necessarily a bool] ?: [PERHAPS][would be equivalent to 'x ? x : y' and to 'x || y'] == [equals] != [not equal][PERHAPS: case-insensitive not equals (e.g. AutoHotkey)] <> [not equal][note: != and <> would both be present] < > <= >= [less than/greater than, less than or equal to/greater than or equal to] = [assign][PERHAPS: case-insensitive equals (e.g. AutoHotkey)] := [assign] ++ -- [increment/decrement] <=> [comparison (spaceship operator)] !== [PERHAPS] === [PERHAPS] => [fat-arrow function] .. [range (inclusive end)][PERHAPS] ..< [range (exclusive end)][PERHAPS] ~= [RegExMatch (e.g. AutoHotkey)][PERHAPS] non-operators: // [comments] /* */ [multi-line comments (and single-line comments)] ; [no role][PERHAPS: comments (e.g. AutoHotkey)] \ [escape character] ` [no role][PERHAPS: escape character (e.g. AutoHotkey)][PERHAPS: template literals (e.g. JavaScript)] :: [PERHAPS][hotkey/hotstring (e.g. AutoHotkey)] # [directives] , [separate statements] [ ] [get object value (aka subscript)] { } [scope, define object, noop] ( ) [group] _ [often used as a variable name][numeric literal separator] " " [literal string] ' ' [literal string (but its use discouraged, prefer " ")] : [object property assignment, and part of ternary operators] also: spare binary operators that can be defined by 2-parameter functions: op_a to op_z [possible future operators (author's proposal), least worst option so far]

Inventing Operators

possible operators for C-style integer division: i.e. the values (integers or floats) are divided as floats then truncated (towards 0) to the nearest integer: ~/ (and ~/=) (e.g. Dart) possible operators for floor division: i.e. the values (integers or floats) are divided as floats then floored (rounded down) to the nearest integer: // (and //=) is used by Python (but is often unavailable since it's used for comments) ~~/ (and ~~/=) (author's proposal) (the least worst option so far) _/ (and _/=) (author's proposal), but _ is often a variable name possible operators for true division: i.e. the values (integers or floats) are divided as floats, and a float is returned: / (i.e. ideally int/int would return a float, because it's more intuitive, but if int/int already returns an int, a new symbol is needed ...) /./ (author's proposal) (one of the least worst options so far) ../ (author's proposal) (one of the least worst options so far) (alternatively if int/int already returns an int, it could be prohibited, use ~/ if int/int is wanted) possible spare binary operators that can be defined by 2-parameter functions: i.e. if one programming language has an operator, and one doesn't, or if 2 languages use the same symbol, but the functionality differs, use a spare binary operator, and give it a function, and string replace the old operator with the spare operator, to preserve the code intact, instead of trying to refactor the code to use a custom binary function (which can create bugs): op_a to op_z (e.g. 'a % b' in language 1, 'a op_m b' in language 2)