On Wed, Jan 4, 2012 at 8:35 AM, Lukasz Sokol <el.es...@gmail.com> wrote: > > On 04/01/2012 00:31, Marcos Douglas wrote: > [...] > >> Another interesting article is: > >> http://www.joelonsoftware.com/items/2003/10/13.html > > > > Very interesting and I agree when he say: > > "I think the reason programmers in C/C++/Java style languages have > > been attracted to exceptions is simply because the syntax does not > > have a concise way to call a function that returns multiple values, so > > it's hard to write a function that either produces a return value or > > returns an error." > > > > If we could return more than one value, ok we (maybe) do not need > > Exceptions. > > > > Marcos Douglas > > I find myself often doing either: > > function Bla(parameters): integer; > - > returns => 0 for success/value returned, < 0 for error and upper layers > recognize the error codes > (this is pretty much like c common usage you can find in c programs) > or > function Bla(some_params; out ErrorMessage: string):boolean; > or > function Bla(some_params; out ErrorCode: integer): > some_type_other_than_integer; > > so it's not like you /can't/ return more than one value... > but you need to prepare yourself for it ;)
Ok, I expressed myself poorly. When I said: "If we could return more than one value, ok we (maybe) do not need Exceptions." I mean: "If we could return more than one value, using a better way than 'out arguments' or 'array of const', ok we (maybe) do not need Exceptions in many times". I know we can use 'out args', 'array' or a object (this provides many results) but this is not beautiful. 1- out args: we always have a local variable ErrorCode/ErrorMsg (like your example) and this is boring. 2- array of const: we need 'unpack' the array; memleak could happen; etc; 3- object: we have a local variabel or use 'with' but memleak could happen any way; Marcos Douglas _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal