mastodon.ar.al is one of the many independent Mastodon servers you can use to participate in the fediverse.
This is my personal fediverse server.

Administered by:

Server stats:

1
active users

Aral Balkan

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

Codeberg.orgappA web development kit that’s small, purrs, and loves you.

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

@masukomi @aral 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 :)

@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 :)

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

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

codeberg.org/kitten/app/src/br

Codeberg.orgappA web development kit that’s small, purrs, and loves you.

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