473,405 Members | 2,310 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,405 software developers and data experts.

I don't like this behavior - implicitly returning value types

I just noticed this about value types and return values, and it kind
of bugs me that the compiler won't treat it as an error, even with
Option Strict On.

Try this out:

Option Strict On

Public Class MyClass

Private Sub ExtractionSettings_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox(MyProp.ToString())
End Sub

ReadOnly Property MyProp() As Int16
Get

End Get
End Property

End Class

This will compile and run perfectly fine (if I typed it right :-) ),
always showing 0 in the opening messagebox. I really wish that the IDE
would tell me that I didn't explicitly specify a return value for
MyProp. (Yes, I know it's a value type and therefore it has a value of
0 at instantiation so it is returning a value, and thus not violating
the return value rules).

Is there a setting I missed somewhere that I could use to flag this as
an error?

Thanks,

Seth Rowe

Jan 30 '07 #1
6 1063
On Jan 30, 3:02 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
I just noticed this about value types and return values, and it kind
of bugs me that the compiler won't treat it as an error, even with
Option Strict On.

Try this out:

Option Strict On

Public Class MyClass

Private Sub ExtractionSettings_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox(MyProp.ToString())
End Sub

ReadOnly Property MyProp() As Int16
Get

End Get
End Property

End Class

This will compile and run perfectly fine (if I typed it right :-) ),
always showing 0 in the opening messagebox. I really wish that the IDE
would tell me that I didn't explicitly specify a return value for
MyProp. (Yes, I know it's a value type and therefore it has a value of
0 at instantiation so it is returning a value, and thus not violating
the return value rules).

Is there a setting I missed somewhere that I could use to flag this as
an error?

Thanks,

Seth Rowe
Yeah I've noticed this too... I forget a return in a Get and I was
tired so I didn't notice for half an hour... I thought I was going
crazy ("WTF is there no value in that control?!?!') until I saw that
mistake... I just sorta grumbled and added the missing return.

Jan 30 '07 #2
On Jan 30, 1:02 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
I just noticed this about value types and return values, and it kind
of bugs me that the compiler won't treat it as an error, even with
Option Strict On.

Try this out:

Option Strict On

Public Class MyClass

Private Sub ExtractionSettings_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox(MyProp.ToString())
End Sub

ReadOnly Property MyProp() As Int16
Get

End Get
End Property

End Class

This will compile and run perfectly fine (if I typed it right :-) ),
always showing 0 in the opening messagebox. I really wish that the IDE
would tell me that I didn't explicitly specify a return value for
MyProp. (Yes, I know it's a value type and therefore it has a value of
0 at instantiation so it is returning a value, and thus not violating
the return value rules).

Is there a setting I missed somewhere that I could use to flag this as
an error?

Thanks,

Seth Rowe
I agree with you Seth, that this is bad behavior. There is no way to
"turn it off" that I know of. This, IMHO, is the result of trying to
stay compatabile with VB.CLASSIC. VB has always returned it's values
from functions/properties via assigning to the function name - if you
didn't assign then it returned the default value.

--
Tom Shelton

Jan 30 '07 #3
Tom Shelton wrote:
On Jan 30, 1:02 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
>I just noticed this about value types and return values, and it kind
of bugs me that the compiler won't treat it as an error, even with
Option Strict On.
.. . .
>Try this out:

ReadOnly Property MyProp() As Int16
Get

End Get
End Property
.. . .
>This will compile and run perfectly fine (if I typed it right :-) ),
always showing 0 in the opening messagebox. I really wish that the IDE
would tell me that I didn't explicitly specify a return value for
MyProp.
I agree with you Seth, that this is bad behavior. There is no way to
"turn it off" that I know of. This, IMHO, is the result of trying to
stay compatabile with VB.CLASSIC. VB has always returned it's values
from functions/properties via assigning to the function name - if you
didn't assign then it returned the default value.
Perhaps the next version of Visual Basic will insist on explicit Return
statements in property Get routines and will then complain that there's
no value returned on every code path... :-)

(Oh, there I go again; giving Our Friends in Redmond ideas...)

Regards,
Phill W.
Jan 31 '07 #4
On Jan 31, 8:07 am, "Phill W." <p-.-a-.-w-a-...@o-p-e-n-.-a-c-.-u-k>
wrote:
Tom Shelton wrote:
On Jan 30, 1:02 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
I just noticed this about value types and return values, and it kind
of bugs me that the compiler won't treat it as an error, even with
Option Strict On.
. . .
Try this out:
ReadOnly Property MyProp() As Int16
Get
End Get
End Property
. . .
This will compile and run perfectly fine (if I typed it right :-) ),
always showing 0 in the opening messagebox. I really wish that the IDE
would tell me that I didn't explicitly specify a return value for
MyProp.
I agree with you Seth, that this is bad behavior. There is no way to
"turn it off" that I know of. This, IMHO, is the result of trying to
stay compatabile with VB.CLASSIC. VB has always returned it's values
from functions/properties via assigning to the function name - if you
didn't assign then it returned the default value.

