473,789 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1210
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.c o.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
3507
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 of the ones I looked, classified by how I would rewrite them (if I could): * Rewritable as def statements (<name> = lambda <args>: <expr> usage) These are lambdas used when a lambda wasn't needed -- an anonymous function was created with...
7
1909
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var decimalPointDelimiter = ".";
13
5060
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
3310
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 perfectly except when the component is deleted from the page. Here are the details. I add the component to the page from the toolbox and then add items using the collection editor. I can delete those items from the collection using the collection...
8
2495
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" type="text/javascript"> <!-- ; var newwindow = ''
18
3136
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 how global variables and function returns work... For example, I have a global array "char datestring;" which is defined in the function speakdate. speakdate just converts a set of integers (date variables) to a string.
669
26234
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
4
1577
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 of my form, test.cgi doesnt exsist but i think it should run the function before the action. Is this correct???
4
6697
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 = "Content-Type: text/html\r\n"; Why is the second const needed and what does it do? Thanks
9
1935
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 like this : (very simple..........) 010001010110001101010101010101010101010101 #include<stdio.h>
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.