News for hackers. Stuff that matters.
Re:JavaScript from 2001 on India's largest private bank site by jfrunyon on Tuesday March 16, 2021 @11:12AM (#26477793)
On the other hand, look at the validation:

- Why not check the length of the string before the switch? - Why return a string which is (meant to be) identical to a variable? - Why not set the regex into a variable and then only have one if-block?

"Don't repeat yourself" is a very good rule for many very good reasons, but a big one is that you don't have to change 10* different places to change 1 thing, which gets rid of a whole class of extremely common bugs. Also, it makes it much more obvious what the code is doing, since your brain only needs to parse 10 different one-line assignments instead of 10 different six-line blocks.

* Replace "10" with whatever the actual number is.

There are no comments on this comment yet.