473,387 Members | 1,520 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,387 software developers and data experts.

writing a Sub versus writing a Function with no return value


Hi Everyone.

What is the real difference between writing a Sub versus writing a Function
with no return value?

It seems to me that both of these would need to compile to the same IL, so
it seems they are identical.

Please advise.

Thank you.

--Mark.
Nov 19 '05 #1
4 7693
"Mark Kamoski" <mk******@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

Hi Everyone.

What is the real difference between writing a Sub versus writing a Function with no return value?

It seems to me that both of these would need to compile to the same IL, so
it seems they are identical.


When you write code, do you write it based on how you know the IL will
result? The goal is to make your code easier to understand, if the resulting
IL is the same either way, that just makes a better argument to use the
proper mechanisms that are provided by the language. In some cases, you
write your code around IL because you know it will be mucked up other wise
(such is the case of constructors and private field initialization).

Why would you want to only use Functions? This is a step backwards. Here is
another question - Why use Properties if it is only a thin wrapper for a
public field (a property with no validation or logic)? Why use an event when
you can just use a manual Callback via the Win32 API? Why use strong
variable types? Why use Classes & objects, why not just write purely
procedural code? After all IL is just one long list of function calls right?

HTH,
Jeremy

Nov 19 '05 #2
"Mark Kamoski" <mk******@yahoo.com> schrieb
What is the real difference between writing a Sub versus writing a
Function with no return value?

It seems to me that both of these would need to compile to the same
IL, so it seems they are identical.

Please advise.


What is a function without a return value? Example?
--
Armin

Nov 19 '05 #3
Mark,
As Herfried suggests, have you looked at the code with ildasm.exe?

They are not identical, there is overhead in the function for the return
value, although you never explicitly use or set the return value, VB.NET
implicitly sets the return value.

Further I totally agree with Jeremy. Write code that indicates the intent.
If you have a 'function' that does not return a value, then make it a sub.
In 6 months you will be happier, and any one who takes over you code will be
happier. Otherwise someone may be spending the day, cursing your name 'This
routine never returns a value, what value should we be returning' :-)

Just a thought
Jay

"Mark Kamoski" <mk******@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

Hi Everyone.

What is the real difference between writing a Sub versus writing a Function with no return value?

It seems to me that both of these would need to compile to the same IL, so
it seems they are identical.

Please advise.

Thank you.

--Mark.

Nov 19 '05 #4
The other answers were good, but they weren't to the point. The real
difference between a sub and a function is that a function has a return
value and a sub does not. Functions are called as below:

myVar = myFunction(myArgumentList)
(ex. myInt = myIntCalc(Princ, Rate, Time)

where the return value is of the same type as myVar. Subs are called thus:

mySub(myArgumentList)
(ex. LoadTreeView(myNodes,myArr))

The argumentlist may contain variables that pass infomation between the
calling sub and the function or sub but these are not considered return
values. HTH

Kim

"Mark Kamoski" <mk******@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

Hi Everyone.

What is the real difference between writing a Sub versus writing a Function with no return value?

It seems to me that both of these would need to compile to the same IL, so
it seems they are identical.

Please advise.

Thank you.

--Mark.

Nov 19 '05 #5

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

Similar topics

7
by: franky.backeljauw | last post by:
Hello, I have the following code: <code> class X { ___ sin(); } X sin( X ) { return sin( y, x ); }
5
by: Phil Kelly | last post by:
Hi I need to write the contents of a structure to a binary file - there is one string and 2 integers, but I can't seem to figure out how to write the data correctly. If I am simply writing...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
6
by: Adam Honek | last post by:
Can anyone spot why the below function is failing? It returns true but when looking inside the INI file there's no new added section. ****CODE**** Public Function WriteINIFileSection(ByVal...
7
by: Matt Kowalczyk | last post by:
Hello, I am working on a compression project and I want to write ASCII characters using the minimum amount of bits. Since I will be writing ASCII characters from 0-127 I only need 7 bits to...
6
by: radhikutti | last post by:
Hi All, Please explain me the Adv and DisAdv between Procedures and functions Thanks in Advance Radhi
83
by: sunny | last post by:
Hi All What is C99 Standard is all about. is it portable, i mean i saw -std=C99 option in GCC but there is no such thing in VC++.? which one is better ANSI C / C99? can i know the major...
42
by: John Doty | last post by:
I realized that I have a little job on the table that is a fine test of the Python versus Standard Forth code availability and reusability issue. Note that I have little experience with either...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.