- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.
Admin
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.
Admin
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)?!
Admin
Yeah, we should let the AIs do the coding! :( DOH!!!
Admin
Imagine using a company purchased subscription to ChatGPT or the lot to compose code.
Brand new dimensions for TheDailyWTF!
Admin
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;
Admin
Early returns? bad bad BAD . do you not remember the early return headline "Dewey Wins" ?
Admin
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.
Admin
Not really. This code uses early returns and lots of levels of nesting. What do you think all those
Exit Sub
statements are doing?Admin
Doesn't a default MsgBox just have an OK button? What is DefaultButton2?
Admin
Even without early returns, you could fix the nesting issues by simply flipping around the true/false branches and using ElseIf.
Admin
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.