How to write function neatly? considering log, one return, no more indentation?
> There is a function Foo, Foo first calls Bar(), and then some
> statements; then Foo calls Walk(), and then some statemenets;

then Foo calls Run(), and then some statements; then Foo calls Fly, and then some stamentments.

There some ways, I can write Foo(), As it shows. Some one is clean, but it doesn't safe, some one is really ugly somehow, but it 
records all the logs, I really  confused about this. 

Which one is better and Do you have a better idea?

Can anyone help me ?

I have thought this problem from five dimention, (clean[no unnecessary indentation]), (one return), (no goto), (print log), (check return value).
But I still confused. 
Does goto a really problem??
Is it neccesary to log everything?

fig1
Pros. Clean.
cons. no log & doesn't check return value

    int Foo()
    {
    	Bar();
    	// aStatement;
    	Walk();
    	// bStatement;
    	Run();
    	// cStatement;
    	Fly();
    	// dStatement;
    	return;
    }

fig2
Pros. clean & log.
Cons. Multi return.

    int Foo() {
    	int status;
    	satatus = Bar();
    	if (!OK(status)) {
    		Log("...");
    		return status;
    	}
    	// aSatement
    	status = Walk();
    	if (!OK(status)) {
    		Log("...");
    		return status;
    	}
    	// bStatement
    	status = Run();
    	if (!OK(status)) {
    		Log("...");
    		return status;
    	}
    	// cStatement
    	status = Fly();
    	if (!OK(status)) {
    		Log("...");
    		return status;
    	}
    	// dSatement
    	return status;
    }

fig3
pros. clean & log
cons. goto problem

    int Foo() {
    	int status;
    	satatus = Bar();
    	if (!OK(status)) {
    		Log("...");
    		goto RETLINE;
    	}
    	// aSatement
    	status = Walk();
    	if (!OK(status)) {
    		Log("...");
    		goto RETLINE;
    	}
    	// bStatement
    	status = Run();
    	if (!OK(status)) {
    		Log("...");
    		goto RETLINE;
    	}
    	// cStatement
    	status = Fly();
    	if (!OK(status)) {
    		Log("...");
    		goto RETLINE;
    	}
    	// dSatement
    RETLINE:
    	return status;
    }

fig4
pros. use do while, no multi return
cons. more indentation 

    int Foo() {
    	int status;
    	
    	do {
    		status = Bar();
    		if (!OK(status)) {
    			Log("...");
    			break;
    		}
    		// aStatement
    		status = Walk();
    		if (!OK(status)) {
    			Log("...");
    			break;
    		}
    		status = Run();
    		if (!OK(status)) {
    			Log("...");
    			break;
    		}
    		// cStatement
    		status = Fly();
    		if (!OK(status)) {
    			Log("...");
    			break;
    		}
    		// dStatement
    	} while(false);
    	return status;
    }

fig 5
pros. clean & one return
cons. no log

    int Foo() {
    	int status;
    	status = Bar();
    	if (Ok(status)) {
    		status = Walk();
    		// aStatement
    	}
    	if (OK(status)) {
    		// bStatement
    		status = Run();
    	}
    	if (OK(status)) {
    		// cStatement
    		status = Fly();
    	}
    	if (Ok(status)) {
    		// dStatement
    	}
    	return status;
    }

fig 6
pros. log & one return
cons. more indentation

    int Foo() {
    	int status;
    	
    	status = Bar();
    	if (!OK(status)) {
    		Log("...");
    	}
    	if (Ok(status)) {
    		// aStatement
    		status = Walk();
    		if (!OK(status)) {
    			Log("...");
    		}
    	}
    	if (OK(status)) {
    		// bStatement
    		status = Run();
    		if (!OK(status)) {
    			Log("...");
    		}
    	}
    	if (Ok(status)) {
    		// cStatement
    		status = Fly();
    		if (!OK(status)) {
    			Log("...");
    		}
    	}
    	if (Ok(status)) {
    		// dStatement
    	}
    	return status;
    }

fig7
pros. log & one return
cons. more indentation

    int Foo() {
    	bool flag = true;
    	int status;
    	status = Bar();
    	if (!OK(status)) {
    		Log("...");
    		flag = false;
    	}
    	if (flag) {
    		// aStatement
    		status = Walk();
    		if (!OK(status)) {
    			Log("...");
    			flag = false;
    		}
    	}
    	if (flag) {
    		// bStatement
    		status = Run();
    		if (!OK(status)) {
    			Log("...");
    			flag = false;
    		}
    	}
    	
    	if (flag) {
    		// cStatement
    		status = Fly();
    		if (!Ok(status)) {
    			Log("...");
    			flag = false;
    		}
    	}
    	if (flag) {
    		// dStatment
    	}
    	return status;
    }







