|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Function versus ReadOnly PropertyIs 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
Show quote
Hide quote
> Is there any reason to use: One practical reason is that ASP can't bind to a function (or at least it > > 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 couldn't, haven't played with ASP 2.0 enough if this is no longer the case). Hi,
In addition to Jim comments I really dont think it is good form to have a property that has a parameter. Ken ------------------ Show quoteHide quote "eric.gofo***@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 > > Hello eric.gofo***@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 Show quoteHide quote > 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 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 <eric.gofo***@gmail.com> schreef in bericht Show quoteHide quote news:1149712149.601589.128150@j55g2000cwa.googlegroups.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 > eric.gofo***@gmail.com wrote:
Show quoteHide quote > Is there any reason to use: Any particular reason you've used ByRef in these snippets? ByVal should> > 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 be your preferred default. -- Larry Lard Replies to group please <eric.gofo***@gmail.com> schrieb:
Show quoteHide quote > Is there any reason to use: That's hard to say based on the sample you posted. IMO the decision between > > 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 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/> On 2006-06-07, eric.gofo***@gmail.com <eric.gofo***@gmail.com> wrote:
Show quoteHide quote > Is there any reason to use: In addition to Herfried's comments, I'd add that Properties really> > 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 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? 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] Show quoteHide quote "david" <da***@woofix.local.dom> schreef in bericht news:slrne8hbkd.gdb.david@localhost.localdomain... > On 2006-06-07, eric.gofo***@gmail.com <eric.gofo***@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? > > 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. Show quoteHide quote "Michel Posseth [MCP]" <M***@posseth.com> wrote in message news:Oecu0tWjGHA.4040@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:slrne8hbkd.gdb.david@localhost.localdomain... > > On 2006-06-07, eric.gofo***@gmail.com <eric.gofo***@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? > > > > > > > Michel Posseth [MCP] wrote:
> I am currently working in a project team where everyone is passing Is it? Have they checked? Can they prove it?> 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 .... > if someone has a good counter to this logic be my guest I tend to struggle to deal logically with people who are prepared tobreak semantic contracts for illusory (and even if not illusory, negligible) performance gains. -- Larry Lard Replies to group please Larry,
Show quoteHide quote > I was writing the same, but did not, it would not help Michel at all.> 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. > 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/microsoft.public.dotnet.languages.vb/browse_frm/thread/974e13b6efdc0715/7e7401cc7316d84e#7e7401cc7316d84e Cor 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... -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Michel Posseth [MCP]" <M***@posseth.com> wrote in message news:Oecu0tWjGHA.4040@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:slrne8hbkd.gdb.david@localhost.localdomain... | > On 2006-06-07, eric.gofo***@gmail.com <eric.gofo***@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? | > | > | |
VB.NET Threading CPU Issue
le nom 'vb6' n'est pas déclaré Overload resolution failed All I'm looking for is a simple answer to a simple question DataGrid Control How do I use a class, when the class requires functions in the main form? Memory Manipulation Object-to-Relational Tool Error while file copying over network. Unmanaged C++ Void* |
|||||||||||||||||||||||