All PHP code gets tested. Most of it is tested by the developer when they check to make sure the webpage looks right in their browser; some when you run an API response tool, like Postman. Some of it is tested when that same developer writes automated tests and runs them against it---this is our focus. Sometimes code is first tested when the unfortunate client or user feels like using the feature and tests the developer's work. Hopefully, they're not disappointed.
First and foremost, scraping the web (in PHP) is bad, mkay? PHP web scraping isn't worse than doing it with other languages, it's just that web scraping in general is most likely to be looked by with disdain by content-producers. And it'll make your code more brittle than it should be, and is general going to make an application more complex to build.
Computers process information differently than humans do. Anyone who's first learning to program understands this well. What's hard about programming for a beginner isn't really big hard esoteric concepts, but that you've got to be so painfully exacting in how you describe everything to a (dumb) computer. That's why we do rubber duck debugging.
This is the second in a series detailing what I consider "Thoughtful Code." In the first one, I highlighted the high-level overview of what I consider "good" code, here I'm going to go (a lot) deeper into what this overarching framework means in its specific components. Well one of it's components. Specifically, the context in which our code lives, and how that shapes our definition of code quality.
I've been thinking a lot lately about what makes code "good." Let's take it for granted that "good" is so meaninglessly subjective that it's not really a useful term for one to use when talking about a program or block of code. So let's say that "thoughtful code" is code that meets my personal subjective definition of "good." But before you zone out, I want you to know that a lot of "bad" code is actually "good" and vice-versa. The counter-intuitive reality is that WordPress contains some of the best PHP code on the planet. Let me explain why…
Namespaces are a great feature of PHP. They've taken it from being a complex-to-scale and rather small-scale-only language into something where most projects have a healthy-level of outside code (pulled in with the Composer dependency manager) and a whole lot more clarity about what is where and why.
One of the topics of seemingly perennial discussion among programmers is whether object-relational mapping (often abbreviated to ORM) is evil or not. Opinions seem to run the gamut from "I use and love it" to "I tried it once and never will again." And you often encounter at least a few "what are you talking about?"s.
I've given the talk "Banishing Loops with Functional PHP" (or "Functional Programming, it just depends on how I titled it) at least three times. But it's still, mostly a talk. You can watch a talk I've given many times right here:
Recently (at the end of 2017), OWASP updated its Top 10 list. For the unfamiliar, let me briefly explain what that means: the industry standard of basic-web-security education has altered. Though it's never been a complete security education, the OWASP Top Ten is where almost all standards for web-developer security education begin. So when it changes, that's kind of important.
Let's get it out of the way early: PHP is a strange and ugly language. It's not exceptionally fast. It's not beautiful syntactically. It's not formulated around a clear opinion about good software development practices. And it's still what I write a lot of software in. The obvious question is: why? Why use PHP today?