Recently a X post about an Argentinian government WebApp code was shared on X and led to a big argument about “code shaming,” readability, and seniority. Instead of entering that discussion; let’s focus on “fixing” the issues with that code to make it production-ready. First, the problematic code:
Initially, we can remove duplicated lines and duplicated logic:
Without the bloat, it is a little bit easier to read. Now, let’s focus on turning that multi-line AND/OR into a nested if structure:
That’s an improvement, but we can do even better. Let’s move some of the logic into constants with names that allow the developer to understand what’s happening:
That’s very readable and far better than the initial implementation. Of course, we could go one step further, turning this into a fully functional approach, but that might not be easy to read for some folk, so this last step is “optional.” Still, if we separate that logic into several files, it becomes far easier to maintain and test:
So in the places where we need this logic, we can call
redirectPatient(patient, history); and done!
We could come up with many different solutions, but I believe the main thing we should be discussing is:
Public government apps should be open source and accept “pull requests” from developers to be improved. Especially if it implies public health.
And before discarding this as a “political” post, I’m just pointing out that government apps, as anything government-related thing, should be “democratic” and “auditable,” and there isn’t anything more democratic than open source.