473,703 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why there's no "Function does not return value" warning?

Hi all,

I think the VB .NET compiler should at least issue a warning when a function
does not return value. C# and C++ compilers treat this situation as an error
and I believe this is the right thing to do. And I wonder why VB .NET keeps
silence and makes such function return some default value instead. Isn't it
error-prone?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Nov 20 '05 #1
5 8085
Have you switched on option strict?

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote
in message news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Hi all,

I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right thing to do. And I wonder why VB .NET keeps silence and makes such function return some default value instead. Isn't it error-prone?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Nov 20 '05 #2
Actually, forget that, I just tried it and even though strict is on, I still
don't get a compile time error that nothing was returned.

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote
in message news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Hi all,

I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right thing to do. And I wonder why VB .NET keeps silence and makes such function return some default value instead. Isn't it error-prone?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Nov 20 '05 #3
Dmitriy,
And I wonder why VB .NET keeps
silence and makes such function return some default value instead. Isn't it error-prone? Because VB.NET has defined a 'hidden' variable that is returned by the
function, this variable is the same name as the function. If you do not use
the Return statement, this variable is returned automatically. If you do not
set the variable the default value is used. So the check cannot simply check
for no Return statement, it would need to check that all code paths have set
this hidden variable or used the Return statement.

Is it error-prone, yes. This is one of those things I see value in a Code
Critic/Code Analyzer/Lint type products that ensures that all functions have
a return value, among other things. Rather then an outright compile warning.

Hope this helps
Jay
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote
in message news:%2******** *******@TK2MSFT NGP11.phx.gbl.. . Hi all,

I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right thing to do. And I wonder why VB .NET keeps silence and makes such function return some default value instead. Isn't it error-prone?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Nov 20 '05 #4
In article <#H************ *@TK2MSFTNGP11. phx.gbl>, Dmitriy Lapshin [C# / .NET MVP] wrote:
Hi all,

I think the VB .NET compiler should at least issue a warning when a function
does not return value. C# and C++ compilers treat this situation as an error
and I believe this is the right thing to do. And I wonder why VB .NET keeps
silence and makes such function return some default value instead. Isn't it
error-prone?


Yes it is error prone, and I agree with you. I don't know if this is an
attempt to stay compatible with VB.CLASSIC code - but I wish there was
at least an option to change this behavior.

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #5
> Is it error-prone, yes. This is one of those things I see value in a Code
Critic/Code Analyzer/Lint type products that ensures that all functions have
Jay, this reminds me of I bug I encountered in my own code because of this
behaviour.
To digresss a little, here is an excerpt of the MSHelp documentation.
If you use Exit Function [ed. or exit a function without returning a value]
without assigning a value to name, the function returns the default value
appropriate to argtype. This is 0 for Byte, Char, Decimal, Double, Integer,
Long, Short, and Single; Nothing for Object, String, and all arrays; False
for Boolean; and #1/1/0001 12:00 AM# for Date.
After reading this I naively thought I would end up with two dialog boxes
saying "01/01/0001 ..", 0, and throw an exception when attempting to display
the third dialog (casting Nothing.ToStrin g() throwing an Exception). But no!
Public Class Form1
Inherits System.Windows. Forms.Form

'= Windows Form Designer generated code

Private Function test1() As Date
End Function

Private Function test2() As Integer
End Function

Private Function test3() As AcceptRejectRul e
End Function

Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
MsgBox("test1=" + test1.ToString( ))
MsgBox("test2=" + test2.ToString( ))
MsgBox("test3=" + test3.ToString( ))
End Sub
End Class

We can explain the behaviour but never-the-less, a trap for young players.
Hexathioorthoox alate


"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:u7******** ******@TK2MSFTN GP10.phx.gbl... Dmitriy,
And I wonder why VB .NET keeps
silence and makes such function return some default value instead. Isn't it
error-prone?

Because VB.NET has defined a 'hidden' variable that is returned by the
function, this variable is the same name as the function. If you do not

use the Return statement, this variable is returned automatically. If you do not set the variable the default value is used. So the check cannot simply check for no Return statement, it would need to check that all code paths have set this hidden variable or used the Return statement.

Is it error-prone, yes. This is one of those things I see value in a Code
Critic/Code Analyzer/Lint type products that ensures that all functions have a return value, among other things. Rather then an outright compile warning.
Hope this helps
Jay
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote
in message news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Hi all,

I think the VB .NET compiler should at least issue a warning when a

function
does not return value. C# and C++ compilers treat this situation as an

error
and I believe this is the right thing to do. And I wonder why VB .NET

keeps
silence and makes such function return some default value instead. Isn't

it
error-prone?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE



Nov 20 '05 #6

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

Similar topics

8
3701
by: c | last post by:
RH9, Apache 2.0.49, php 4.3.6 been away from php for about 2 years and this way used to work, still does in older php versions, now it doesn't. is there a reason for this? a work around? Thanx in Advance!!
6
9760
by: kelvSYC | last post by:
This little bit of seeminly innocent code seems to give me these two errors, all on the line that declares check(). Is there some part of C++ that I'm missing out on? class Condition { public: Condition() {} virtual ~Condition() {} virtual bool check() const;
13
3081
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled across "null" string. I know that I will get an "undefined" when I try to retrieve something from the DOM which doesn't exist. I have used null myself to initialize or reset variables. But in which
11
2651
by: ajikoe | last post by:
Hello, I used Visual C# Standard Edition. I want to comment my program using xml commentary method, I don't know why if I use value and example tag, it is not working / showed in the html result. for example I have Property ///<value>this is in description</value> ///<example>this is in Example</example> public int A{
10
2188
by: mdh | last post by:
Quick question about pointers. Wrote this "trying to understand this better" code: int *ptr, x = 565; ptr= &x; printf("\n\n\nThe value of x is %d\n", x);
13
38592
by: alvin.yk | last post by:
Hi, Normally, a piece of code such as <a href="http://www.yahoo.com" onclick="alert('hello');return false;">link</a> will stop the browser from actually going to href's destination. However, this is not the case with the IE7 I am using. What has changed?
21
2407
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the C++ Standard: "" "...sequence of operators and operands that specifies a computation...". That means to me that an expression can be "executed". I am purposely
8
1637
by: mdh | last post by:
May I ask this. Given the declaration: int myf( int, int); and a function pointer: (*fp)=int myf(int, int); where I am initializing fp to point at myf....or trying to..
3
10369
by: moltendorf | last post by:
I copied the files from my "test" database on my old server (MySQL was not running) to my new server ("./mysql/data/test" folder), and after starting the server, SHOW TABLES; shows all of the tables that are supposed to be there, but running a SELECT * FROM `configuration`; (for example) returns "test.configuration does not exist). I've tried the following repair statement since I'm not too familiar with backing up and restoring data. ...
0
8739
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8983
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8941
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
7832
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
6575
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
5910
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
4668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2406
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2037
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.