Click here to Skip to main content
15,886,519 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
Adar Wesley21-Aug-20 4:19
Adar Wesley21-Aug-20 4:19 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
F Margueirat21-Aug-20 4:16
F Margueirat21-Aug-20 4:16 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
Rick York21-Aug-20 5:07
mveRick York21-Aug-20 5:07 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
TnTinMn21-Aug-20 7:22
TnTinMn21-Aug-20 7:22 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
Rick York21-Aug-20 9:16
mveRick York21-Aug-20 9:16 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
patbob21-Aug-20 14:19
patbob21-Aug-20 14:19 
GeneralGoogle Docs and inline images (CP related) Pin
raddevus12-Aug-20 10:34
mvaraddevus12-Aug-20 10:34 
Generalinvert if : visual studio code helper Pin
raddevus4-Aug-20 5:15
mvaraddevus4-Aug-20 5:15 
Writing a simple console app.
I wrote this to insure there is at least one argument provided by user.
C#
if (args.Length < 1){
      Console.WriteLine("Need at least one arg.");
      return;
}


Interesting thing is that Visual Studio Code has these little helpers that pop up at various times which state [Show fixes]. This one says, "invert if"[^].

If you click, it changes the code to:

C#
if (args.Length >= 1){
    return;
}
Console.WriteLine("Need at least one arg.");
return;

Do you find that clearer?
I don't.

In my case, the if statement occurs at the top and if it is not fulfilled then the app exits.
In that case there is no need to think about other code.
Plus, the code that executes normally will not be wrapped in any outer if statement, instead it will simply following the if statement in a normal reading flow.
Inverted Case
In the inverted if then when there is at least one argument then all of your base code is now wrapped in the if statement and you have to think backwards. It's weird.
AI you have failed me. Hmmm | :|
GeneralRe: invert if : visual studio code helper Pin
honey the codewitch4-Aug-20 5:41
mvahoney the codewitch4-Aug-20 5:41 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 6:02
mvaraddevus4-Aug-20 6:02 
GeneralRe: invert if : visual studio code helper Pin
Mircea Neacsu4-Aug-20 8:23
Mircea Neacsu4-Aug-20 8:23 
GeneralRe: invert if : visual studio code helper Pin
Nelek4-Aug-20 19:42
protectorNelek4-Aug-20 19:42 
GeneralRe: invert if : visual studio code helper Pin
SteakhouseLuke5-Aug-20 4:44
SteakhouseLuke5-Aug-20 4:44 
GeneralRe: invert if : visual studio code helper Pin
Nelek5-Aug-20 6:55
protectorNelek5-Aug-20 6:55 
GeneralRe: invert if : visual studio code helper Pin
englebart23-Aug-20 8:01
professionalenglebart23-Aug-20 8:01 
GeneralRe: invert if : visual studio code helper Pin
Mircea Neacsu23-Aug-20 9:03
Mircea Neacsu23-Aug-20 9:03 
GeneralRe: invert if : visual studio code helper Pin
Maximilien4-Aug-20 5:52
Maximilien4-Aug-20 5:52 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 6:04
mvaraddevus4-Aug-20 6:04 
GeneralRe: invert if : visual studio code helper Pin
Nelek4-Aug-20 8:18
protectorNelek4-Aug-20 8:18 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 8:39
mvaraddevus4-Aug-20 8:39 
GeneralRe: invert if : visual studio code helper Pin
Jon McKee4-Aug-20 10:44
professionalJon McKee4-Aug-20 10:44 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 11:40
mvaraddevus4-Aug-20 11:40 
GeneralRe: invert if : visual studio code helper Pin
Jon McKee4-Aug-20 12:11
professionalJon McKee4-Aug-20 12:11 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 16:43
mvaraddevus4-Aug-20 16:43 
GeneralRe: invert if : visual studio code helper Pin
Richard Deeming4-Aug-20 23:41
mveRichard Deeming4-Aug-20 23:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.