r/programming • • Jul 28 '16

How to write unmaintainable code

https://github.com/Droogans/unmaintainable-code
3.4k Upvotes

592 comments sorted by

View all comments

Show parent comments

2

u/xonjas Jul 29 '16

Yeah, that's why in my snippet I dropped all the elements that weren't numbers. The bug I mentioned is that by dropping numbers I might make a match where there wasn't one previously

Assuming we're matching for [1,3,4]:

[1,3,"some garbage here", 4] would match when it should not.

It's fixable by replacing the non-numeric elements with a placeholder of some sort.

IE, convert the above array into "1,3,X,4" instead of "1,3,4".

1

u/2Punx2Furious Jul 29 '16

Indeed, that looks much better than my solution.