22 comments

[ 2.9 ms ] story [ 60.1 ms ] thread
I ran into a Yoda Expression when coding a step condition check in JCL: http://publib.boulder.ibm.com/infocenter/zos/v1r11/index.jsp...

It was infuriating because the logic is not forward thinking - if you want to check if a return code is an error (RC > 4) then your check has to be 4 < RC. The worse part was, the COND function was to test if the step was being skipped, so if you wanted to invert the logic to execute the step if the previous steps had no errors, it became 4 >= RC.

Edit: And because it is more of a "function" call, you can't modify the order. You MUST use it that way.

Yeah, they can be tricky to read sometime. The only reason I've ever heard for writing code like that is to prevent accidental assigning in an if block. For instance if(ptr = 0) compiles fine in C and is almost certainly not what you want, but if(0 = ptr) is a compile error.
Sadly, I've seen them in other languages that don't have the same problem, because people have picked up the habit without really understanding why and where it should be used.
Unfortunately they are becoming more and more prevalent in the PHP community. For example, here they are in the Symfony project's coding standards: http://symfony.com/doc/current/contributing/code/standards.h...

The rationale is that they make it a compiler error if you accidentally perform an assignment operation ("xyz" = $name) instead of a comparison ("xyz" === $name). The thing is, this is only a significant risk if you adopt the bad habit of performing assignment operations within conditional statements, like this:

    if (null !== ($charset = $env->getCharset())) {
The above style has been popularised in PHP by the Symfony project. I think it's hideous, and that the idea of adopting one ugly style choice (Yoda Expressions) to mitigate the risk introduced by another ugly style choice (assignment in conditional operations) is reminiscent of the children's song about the old lady who swallowed a fly.
I used to advocate for Yoda in PHP for the same reason that it's useful in C:

   if ($var = 1) ...
will always evaluate true.

But since you should be using === in this context, there's really no excuse for using a single...

    if ($var === 1) ...
Also, can PHP devs please do me the favor of splitting

    if (null !== ($charset = $env->getCharset())) {
into two lines:

    $charset = $env->getCharset();
    if ($charset !== null) {
    ...
Isn't that prettier? The line that the first one saves doesn't really make anyone's life easier...
Huh? You might still mistype/forget an =, even if you never intend to perform assignment in a conditional. You never have to do it on purpose to do it by mistake, in other words.
That was indeed the rationale when they first appeared.
i see it making sense for equality tests ( != , == ), but not for comparisons...
They are counter-intuitive and make code unnecessarily harder to read and reason about. It doesn't make sense to first be presented with a predicate and then have to figure out the subject.
This was extensively discussed on HN when it first appeared in 2012:

https://news.ycombinator.com/item?id=4273034

I was just thinking that everything from Coding Horror has to have appeared here at least once.
I find it fascinating that so many of the responses in that thread were along the lines of "Not allowing the community to do what it likes is destroying the community of StackOverflow."

I say fascinating because it's a perspective I genuinely would not have suspected be prevalent. I've always felt that SA was a place to ask technical questions, and that there never really was meant to be a "community" or discussion, only a service.

It's a bit like SA wanted to address one thing (ask technical questions, get technical answers), meanwhile ton of people discovered that SA's format was more useful for some discussions than a forum, and now the community wants something that was never the goal.

I'm curious if there's something like SA, but dedicated to the discussion that SA avoids.

I see it as more a bunch of aspies fighting over technicalities. Unfortunately, the aspies in charge in this case and squashed a valuable use case. There are countless questions where the number of answers is unlimited. StackOverflow tends to be very useless for me since the questions they allow I can lookup quicker in the docs and the questions they don't are the ones that are super useful for me.

A typical allowed question is how to read the gyro on Android. Well that's well documented and useless to talk about further anyway. A typical question not allowed is the best way to make money in your app. This is very valuable to me since I've tried dozens of different ad networks. It took me a long time to figure out Google and AdMob pay terribly vs. all the others, etc.. Hell, even the question they cite as being frat house and not college is really useful to me since I could pickup new jargon, something not straight out of the docs.

Anyway, the site they made for this is here: programmers.stackexchange.com

Although I still think it is a stupid distinction not to just allow it on the main site. The best content they have for experienced programmers who have passed the point where the main site is useful is shoved off into some ghetto. It is kind of like how you see lots of dead people on Hacker News who actually post interesting and useful stuff. HN bans people who are not outright spammers and trolls just for disagreeing, and it hurts the site.

> I'm curious if there's something like SA, but dedicated to the discussion that SA avoids.

It's called HN.

I'm curious if there's something like SA, but dedicated to the discussion that SA avoids.

Assuming SA means Stack Overflow, some of the other Stack Exchange sites are probably better venues for some kinds of question. For example, programmers.stackexchange.com is for more conceptual questions. It's still explicitly not intended to be a discussion forum, though, if that's what you're looking for.

Apart from being based on a piece of programming terminology, the twelfth item in the list seems not to be about programming at all, but rather a flagrant plug for a book.

How is this the first time I have noticed that?

"7. Stringly Typed ..."

Hey, JavaScript developers have feelings too, you know!

Ah, thought it was going to be about "reposotories" (aka Fox News git jargon)
try { } catch (Exception ex) { // Gotcha! }

I see this a lot in Java code. However, this does not catch all exceptional conditions, specifically not Errors. If you want to do catch everything, then catch Throwable, rather than Exception.

However, this does not catch all exceptional conditions

You say that as if it is a bad thing. If you are catching Throwables, and hence Errors, you are likely doing something very wrong.

My favorites: 9. Doctype Decoration , 16. Fear Driven Development - very common these days , 20. Ninja Comments - classic!, 22. Protoduction - Hilarious! , 27. Mad Girlfriend Bug