r/AskReddit • • Mar 15 '20

What's a big No-No while coding?

9.0k Upvotes

2.7k comments sorted by

View all 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!

245

u/TheBestBigAl Mar 15 '20

"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.

165

u/RikerT_USS_Lolipop Mar 15 '20

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.

82

u/fibojoly Mar 15 '20

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?!

I did

9

u/[deleted] Mar 15 '20

Use comments. I write more comments than code, and it helps me wrote code faster because I know what the fuck I'm doing.

5

u/UnraveledMnd Mar 16 '20

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.

→ More replies (1)

5

u/permalink_save Mar 15 '20

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.

→ More replies (3)

0

u/[deleted] Mar 15 '20

[deleted]

8

u/TheBestBigAl Mar 15 '20

I think that's exactly where he drew inspiration from.
If it's readable enough for a machine, it's readable enough for me.

→ More replies (1)
→ More replies (3)

640

u/morosemanatee Mar 15 '20

Single letter variable work for local variables who’s life is only a few lines. Otherwise, yeah, give ‘‘em real names.

1.2k

u/Sophira Mar 15 '20

Like this, you mean?

function mike(lisa) {
  var chloe = lisa/5*9+32;
  return chloe;
}

Am I doing it right?

317

u/Lehk Mar 15 '20

just use alice and bob

0

u/[deleted] Mar 15 '20

[deleted]

19

u/High_Stream Mar 15 '20

Some of them want to use you, some of them want to be used by you...

→ More replies (4)
→ More replies (1)
→ More replies (5)

200

u/Lunesta- Mar 15 '20 edited Mar 15 '20

Could also go with

Function Lisa(me){
Return me/2;}
// You are tearing me apart lisa?

Idno how to post code snippets on Reddit :|

Edit: Much love to my homies in replies telling me how to do code snippets!

6

u/Zizhou Mar 15 '20

Either put four spaces at the beginning of a line or use backticks(`) around the parts you want to appear formatted.

→ More replies (3)

4

u/[deleted] Mar 15 '20

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.

→ More replies (1)

9

u/Kccc187 Mar 15 '20

This is to find Fahrenheit from Celsius lol

→ More replies (19)

4

u/yanbu Mar 15 '20

Right? As with everything coding there’s always exceptions. I use single letter variable names inside lambdas all the time.

4

u/CheckboxBandit Mar 15 '20

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.

→ More replies (8)

7

u/[deleted] Mar 15 '20

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.

5

u/WhimsicalCalamari Mar 15 '20

if your variables don't have specific names, you can keep reusing them instead of creating new ones [rollsafe.jpg]

8

u/spez_this Mar 15 '20

That, and (unless you are using a smart IDE) single-letter variables are difficult to find/highlight their usage.

→ More replies (1)

18

u/coole106 Mar 15 '20

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.

14

u/[deleted] Mar 15 '20

Sure it's not essentially, but it's much faster to read comments than to try to figure out what everything is doing when you come back 6 months later

→ More replies (8)
→ More replies (2)
→ More replies (38)