When doing a conditional expression, it’s a smelly code pattern to then return true or false. Why? The conditional expression already returns a true or false state. Therefore, you do not need to be so verbose and hardcode a boolean return. Here is the smelly code pattern: Refactor this code down to one line to make it more readable. It’s less code too (skinny). Strive to reduce your code and make it more simple. If you see this pattern in your code, then refactor it. Remember, you want your code to be as skinny (as few lines) as possible.
Code Building Blocks Empower You to Build Whatever in Code
Here is a master insight from me to you: the code building blocks empower you to build whatever you want in code. All code, no matter how simple or complex and no matter the language or technology, is built with a combination of basic building blocks. These are the foundation of computation and your ability to get that computer to do what you need it to do. Being able to build anything in code means you are proficient with the basic building blocks, i.e. the fundamentals of computation. Once you focus yourself on one language and become proficient with it, […]
Focus. Make Yourself an Invaluable WordPress Software Professional
Here is a master insight from me to you: Focus to make yourself invaluable. You need to marshall all of your energies and time to focus yourself. Proficiency in any business, and especially in software development, comes from focusing on building your craft and skills. Stop chasing the shiny new fads and efficiency tools. These make you more efficient but will not help you to write clean, quality code from scratch. They will not help you to be able to evaluate code, identify the strengths and weaknesses, and know how to integrate it into your project. These are efficiency tools […]
Computers do not think. You do.
This quick lesson will help you to understand your relationship as the programmer with the computer. It is one of the essential building blocks in your quest to build anything in software. Software development is a thinking profession. Computers cannot read your mind. They cannot infer or figure out what you want it to do. They are literal and exact. They only do exactly what you tell them to do. That’s it. Computers do not think. You do. When a computer is not doing what you want, stop and look at your code. Remember this tip. Then spend your time […]
Code Tip: Specify a default for get_option()
In this quick tip, you will see that you can specify a default return value for the WordPress function get_option(). When the option does not exist in the database, such as you are setting up a theme options page, then you can specify a return value as the default. Otherwise, you will get “false” back.
Code Tip: Return Early
Within a function, when you are done processing, i.e. the conditions are set, then return early. Don’t wait until the end of a function to return. Don’t wrap up your code in conditional expressions when you could have just returned early if the conditions were not met. Why? It makes your code hard to read. The guideline is this: When done, return. Otherwise, continue processing.
Code Tip – Alternate Ternary Operator syntax ?:
The ternary operator can be confusing, as it dehydrates the longer if/else code blocks into a single line of code. It eliminates the repeating pattern. But what about the ?: syntax? How does that work? When should you use it? Check out the other syntax here. This tip is valid for JavaScript and PHP.
Code Tip: Purposeful Naming
Let’s talk about naming of variables, functions, etc. in your code. In this video, you will learn some handy guidelines on naming by intent to let your code express what it’s doing, why it exists, how to use it, and what to expect from it. This tip is valid for all programming regardless of the language or technology.
Procedural, functional, or OOP?
Question: Which programming paradigm should I do? Answer: It doesn’t matter. Nope. You can program in any of these paradigms. What matters is you write clean, quality code and that you are proficient in one of these paradigms.
PHP Tip: What makes a conditional expression false (falsey state)?
In this video, you will learn the intent of this `if` conditional expression as well as what evaluates to false. This is known as checking the falsey state.