realbasic-nug
[Top] [All Lists]

Re: Method vs Property

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Method vs Property
From: Guyren Howe <guyren at mac dot com>
Date: Sat, 30 Sep 2006 01:31:05 -0500
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20060929170038 dot 743DC153AF65 at lists dot realsoftware dot com> <1108DAEC-0D85-44AB-9D29-3F123622D610 at mac dot com>
On Sep 30, 2006, at 1:05 AM, Robert Livingston wrote:

When is something a property and when a method?

Take the ListBox class as described in the LR

Cell is said to be a method

ListBox1.Cell(1,2) = "Dog"

CellType is said to be a property

ListBox1.CellType(1,3) = True

The syntax of their use seems to be the same. What makes one a property and the other a method? Its seems strange to me that you can assign a value to a method. (ListBox1.Cell(1,2) = "Dog")

The REALbasic documentation is pretty bad: they call things properties when they're methods, they don't indicate when arrays are zero-or one-based, they're riddled with many other sorts of out-and- out errors and missing information.

When in doubt, perform tests, and depend on what the tests say, not what the docs say.

Guyren G Howe
Relevant Logic LLC

guyren-at-relevantlogic.com ~ http://relevantlogic.com

REALbasic, PHP, Python programming
PostgreSQL, MySQL database design and consulting
Technical writing and training


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


From  Sat 30 Sep 2006 03:09:05 -0400
Return-Path: <realbasic-nug-bounces at lists dot realsoftware dot com>
X-Original-To: listarchive at realsoftware dot com
Delivered-To: listarchive at realsoftware dot com
Received: by xmail.realsoftware.com (Postfix, from userid 1037)
        id 1FED9CAAE82; Sat, 30 Sep 2006 00:09:28 -0700 (PDT)
X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on realxserve.local
X-Spam-Level: X-Spam-Status: No, score=-0.5 required=4.5 tests=AWL,NO_REAL_NAME autolearn=disabled version=3.1.1
Received: from lists.realsoftware.com (lists.realsoftware.com [209.198.132.125])
        by xmail.realsoftware.com (Postfix) with ESMTP id 23FF2CAAE7B;
        Sat, 30 Sep 2006 00:09:27 -0700 (PDT)
Received: from lists.realsoftware.com (localhost [127.0.0.1])
        by lists.realsoftware.com (Postfix) with ESMTP
        id 20F06153F1CB; Sat, 30 Sep 2006 02:09:13 -0500 (CDT)
X-Original-To: realbasic-nug at lists dot realsoftware dot com
Delivered-To: realbasic-nug at lists dot realsoftware dot com
Received: from mail1.mx.voyager.net (mail1.mx.voyager.net [216.93.66.204])
        by lists.realsoftware.com (Postfix) with ESMTP id C5033153F1BD
        for <realbasic-nug at lists dot realsoftware dot com>;
        Sat, 30 Sep 2006 02:09:06 -0500 (CDT)
Received: from [192.168.0.103] (c-24-56-228-68.chrlmi.cablespeed.com
        [24.56.228.68])
        by mail1.mx.voyager.net (8.13.2/8.10.2) with ESMTP id k8U795uQ028578
        for <realbasic-nug at lists dot realsoftware dot com>;
        Sat, 30 Sep 2006 03:09:06 -0400 (EDT)
Mime-Version: 1.0 (Apple Message framework v752.2)
In-Reply-To: <1108DAEC-0D85-44AB-9D29-3F123622D610 at mac dot com>
References: <20060929170038 dot 743DC153AF65 at lists dot realsoftware dot com>
        <1108DAEC-0D85-44AB-9D29-3F123622D610 at mac dot com>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
Message-Id: <73F61F5D-0DF6-4D46-9846-5A48BCEE74D9 at kellerfarm dot com>
Content-Transfer-Encoding: 7bit
From: andrew at kellerfarm dot com
Date: Sat, 30 Sep 2006 03:09:05 -0400
To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
X-Mailer: Apple Mail (2.752.2)
Subject: Re: Method vs Property
X-BeenThere: realbasic-nug at lists dot realsoftware dot com
X-Mailman-Version: 2.1.2
Precedence: list
Reply-To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Sender: realbasic-nug-bounces at lists dot realsoftware dot com
Errors-To: realbasic-nug-bounces at lists dot realsoftware dot com

On Sep 30, 2006, at 2:05 AM, Robert Livingston wrote:
The syntax of their use seems to be the same. What makes one a property and the other a method? Its seems strange to me that you can assign a value to a method. (ListBox1.Cell(1,2) = "Dog")

A property is a slot in memory that contains a value that you can simply go get, and there is no background involved. A method is a subroutine that you can run that can accept parameters and can return a value, and it is primarily characterized by the presence of code needed to do it's job.

You could also argue that a property is a method with preset code for storing and retrieving a specific data type from memory, and a method is a build-it-yourself situation.

For example, an integer variable declared as a property on a window is a property. You can input a value, you can get the value, and there is no unusual background code related in getting or setting the value.

A method, on the other hand, is basically just more complex. In it's simplest form, you could easily confuse it with a property (except for the fact that all properties are listed under the "Properties" category and all the methods are listed under the "Methods" category).

This is where methods can become similar to properties. There are two keywords that you can apply to your list of properties that change how you call your method: Extends, and Assigns. This is how they change things:

Function Foo(input As Integer) As Integer
.... is used....  result = Foo(input)

Function Foo(Extends input As Integer) As Integer
.... is used....  result = input.Foo

Function Foo(Assigns input As Integer)
.... is used....  Foo = input

So as you can see, you can easily mix and match the above to masquerade a method to be used like a property. As for the inconsistencies in the LR, well, either RB is really weird, or the LR could be inaccurate. I know that I personally mix them up all the time because of how method can look like a property, and with multiple people working on that LR, one can see how differences can occur.

Just for another example, if you wanted to simulate the Cell property of a Listbox, you would do it like this:

Function Cell(Extends lbox As Listbox, row As Integer, col As Integer, Assigns value As String)
  // update variables and refresh the listbox
End Function


HTH
Andrew Keller
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>