- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
My least-worst guess is that it was originally just the header with the conditional button, and then someone said, "That empty header without the button looks pretty stupid. You should hide it," so the programmer wrapped the header in the same condition, on the "smallest change possible" theory.
Admin
It did add breakage to the syntax highlighting, so that's something.
Admin
My guess is that at some point someone was copy pasting things and did not bother to think too much.
Admin
This isn't necessarily wrong - the real question is what is the backend doing? If you've got proper security in your API, then the client-side conditions are merely to avoid rendering empty sections and non-functional controls. Considering what site we're on, though, I'd wager that's not the case here.
Admin
Oops, disregard that previous comment. My brain apparently filtered out that second conditional - I read it as a "dumb client-side security" post, not a "dumb unnecessary code" post.
Admin
Haven't coded with it, but it seems odd (read, "mangling") to mix boolean operators with rendering blocks.
Admin
Those admin rights can be revoked fast, so better check regularily if they're still there.
Admin
In my experience, things like admin panels are extremely volatile. Project Management will often ask for multiple changes within the same sprint to tweak or adjust how things are rendered or for whom - usually with contradictory requirements. You can quickly get into a place several sprints in where nobody is really sure who's supposed to have access to which toggles under what conditions. :/
Admin
I'd actually put my money on the
isAdmin || canSeeResultscheck originally being two separate sections to render "admin results" and "non-admin results" that were later combined and the dev didn't think to check what is likely several hundred lines above for how to simplify the checks. And who knows, PM will likely change their mind tomorrow anyway.Admin
It seems fairly common and idiomatic (in my limited experience).
Admin
My guess would be that there used to be more controls. The heading would be displayed if any of the controls were available - something like "(isAdmin || canSeeResults || canSeeSummary || canSeeDetails). Then each control would have (isAdmin || canSeeSummary) etc. So different users would see different combinations of controls, but the heading would always appear, unless the user could see none of the controls. Then all but one of the controls was deleted, making the conditions identical and the inner check redundant.