Perhaps the next version of Visual Basic will insist on explicit Return
statements in property Get routines and will then complain that there's
no value returned on every code path... :-)

(Oh, there I go again; giving Our Friends in Redmond ideas...)

Regards,
Phill W.
Perhaps the next version of Visual Basic will insist on explicit Return
statements in property Get routines and will then complain that there's
no value returned on every code path... :-)
You mean something like "Option C# Warnings On"

:-)

Thanks,

Seth Rowe
Jan 31 '07 #5
On Jan 30, 2:02 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
I just noticed this about value types and return values, and it kind
of bugs me that the compiler won't treat it as an error, even with
Option Strict On.

Try this out:

Option Strict On

Public Class MyClass

Private Sub ExtractionSettings_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox(MyProp.ToString())
End Sub

ReadOnly Property MyProp() As Int16
Get

End Get
End Property

End Class

This will compile and run perfectly fine (if I typed it right :-) ),
always showing 0 in the opening messagebox. I really wish that the IDE
would tell me that I didn't explicitly specify a return value for
MyProp. (Yes, I know it's a value type and therefore it has a value of
0 at instantiation so it is returning a value, and thus not violating
the return value rules).

Is there a setting I missed somewhere that I could use to flag this as
an error?

Thanks,

Seth Rowe
Seth,

I wonder if it's like that to keep as much compatibility with VB6 as
possible. Though, you'd think a warning would be an acceptable
compromise.

Brian
Jan 31 '07 #6
On Jan 31, 6:07 am, "Phill W." <p-.-a-.-w-a-...@o-p-e-n-.-a-c-.-u-k>
wrote:
Tom Shelton wrote:
On Jan 30, 1:02 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
I just noticed this about value types and return values, and it kind
of bugs me that the compiler won't treat it as an error, even with
Option Strict On.
. . .
Try this out:
ReadOnly Property MyProp() As Int16
Get
End Get
End Property
. . .
This will compile and run perfectly fine (if I typed it right :-) ),
always showing 0 in the opening messagebox. I really wish that the IDE
would tell me that I didn't explicitly specify a return value for
MyProp.
I agree with you Seth, that this is bad behavior. There is no way to
"turn it off" that I know of. This, IMHO, is the result of trying to
stay compatabile with VB.CLASSIC. VB has always returned it's values
from functions/properties via assigning to the function name - if you
didn't assign then it returned the default value.

Perhaps the next version of Visual Basic will insist on explicit Return
statements in property Get routines and will then complain that there's
no value returned on every code path... :-)

(Oh, there I go again; giving Our Friends in Redmond ideas...)

Regards,
Phill W.- Hide quoted text -

- Show quoted text -
Not a bad idea. IMHO, it should just be incorporated into option
strict. That already makes a lot of code not vb.classic compliant
anyway :)

--
Tom Shelton

Jan 31 '07 #7

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

Similar topics

14
by: Clay_Culver | last post by:
My professor claims that this code: int f() { int x = 5; int &y = x; x += ++y; return x; }
16
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't...
7
by: jammie_linux | last post by:
Hi, Please look at the following code. In my opinion, the value of "char *str" in the main function should not change even after calling the function "funct" and that's beacuse the "char *str" in...
22
by: Christoph Boget | last post by:
I am getting an error (a few among many) for the following lines of code: retval.BrokerName = (( curRow == System.DBNull.Value ) ? SqlString.Null : (string)curRow ); retval.BrokerGroupId = ((...
0
by: Clay_Culver | last post by:
I have a function which needs to return different values but that takes no arguments, this is the function: template <class T> T funct(); For each type T for different types, there are...
9
by: ais523 | last post by:
I have some code, which I know will not work (I haven't included <math.h>, so sqrt will be assumed to return an int). What I want to know is, is an ANSI-compliant implementation required to produce...
6
by: Sree | last post by:
If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output? main(int argc, char *argv) { int i; for(i=0;i<argc;i++) printf("%s",argv); }
10
by: subramanian100in | last post by:
Consider the following code: #include <iostream> #include <cstdlib> using namespace std; int main() { const double& ref = 100;
3
by: c.lang.myself | last post by:
#include <stdio.h> float puzzle( float inp ) { const float ths = 1.5F; const long k = 21*76069667; float a, b; int c;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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,...
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...

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.