vincentdnl

Programming memes are wrong

April 5th, 2020

I'm on Reddit. A lot. Maybe too much. Like a lot of programmers, I follow /r/ProgrammerHumor and have a good laugh. But there are some memes that just make me facepalm when I see them.

I know what memes are. They are supposed to be jokes. But they just show that programmers are doing things that are wrong. Sometime because they don't know better (lack of experience), sometime because they just don't care. And judging by the upvotes, many developers do relate to these situations!

Semicolon hide and seek

You have seen them already... Here is the kind of meme I'm talking about:

Or this one:

Let's make this clear: as a developer, your job is NOT to find missing semicolons for hours. I hope someone didn't hire you basically just to proofread text. The job of a developer is to create a solution to a problem by using coding skills. Your time should be spent thinking of a solution that satisfies requirements. If you spend it fixing static errors in your code, then your tooling sucks.

What you need is a linter. Most IDE/editors and languages have one. You are welcome.

It was a typo!

Same goes for this one:

And this one:

If you are coding in English (and you should) you can avoid typos by properly configured IDE or editor. In Jetbrains IDEs, this feature is there by default. If you use VSCode, you can probably use Code Spell Checker. If you use something else, there is probably a plugin as well.

Even if you forget about the spell checker, the linter will probably tell you something like "unused variable". If you see an unused variable and you are sure that you have declared this variable, then you made a typo.

In Jetbrains IDEs and VSCode, at least for Javascript and Typescript, you can type an exported variable from another module and import it directly. Because these tools are clever. When using this auto-import, there is no room for typos. If you are using a class that's defined somewhere else, the properties and methods should be suggested for autocompletion. If you are using a function, the definition should appear to tell you what parameter it expects. These features are called Intelligent code completion or IntelliSense.

If you are not using these tools, you are making your life more complicated than it should. It's not your job to remember the name of every variable/method/class/symbol you defined in your program. You should not have to switch constantly between tabs to check for the correct spelling. Again, you are not a proofreader!

Print debugging

When we started programming we all did this:

Print or console.log to dump the value of a variable:

This has to stop. Debuggers do exist for a reason. Just take the time to learn how to use one.

Look at this thing, it stops where you want, without modifying your code! And you can unfold every property and method of an object!

Now imagine this situation with your classic print debug workflow: your print a variable that's a Python dictionary. It's a very large dictionary with lots of lines. You have nested properties and you have to modify your print and restart your app/rerun your test suite every time you want to go deeper in this nested dictionary. That's daunting. Just use a debugger.

Here is the VSCode one.

There are a lot of debugging options out there. Just pick the one you prefer. There is even one directly in Chrome and Firefox! No excuse.

Spacing indented languages like Python

This one is actually funny:

This one is just sad:

You should not format your code manually. Life is short. There are plenty of cool things to do, like learning how to play guitar or printing stuff with a 3D printer. But formatting your code manually?

You guys seriously spend time typing spaces to align things? Here is a thing: no one should for two reasons:

  • This can be done automatically by tooling, like for example this formatter called Black for Python or Prettier for Javascript. So why spend time doing it yourself?
  • Everyone has its preferences. Therefor, there should be a team setting shared by everyone in the project and preferably applied automatically, for example using commit hooks. No one cares what your personal preference is. You are working with a team. Make it easy for everyone to read!

Don't do the stupid work, let chunks of code do it for you.

Tab vs spaces

This one is hilarious:

This one implies harmful behavior:

Just ask what the team is using, configure your IDE properly and call it a day. I've seen a mix of tabs and spaces in some production code and this is depressing. This shows an absence of consideration that code is a social construct. Everyone should be on the same page.

It's a bit like simple-quote vs double-quotes. This should be decided upfront by your team as a coding style and enforced by tooling. No personal preference here, buddy.

Conclusion

Programming memes are fun but some just show behaviors that create frustration for both the developer and people working with him. Some part of programming are hard but these parts should not be "finding the missing semicolon" or "hitting 12 times space to indent your line". So get good tooling and start focussing on the things that matter!