Programming

My career is in software/web development and I have about 15 years of professional experience. Over that time, I've found many helpful resources for coders to use, so I am gathering them from all over my files and bookmarks to put on this page as I find them.

An aside:

Open source software is a wonderful thing, and certainly computing would be far worse off without it, as would the internet itself and therefore the whole world. I believe in using open source software whenever possible, not only because it usually doesn't cost anything, but also to support an open and transparent way of creating and sharing software that can be improved upon by its users, rather than the proprietary and inflexible ways of the clunky computer-beige 4:3 CRT era.

But one thing that breaks my heart to see the OSS community proudly and almost universally embracing is this nonsense:

function doSomething($array) {
    foreach ($array as $v) {
        somethingElse($v);
    }
}

What the hell is this crap? Curly braces strewn asunder throughout the code? There's no reason for that. Is there? I've never found a good reason for this, and not from lack of searching. Everyone I've talked to either agrees with me or says shut up and follow the coding standards like a good obedient coder. (Some have said both!) Never a rationale for writing code like that, because there isn't one. It's sloppy and unsightly. Far be it from me to praise a certain proprietary software megacorporation, but they did get one thing right:

function doSomething($array)
{
    foreach ($array as $v)
    {
        somethingElse($v);
    }
}

This, folks, is the correct way to code. It is cleaner and visually nicer than the other way, and easier to edit, especially if you have dozens of nested curly braces. And for those who say you should never nest more than 3 braces deep, there will be times when you have to. Or when you are tasked with fixing a bug in some code that is nested all the way to fubar and if you change it more than a little you'll get scathed in the code review. It can be a nightmare if the braces don't line up and you can't tell which closing brace goes to which opening brace.

I'm told the braces don't have to line up since all modern IDEs have syntax highlighting. But what if you have to do some coding on a system with limited display resolution so you can only use Mousepad or KWrite? Or maybe you're coding and checking in a quick fix on a headless server so you do it in nano or vim. I've been in both situations multiple times recently. You might not always get to code in an IDE, and people editing your code won't always have access to an IDE.

I'm told it's less compact to devote an entire line to one little brace if you want a printout. What? A printout? Why? Why are you printing code? You don't gotta print code. All that "paperless office isn't" stuff is for accountants during Y2K. You're a developer. It's the 21st century. You have other options besides printing code. You can probably think of at least 5 other options off the top of your head.

But ok, suppose you print the code. There goes your syntax highlighting. Now you have a hard to read hard copy full of randomly scattered braces. A tree just died for you, and this is how you defile its corpse?

If you want compact code, why not use Horstmann style?

function doSomething($array)
{   foreach ($array as $v)
    {   somethingElse($v);
    }
}

Except everyone hates Horstmann style for some reason. They tell me it looks like someone lost their enter key... but that's the nature of compact code. Can't have it both ways. Compare it to the sloppy format at the top of this aside and everything is in exactly the same place except the curly braces, which are tidy this time. Anyone who likes sloppy code should love Horstmann style. Tell you what, humor me this. Try using Horstmann for your main personal project just for a month. You can convert your codebase with something like astyle that way you always have the option to convert it back. Make sure to work on your project at least a couple hours each day. After the month is up, ask yourself, does this code look good? Is it readable? Is it tidy?

And let's not forget...

} else {

No, just no. There's no excuse for that. It is a garbage way to code. It is trash. It looks like a spaceship that's about to blast holes in the screen. Send it back to planet Crapulon. Every single PSR should be declared null and void for the blunder of recommending that stupidity.

Now, all that said, there is one and only one case in which I agree with the sloppy code style, spaceship and all:

<!-- some HTML code -->
<?php if (one_liner_condition()) { ?>
    <!-- some more HTML code, less than a screenful, with ABSOLUTELY NO NESTED CURLY BRACES -->
<?php } else { ?>
    <!-- I MEAN IT! LESS THAN ONE SCREEN AND NO NESTED CURLY BRACES! -->
<?php } ?>
<!-- the rest of the HTML code -->

In this case it doesn't matter that the curly braces don't line up because A.) we're not nesting them, and 2.) the sloppiness of the braces not lining up is offset by the tidiness of having the PHP tags be one-liners. Of course, this exception does not apply at all if any of the PHP tags are multi-line for any reason.

Yanno, even though I do code this way in this very specific kind of situation, it still looks wrong.

Linux and OSS

Raspberry Pi

Expressions, Algorithms, Formulae

PHP

AI/ML

Javascript

HTML/CSS

SQL