Code Smell Alert: A common code pattern that I see is where the if/else logic and the if conditional is backwards. I call this the “if/else backwards code pattern.” This code pattern makes the code less readable, which decreases its quality. There are two clues to let you know that you have stumbled into this pattern: The if conditional is set off of a false state. Typically you’ll see a not operator (!) as your clue. The if logic is setting a default state. But that is the job of the else. Smelly Version This is the smelling code pattern: […]
For the month of April 2016, Know the Code will focus on thoroughly explaining and breaking down the Genesis framework for you. The goal for the month is to explain the framework including its major structures, instructions, and events. By the end of the month, you will be able to build custom child themes using this framework. Here’s a bonus: when you go to other sites and read their tutorials, such as Sridhar’s, you’ll be able to understand it further and know how to adapt it for your specific needs. And don’t worry, I will be doing a lot of […]
I often hear how it’s difficult to make time for continuous learning. In this profession, we have to dedicate ourselves to staying current. That means we must give time to continuous learning. Here is a solution for you, a tip from me to you: Take one or two lunches per week, 2 hours total per week, and spend that time eating your lunch while you learn. I did this with my teams and staff over the years. It’s highly effective. The key is making sure you are spending the time learning from a teacher who helps you adapt the knowledge […]
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.
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, […]
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 […]
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 […]
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.
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.