Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Aug 16th, 2005, 11:49 AM   #1
Arla
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 166
Rep Power: 4 Arla is on a distinguished road
Recommended Practice for returning data from function

Okay, so I've been thinking this through quite a bit, and have a few questions

I have some functions, that essentially return two disparate sets of data, one set of data is the error messages, which are standard across every function I write, the other is the actual data (these are database functions, so mostly return table data).

What I'm trying to work out is the best way to return this data, now it seems I have about three options.

1. Return error data from function as in (assume ErrorData is some sort of data structure)

public ErrorData Function(int x, int y, int z)

I like this approach at least for the ErrorData because it allows me to assign the return to a variable and immediately reference it, the other option would be to have it as a :out from the function eg

public void Function (int x, int y, int z, out ErrorData errors)

or even Ref (although since in my code errors start at the lowest level of the program and bubble up, I'd never have any need to pass the errors in).

Now same goes for the "return" data, the only issue being that having two sets of returns from a function isn't possible, so then I either have to create another class that contains both the error data and the return data, or I have to return one of them with out or ref parameter.

Alternatively, I can make variables inside the functions class public, and just reference them, however I don't like that as it seems to me it allows for them to change without necessarily meaning it (global variables).

So any thoughts? Currently I'm thinking maybe that passing the errors as the return from the function, and using out in the function for the return data, however a lot of things say "NEVER USE OUT parameters" but never seem to say why they are bad.
Arla is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC