Why can't I ignore function results? (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: Cmd-1 for help menu item
Next thread: Windows / Visual Basic Declare site url needed


Why can't I ignore function results?   -   Lars Jensen
  Re: Why can't I ignore function results?   -   Will Leshner
  Re: Why can't I ignore function results?   -   Terry Ford
  Re: Why can't I ignore function results?   -   Joseph J. Strout
   Re: Why can't I ignore function results?   -   William Mahaffey
    Re: Why can't I ignore function results?   -   Joseph J. Strout
     Re: Why can't I ignore function results?   -   William Mahaffey
      Re: Why can't I ignore function results?   -   Noah Desch
   Re: Why can't I ignore function results?   -   William Mahaffey
    Re: Why can't I ignore function results?   -   Charles Yeomans
  Re: Why can't I ignore function results?   -   Terry Ford
  Re: Why can't I ignore function results?   -   Greg Ewing
  Re: Why can't I ignore function results?   -   Joseph J. Strout
  Re: Why can't I ignore function results?   -   Terry Ford
   Re: Why can't I ignore function results?   -   Paul Goracke
    Re: Why can't I ignore function results?   -   Terry Ford
     Re: Why can't I ignore function results?   -   Paul Goracke
    Re: Why can't I ignore function results?   -   Joseph J. Strout
  Re: Why can't I ignore function results?   -   Joseph J. Strout
  Re: Why can't I ignore function results?   -   Lars Jensen
   Re: Why can't I ignore function results?   -   Greg Ewing
   Re: Why can't I ignore function results?   -   Charles Yeomans
  Re: Why can't I ignore function results?   -   Lars Jensen
  Re: Why can't I ignore function results?   -   Lars Jensen

Why can't I ignore function results?
Date: 12.12.02 20:42 (Thu, 12 Dec 2002 14:42:08 -0500)
From: Lars Jensen
When I don't care about the return value of a function, it would be more
convenient if I didn't have to dim a variable just to receive it. Why does
RB disallow this?

lj

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 12.12.02 20:53 (Thu, 12 Dec 2002 11:53:19 -0800)
From: Will Leshner
Because it can lead to errors and RB tries to help you avoid errors in
your code.

On Thursday, December 12, 2002, at 11:42 AM, Lars Jensen wrote:

> When I don't care about the return value of a function, it would be
> more
> convenient if I didn't have to dim a variable just to receive it. Why
> does
> RB disallow this?


---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 12.12.02 21:00 (Thu, 12 Dec 2002 12:00:51 -0800)
From: Terry Ford
>When I don't care about the return value of a function, it would be more
>convenient if I didn't have to dim a variable just to receive it. Why does
>RB disallow this?
>
>lj
>

Wouldn't a subroutine be what you are looking for?

Re: Why can't I ignore function results?
Date: 12.12.02 21:17 (Thu, 12 Dec 2002 12:17:03 -0800)
From: Joseph J. Strout
At 2:42 PM -0500 12/12/02, Lars Jensen wrote:

>When I don't care about the return value of a function, it would be more
>convenient if I didn't have to dim a variable just to receive it. Why does
>RB disallow this?

Because it's usually a mistake. Here's what I recommend, at least
until we build this in: make a global subroutine "Call(v as Variant)"
with nothing in it. Now you can do "Call foo" where "foo" is any
function.

Cheers,
- Joe

Re: Why can't I ignore function results?
Date: 12.12.02 23:46 (Thu, 12 Dec 2002 14:46:32 -0800)
From: William Mahaffey

On Thursday, Dec 12, 2002, at 12:17 US/Pacific, Joseph J. Strout wrote:

> Because it's usually a mistake. Here's what I recommend, at least
> until we build this in: make a global subroutine "Call(v as Variant)"
> with nothing in it. Now you can do "Call foo" where "foo" is any
> function.

interesting. never considered the possibility that could be done.

