Screenshot of collapse button for an open details element
JavaScript

Collapse an Open Details Element (JavaScript)

The <details> HTML element is really great. And paired with <summary> you've got all you really need to make easy-to-read expandable/collapsable sections of a document. But I recently wanted to have at the bottom of each segment a quick way to close the expanded details segment I'd just scrolled through. By default, you can simply click on the <summary> element you used to open it. But what if your sections are long enough that that has drifted off the top of your screen? That's the situation I was in that led me to want to write as little JavaScript as possible to reach up to the top from the bottom of my (long) details section and collapse it. So we're going to explore how to collapse an open details element in this article.

Continue reading

Standard
PHP

How to Learn PHP Unit Testing With Katas

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.

Continue reading

Standard
PHP

PHP Web Scraping: What to know before you start with Symfony Panther, Goutte, and more

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.

Continue reading

Standard
High-Level Concepts

All Programs Have a Surrounding Human Context. This Matters

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.

Continue reading

Standard
High-Level Concepts

Thoughtful Code is Contextual, Intelligible, Verifiable, and Cellular

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…

Continue reading

Standard