• (nodebb)

    I've been in a place where early returns were considered the epitome of evil. that's how you end up with code like this.

  • (nodebb)

    I really wish we'd stop letting engineers code without supervision. Someone should at least tell them about early returns.

    The problem is how to persuade the Powers That Be, and Those Who Decide (hopefully the same people!), of this. As I've noted before, this is something you have to construct as an argument in Businessese rather than in Engineerian - that is, an appeal based on the costs in time, in work lost (and therefore time lost to redo it), and so on. Fuss about the quality of the code later, but start by getting source control in operation to eliminate (er, reduce) the need for rework.

    At least the code is clear: if all these fields are filled, process the object, otherwise whine in a message box about the first missing field.

  • Officer Johnny Holzkopf (unregistered)

    The filename Custom.vb is terribly misleading. It should be something like SourceCode.vb - how else could you differentiate it from invoices (Invoice.xls) or reports (Report.doc)?!

  • Bogolese (unregistered)

    Yeah, we should let the AIs do the coding! :( DOH!!!

  • NotAI (unregistered)

    Imagine using a company purchased subscription to ChatGPT or the lot to compose code.
    Brand new dimensions for TheDailyWTF!

  • (nodebb) in reply to thosrtanner

    Eh, you can work around that with minor effort, assuming that convincing the other person is a lost cause:

    string message = "";

    if (condition1) { message = "problem1"; }

    if (message == "" && condition2) { message = "problem2"; }

    ...

    if (message == "") { do stuff; } else { display message; }

    return;

  • (nodebb)

    Early returns? bad bad BAD . do you not remember the early return headline "Dewey Wins" ?

  • (author) in reply to cellocgw

    The actual headline was "Dewey Defeats Truman", but what's usually left out is the defeat was in a swimsuit competition, not the election itself.

  • (nodebb) in reply to thosrtanner

    I've been in a place where early returns were considered the epitome of evil. that's how you end up with code like this.

    Not really. This code uses early returns and lots of levels of nesting. What do you think all those Exit Sub statements are doing?

  • (nodebb)

    Doesn't a default MsgBox just have an OK button? What is DefaultButton2?

  • (nodebb)

    Even without early returns, you could fix the nesting issues by simply flipping around the true/false branches and using ElseIf.

    If Item.objNamDe Is String.Empty Then
    	MsgBox("objNamDe is missing or empty.", MsgBoxStyle.DefaultButton2, "Information RS2TC")
    ElseIf Item.objNamEn Is String.Empty Then
    	MsgBox("objNamEn is missing or empty.", MsgBoxStyle.DefaultButton2, "Information RS2TC")
    ElseIf Item.artCat Is String.Empty Then
    	MsgBox("Property artCat is missing or empty.", MsgBoxStyle.DefaultButton2, "Information RS2TC")
    ' ...
    Else
    	' I omitted 134 lines of logic that really should be their own function
    End If
    
  • CompletelyAutomatedDis (unregistered) in reply to thosrtanner

    The "single return statement" rule is the epitome of cargo cult. Having seen some convoluted horrors with return statements buried in many layers of loops and if statements, I get how that rule came about, but practically always, rewriting a hard-to-follow function with multiple returns to conform to the rule without some additional refactoring just makes it even more convoluted and hard to follow.

  • olgi (unregistered)
    Comment held for moderation.
  • Duke of New York (unregistered) in reply to CompletelyAutomatedDis
    Comment held for moderation.

Leave a comment on “What a CAD”

Log In or post as a guest

Replying to comment #682866:

« Return to Article