News for hackers. Stuff that matters.
Re:JavaScript from 2001 on India's largest private bank site by Cthulhu_ on Tuesday March 16, 2021 @04:42AM (#26474289)
On the positive side, it's straightforward and is void of cleverness (yes I've been doing Go, can you tell?).

I mean if I were to change that option string generator, I could make a numeric for loop from 1 to 12, left-pad a zero for the value, and lookup the month label from a label array or create a Date object and use its formatting options to output the label. I loop over an array of objects with a value and label. With ES6 I could do that with a .map() operation.

It's inelegant but it does what it says on the tin. Can't have an off-by-one error if you don't use loops or indices.

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.

Re:JavaScript from 2001 on India's largest private bank site by deepstack on Tuesday March 16, 2021 @06:47AM (#26475078)
For sure. Using code or data structure to generate code is recent (or resurrection ) phenomenon of function programming.

The function is formatted and it does what it suppose to do. It can be refactored to make it less code.

Re:JavaScript from 2001 on India's largest private bank site by jfrunyon on Tuesday March 16, 2021 @11:15AM (#26477840)
> Using code or data structure to generate code is recent (or resurrection ) phenomenon of function programming.

I'm not entirely sure how you came to that conclusion. Lookup tables and format strings have been around for... well, I'd guess almost a century.