-1

Ive started coding for Wordpress and the coding standards recommend using Yoda conditions.

if ( true == $the_force ) { $victorious = you_will( $be ); } 

But I also do some Android development, Javascript and have plans for robotics programming and some languages don't like Yoda style.

Im planning NOT to use Yoda conditions for WP for the sake of consistency, I dont know if its going to cause any problems.

7
  • How to mix different styles of programming on several languages? Commented May 7, 2015 at 19:29
  • Im sorry how is it relevant to my question? Im saying Im not going to use Yoda for WP development as recommended by WP and not sure if this is going to cause problems Commented May 7, 2015 at 19:33
  • 4
    Why would this cause problems? Code is code, conventions are just that: conventions. This question is simply polling for opinions. Commented May 7, 2015 at 19:36
  • In some cases there is really no definite right or wrong when it comes to programming practices, is there? Commented May 7, 2015 at 19:38
  • 2
    @ed-ta look at why yoda conditionals exist in php (because if($the_force = 42) is valid and likely a bug). Try writing that bug in Java: int theForce; if(theForce = 42) { ... } and see what you get. Then ask "why am I doing this in the first place?" Commented May 7, 2015 at 19:57

2 Answers 2

2

Coding standards are there to make it easy to visually parse the code. They are often different for each language, and rightly so.

If someone else is going to read this code, then keep to the Wordpress conventions when programming for Wordpress. If you are the only person who will read the code, then do what makes it easiest for you.

Personally, I wouldn't bother trying to keep the coding conventions for all of your projects consistent. I would keep the coding conventions for your projects in a particular language consistent.

The primary reason for this is that it will make it easier to get used to switching between coding standards, as it is almost certain that the various projects you will work on during your career will not use identical styles.

0

Unless you are an extremely error-prone programmer with no code reviewers or automated linters to back you up, this particular choice is unlikely to be anything other than a stylistic preference with potentially minor benefits, so go right ahead.

It's worth noting that coding styles shouldn't necessarily be similar across languages. The most important rules in a coding style are generally motivated by how the language actually works (eg, in Javascript use === not ==), so they won't apply to other languages. However, there are rules that can be sanely applied to multiple languages, and those are usually the "cosmetic" choices like indentation, brace style, or whether or not to use yoda conditions.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.