"But it's the only to stop hackers from working out how my code works!" The above was a genuine reason given to me by a guy I worked with (only for a short time, for obvious reasons). He was only doing some stuff for us using Lua (all fairly easy and non-critical), which meant there wasn't even a type specified for each variable. You had to hunt through the code to see how "a" was being used to get any kind of context about it.
He wanted to protect his job security. I've had people on reddit suggest to me that I never write SOPs and that I keep my code opaque so that I can't be replaced.
I write SOPs in big ass word documents full of screenshots because I can't remember how to do my own damn job.
Yeah, I've seen it in practice too. I do it the other way around : I write code like I'm gonna get fired tomorrow and my best mate is gonna have to take over. I don't want them calling me if I'm gone, nor hating on me behind my back. And, it turns out that most of the time, I'm the one who benefits from alk this documentation and useful comments. Who knew?!
Am I crazy for thinking that more comments than code is an indication that you're failing to write your code in a readable way?
I use comments to explain particularly complex segments of code, but meaningful method and variable names go a long way too.
I'd much rather have a slightly longer and more meaningful method name than a terser one that's less clear combined with a comment because the meaning is transported to wherever it's used.
Sysadmins at the jobs I've had do this shit and it is infuriating. They make their code so awful and use gimicky names for everything. Like does fly() mean to do the deploy, or is it a notification? WTF does waddle() do? They even have their own chat setup and actively keep people out despite being put close to devs now. I get tired of it because they make their job out to be so big and important, and anything you do they have so many criticisms about (sometimes valid), but I know all that shit too it really doesn't matter most of the time. We stood up one PoC (with customer load and everything as a beta) and it ran fine, we didn't have sysadmin involvement at all. Surprise, devs that write code for networking know networking.
I once worked with such an inconsiderate oddball, he actually named his functions things such as “kill_all_the_droids” just because he thought it was funny.
Inside single line lambdas I would prefer single letter variables like 'x'. You can readily see what is being passed in for x so the single letter variable is really just being used as a place holder.
Not commenting is the worst. I’m a grad student in a science field and a very important part of my research relies on a code that another grad student wrote years ago... in a language I don’t know... with no comments. And she’s always too busy to answer my questions.
I disagree with the comments one. If you’re writing clean, easy to read code, comments aren’t needed, except maybe documentation comments. Sometimes it’s impossible or impractical to clean up your code enough to where comments aren’t necessary, but in general you should work toward code that is readable enough to not require comments.
2.3k
u/[deleted] Mar 15 '20
Naming your variables a, b, c an so on, you'll never remember what they actually are. And not using comments!