Important Tip: Stop Hardcoding 😅

I’ve been reading a lot of comments over the past week and a half, and one consistent problem I’ve noticed in peoples’ code is that they keep setting variables to be what the example showed.

For example, say we had to take two values and add them together.

The example might say something like this:
a = 1;
b = 2;


(this is very simple im not good at making examples bare with me)

A lot of people might look at this example and then instead of using the variables a and b in their function, they’d use 1 and 2 directly:

return 1 + 2;

So then when the values of a and b change during testing, they’ll end up getting the answer wrong. Not because their code is actually bad or anything, but simply because they hardcoded the values.

I’m not shaming anyone for this by the way, it’s not an uncommon mistake, and it doesn’t mean you’re incompetent or something. That’s not it. I just want you guys to be more aware of this :sweat_smile:
If you remember not to hardcode stuff and instead use the variables given, then you’ll save yourself a lot of trouble and frustration

Well, that’s it for this post. Keep up the good work everyone!


We LOVE a supportive coding warrior! Thank you for sharing your tips! We have no doubt you’re helping lots of fellow coders!

1 Like

Definitely I have seen a lot of this.
Hard coding can be useful when you’re trying to verify a function or method is working as expected, but you need to replace this with the provided inputs once you’re certain.

1 Like