Monday, October 31, 2016

Programming Style Woes

Woulda put this in my tech-wiki, but it's really just a rant and of no real technical value.

Look, I get that the language you wrote your program in isn't your preferred language - and that when you program in your preferred language you're just fine - but there's no excuse for being internally-inconsistent.
  • I don't care if you want to do indents as tabs, two spaces, three spaces four spaces or multiples of one of the preceding. What I do care about is that you pick one and stick with it.
  • PICK A FUCKING TERM-WIDTH AND STICK WITH IT. I don't want to have to keep widening my xterm each time you write a new, wider line than any line you previously wrote
  • I don't care if you want to use module or path/to/module - just be freaking consistent
  • I don't care whether you pre-declare your variables (so you can set their type - even if the initial value is null) or not - just make sure that if you pre-declare some variables you pre-declare all your variables.
  • There really are better ways to write to a file than "open -> append-write -> close ; open -> append-write -> close": just open the damned file, do all your freaking writes to it, then close it
  • If you're gonna regex something using a function that supports multiple operations, call that function ONCE.
  • If you're going to explicitly declare that your regex is an extended-regex, make sure that you're actually doing extended regex rather than standard-regex.
  • If you're doing the exact same things more than once in the same program, CREATE A FUNCTION AND USE IT. Seeing the same two dozen lines of code scattered multiple times throughout a program is not acceptable.
  • Be consistent with how you declare and structure your functions.
  • Be consistent with deciding to create functions: don't turn some things into functions and leave other things repetatively declared elsewhere
  • Be consistent with how you use logic-branching: don't use nested "else ; if" once place and "elif" in others; don't use case-branching logic one place and ginormous if/elifs elsewhere.
I write in a bunch of different languages. If you're familiar with the various languages, it's easy to tell when I've slipped back into my "mother tongue". That said, I try to at least be consistent with my writing within a given program - even if that means my Python looks very shell-ish (etc.).

I can't figure out how people can debug their own code if they don't at least make it internally-consistent. How the hell do they expect anyone else to work with the code if it's constructed so that even the code-owner is going to struggle with it??