raises a question...
since subroutines can be passed as parameters...

how about a table of variants, then load it up with
addresses of subroutines (sorry for the terminology),
then, depending on the value of a variable/parameter
which is an offset into the array,
call the routine at that offset.

I've done that in other languages and it has
saved me lotsa time.

any chance?

bill mahaffey

-------------------------
"Law is often but the tyrant's will, and always so when it
violates the right of an individual."
--Thomas Jefferson to I. Tiffany, 1819.

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 13.12.02 00:52 (Thu, 12 Dec 2002 15:52:52 -0800)
From: Joseph J. Strout
At 2:46 PM -0800 12/12/02, William Mahaffey wrote:

>interesting. never considered the possibility that could be done.
>
>raises a question...
>since subroutines can be passed as parameters...

They can't. You're calling the function, and passing the *result* to
a subroutine. Which does nothing with it, and returns.

I'm sorry this was so confusing... I'll make an effort to explain it
more clearly next time.

Cheers,
- Joe

Re: Why can't I ignore function results?
Date: 13.12.02 03:20 (Thu, 12 Dec 2002 18:20:44 -0800)
From: William Mahaffey
not confusing really.
just extreme wishful thinking on my part which caused me
to read into it what I wanted to.
(I've never done that before!)

bill

On Thursday, Dec 12, 2002, at 15:52 US/Pacific, Joseph J. Strout wrote:

> At 2:46 PM -0800 12/12/02, William Mahaffey wrote:
>
>> interesting. never considered the possibility that could be done.
>>
>> raises a question...
>> since subroutines can be passed as parameters...
>
> They can't. You're calling the function, and passing the *result* to
> a subroutine. Which does nothing with it, and returns.
>
> I'm sorry this was so confusing... I'll make an effort to explain it
> more clearly next time.
>
> Cheers,
> - Joe
>
> --
> ,------------------------------------------------------------------.
> | Joseph J. Strout REAL Software, Inc. |
> | <email address removed> http://www.realsoftware.com |
> `------------------------------------------------------------------'
>
> ---
> A searchable archive of this list is available at:
> <http://dbserver.realsoftware.com/KBDB/search.php>
> Unsubscribe:
> <mailto:<email address removed>>
> Subscribe to the digest:
> <mailto:<email address removed>>

-------------------------------
Work is the curse of the drinking class.
--Oscar Wilde

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 13.12.02 03:47 (Thu, 12 Dec 2002 21:47:39 -0500)
From: Noah Desch

On Thursday, December 12, 2002, at 09:20 PM, William Mahaffey wrote:

> not confusing really.
> just extreme wishful thinking on my part which caused me
> to read into it what I wanted to.

Heh, same here. I was like "Wow, since when have they been hiding function
objects from us?!" but it was not to be... :(

-Noah Desch
Wireframe Software
http://wireframe.virtualave.net

"No beer and no TV make Homer go something something"
-Homer Simpson

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 12.12.02 23:54 (Thu, 12 Dec 2002 14:54:53 -0800)
From: William Mahaffey

On Thursday, Dec 12, 2002, at 12:17 US/Pacific, Joseph J. Strout wrote:
>
> Because it's usually a mistake. Here's what I recommend, at least
> until we build this in: make a global subroutine "Call(v as Variant)"
> with nothing in it. Now you can do "Call foo" where "foo" is any
> function.

internal compiler error at "Call foo".
4.5.2

bill mahaffey

-------------------------
If you give me six lines written by the most honest man, I will find
something in them to hang him.
-- Cardinal de Richelieu

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 13.12.02 01:13 (Thu, 12 Dec 2002 19:13:41 -0500)
From: Charles Yeomans

On Thursday, December 12, 2002, at 05:54 PM, William Mahaffey wrote:

>
> On Thursday, Dec 12, 2002, at 12:17 US/Pacific, Joseph J. Strout wrote:
>>
>> Because it's usually a mistake. Here's what I recommend, at least
>> until we build this in: make a global subroutine "Call(v as Variant)"
>> with nothing in it. Now you can do "Call foo" where "foo" is any
>> function.
>
> internal compiler error at "Call foo".
> 4.5.2
>

Hmmm, I just tested using 4.5.2 Classic and couldn't generate an error.

Charles Yeomans


---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 12.12.02 22:10 (Thu, 12 Dec 2002 13:10:23 -0800)
From: Terry Ford
>At 2:42 PM -0500 12/12/02, Lars Jensen wrote:
>
>>When I don't care about the return value of a function, it would be more
>>convenient if I didn't have to dim a variable just to receive it. Why does
>>RB disallow this?
>
>Because it's usually a mistake. Here's what I recommend, at least
>until we build this in: make a global subroutine "Call(v as
>Variant)" with nothing in it. Now you can do "Call foo" where "foo"
>is any function.
>
>Cheers,
- Joe
Maybe I'm missing the object of this thread. When you say '"foo" is
any function', are you referring to different functions that are
determined by the value of foo or to a single method in the global
"Call" method?

Re: Why can't I ignore function results?
Date: 12.12.02 23:20 (Fri, 13 Dec 2002 11:20:39 +1300 (NZDT))
From: Greg Ewing
Lars Jensen <<email address removed>>:

> When I don't care about the return value of a function, it would be more
> convenient if I didn't have to dim a variable just to receive it.

If you find yourself wanting to ignore return values
a lot, it's probably a sign that you need to rethink your
design.

If you keep in mind that you're writing in a language
that doesn't let you ignore return values, you shouldn't
have much trouble coming up with a design that doesn't
require this except in very rare circumstances.

A good rule of thumb is that if you're calling it to
calculate something, it should return a value, whereas
if you're calling it to do something, it shouldn't
return a value. Don't create methods which both
return values and have side effects.

There are cases where it's reasonable to disregard
this (such as a method which reads something from a
file), but in those cases you do want the return value
most of the time.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
<email address removed> +--------------------------------------+

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 12.12.02 23:24 (Thu, 12 Dec 2002 14:24:01 -0800)
From: Joseph J. Strout
At 1:10 PM -0800 12/12/02, Terry Ford wrote:

>>Because it's usually a mistake. Here's what I recommend, at least
>>until we build this in: make a global subroutine "Call(v as
>>Variant)" with nothing in it. Now you can do "Call foo" where
>>"foo" is any function.

> Maybe I'm missing the object of this thread. When you say '"foo" is
>any function', are you referring to different functions that are
>determined by the value of foo or to a single method in the global
>"Call" method?

"foo" is just a placeholder for whatever you want. It could be "Call
ParseDate" or "Call SelectColor" or whatever.

Cheers,
- Joe

Re: Why can't I ignore function results?
Date: 13.12.02 00:09 (Thu, 12 Dec 2002 15:09:58 -0800)
From: Terry Ford
>
>"foo" is just a placeholder for whatever you want. It could be
>"Call ParseDate" or "Call SelectColor" or whatever.
>
>Cheers,
>- Joe

Thanks.

Am I correct in assuming then that the functions being called are the
built-in ones in REALbasic as opposed to methods the programmer codes
himself? If the latter is also applicable, I would assume these would
probably have to be global if they weren't instantiated in a class.

Can you point me to somewhere in the developer's guide or Matt's
Definitive guide where this is explained. I have seen methods and new
events with no code but am having a bit of difficulty understanding
how they work and when to use them.

I still have a lot to learn about class interfaces, etc.

Re: Why can't I ignore function results?
Date: 13.12.02 00:22 (Thu, 12 Dec 2002 15:22:57 -0800)
From: Paul Goracke
Terry Ford wrote:

>>
>> "foo" is just a placeholder for whatever you want. It could be "Call
>> ParseDate" or "Call SelectColor" or whatever.
>>
>> Cheers,
>> - Joe
>
> Thanks.
>
> Am I correct in assuming then that the functions being called are the
> built-in ones in REALbasic as opposed to methods the programmer codes
> himself? If the latter is also applicable, I would assume these would
> probably have to be global if they weren't instantiated in a class.

I think you're looking at it backwards--it took me a while to see it,
too. You're not passing "Call" a function pointer which it then calls;
you're calling the function, then passing its results to Call--it
accepts whatever value it is (changing it into a Variant param) and
doesn't return anything.

pg

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 13.12.02 00:49 (Thu, 12 Dec 2002 15:49:38 -0800)
From: Terry Ford
>Terry Ford wrote:
>
>>>
>>>"foo" is just a placeholder for whatever you want. It could be
>>>"Call ParseDate" or "Call SelectColor" or whatever.
>>>
>>>Cheers,
>>>- Joe
>>
>>Thanks.
>>
>>Am I correct in assuming then that the functions being called are
>>the built-in ones in REALbasic as opposed to methods the programmer
>>codes himself? If the latter is also applicable, I would assume
>>these would probably have to be global if they weren't instantiated
>>in a class.
>
>I think you're looking at it backwards--it took me a while to see
>it, too. You're not passing "Call" a function pointer which it then
>calls; you're calling the function, then passing its results to
>Call--it accepts whatever value it is (changing it into a Variant
>param) and doesn't return anything.
>
>pg

OK, I think I am starting to understand how it works. My question now
is when this would be a benefit over a Sub method in your own
programming (i.e. overloading or setting other parameters in the OS)?

Re: Why can't I ignore function results?
Date: 13.12.02 01:02 (Thu, 12 Dec 2002 16:02:54 -0800)
From: Paul Goracke
Terry Ford wrote:

> OK, I think I am starting to understand how it works. My question now
> is when this would be a benefit over a Sub method in your own
> programming (i.e. overloading or setting other parameters in the OS)?

It's generic. Once you have this method, you can use it any time you
want to ignore the result without having to write an overloaded
function. Personally, I'd name it something like "IgnoreResult" instead
of "Call"--but then I would just deal with the function result in the
first place :^)

pg

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 13.12.02 01:04 (Thu, 12 Dec 2002 16:04:54 -0800)
From: Joseph J. Strout
At 3:49 PM -0800 12/12/02, Terry Ford wrote:

>OK, I think I am starting to understand how it works. My question
>now is when this would be a benefit over a Sub method in your own
>programming

It's not. The main use is for built-in or plug-in functions that
return a result about which you don't care -- like ParseDate or
SelectColor, perhaps. If you don't feel that particular need, then
you can safely ignore this thread.

Cheers,
- Joe

Re: Why can't I ignore function results?
Date: 13.12.02 00:26 (Thu, 12 Dec 2002 15:26:45 -0800)
From: Joseph J. Strout
At 3:09 PM -0800 12/12/02, Terry Ford wrote:

>Am I correct in assuming then that the functions being called are
>the built-in ones in REALbasic as opposed to methods the programmer
>codes himself?

In my examples they were. But any will work.

> If the latter is also applicable, I would assume these would
>probably have to be global if they weren't instantiated in a class.

No, you could do "call someObject.someMethod" too.

>Can you point me to somewhere in the developer's guide or Matt's
>Definitive guide where this is explained.

Where what is explained? There is no new concept or technique here.
I was only pointing out a possible function you can create, which can
be used to easily ignore the results of other functions.

> I have seen methods and new events with no code but am having a bit
>of difficulty understanding how they work and when to use them.

What I've suggested is a method with no code. It works by doing
absolutely nothing. It takes any type of argument (since the
parameter is a Variant), and does absolutely nothing with it, then
returns. Thus, it's a handy way to ignore things.

Cheers,
- Joe

Re: Why can't I ignore function results?
Date: 13.12.02 01:22 (Thu, 12 Dec 2002 19:22:51 -0500)
From: Lars Jensen
> If you find yourself wanting to ignore return values
> a lot, it's probably a sign that you need to rethink your
> design...Don't create methods which both
> return values and have side effects.

This seems to promote multiple methods unnecessarily. It's not so momentous
as to be a "design" issue but more a matter of API convenience.

Example: a routine that creates instances of a class, like maybe a new
document window. In addition to the "side effect" of opening the window, it
might return it so you could do stuff with it. But if you don't want to do
more stuff, you could just ignore the return value.

Annoying:

dim win as DocWindow
...
win = NewDocWindow

Still annoying but at least localized:

call NewDocWindow

Ahhh...:

NewDocWindow

If RB wants to do me a favor by pointing out ignored return values, then I'd
argue that it should be a warning, not an error.

lj

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 13.12.02 01:42 (Fri, 13 Dec 2002 13:42:44 +1300 (NZDT))
From: Greg Ewing
Lars Jensen <<email address removed>>:

> Example: a routine that creates instances of a class, like maybe a new
> document window. In addition to the "side effect" of opening the window, it
> might return it so you could do stuff with it. But if you don't want to do
> more stuff, you could just ignore the return value.

I don't disagree that there are sometimes legitimate reasons for
ignoring a return value. But in my experience they occur sufficiently
rarely that they're not a major annoyance. For example, in any given
application there is perhaps 1 or 2 places where there's a line of
code that creates a new document window.

In other cases, most of the time it represents a mistake, and I don't
mind having RB tell me about it.

A more convenient way of *explicitly* ignoring the result might be
useful. As has been pointed out, you can easily create one yourself in
the form of a function that takes any value and does nothing.

> If RB wants to do me a favor by pointing out ignored return values,
> then I'd argue that it should be a warning, not an error.

But then you'd need some way of silencing the warning, or put up with
getting it over and over again every time you compile & run. So it
might as well be an error!

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
<email address removed> +--------------------------------------+

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 13.12.02 02:18 (Thu, 12 Dec 2002 20:18:53 -0500)
From: Charles Yeomans

On Thursday, December 12, 2002, at 07:22 PM, Lars Jensen wrote:

>> If you find yourself wanting to ignore return values
>> a lot, it's probably a sign that you need to rethink your
>> design...Don't create methods which both
>> return values and have side effects.
>
> This seems to promote multiple methods unnecessarily. It's not so
> momentous
> as to be a "design" issue but more a matter of API convenience.

On the contrary, this is a design issue, and an important one.
Command-query separation helps clarify class design and allows one to
be able to test a class with assertions.

Charles Yeomans


---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 13.12.02 02:23 (Thu, 12 Dec 2002 20:23:09 -0500)
From: Lars Jensen
>>> make a global subroutine "Call(v as Variant)" with nothing in it.
>>
>> internal compiler error at "Call foo".
>> 4.5.2
>
> Hmmm, I just tested using 4.5.2 Classic and couldn't generate an error.

No error for me either, with 4.5.3fc2 Classic. (Neat trick too.)

lj

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Why can't I ignore function results?
Date: 13.12.02 07:29 (Fri, 13 Dec 2002 01:29:17 -0500)
From: Lars Jensen
> Command-query separation helps clarify class design and allows one to
> be able to test a class with assertions.

Sure, but not all situations warrant it. If I want command-query separation,
I'll implement it. Forcing me to deal with a return value in the meantime
doesn't help me.

>> If RB wants to do me a favor by pointing out ignored return values,
>> then I'd argue that it should be a warning, not an error.
>
> But then you'd need some way of silencing the warning, or put up with
> getting it over and over again every time you compile & run. So it
> might as well be an error!

I had in mind the ignorable kind of warning, like in the tip window.

But "Call" isn't that bad a solution. Short, local, low overhead...even
better if it were built in.

lj

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>