Skip to main content


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

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)

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…

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.

in reply to masukomi

@masukomi in the same line, I would also suggest the following alternative: if().thenDo().elseDo()
Not definitive, but I think a step in the right direction at least :)
in reply to Vancha

@vancha @masukomi I wish I could use if but it’s sadly a reserved word in JavaScript. Otherwise that would have been my first choice too :)
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.

in reply to Aral Balkan

@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.