Faultd.

Journal of a software engineer.

HTMT, but for PHP

29 November, 2024

Now that I'm comfortably on SourceHut with my work, I've also managed to get a 1.0 out for a PHP port of HTMT, my templating library for C#. The PHP port is called Toretto, because it is based on the new \DOM\HTMLDocument that came with PHP 8.4. Get it? DOM? As in, Dominic Toretto? Well, I think it's quite clever if I do say so myself.

In other news, I'm working on a YAML-like (but flat) serialization language as well (that supports boolean functions). It'll appear here as work progresses. I'm also dabbling with building a e-mail client to solve some of my many gripes with modern e-mail clients and their unneccecary complexity, but I don't have much progress to report in that front yet. All I can say is that I'm slowly figuring out IMAP and SMTP protocols at the moment. It's a rather large undertaking, so I don't expect to make much progress for a while.

I don't like social coding

19 November, 2024

I've come to the conclusion that I don't like GitHub. No, not the website or the company, but the idea itself. "Social coding", the thing that has been its tagline. And no, not even the social part, but everything that we've come to accept as part of the "social" whenever we encounter other social things, like social networks. The vanity stuff, in particular.

You see, some of my projects get recognition, and that makes me feel good. My lizard brain takes it as validation, and concludes that for the brief moment following the seeing of a new "star" or "follow", I actually matter. I make a difference in the world. People like what I do. And this is great.

But then on the flip side, the vast majority of my projects get no stars or recognition at all. This, then, makes me feel bad. Am I not making good enough software? Am I even a good programmer? Maybe people just don't like me? And this is not great.

Maybe I'm just too sensitive to the subconscious mind programming of the modern world, but I'd rather not have any of this at all. Ultimately I make my projects because I want to make them. I make them because they are useful to me, and I wouldn't care if anyone even knows about my existence if it were not for all the indications showing me constantly if they do or not.

I've found that even the mere existence of these metrics on the page subconsciously make me crave recognition, and then make me want to partake in social media where I would post about my projects so that maybe someone would find it useful and "star" it or something. Whatever it is, I don't like it, and it's not something I want my hobby programming to be about, or even partly have, in no matter how small of a part.

Thus, I'm starting my move to SourceHut. I don't really care which platform is superior in features or whatever. This is not me saying you should also use SourceHut. I just want a simple git hosting with CI/CD and not much else, and from what little research I did, it seems to be the only such service without vanity metrics, and from what I can gather its founders also have no interest in something like that.

Loggr, so your days would be more enjoyable

11 November, 2024

I've created a new PHP library called Loggr. Just like the name would suggest, it is a logging library. However, unlike most logging libraries out there, it does not invent a yet-another-logging-format and instead implements multiple, popular, already-existing formats like IntelliJ, JSON, Laravel and Symfony.

Born out of the frustration of having to read through endless log files and not having any log viewing tool support any of the log files created, I hope to bring a little sunshine back to your life. It certainly has to mine.

PHP 8.4

9 November, 2024

In a week or so, PHP 8.4 will be out, and the most notable thing about it, to me at least, is the ability to use property hooks. The abuse of getter/setter methods has always bothered me in OO languages (especially Java), and I'm glad that the getters and setters can be written directly to the property itself now.

Clean Code Evangelists are probably not happy that this encourages directly using the properties instead of a wrapper method, but they can all get fucked anyway. To me, pragmatic and simple to understand code is the best, and religious bullshit cargo-culting of design patterns is not something I'm interested in.

Anyway, this is what it looks like:

class BookViewModel
{
    public function __construct(
        private array $authors,
    ) {}
    
    public string $credits {
        get {
            return implode(', ', array_map(
                fn (Author $author) => $author->name, 
                $this->authors,
            ));
        }
    }
    
    public Author $mainAuthor {
        set (Author $mainAuthor) {
            $this->authors[] = $mainAuthor;
            $this->mainAuthor = $mainAuthor;
        }
        
        get => $this->mainAuthor;
    }
}

(I stole this from Brent Roose's excellent blog post with a lot more info on PHP 8.4).

Boolean Expressions and Interpolated Expression Modifiers in HTMT

30 October, 2024

I recently released the 2.0 version of HTMT, and with it came new features, such as boolean expressions and interpolated expression modifiers. I feel like these are the two features that make HTMT pretty feature-complete now and allow me to focus on other projects, such as the Markdown parser that powers Tobey, and further down the line porting Invobi over to C# from its current PHP implementation.

Anyway, let's dive into these features.

Boolean Expressions

Boolean expressions are an addition to the if and unless attributes in HTMT. While previously you could only use these attributes to check if a variable was truthy or falsy, you can now use boolean expressions to check for equality,

So for example you could do something like this:

<div x:if="(a is b) or (b is c)">
    <p>Either a is b or b is c</p>
</div>

It supports the following operators: is, and and or, and you can use parentheses to group expressions. You can not only compare variables, but also strings and numbers (ints and floats).

Of course a simple truthy/falsey check is still possible, but if HTMT detects any spaces in the expression, it will treat it as a boolean expression.

I do plan to add more operators in the future, such as is not, is less than, is more than, and so forth. I like natural language, so I want to make it as easy to read as possible, and something that designers can easily understand.

Interpolated Expression Modifiers

Interpolated expression modifiers are a way to modify the output of an expression. They are added to the end of an expression and are separated by a pipe |, allowing you to chain multiple modifiers together, like so:

<p x:inner-text="{title|uppercase|reversed}">

This would output the title variable, but it would make the output uppercase and then reverse it.

Modifiers can also take arguments, like so:

<p x:inner-text="{title|truncate:10}">

This would truncate the title variable to 10 characters.

The arguments can be anything, and it is up to the modifier to parse them into what they need. All of this is, of course, extendable, meaning that you can create your own modifiers and use them in your templates.

Currently, the following modifiers are available in HTMT:

I don't have any need for more right now, but I'm open to pull requests if you want to contribute.


All in all I'm really happy with how HTMT is turning out, and I'm excited to see what people will build with it. It has been immensely useful to myself, and has been very fun to build. I really enjoy C# and the .NET ecosystem, and I'm looking forward to building more tools and libraries in this space.