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?)
codeberg.org/kitten/app#how-ma…
#interfaces #code #design
masukomi
in reply to Aral Balkan • • •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 Balkan
in reply to masukomi • • •@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?
codeberg.org/kitten/app/src/br…
app
Codeberg.orgmasukomi
in reply to Aral Balkan • • •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.
Vancha
in reply to masukomi • • •Not definitive, but I think a step in the right direction at least :)
Aral Balkan
in reply to Vancha • • •Aral Balkan
in reply to Aral Balkan • • •@vancha @masukomi Mind you, what would work is to have a global namespace (object), e.g., kitten, and have the functions defined there.
So: kitten.if().then().else().endIf()
But I’m not sure if that’s better than is().yes().no().endIs() when reading it.
Vancha
in reply to Aral Balkan • • •