So, folks who build web sites, I just added this conditional syntax to Kitten HTML template strings. Thoughts?
(See third code example. The is().yes().no().endIs() function chaining. My goal is to provide an alternative to the JavaScript ternary operator that’s easier to read. Does this succeed? Any suggestions?)
https://codeberg.org/kitten/app#how-many-kittens-are-too-many-kittens
@aral initial reaction:
i don't like the .endIf - feels really awkward.
yes & no feel wrong because it's not a yes/no question it's a true/false question. it's introducing new terminology that isn't clearer than old. if sticking with that, then what about
isTrue().yes().no()
or
test().trueResult().falseResult()
Also, if thinking about how to better it, I can't help but think about simplicity of the lisp/scheme version (test true-result false-result)
@aral @masukomi Ah apologies, I should have changed the if part. What i wanted to emphasize was the thenDo() and elseDo() part, to highlight that the latter two blocks are dependent on value inside the if. :) Either way I like the idea of improving on the confusing ternary operator in the first place, it's less than intuitive.
@masukomi Thanks, I don’t like it either but I’m not sure how else to model it as the chain needs a terminator to provide the final value.
This is what I have at the moment… any ideas?
https://codeberg.org/kitten/app/src/branch/main/src/Server.js#L244
@aral hhaheh. I'm sorry to report that my gut reaction was "...wha uh.. oh gods i hate javascript" ;)
BUT... overall looks fine
1. i think i want the option of `.is().yes()` (without `.no()`)
2. I feel like there "must" be a way to consolidate that code ...something something recursion? not sure.