I hear you. I dabbled in Go for a while, and I generally like it, but most of all the generation of a single binary that can bundle frontend code, too.
If I had the time, I’d learn Go and Rust next to Elixir. Zig would be the next one on my list.
Knowing many programming languages and their ecosystem also helps with cross-polination of ideas.
For example, on a plain-PHP backend I’ve been maintaining, I got tired of the same query-params and request-body validations in every route handler, so I wrote two classes that make it possible to do this:
function schema_finance(): Schema
{
$schema = new Schema();
$schema->add_field('rel_slug', 'string');
$schema->add_field('title', 'string');
$schema->add_field('transaction_type', 'string', false, 'finance_transaction_type');
$schema->add_field('due_date', 'string', true, 'finance_due_date');
$schema->add_field('amount', 'float', false, 'finance_amount');
$schema->add_field('payment_method', 'string', false, 'finance_payment_method');
$schema->add_field('payment_reference', 'string', true, 'finance_payment_reference');
$schema->add_field('category', 'string', true, 'finance_category');
$schema->add_field('subcategory', 'string', true, 'finance_subcategory');
return $schema;
}
function changeset_finance_create(array $body): Changeset
{
$schema = schema_finance();
$permitted = $schema->get_fields();
$optional = ['due_date', 'payment_reference', 'category', 'subcategory'];
$required = array_diff($permitted, $optional);
$helper = new GlobalConstants_Helper();
$transaction_types = array_keys($helper->getTransactionTypes());
$payment_methods = $helper->getPaymentMethods();
$changeset = new Changeset($schema);
$changeset
->cast($body, $permitted)
->validateRequired($required)
->validateLength('rel_slug', ['is' => 26])
->validateLength('title', ['max' => 50])
->validateNumber('amount', ['min' => 0.01, 'max' => 100000])
->validateInclusion('transaction_type', $transaction_types)
->validateInclusion('payment_method', $payment_methods)
->validateLength('payment_reference', ['max' => 30]);
return $changeset;
}
That’s thanks to my continued exposure to Ecto, which makes the use of schemas and changesets seem like a very good way of doing things.
It doesn’t yet track the state of changes to avoid updating unchanged fields, but has already helped cut down massively on code repetition. Plus, I enjoyed bringing a bit of Elixir flavor into a PHP codebase.