How to write function neatly? considering log, one return, no more indentation?
===

> There is a function Foo, Foo first calls Bar(), and then some
> statements; then Foo calls Walk(), and then some statemenets;

then Foo calls Run(), and then some statements; then Foo calls Fly, and then some stamentments.

There some ways, I can write Foo(), As it shows. Some one is clean, but it doesn't safe, some one is really ugly somehow, but it 
records all the logs, I really  confused about this. 

Which one is better and Do you have a better idea?

Can anyone help me ?

I have thought this problem from five dimention, (clean[no unnecessary indentation]), (one return), (no goto), (print log), (check return value).
But I still confused. 
Does goto a really problem??
Is it neccesary to log everything?

fig1
Pros. Clean.
cons. no log & doesn't check return value

    int Foo()
    {
    	Bar();
    	// aStatement;
    	Walk();
    	// bStatement;
    	Run();
    	// cStatement;
    	Fly();
    	// dStatement;
    	return;
    }

fig2
Pros. clean & log.
Cons. Multi return.

    int Foo() {
    	int status;
    	satatus = Bar();
    	if (!OK(status)) {
    		Log("...");
    		return status;
    	}
    	// aSatement
    	status = Walk();
    	if (!OK(status)) {
    		Log("...");
    		return status;
    	}
    	// bStatement
    	status = Run();
    	if (!OK(status)) {
    		Log("...");
    		return status;
    	}
    	// cStatement
    	status = Fly();
    	if (!OK(status)) {
    		Log("...");
    		return status;
    	}
    	// dSatement
    	return status;
    }

fig3
pros. clean & log
cons. goto problem

    int Foo() {
    	int status;
    	satatus = Bar();
    	if (!OK(status)) {
    		Log("...");
    		goto RETLINE;
    	}
    	// aSatement
    	status = Walk();
    	if (!OK(status)) {
    		Log("...");
    		goto RETLINE;
    	}
    	// bStatement
    	status = Run();
    	if (!OK(status)) {
    		Log("...");
    		goto RETLINE;
    	}
    	// cStatement
    	status = Fly();
    	if (!OK(status)) {
    		Log("...");
    		goto RETLINE;
    	}
    	// dSatement
    RETLINE:
    	return status;
    }

fig4
pros. use do while, no multi return
cons. more indentation 

    int Foo() {
    	int status;
    	
    	do {
    		status = Bar();
    		if (!OK(status)) {
    			Log("...");
    			break;
    		}
    		// aStatement
    		status = Walk();
    		if (!OK(status)) {
    			Log("...");
    			break;
    		}
    		status = Run();
    		if (!OK(status)) {
    			Log("...");
    			break;
    		}
    		// cStatement
    		status = Fly();
    		if (!OK(status)) {
    			Log("...");
    			break;
    		}
    		// dStatement
    	} while(false);
    	return status;
    }

fig 5
pros. clean & one return
cons. no log

    int Foo() {
    	int status;
    	status = Bar();
    	if (Ok(status)) {
    		status = Walk();
    		// aStatement
    	}
    	if (OK(status)) {
    		// bStatement
    		status = Run();
    	}
    	if (OK(status)) {
    		// cStatement
    		status = Fly();
    	}
    	if (Ok(status)) {
    		// dStatement
    	}
    	return status;
    }

fig 6
pros. log & one return
cons. more indentation

    int Foo() {
    	int status;
    	
    	status = Bar();
    	if (!OK(status)) {
    		Log("...");
    	}
    	if (Ok(status)) {
    		// aStatement
    		status = Walk();
    		if (!OK(status)) {
    			Log("...");
    		}
    	}
    	if (OK(status)) {
    		// bStatement
    		status = Run();
    		if (!OK(status)) {
    			Log("...");
    		}
    	}
    	if (Ok(status)) {
    		// cStatement
    		status = Fly();
    		if (!OK(status)) {
    			Log("...");
    		}
    	}
    	if (Ok(status)) {
    		// dStatement
    	}
    	return status;
    }

fig7
pros. log & one return
cons. more indentation

    int Foo() {
    	bool flag = true;
    	int status;
    	status = Bar();
    	if (!OK(status)) {
    		Log("...");
    		flag = false;
    	}
    	if (flag) {
    		// aStatement
    		status = Walk();
    		if (!OK(status)) {
    			Log("...");
    			flag = false;
    		}
    	}
    	if (flag) {
    		// bStatement
    		status = Run();
    		if (!OK(status)) {
    			Log("...");
    			flag = false;
    		}
    	}
    	
    	if (flag) {
    		// cStatement
    		status = Fly();
    		if (!Ok(status)) {
    			Log("...");
    			flag = false;
    		}
    	}
    	if (flag) {
    		// dStatment
    	}
    	return status;
    }






