Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Rust
- - `cargo update` will update to newer patch levels but not minor or major versions
- - Statically determined constants that can't be set to a function return value
- - `let mut` defines a mutable variable
- - Shadowing with `let` keyword (useful for initial transformations to a later immutable, only way to change type)
- - Integer overflow causes panic in debug mode only
- - i32 default numerical type
- - Optional underscores in numeric literals, e.g. `100_000` == `100000`
- - Number literals allow a type suffix (except byte)
- - 0x (hex)
- - 0o (octal)
- - 0b (binary)
- - b'A' (byte, u8 only)
- - Scalar types
- - Integer: i/u 8, 16, 32, 64, 128, size (32 or 64 depending on CPU architecture)
- - Floating-point: f32, f64 (default)
- - bool
- - char, a four-byte Unicode Scalar Value!
- - Compound types
- - Tuple
- - Optional types declaration
- - Destructing
- - Element access with dot operator and index
- - Supports assignment
- - Array
- - let a: [i32; 5] = [1, 2, 3, 4, 5]
- - let a = [3; 5] sets all 5 elements to 3
- - Enforced bounds checks at runtime (no conpilation errors)
- - Define functions with `fn`
- - Statements do NOT return values
- - Blocks can have implicit return values if they end with an expression (no semicolon)
- - `if` is itself an expression
- - No parenthesis
- - Conditions must be strictly bool
- - Possible return types must all match
- - String::from("string literal
- - println! requires string literals
- - Ownership
- - Compile time memory management
- - Every value has exactly one owner variable and is dropped when the owner goes out of scope
- - Assignment doesn't deep copy, it moves (shallow copy followed by reference invalidation)
- - Inexpensive because shallow copy
- - Reference invalidation prevents double free
- - Stack-only types have the `Copy` trait and don't undergo reference invalidation
- C++:
- - Macros (name ends with !)
- - Static methods (called associated functions)
- - Static type system with type inference
- - stdlib vector
- - Inline/block comment syntax
- - `drop` is similar to RAII
- FP:
- - Variables immutable by default (safety and concurrency benefit)
- - `let` for variable assignment
- - Functions are expressions (as long as there's no ending semicolon)
- Lisp
- - void represented by empty tuple
- npm
- - cargo
- - `cargo update` updates `Cargo.lock` based on `Cargo.toml` (like `package.json` and `package-lock.json`)
- - Semantic versioning
- PHP
- - Functions can be called before definition
- Python
- - Destructuring tuples
- - Tuples with non-homogenous type
- - Snake case for functions and variables
- - Return type decvlared with ->
- - Ternary using if/else syntax as an expression
- - For loop as a for-in that is optimized for traversing an iterable
- R
- - Match keyword runs different code blocks based on the return value of a function
- - Optional implicit returns
- Sprak
- - Infinite loop with `loop` keyword
- TypeScript:
- - Type hinting with colon after symbol name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement