Skip to content

Conversation

@TheFox0x7
Copy link
Contributor

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 16, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin labels Mar 16, 2025
@silverwind
Copy link
Member

I think I was also suggesting this previously. Should also do the same-named template helper.

@github-actions github-actions bot added the modifies/templates This PR modifies the template files label Mar 16, 2025
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 16, 2025

If you google "Iif", it also matches a lot, and also easy to remember (inline-if)

TBH I don't like Ternary personally.

@TheFox0x7
Copy link
Contributor Author

It's your call - this isn't a high effort PR and it's usefulness subjective.

My primary issues with Iif vs Ternary is the first one is marked by spellchecking as not a word and looks like I pressed i twice on accident.
TBH I had no idea Iif isn't just a made up term but it's used somewhere else, so TIL. Thanks :)

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 17, 2025

Share the background about the naming decision:

  • We need some handy util functions to make Golang could take a true/false value easily.
  • Ternary means "an operator for three operands", not only for the "if" checking. It is a too general name.
  • There is a "if" family like util.IfZero
  • Gitea heavily uses SQL and IIF is a widely used SQL function name, and it also exists in some other languages. So it won't be too surprising for most developers.
  • Then candidate names:
    • iif: it doesn't work because Golang forces public functions should have a upper-case first-letter.
    • IIF: all upper-case doesn't read like "Golang" style
    • InlineIf: it seems wordy
    • If: it is not a real "if" and it evaluate the values before checking the expression.

Wiki: https://en.wikipedia.org/wiki/Ternary_conditional_operator (the real name is ternary conditional operator)

image

@TheFox0x7
Copy link
Contributor Author

Okay, fair enough, I see the logic.

@TheFox0x7 TheFox0x7 closed this Mar 17, 2025
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jun 15, 2025
@TheFox0x7 TheFox0x7 deleted the ternary branch October 31, 2025 22:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants