Click here to Skip to main content
15,905,322 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
charlieg23-Jan-17 12:05
charlieg23-Jan-17 12:05 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
Super Lloyd23-Jan-17 13:54
Super Lloyd23-Jan-17 13:54 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
BillWoodruff23-Jan-17 14:33
professionalBillWoodruff23-Jan-17 14:33 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
Pete O'Hanlon23-Jan-17 22:21
mvePete O'Hanlon23-Jan-17 22:21 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
BillWoodruff24-Jan-17 18:18
professionalBillWoodruff24-Jan-17 18:18 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
den2k8823-Jan-17 21:51
professionalden2k8823-Jan-17 21:51 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
OriginalGriff23-Jan-17 22:03
mveOriginalGriff23-Jan-17 22:03 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
den2k8823-Jan-17 22:20
professionalden2k8823-Jan-17 22:20 
Validation usually ends the function right there, I was speaking of the core of the function. In the end, for uniformity, I often change validation too to a single poit of exit - but once the code is something like

C++
int function(...){
  bool condition_ok = true;
  int returnvalue = ERR_OK;
  if (condition_ok) {
    // do phase 1
    if (failed) then {
      condition_ok = false;
      returnvalue = errcode1;
    }
  }

  if (condition_ok) {
    // do phase 2
    if (failed) then {
      condition_ok = false;
      returnvalue = errcode2;
    }
  }
  ...
  return returnvalue;
}

Then for uniformity it comes very easy to add validation also in this form. Functions like this are usually hardware initialization, connections, communications with retries and manual error corrections...
CALL APOGEE, SAY AARDWOLF
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver

"Go ahead, make my day"

GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
User 1013254623-Jan-17 23:55
User 1013254623-Jan-17 23:55 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
den2k8823-Jan-17 23:57
professionalden2k8823-Jan-17 23:57 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
User 1013254624-Jan-17 0:09
User 1013254624-Jan-17 0:09 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
den2k8824-Jan-17 0:15
professionalden2k8824-Jan-17 0:15 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
User 1013254624-Jan-17 0:19
User 1013254624-Jan-17 0:19 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
den2k8824-Jan-17 0:25
professionalden2k8824-Jan-17 0:25 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
User 1013254624-Jan-17 0:42
User 1013254624-Jan-17 0:42 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
den2k8824-Jan-17 0:49
professionalden2k8824-Jan-17 0:49 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
User 1013254624-Jan-17 0:54
User 1013254624-Jan-17 0:54 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
BillWoodruff25-Jan-17 17:49
professionalBillWoodruff25-Jan-17 17:49 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
Mark_Wallace23-Jan-17 22:48
Mark_Wallace23-Jan-17 22:48 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
den2k8823-Jan-17 23:10
professionalden2k8823-Jan-17 23:10 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
#realJSOP23-Jan-17 23:22
professional#realJSOP23-Jan-17 23:22 
GeneralRe: brain cells fading... article discussing the use of early returns from functions... Pin
den2k8823-Jan-17 23:27
professionalden2k8823-Jan-17 23:27 
GeneralRollercoaster... Pin
R. Giskard Reventlov23-Jan-17 10:52
R. Giskard Reventlov23-Jan-17 10:52 
GeneralRe: Rollercoaster... Pin
Mark_Wallace23-Jan-17 11:13
Mark_Wallace23-Jan-17 11:13 
GeneralRe: Rollercoaster... Pin
Sander Rossel23-Jan-17 11:18
professionalSander Rossel23-Jan-17 11:18 

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.