- 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
It also doesn't quite do exactly the same thing, so if you really needed array_key_exists(), you better not try to subsititute isset() for it.
Filed Under: not that we've been burned by that shit where I work.... that's totally not why I know this.
Admin
isset returns false in all cases that array_key_exists returns false, so you could just do
if isset || array_key_exists
to get the performance without making your code easy to read or changing its meaning.Admin
Except in the one circumstance that I recall, that specifically wasn't what we wanted. We needed the true case, which only array_key_exists would tell us. (or the other way around.... I'm not going to try to go look it up, it wasn't even my project, I just got asked the question by someone else saying "wtf is going on?")
edit - though that is interesting to think about - i'll have to keep in mind the next time I'm in PHP. Thankfully we're moving towards all .NET (C#)
Admin
Hm. Further thinking makes me wonder, if it's 10x better to do isset() than array_key_exists(), then perhaps I should have my colleague use your logic every time, in the cases where the isset() is expected to take precedence at least 10%+ of the time.
I always used isset() anyways, because I didn't allow the 1 case that array_key_exists() works instead to even happen.
Admin
In Go, isset and array_key_exists are equivalent in speed, and 57.6ns is probably about the time it takes to execute a comment in PHP.
Admin
Admin
You could be happy if you use Python or RoR. Personally I am making preference of python, but I have heard that RoR is equally good if not better.
Admin
Which framework are you using? I like Ruby, the language, better. But Python is a fine language. Ruby on Rails is definitely full of good features. Django is pretty good too.
Admin
I am working in ASP .NET with C#. Some good day I am using MVC. Right now my assignment is related to Salesforce.com I have ot create some stuff in Salesforce.com I am learning to insert jquery in my Visual Force page.
Almost missed java servlets. That is where the reporting application is.
Admin
Why do I get the feeling that the project at my last company is being outsourced to you?
Admin
Because you work with extremely common tools in a well understood domain and are therefore a fungible commodity.
Admin
Yeah, but some of the specifics to SFDC have hit home (not just limited to the above comment).
Admin
Scary scary scary. PM me with your real life name and client name.
Admin
There should be only one San Diego company that would outsource its SFDC work.
Admin
"The only practical application of ternary operator is to either intentionally obfuscate your code or use it as a soapbox to brag about how "l33t" you are."
This could be said of pretty much any element of any programming language, if you don't ever use that element. While I agree that this particular instance is hard to read, it doesn't invalidate the code itself. Besides, I fail to see how this is any better:
Admin
There are several places that need ternaries where a plain old if won't do; constexpr functions and member initialisers come to mind. One of the most esoteric uses I heard of though was in macro programming where you wrote
f(true ? any_type() : ARG)
which resulted in templatingf
over the type ofARG
without actually evaluatingARG
. (Nowadays you probably just writef<decltype(ARG)>()
instead.)If I really wanted to use ternary operators, rather than the neat array that @Zecc used, I would write it something like this:
Admin
Um,
?
is right associative.Admin
Works for me in both JS and C (after replacing the quotes).
Admin
Yes, it would "work". But it's utterly unreadable. It effectively treats the operator as left associative. In that case, you might as well collapse it to:
and use some sensible data structures.
Admin
http://what.thedailywtf.com/badges/128/someone-didn-t-get-the-joke
Admin
Oh, alright then...
Admin
Who among us has not deserved this at some time?
Admin
Given the likes of @Nagesh and @SpectateSwamp on this forum, perhaps we all do.
Me, I'm still waiting for mine.
Admin
I'm waiting for feedback from upstream.
Admin
Damn you... I never got one, I assume because it was too easy for @PJH to fix the CSS, making it a weak Dicsourse configuration flaw.
Admin
Speaking of Discourse...
https://meta.discourse.org/t/invisible-topic-is-not-invisible/17603
Find one bug, get one free!
Admin
I do get distracted occasionally...
Admin
Admin
My proudest TDWTF moment.
Admin
Which is easier to read?:
Versus a "tabular ternary" (note the comments):
Just another example of how people can't write legible or maintainable code.
Admin
Don't get started on British PHP:
Admin
Just realized I bufu'd the "Dear Dr" regex on the rewrite to the tabular version:
Should be:the
(.*)
under/s
grabs newlines where the([^\n]*)
grabs anything but newlines...Moral : Definitely require code reviews after refactoring!
Admin
How many strokes is that in golf exactly?
Admin
Weeell... removing extraneous (auto-format-able type) white space: 262→215 = -47 :)
Admin
Filed under: broken quote
Admin
Ding Ding Ding! We have a winner on the "Easter Egg" hunt :)
Admin
Yes, I was assuming a sane language. I suppose in PHP I would have had to wrap everything in parentheses making it as ugly as the original article.