Found in production codebase



  • <font size="3" face="Times New Roman">

    </font>

    <font size="3"><font face="Calibri">Foo parentFoo =
    GetFooFromDbById(parentFooId);<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></font></font>

    <font size="3" face="Times New Roman">

    </font>

    <font size="3"><font face="Calibri">List<Foo> foos =
    GetFoosFromDbByBatch(parentFoo.BatchId);<o:p></o:p></font></font>

    <font size="3" face="Times New Roman">

    </font>

    <o:p><font size="3" face="Calibri"> </font></o:p>

    <font size="3" face="Times New Roman">

    </font>

    <font size="3"><font face="Calibri">for (int i = 0; i <
    foos.Count(); i++)<o:p></o:p></font></font>

    <font size="3" face="Times New Roman">

    </font>

    <font size="3"><font face="Calibri">{<o:p></o:p></font></font>

    <font size="3" face="Times New Roman">

    </font>

    <font size="3"><font face="Calibri">               
    if (foos[i].Bar == parentFoo.Bar) continue;<o:p></o:p></font></font>

    <font size="3" face="Times New Roman">

    </font>

    <font size="3"><font face="Calibri">               
    foos[i] = GetFooFromDbById(foos[i].Id);<o:p></o:p></font></font>

    <font size="3" face="Times New Roman">

    </font>

    <font size="3"><font face="Calibri">               
    foos[i].Bar = parentFoo.Bar;<o:p></o:p></font></font>

    <font size="3" face="Times New Roman">

    </font>

    <font size="3"><font face="Calibri">               
    SaveFooToDb(foos[i]);<o:p></o:p></font></font>

    <font size="3" face="Times New Roman">

    </font>

    <font size="3"><font face="Calibri">}<o:p></o:p></font></font>

    <font size="3" face="Times New Roman">

    </font>


  • I pity da foos.



  •  Foos Do Rah!



  • Well, how else did you expect to UPDATE the Bars of Foos WHERE foo.parent = parentFoo?



  • Well, this is the problem with using full ORMs. Doing mass updates or mass deletes is more trouble than it is worth. Micro-ORMs for the win.



  •  Oh I wish this were using an ORM.  These are POCOs that end up getting sent to a stored procedure to update the database.  Looking past using for instead of foreach and then the fun continue in the loop instead of just inverting the if, but hitting the db again and mapping the results back into the object just to end up with what was already there is pretty inexcusable.



  • @Dinkus said:

    the fun continue in the loop instead of just inverting the if
     

    I do this, too, so that the code doesn't end up very indented.

    Of course re-reading an existing object is a WTF.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.