<!-- Markdown version of https://ocxly.com/hidden-features-programming-languages.html · auto-generated, may lag the live page -->

# Hidden Features andLesser-Known Tricks in Popular Languages

The gap between a developer who knows a language's basics and one who knows it deeply is often not about algorithms or data structures — it is about the features built into the language that eliminate entire categories of boilerplate, express intent more precisely, or solve common problems in ways that beginners reach for a dozen lines to accomplish. These features are documented; they are just rarely taught in introductory materials.

## Python

### The walrus operator (:=)

Introduced in Python 3.8 (PEP 572), the walrus operator assigns a value to a variable as part of an expression — allowing assignment and use in the same statement. Its most useful application is avoiding repeated function calls in conditions:[[1]](#ref-1)

```
# Without walrus: calls len() twice
if len(data) > 10:
    print(f"Long list: {len(data)} items")

# With walrus: calls len() once
if (n := len(data)) > 10:
    print(f"Long list: {n} items")
```

Particularly useful in `while` loops that read chunks from a stream:

```
while chunk := file.read(8192):
    process(chunk)
```

### Dictionary merge operators (| and |=)

Since Python 3.9, dictionaries support merge (`|`) and update-in-place (`|=`) operators — cleaner than `{**a, **b}` unpacking:

```
defaults = {"timeout": 30, "retries": 3}
overrides = {"retries": 5, "verbose": True}
config = defaults | overrides
# {"timeout": 30, "retries": 5, "verbose": True}
```

### functools.cache — one-line memoisation

`@functools.cache` (Python 3.9+) memoises a function's return values automatically, caching results keyed on arguments. For recursive functions that recompute the same values repeatedly (Fibonacci, dynamic programming), it converts exponential time complexity to linear with a single decorator:

```
from functools import cache

@cache
def fib(n):
    return n if n < 2 else fib(n-1) + fib(n-2)
```

### Structural pattern matching (match/case)

Python 3.10 added structural pattern matching — significantly more powerful than a switch statement. It matches on value, type, structure, and destructures simultaneously:

```
match command:
    case {"action": "move", "direction": d}:
        move(d)
    case {"action": "attack", "weapon": w}:
        attack(w)
    case _:
        raise ValueError(f"Unknown: {command}")
```

## JavaScript

### The Proxy object

JavaScript's `Proxy` wraps an object and intercepts fundamental operations — property access, assignment, function calls — enabling reactive programming patterns, validation, and logging without modifying the target object:[[2]](#ref-2)

```
const handler = {
  set(target, key, value) {
    if (typeof value !== 'number') throw new TypeError('Numbers only');
    target[key] = value;
    return true;
  }
};
const stats = new Proxy({}, handler);
stats.score = 42;    // OK
stats.name = "Ali";  // Throws TypeError
```

### Nullish coalescing and optional chaining

The `??` operator (nullish coalescing) returns the right side only when the left is `null` or `undefined` — unlike `||` which also triggers on `0`, `""`, and `false`. Combined with optional chaining (`?.`), it allows deeply nested property access without defensive null checks:

```
const city = user?.address?.city ?? "Unknown";
// Safely reads nested props; returns "Unknown" only if null/undefined
```

### Labeled statements for breaking nested loops

JavaScript allows labeling loops, enabling `break` or `continue` to target an outer loop — a feature almost never taught but genuinely useful:

```
outer: for (const row of matrix) {
  for (const cell of row) {
    if (cell === target) break outer; // exits both loops
  }
}
```

## Java

### Sealed classes (Java 17+)

Sealed classes restrict which classes can extend them, enabling exhaustive pattern matching. Combined with records and pattern matching in switch expressions, they enable algebraic data types similar to Rust's enums or Haskell's sum types:[[3]](#ref-3)

```
sealed interface Shape permits Circle, Rectangle, Triangle {}
record Circle(double radius) implements Shape {}
record Rectangle(double w, double h) implements Shape {}

double area(Shape s) {
  return switch (s) {
    case Circle c    -> Math.PI * c.radius() * c.radius();
    case Rectangle r -> r.w() * r.h();
    case Triangle t  -> /* ... */;
  };  // compiler enforces all cases are covered
}
```

### Virtual threads (Java 21)

Project Loom's virtual threads, released in Java 21, allow millions of concurrent threads without the overhead of OS threads. Code written in blocking style (no callbacks, no reactive frameworks) runs at async-level concurrency. Existing blocking I/O code benefits automatically when run on virtual threads.

## C#

### LINQ deferred execution and lazy evaluation

LINQ queries in C# are lazily evaluated — the query is not executed until it is iterated. This allows building complex query pipelines that execute only once, against only the elements needed:[[4]](#ref-4)

```
var expensive = data
    .Where(x => x.IsActive)
    .OrderBy(x => x.Name)
    .Take(10);
// Nothing executed yet — query is a description, not a result
foreach (var item in expensive) { /* executes here */ }
```

### Pattern matching with is and switch expressions

C# 8+ pattern matching allows concise type-testing and destructuring in conditions and switch expressions, eliminating verbose `as`/`null` check patterns:

```
string Describe(object obj) => obj switch {
    int n when n < 0  => "negative integer",
    int n             => $"positive integer {n}",
    string s          => $"string of length {s.Length}",
    null              => "null",
    _                 => "something else"
};
```

> "A language that doesn't affect the way you think about programming is not worth knowing. The hidden features are where the thinking happens." — Alan J. Perlis, *Epigrams on Programming*, ACM SIGPLAN Notices, 1982

## References

1. van Rossum, G., et al. (2018). *PEP 572 — Assignment Expressions*. Python Software Foundation. [peps.python.org](https://peps.python.org/pep-0572/) [↩](#cite-1)
2. MDN Web Docs. (2024). *Proxy — JavaScript*. Mozilla. [developer.mozilla.org](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) [↩](#cite-2)
3. Oracle. (2023). *JEP 409: Sealed Classes*. OpenJDK. [openjdk.org](https://openjdk.org/jeps/409) [↩](#cite-3)
4. Microsoft. (2024). *Language Integrated Query (LINQ)*. Microsoft Docs. [learn.microsoft.com](https://learn.microsoft.com/en-us/dotnet/csharp/linq/) [↩](#cite-4)

---
*Source: [ocxly.com/hidden-features-programming-languages.html](https://ocxly.com/hidden-features-programming-languages.html) — OCXLY, free 100% client-side privacy-first tools. Underutilised features in Python, JavaScript, Java, and C# that experienced developers rely on — from walrus operators and Proxy objects to sealed classes and LINQ magic.*
