Click here to Skip to main content
15,911,035 members

The Insider News

   

The Insider News is for breaking IT and Software development news. Post your news, your alerts and your inside scoops. This is an IT news-only forum - all off-topic, non-news posts will be removed. If you wish to ask a programming question please post it here.

Get The Daily Insider direct to your mailbox every day. Subscribe now!

 
GeneralRe: Avoid else, return early Pin
Tim Carmichael27-Mar-18 2:35
Tim Carmichael27-Mar-18 2:35 
GeneralRe: Avoid else, return early Pin
TheGreatAndPowerfulOz27-Mar-18 5:44
TheGreatAndPowerfulOz27-Mar-18 5:44 
GeneralRe: Avoid else, return early Pin
Tim Carmichael27-Mar-18 6:19
Tim Carmichael27-Mar-18 6:19 
GeneralRe: Avoid else, return early Pin
TheGreatAndPowerfulOz27-Mar-18 7:15
TheGreatAndPowerfulOz27-Mar-18 7:15 
GeneralRe: Avoid else, return early Pin
#realJSOP28-Mar-18 2:28
professional#realJSOP28-Mar-18 2:28 
GeneralRe: Avoid else, return early Pin
#realJSOP28-Mar-18 1:35
professional#realJSOP28-Mar-18 1:35 
GeneralRe: Avoid else, return early Pin
TheGreatAndPowerfulOz28-Mar-18 7:22
TheGreatAndPowerfulOz28-Mar-18 7:22 
GeneralRe: Avoid else, return early Pin
#realJSOP28-Mar-18 7:33
professional#realJSOP28-Mar-18 7:33 
TheGreatAndPowerfulOz wrote:
Here's were some judicious use of goto may be warranted.


Just say no to goto.

I typically define a result variable, and progress through the method setting that variable as appropriate. If I have a longish chain of if/else clauses I indent them like so:

C#
int result = 0;
if (condition)
{
}
else if (condition)
{
}
... and so on
return result;


If conditions are favorable, I'll use a switch statement instead of if/else, but I still try to have only one exit point (exceptions notwithstanding).

I also strive to keep my methods short and specific to the process/task described by the name of the method.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

GeneralRe: Avoid else, return early Pin
TheGreatAndPowerfulOz28-Mar-18 15:47
TheGreatAndPowerfulOz28-Mar-18 15:47 
GeneralRe: Avoid else, return early Pin
Dr.Walt Fair, PE6-Apr-18 13:18
professionalDr.Walt Fair, PE6-Apr-18 13:18 
GeneralRe: Avoid else, return early Pin
#realJSOP8-Apr-18 6:22
professional#realJSOP8-Apr-18 6:22 
GeneralRe: Avoid else, return early Pin
Dr.Walt Fair, PE30-Mar-18 5:36
professionalDr.Walt Fair, PE30-Mar-18 5:36 
GeneralRe: Avoid else, return early Pin
TheGreatAndPowerfulOz27-Mar-18 5:37
TheGreatAndPowerfulOz27-Mar-18 5:37 
GeneralRe: Avoid else, return early Pin
Joe Woodbury27-Mar-18 7:32
professionalJoe Woodbury27-Mar-18 7:32 
GeneralRe: Avoid else, return early Pin
Dominic Burford28-Mar-18 2:49
professionalDominic Burford28-Mar-18 2:49 
GeneralRe: Avoid else, return early Pin
S Douglas30-Mar-18 6:56
professionalS Douglas30-Mar-18 6:56 
NewsThe FTC confirms it’s investigating Facebook over its privacy practices Pin
Kent Sharkey26-Mar-18 7:45
staffKent Sharkey26-Mar-18 7:45 
GeneralRe: The FTC confirms it’s investigating Facebook over its privacy practices Pin
Nelek26-Mar-18 11:08
protectorNelek26-Mar-18 11:08 
GeneralRe: The FTC confirms it’s investigating Facebook over its privacy practices Pin
Kent Sharkey26-Mar-18 11:14
staffKent Sharkey26-Mar-18 11:14 
GeneralRe: The FTC confirms it’s investigating Facebook over its privacy practices Pin
Nelek26-Mar-18 11:18
protectorNelek26-Mar-18 11:18 
GeneralRe: The FTC confirms it’s investigating Facebook over its privacy practices Pin
Dr.Walt Fair, PE6-Apr-18 13:19
professionalDr.Walt Fair, PE6-Apr-18 13:19 
GeneralRe: The FTC confirms it’s investigating Facebook over its privacy practices Pin
Kent Sharkey6-Apr-18 14:22
staffKent Sharkey6-Apr-18 14:22 
NewsA critical analysis of the latest cellphone safety scare Pin
Kent Sharkey25-Mar-18 10:15
staffKent Sharkey25-Mar-18 10:15 
NewsNew web security standard promises safer, faster browsing Pin
Kent Sharkey25-Mar-18 10:15
staffKent Sharkey25-Mar-18 10:15 
NewsDevelopers are using CI more than CD, report finds Pin
Kent Sharkey25-Mar-18 10:15
staffKent Sharkey25-Mar-18 10:15 

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.