Blogging about programming

Jan 15, 2025

Tip #3: Avoid nested ternary operators (?:)

Nested ternary operators in a single line are difficult to read and understand. Instead, refactor them into a separate function or split them across multiple lines with clear grouping. Avoid <View style={{ alignItems: closeToRight ? 'flex-end' : closeToLeft ? 'flex-start' : 'center' }} /> Do function alignItemsByAdjustment (left, right) { if (right) { return 'flex-end' } else if (left) { return 'flex-start' } else { return 'center' } } <View style={{ alignIt...

Jan 14, 2025

Tip #2: Avoid let statements

Do not use let when only used for delayed initialization. Using let is a hint to developers, that variable will change over time so should be avoided if possible by restructuring initialization. Avoid let closeToLeft = false let closeToRight = false if (maxDepthPixelValue < 60) closeToLeft = true if (maxDepthPixelValue > Utils.width - 60) closeToRight = true Do const closeToLeft = (maxDepthPixelValue < 60) const closeToRight = (maxDepthPixelValue > Utils.width - 60)