- 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
frist ? "frist" : "first"
Admin
At least the 2nd example was indented and formatted reasonably so it wasn't completely unreadable.
Remy: Actually, I did that part, because otherwise it was all on one line and impossible to see.
Admin
Tern? Ermahgerd!
Admin
I'm prepared to suggest that the first one used to return more than just a number, but also the text description, either "account" or "accounts" according to singular or plural -- then it got refactored to add the legend somewhere else. Just a bit of leftover cruft, easily overlooked, easily fixed. No biggie.
Admin
Without specifying the language, the first example could be perfectly cromulent*. Several languages use "==" to test "is-roughly-equivalent-to-if-you-cast-it-to-this-type" and "===" to test "is-exactly-this-type-and-value". Other languages provide the ability to override the == operator to provide the same functionality. So it could be saying "if accounts is equivalent to 1 when you cast it to an int, change accounts to be an int of value 1, otherwise keep it as it is".
Admin
PS: Why does the second one have a link to your github in the middle of the code :þ
Admin
Did a little self-promotion slip into the 2nd example? self.buttohttps://github.com/RemyPorter/MassnCog Looks like it should be self.buttonCog without the unrelated github link
Admin
Even though I'm a serial abuser of ternaries (much to the vexation of one of my friends), that second example causes me pain.
Admin
The worst one I ever ran across was blatant "dangling-else" avoidance.
Somebody didn't want to write braces around the inner
if
, so he came up with that monstrosity.Admin
@Remy: Did you mean the code sample to include “
https://github.com/RemyPorter/Mass
”? That looks like a bad paste…Admin
For your WTF viewing pleasure. Or wait, maybe, rather, against it. Also this way Remy appears to be advertising his toys :D
Admin
Aside from the weird URL stuck in there, Remy put the line-breaks in an odd place. I find it clearer to have:
Admin
Remy obviously has autocorrect set up in his word processor so he doesn't have to type out "github.com/RemyPorter/Mass"--he can use the shorter phrase "self.butto" instead. The real question is why the other instances of that string weren't also replaced.
Admin
To make the second one, the one without the link, simpler, of course.
Admin
This one should have unicorns. Aren't we doing unicorns any more?
Admin
Example 1 reminds me of one time I found "if A.equals(B) return A; else return B;" - A and B being Java Strings.
Admin
not frist
Admin
Fun fact: URLs can be inserted verbatim into C/C++/Objective-C code, without needing a comment or string literal (limit 1 per function), and the code still compiles. The colon creates a label, and everything after the // becomes a comment.
Admin
This is truly a gem in my day. I rather like trivia and, frankly, though this was staring me in the face, I never thought that URLs could be embedded in this fashion. Of course, one may only paste such a URL once per function, but still ...
Admin
The unicorns seem to show up late to the article some days. Bummer, cause I like to play Unicorn golf: Count the number of clicks it takes me to find the unicorns. After 8, I go to the source.
Admin
Damn, I'll have to use that one someday.
Admin
Maybe Remy wrote it himself?
Admin
isn't too bad if formatted properly
Admin
So I've seen the practice of using nested ternaries to code a case-statement like expression in languages that don't support those. It actually is fairly readable if formatted correctly:
Admin
@Some Guesty - it's not too bad to read. It's still terrible.
Admin
My standard CSS for every article exposes the unicorns for me:
Admin
My standard CSS for every article exposes the unicorns for me:
Admin
It's still bad. The effect is: "Create a mutable arrat that contains the negSpacer if it exists, followed by self.ButtonCog if it exists". It would be so trivial to make the code follow that description that I would only bore people by writing it out.
Admin
(so boring, in fact, that I didn't notice Remy had done it already. oh well)
Admin
buttonItems = [negSpacer, self.buttonCog].filter(x => x)
Admin
Can't hundred percent kick the coder on this one without knowing what was going on. I agree with others this likely started out as a sensible little if statement and got bloated out by new requirements. I've ended up with things like that where the department has a fanatical obsession to the merest whiff of refactoring existing code, and refactoring (in some PHB eyes) includes adding white space and indentation to make stuff readable. Rearranging if statements so they make more sense (or converting them to a switch or vice versa) requires the filling out of a dozen forms, a goat to be slaughtered over them, and a sign off from God.
Admin
Actually it looks to me like it assigns an empty mutable array, then drops that to construct a new mutable array from the contents of one of its immutable arrays. In other words, the first initialization was completely unnecessary.