ALL


  Introducing the for-if anti-pattern

Over the years, I've seen a bunch of coding anti-patterns.I figured maybe I'll share a few.Today, I'll introducewhat I'm calling the for-if anti-pattern,also known as"We'll sell you the whole seat, but you'll only need the edge."This is a special case of the for-case anti-pattern, whereall but one of the cases is null.for (int i = 0; i < 100; i++) { if (i == 42) { do_something(i); }}This can naturally be simplified todo_something(42);The for-if anti-pattern arises in many forms.For example:foreach (string filename in Directory.GetFiles(".")){ if (filename.Equals("desktop.ini", StringCom...

3,224 0       PROGRAMMING EFFICIENCY ANTI-PATTERN FOR-IF