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

Function versus ReadOnly Property

Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property

instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function

Jun 7 '06 #1
12 2267
> Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property
instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function


One practical reason is that ASP can't bind to a function (or at least it
couldn't, haven't played with ASP 2.0 enough if this is no longer the case).
Jun 7 '06 #2
Hi,

In addition to Jim comments I really dont think it is good form to
have a property that has a parameter.

Ken
------------------

"er**********@gmail.com" wrote:
Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property

instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function

Jun 7 '06 #3
Hello er**********@gmail.com,

As a general rule of thumb, use a property when
1. You do not need to pass parameters (unless of course the data type is
a collection/list and the parameter is the item index)
2. You do not need to do any processing

If conditions 1 or 2 fail then use a function.

-Boo
Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property
instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function

Jun 8 '06 #4
Eric,

Functions do not what properties do by instance they are not serialized do
not show up in property boxes.

In my idea therefore in a class that will be used more times there should be
ever used forever properties.
In by instance a login showdialog window I do not see direct the sense.

Just my 2 Euro cents.

Cor

<er**********@gmail.com> schreef in bericht
news:11**********************@j55g2000cwa.googlegr oups.com...
Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property

instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function

Jun 8 '06 #5

er**********@gmail.com wrote:
Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property

instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function


Any particular reason you've used ByRef in these snippets? ByVal should
be your preferred default.

--
Larry Lard
Replies to group please

Jun 8 '06 #6
<er**********@gmail.com> schrieb:
Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property

instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function

That's hard to say based on the sample you posted. IMO the decision between
a function and a property should be driven by the semantics of the member.
Attributes of an entity (class) should be implemented as properties and
operations the entity can perform should be implemented as methods.
However, there are some other practical guidelines too:

* Setting or getting a property should not involve time and resource
consuming operations.

* Setting or getting a properts should not change an object's state
except the property value. In other words, setting or getting a
property value should not have any hard-to-see side-effects.

VB.NET 2002/2003 do not support declaring the 'Get' and 'Set' accessors of a
property with different scopes. So sometimes it's necessary to implement
either 'Set' or 'Get' as a function to archieve different scopes for 'Set'
and 'Get'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 8 '06 #7
On 2006-06-07, er**********@gmail.com <er**********@gmail.com> wrote:
Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property

instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function


In addition to Herfried's comments, I'd add that Properties really
shouldn't take parameters except for simple keys and indexes. Otherwise
function syntax makes a lot more sense.

BTW, why is MyParam declared ByRef in the above?
Jun 8 '06 #8

I am currently working in a project team where everyone is passing
parameters byref
i told them about the possible bugst this might raise but they said , it is
obvious to me what is happening and byref is faster as byval so ....

well euhhh ,,, yeah .... point ......

if someone has a good counter to this logic be my guest
regards

Michel Posseth [MCP]

"david" <da***@woofix.local.dom> schreef in bericht
news:sl******************@localhost.localdomain...
On 2006-06-07, er**********@gmail.com <er**********@gmail.com> wrote:
Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property

instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function


In addition to Herfried's comments, I'd add that Properties really
shouldn't take parameters except for simple keys and indexes. Otherwise
function syntax makes a lot more sense.

BTW, why is MyParam declared ByRef in the above?

Jun 11 '06 #9
The performance difference between byref and byval is negligible. You
should always use ByVal for clarity and code correctness. Unfortunately,
until you can show a code bug as a result of byref, you won't win this
argument. As for using functions vs. ReadOnly properties, it really depends
on what syntax you're looking for. Note that properties won't let you use
byref.

Mike Ober.

"Michel Posseth [MCP]" <MS**@posseth.com> wrote in message
news:Oe**************@TK2MSFTNGP05.phx.gbl...

I am currently working in a project team where everyone is passing
parameters byref
i told them about the possible bugst this might raise but they said , it is obvious to me what is happening and byref is faster as byval so ....

well euhhh ,,, yeah .... point ......

if someone has a good counter to this logic be my guest
regards

Michel Posseth [MCP]

"david" <da***@woofix.local.dom> schreef in bericht
news:sl******************@localhost.localdomain...
On 2006-06-07, er**********@gmail.com <er**********@gmail.com> wrote:
Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property

instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function


In addition to Herfried's comments, I'd add that Properties really
shouldn't take parameters except for simple keys and indexes. Otherwise
function syntax makes a lot more sense.

BTW, why is MyParam declared ByRef in the above?



Jun 11 '06 #10

Michel Posseth [MCP] wrote:
I am currently working in a project team where everyone is passing
parameters byref
i told them about the possible bugst this might raise but they said , it is
obvious to me what is happening and byref is faster as byval so ....
Is it? Have they checked? Can they prove it?
if someone has a good counter to this logic be my guest


