3 ms·
Love Carmack, but hard disagree on this and a lot of similar functional programming dogma. I find this type of thing very helpful: classList = ['highlighte
by QuadrupleA 1y ago
Love Carmack, but hard disagree on this and a lot of similar functional programming dogma. I find this type of thing very helpful:
classList = ['highlighted', 'primary']
if discount:
classList.append('on-sale')
classList = ' '.join(classList)
And not having to think about e.g. `const` vs `let` frees up needless cognitive load, which is why I think python (rightly) chose to not make it an option.
- ColeShepherd 1y agoSome potential alternatives to consider: 1. classList = ['highlighted', 'primary'] .concatif(discount, 'on-sale') .join(' ') 2. classList = ' '.join(['highlighted', 'primary'] + (['on-sale'] if discount else [])) 3. mut classList = ['highlighted', 'primary'] if discount: classList.append('on-sale') classList = ' '.join(classList) freeze classList 4. def get_class_list(discount): mut classList = ['highlighted', 'primary'] if discount: classList.append('on-sale') classList = ' '.join(classList) return classList classList = get_class_list(discount)
- rudy6912 1y agoFennel (Lisp): (table.concat [:highlighted :primary (if discount :on-sale)] " ")
- deleted 1y ago[deleted]