Technology
What Makes a Senior PHP Developer [Mad] When Reviewing Junior Developer’s Code
What Makes a Senior PHP Developer [Mad] When Reviewing Junior Developer’s Code
As a senior PHP programmer, reviewing the code written by junior developers can sometimes be a source of frustration. In this article, I will describe several common issues that can drive a senior developer mad. These include practices that directly undermine the effectiveness of the codebase or are just plain inefficient. The goal here is to highlight the importance of adhering to best practices and the impact they can have on the overall quality of the code.
Conditionals Based on Test Environments
One issue that stands out is conditional logic that switches based on the environment, especially when it's a test environment. For instance:
if [configSource].env testThis is a common mistake and a bad practice for several reasons. First, it breaks the separation of concerns between configuration and logic. It also defeats the entire purpose of having tests if your code is conditionally executing different logic in test environments. In my experience, I have seen this happen both as a junior and senior developer, and it often causes more harm than good.
Resorting to Regular Expressions Unnecessarily
Another thing that gets me is the over-reliance on regular expressions. For example:
import xmlBlob from filename.whatevern[perform regex substitution on xmlBlob]Regular expressions can be incredibly powerful and flexible, but they can also be complex and error-prone. Before you reach for a regex, always ask yourself if there is a library or function already available that can handle your task more safely and effectively. It's important to prevent your code from becoming vulnerable to injection attacks or other security issues. Always take the time to search for a more reliable and maintainable solution.
Unit Testing APIs
A third issue that is frustrating is when junior developers make a real API call in their unit tests. Testing APIs is not your job; it is the responsibility of the team managing that API. If it's your API, put the tests in the other repository. Unit tests should focus on the internal logic and functionality of your code, and not external dependencies. When these tests produce false failures, they can cause pipeline issues that impede the overall development process. Keep those tests in their rightful place, and avoid creating unnecessary conflict.
Checking Secrets into Git Repositories
Checking sensitive information like secrets into the git repository is another common mistake that can lead to potential security risks. Imagine a scenario where a secrets file is checked in, and subsequently committed to the main branch. If someone discovers this file, it could expose sensitive information such as API keys or database credentials. A better practice is to explicitly ignore secrets files in your .gitignore. This way, you prevent accidental check-ins of sensitive data. It also helps maintain a clean and secure development environment.
Incorrectly Documented Functions
Lastly, I have seen functions with misleading names and comments that no longer reflect the actual implementation. For example:
This function adds two numbers together!nfunction subtract a b { a - b }If the function name and comment do not accurately describe the function's behavior, it can lead to confusion for other developers. Comments, while helpful, can also become outdated, leading to documentation that is incorrect or misleading. Aim to write clear, concise, and accurate comments. This not only aids in understanding the code but also reduces the likelihood of maintenance issues in the future.
Conclusion
These are just a few examples of practices that can make a senior PHP developer's life a bit more difficult. While it's natural for developers, especially juniors, to make mistakes, it's crucial to learn from them and adhere to best practices. Understanding these common pitfalls can help improve the overall code quality and maintainability of the project.