Results for “read only”
Small, practical examples. Search by task or narrow things down below.
Use a fixed-size container with bounds checking
C++: std::array retains its element count and supports checked access through at.
C++✓ Tested
Use a hash map for direct key lookup
C++: unordered_map provides key lookup without promising iteration order.
C++✓ Tested
Use a last-in first-out stack
C#: Stack is useful for reversible traversal and other nested operations.
C#✓ Tested
Use a last-in first-out stack
C++: Read top before pop because pop does not return the removed value.
C++✓ Tested
Use a nonnegative remainder for cyclic indexing
Use a nonnegative remainder for cyclic indexing in a complete Rust program using the standard library.
Rust✓ Tested
Use a switch expression to classify a value
C#: Relational patterns express a small ordered range classification.
C#✓ Tested
Use an associated constructor
Use an associated constructor in a complete Rust program using the standard library.
Rust✓ Tested
Use an optional fallback
Use Optional.orElse to provide a default for a missing Java value.
Java✓ Tested
Use case-insensitive dictionary keys
C#: Choose an ordinal comparer when case-insensitive keys represent identifiers.
C#✓ Tested
Use if to produce a value
Use if to produce a value in a complete Rust program using the standard library.
Rust✓ Tested
Use named states for a controller
Arduino / C: An enum makes state transitions easier to read than unexplained numbers.
Arduino / C✓ Tested
Validate a complete identifier
C++: regex_match requires the pattern to match the complete input sequence.
C++✓ Tested