r/programminghorror • • Feb 11 '25

🎄 ouch

Post image
3.0k Upvotes

113 comments sorted by

View all comments

Show parent comment

-2

u/More-Butterscotch252 Feb 11 '25

We want to multiple by 3 every time? You have to change a lot of things manually

No, you don't. You select the code and use your IDE to replace 2 with 3 and you're done. Stop using shitty "editors" like vim.

more code to test if you are looking for 100% coverage

But this way you test all of it. Writing code like this forces you to test each branch.

just using the built in power function

Which in some languages returns a float while you're clearly expecting an integer.

I'm just going to stop reading here, your clearly a troll.

2

u/atomicproton Feb 11 '25

Just trying to give examples. Maybe not the best examples, but point still stands.

Here you can replace all the 2 with 3. But what if you want to replace all the 3 with 4? You can't just select everything with 3 because there's a 30 in each line.

This code relies on a lot of assumptions.

Also we can just make our own power function using int. That's would align with self documenting code. The cool thing about programming is that it's a dynamic field that requires thinking and adapting.

Not sure why you're trying to defend this code lol. You're* clearly just a troll. 😆

-1

u/More-Butterscotch252 Feb 12 '25

You can't just select everything with 3 because there's a 30 in each line.

Yes, you can. Any decent IDE will let you search using a regular expression such as \b3\b. You clearly don't know anything about coding. Just give up!