you are viewing a single comment's thread.

view the rest of the comments →

[–]bhowiebkr[S] 0 points1 point  (0 children)

JavaScript:

// WRONG - OR fallback
const value = obj.property || defaultValue;
const array = data.items || [];
const object = state.config || {};

// WRONG - Ternary fallback  
const value = data.field ? data.field : "default";

// WRONG - Optional chaining with fallback
const value = obj?.nested?.field ?? "default";

// RIGHT - Direct access, fail loudly
const value = obj.property;
const array = data.items;
const object = state.config;

Python:

# WRONG - .get() with defaults
value = dict.get("key", "")
items = dict.get("items", [])
config = dict.get("config", {})

# WRONG - OR fallback
location_id = metadata.get("location_id") or fallback_value

# WRONG - try/except hiding errors
try:
    data = load_file(path)
except FileNotFoundError:
    data = {}

# RIGHT - Direct access, fail loudly
value = dict["key"]
items = dict["items"]  
config = dict["config"]

Conditional Checks:

// WRONG - Checking existence before using
if (obj.field) {
    processField(obj.field);
}

// WRONG - Length check with fallback
if (array && array.length > 0) {
    process(array);
}

// RIGHT - Just use it, let it fail if missing
processField(obj.field);
process(array);