Michael Chesterton wrote:

> 
> Is there some sort of common practice about where to return from
> a function?

My opnions follow. Other may disagree.

For short functions like the one in your example it simply does
not matter.

For longer functions (say 100 lines) I feel quite comfortable about
having returns at the start and at the end of a function but try
to avoid having returns in the middle of a function.

> Same with exiting a program, I take it it's better to do something like
> 
> if(!foo())
>  exit(1)
> 
> as apposed to exiting from within foo?

As long as you print an error message before exiting, this is much 
less critical. Exiting outside potentially makes foo() reusable as
a function that exits under some circumstances and not others.

Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
I have now spent two days debugging C# on dotnot and all I can say
is OMFG!!!! The MS tools are completely fucking abysmal. Its the
most developer hostile environment I've ever worked on. The fact 
that people are actually able to release software that sort of 
works using these tools completely boggles my mind.
_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders

Reply via email to