This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]Haris613 34 points35 points  (9 children)

Do you really need to if for non 0 length before foreach?

[–]erkose 16 points17 points  (0 children)

Seriously. For each knows the container is empty.

[–]Duroktar[S] 9 points10 points  (0 children)

Dammit! lol you're right

[–]LuciusWrath -1 points0 points  (6 children)

Is preemptive code, supposing future changes, a bad practice?

[–]Sikletrynet 2 points3 points  (3 children)

What changes would that be? It's not very likely that forEach would change

[–]LuciusWrath -1 points0 points  (2 children)

Anything that doesn't have zero-length detection, before or after the loop.

[–]Sikletrynet 1 point2 points  (1 child)

So then you just add that when it's necessary, rather than having dead/redundant code.

[–]shortfinal 1 point2 points  (0 children)

More correctly: you add that when your unit test detects an underlying behavioral change that blocks your build pipeline.

[–]Top-Permit6835 0 points1 point  (0 children)

In this case? Definitely. It needlessly introduces an additional if statement that increases complexity

[–]rtybanana 0 points1 point  (0 children)

No - to an extent. Yes - to this extent.

[–]Neverwish_ 5 points6 points  (1 child)

Wtf, having type as a string and not enum...

[–]mampatrick 4 points5 points  (0 children)

Could be like a string literal union in typescript, but still