473,412 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

What type is best for the return value of a function?

A question that I'm in two minds about - maybe someone more
experienced could offer some advice?

Let's say I have a method in a class whose function is to generate an
image (But it could equally apply to any more complex object that the
method might generate.)

Then it seems to me that I have two options:

1. Set the image as the return value for the function.

2. Have the function update a class property with the new image and
return eg an integer value to denote success or otherwise of the call
to the function.

I'm kind of leaning towards the second option. Although it seems less
elegant and less concise, using an integer as the return value does
give me the option to test the call for different types of errors that
might have occurred in generating the image and then take appropriate
action.

Anyone care to comment on what might be reckoned to be the better
programming practice?

JGD
Jun 30 '06 #1
3 1194
1. Set the image as the return value for the function. I would do this and in addition I would throw an exception from this
function in the case of any error. You can define separate exception for
each kind of error.
2. Have the function update a class property with the new image and
return eg an integer value to denote success or otherwise of the call
to the function.


If you don't want to use exception, use class or structure as return
value. The class can contain image and integer, e.g.:
Class MyImage
Public img as Image
Public errorCode as Integer
End class
--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Jun 30 '06 #2
My personal preference would be to return an image and use Exceptions to
signal an error...

--
Patrice

"John Dann" <ne**@prodata.co.uk> a crit dans le message de news:
1r********************************@4ax.com...
A question that I'm in two minds about - maybe someone more
experienced could offer some advice?

Let's say I have a method in a class whose function is to generate an
image (But it could equally apply to any more complex object that the
method might generate.)

Then it seems to me that I have two options:

1. Set the image as the return value for the function.

2. Have the function update a class property with the new image and
return eg an integer value to denote success or otherwise of the call
to the function.

I'm kind of leaning towards the second option. Although it seems less
elegant and less concise, using an integer as the return value does
give me the option to test the call for different types of errors that
might have occurred in generating the image and then take appropriate
action.

Anyone care to comment on what might be reckoned to be the better
programming practice?

JGD

Jun 30 '06 #3
im in full agreement that you should use a return value from a function. this
makes the code alot more readable without jumping around too much. also
easier to maintain
--
-iwdu15
Jun 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Steven Bethard | last post by:
I thought it might be useful to put the recent lambda threads into perspective a bit. I was wondering what lambda gets used for in "real" code, so I grepped my Python Lib directory. Here are some...
7
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
2
by: S. Justin Gengo | last post by:
Hi, I've created a component that allows me to store database information for various types of databases my company uses. It uses a collection for each type of database. Everything is working...
8
by: johnsonholding | last post by:
Here is the code for a pop-up window that works in Firefox and not in IE - I get a java error or something, Here is the code : </script> <SCRIPT language="JavaScript"...
18
by: ben.carbery | last post by:
Hi, I have just written a simple program to get me started in C that calculates the number of days since your birthdate. One thing that confuses me about the program (even though it works) is...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
4
by: brian | last post by:
i broke down where i think the problems areas would be. any help would be greatly appreciated. where the file is called <script type="text/javascript" src="k.js"> </script> the beginning...
4
by: grizggg | last post by:
I have searched and not found an answer to this question. I ran upon the following statement in a *.cpp file in a member function: static const char * const pacz_HTMLContentTypeHeader =...
9
by: xiao | last post by:
It always dumped when I tried to run it... But it compiles OK. What I want to do is to do a test: Read information from a .dat file and then write it to another file. The original DAT file is...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.