Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Greppability is really a proxy metric here - these changes all have other benefits even if you never grep (mostly readability tbh).

    const getTableName = (addressType: 'shipping' | 'billing') => {
        return `${addressType}_addresses`
    }
This is a simplified example but in a longer function, readability of the `return` lines would be improved as the reader wouldn't have to reference the union type (which may or may not be defined in the signature). The rewrite is also safer as it errors out if a runtime `addressType` value doesn't match the union type (above code would not throw an error, just return an indeterminate value which would cause undefined behaviour).

"Flat is better than nested" also greatly improves readability in both examples: either reading the i18n line, or reading the classname at definition / call will be more readable when the name contains full context of function.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: