Easing Into a Language and Environment: Week 3 with PHP

Based on the calendar, I’m about two months into a server script project for the Zettelkasten website, but measured in actual work weeks, it’s now the start of week three. I notice that I’m now in a comfortable rhythm to develop features, and that’s always an exciting milestone.

Week 1 was about getting a demo done and check out how things work at all. PHP 8 is a much better language today than the PHP 4 I left in the early 2000s. The tools have matured even more, the language has (optional) type annotations, and static code analyzers can help with adhering to the type rules you set up for your project. Paired with LSP, the feedback was good.

I confess that I also used GPT-4 liberally to look at (possibly hallucinated) conventions to set up a project, and how to partition objects and namespaces, and how to work with a database nowadays. This speed up time to get anything done at all and not worry about syntax and library usage at the same time.

Week 2 was about introducing tests and refactoring the code with the help of an improving test harness. This was also when I tweaked the tools more, introducing phpunit-watcher to automatically run the test suite.

With Emacs as my text editor, and a language server (LSP) as the completion engine, I still wanted to reduce some typing of curly braces and configured text expansion snippets. Quite clever ones that autopopulate attribute declarations and setting initial values from a constructor, generating a docstring in the process. I’ll share these in a while after working with them a bit more.

LSP-wise, I’m using PHPActor for most of the time. I also have a license for intelephense, and intelephense does a much better job at providing feedback on syntax errors like missing semicolons as I type. It’s also very good at formatting code for me. But it sometimes fails and reports false-positives, and PHPActor does a better job at auto-importing and offering suggestions. A combination of both would be ideal – but while PHPActor lacks a couple of features, it works with flycheck-mode to report issues and suggest changes properly, which I can hook into sideline. Seeing incomplete feedback is preferable to not seeing the feedback of intelephense at all. This may change in the future and I’ve switched back and forth a bit.

The journey up to that point spawned a lot of Zettel notes about atomic PHP language details I wanted to remember, and a couple of higher-order notes about more complex processes and object structures. That part was the most exciting, and I’m in the process of writing things up to share language learning with a Zettelkasten in the future.

Week 3 now is about building upon what I learned about structuring the project, and using the flow of TDD to write new services to perform new tasks. That’s a comfortable flow for me, so I can add a couple of features in a tested and somewhat safe manner now and probably finish everything by the end of the week.

One thing I did not get comfortable with in that time is isolating the project with a Docker container. It kinda sorta works, and I can run and reset it to test APIs I am working on. But it’s not in a state where I can confidently deploy the app (via rsync) to a virtual server while using Docker locally. (I don’t want to run this thing containerized on the server, though, that’s a waste of resources.)