Yoda logic

Not that confusing, it is. 

Back end web programming is all about logic. You create a bunch of conditions in which you want your code to run and then you run it. For instance, you would say “If this post has the category ‘featured’ checked off, display it. If not, do not display it.”. That is one of the most common pieces of logic you will encounter in all types of computer programming.

So what in the world is Yoda Logic?

It pretty much is what it sounds like it might be. It’s basically the method for building your logic that, when said aloud, sounds like yoda. Check out this example:

The first part of your statement is the constant, which is the term  “true” and the second part of your statement is the variable, which is the force. Truth always exists but the force may or may not, in this example. (deep stuff!)  It’s called Yoda Logic because our normal language would have you say “if the force is true, you will be victorious” but that’s not the order in which it’s actually written in the code. If you actually read the code aloud it sounds like “If true is the force, victorious you will be”. Sounds like yoda, right?! BAM! Lesson learned.

Mostly.

A little more info on conditional logic. (for the over achiever)

Notice how we used ‘==’ instead of just ‘=’? We do this because there are really two types of ways you can equate things to each other. You can tell the code “This equals that” in the same way you would assign a variable to some content. Like this:  $the_force = 'a power inside of you' . This code allows you to use the variable $the_force anywhere you might want to say “the power inside of you”. This works because it’s a shorter and more concise way of saying it. Basically, you just assigned a variable using ‘=’.

So when is the ‘==’ sign used? It’s used when you’re comparing two things. You’re checking to see if they’re equal, you’re not proclaiming them to be equal. You use the ‘==’ inside of if statements such as the one listed above.

Yoda logic is basically meant to save you from your own mistakes.

 

Checkout what WordPress has to say on Yoda Conditions 

 

The_Idiot

About Lindsay

Self made millionaire.. Oops I mean web developer.. who started out learning how to build websites with tables and dreamweaver, I now almost entirely focus on CMS-based development, usually WordPress. I love coding and designing and regularly switch between my left and right brains.

One thought on “Yoda logic

  1. webdesignforidiots.net has potential, you can make your blog go viral easily
    using one tricky method. Just type in google:
    Kimting’s Method To Go Viral

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">