I tend to struggle to deal logically with people who are prepared to
break semantic contracts for illusory (and even if not illusory,
negligible) performance gains.

--
Larry Lard
Replies to group please

Jun 12 '06 #11
Larry,

Michel Posseth [MCP] wrote:
I am currently working in a project team where everyone is passing
parameters byref
i told them about the possible bugst this might raise but they said , it
is
obvious to me what is happening and byref is faster as byval so ....


Is it? Have they checked? Can they prove it?
if someone has a good counter to this logic be my guest


I tend to struggle to deal logically with people who are prepared to
break semantic contracts for illusory (and even if not illusory,
negligible) performance gains.


I was writing the same, but did not, it would not help Michel at all.

In my ideas shows it a very big gap in knowledge with the people Michel has
to deal with while he probaly knows himself all in and outs.

Here is by the way a messagethread which is in my idea very complete.

http://groups.google.com/group/micro...7401cc7316d84e

Cor
Jun 12 '06 #12
Michel,
I would recommend you & your team review:

http://www.yoda.arachsys.com/csharp/parameters.html

Yes its C#, however the concepts on what ByRef (reference) & ByVal (value)
parameters are verses Reference types & Value types. Unfortunately far too
many developers confuse ByRef parameters with Reference Types.
I recommend only using ByRef when you actually need ByRef, that is when you
intend on changing the caller's variable itself. Anything else is simply
misleading & confusing programming.

Remember that ByVal & ByRef are how you pass parameters, Reference Types &
Value types are have values are stored...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Michel Posseth [MCP]" <MS**@posseth.com> wrote in message
news:Oe**************@TK2MSFTNGP05.phx.gbl...
|
| I am currently working in a project team where everyone is passing
| parameters byref
| i told them about the possible bugst this might raise but they said , it
is
| obvious to me what is happening and byref is faster as byval so ....
|
| well euhhh ,,, yeah .... point ......
|
| if someone has a good counter to this logic be my guest
|
|
| regards
|
| Michel Posseth [MCP]
|
| "david" <da***@woofix.local.dom> schreef in bericht
| news:sl******************@localhost.localdomain...
| > On 2006-06-07, er**********@gmail.com <er**********@gmail.com> wrote:
| >> Is there any reason to use:
| >>
| >> Private newPropertyValue As Integer
| >> Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
| >> Integer
| >> Get
| >> Return newPropertyValue
| >> End Get
| >> End Property
| >>
| >> instead of:
| >>
| >> Dim MyValue as Integer
| >> Public Function MyFunction(ByRef MyParam as Integer) As Integer
| >> Return MyValue
| >> End Function
| >
| > In addition to Herfried's comments, I'd add that Properties really
| > shouldn't take parameters except for simple keys and indexes. Otherwise
| > function syntax makes a lot more sense.
| >
| > BTW, why is MyParam declared ByRef in the above?
| >
| >
|
|
Jun 14 '06 #13

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

Similar topics

6
by: | last post by:
Hello, I am new to object oriented programming and .net. I have a question concerning using singletons. Lets say I have the following: public class Engine { public static readonly Engine...
10
by: GP | last post by:
Is it possible to iterate through all the controls collection and make the textboxes alone as read only.I don't see a readonly property for the Control.Can some one help me in this context? I...
4
by: Woody Splawn | last post by:
How would I pass an array back to a sub routine from a function? That is, I have a function that looks like this Public Function arrayTest() As Array Dim states() As String = { _ "AZ", "CA",...
2
by: Marcin Floryan | last post by:
I am creating a custom control (Inherits UserControl) and my control containt a TextBox control. TextBox control has a Property called "ReadOnly". I would like to expose this property outside my...
5
by: fred | last post by:
With a Class is there any difference between a readonly property and function besides having to use Get/End Get. Are there any performance/resource advantages for either. Thanks Fred
1
by: Paul | last post by:
Aside from a property being able to show up in the forms designer, is there any reason - other than adhering to a particular coding convention for its own sake - to use a readonly property instead...
27
by: sklett | last post by:
I just found myself doing something I haven't before: <code> public uint Duration { get { uint duration = 0; foreach(Thing t in m_things) { duration += t.Duration;
49
by: Emmett | last post by:
I am working with a .NET development team and I am looking for reasons, that I can present to management, as to why we should develop our software using C# rather than VB.NET.
6
by: Michael | last post by:
I need to copy a huge file (around 300Mb) from a mapped network drive to another. I have created a console application and used System.IO.File.Copy function. But I want to know the process of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...
0
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...
0
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,...

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.