Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Basic Misc > Re: QBASIC colo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 7 Topic 1374 of 1492
Post > Topic >>

Re: QBASIC color numbers

by Adam <no@[EMAIL PROTECTED] > Nov 12, 2007 at 07:48 PM

On Mon, 12 Nov 2007 01:35:15 -0800, news@[EMAIL PROTECTED]
 wrote:

>On Nov 12, 2:52 am, david.willi...@[EMAIL PROTECTED]
 (David Williams) wrote:
>> I have many times written code in which this feature of
>> BASIC is put to good use. So its advantages (many) outweigh its
>> disadvantages (none).
>
>As I said to Tom, it seems to me that this is an argument for it being
>*available*, not for it being the *default*.  Indeed, I cannot think
>of any argument whatever for it being the default.

Not a general argument, but here is one possibility:

Suppose that:
1.  One wishes to call a subroutine which has only one parameter.
2.  The subroutine isn't modifying any global/static variables.
3.  The purpose of the routine is not to send output to a screen or
other device which is open by default.

In this case, one would want the value of the parameter to change.
Defaulting to "pass by reference" for subroutines is more convenient
in this case.

The same result might be obtained using a function:

	let x = foo(x)

But that's a different scenario, and this is easier to type and read
(if one assumes that "pass by reference" is the default):

	call foo(x)


I agree with this:
On Nov 9, 2:17 pm, "Judson McClendon" <ju...@[EMAIL PROTECTED]
> wrote:
> passing sub arguments by reference makes sense because the purpose of
> subroutines is often to modify one or more of the arguments, since subs
> do not return a value as do functions.

The purpose of calling a routine (for any purpose for other than
output to a printer, etc.) would seem to involve changing/producing
_at least_ one value.

A function can produce only one value.  If one wants to return _only_
one value, then protecting all the parameters from "damage" and
returning that one value separately is desirable.  That is exactly
what functions do.

If one wants to change more than one value, then a subroutine is the
only option (unless there are global variables, etc.).  Defaulting to
the behavior which makes it easier to achieve what only a subroutine
can accomplish makes sense to me.

But this lines up with all my experience using BASIC, so I'm
prejudiced to find reasons why this behavior is "better".

As a subroutine's list of parameters becomes longer, it is less likely
that the programmer will actually want all of the parameters
vulnerable to tweaking within the routine.  And defaulting to "pass by
value" becomes "safer", though more tedious.

Another thought:

I believe that:
1.   GOSUB was the only way to call subroutines in the earliest
versions of BASIC, and
2.  All variables were global

Existing subroutines which were the targets of GOSUBs were allowed to
change the value of any variable within the routine.  And the result
was effective in the calling routine because all variables were
global.

Repackaging existing code to use CALL statements and parameter lists
would have been easier if the default type of parameter was "by
reference".

Myself, I find type-declaration and specifying the method of
parameter-passing to be tedious.

That is, it is much quicker for me to type (and read) this:

	SUB foo(x, y)

than this:

	SUB foo(ByRef x As Integer, ByRef y As Integer)


Also, copy-and-paste is easier when I don't want to retype a parameter
list from scratch:

Copying and converting this:
	SUB foo(x, y)
to this:
	CALL foo(x, b)

Doesn't require all the tedious deletion involved in converting this
copy:
	SUB foo(ByRef x As Integer, ByRef y As Integer)
to this:
	CALL foo(x, b)

--
Adam

-- 
Posted via a free Usenet account from http://www.teranews.com
 




 7 Posts in Topic:
Re: QBASIC color numbers
david.williams@[EMAIL PRO  2007-11-11 20:52:10 
Re: QBASIC color numbers
ArarghMail711NOSPAM@[EMAI  2007-11-11 22:15:09 
Re: QBASIC color numbers
"news@[EMAIL PROTECT  2007-11-12 01:35:15 
Re: QBASIC color numbers
Adam <no@[EMAIL PROTEC  2007-11-12 19:48:58 
Re: QBASIC color numbers
"Judson McClendon&qu  2007-11-12 07:45:01 
Re: QBASIC color numbers
Derek <derekrss@[EMAIL  2007-11-12 20:46:03 
Re: QBASIC color numbers
"Judson McClendon&qu  2007-11-13 02:05:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 14:58:39 CDT 2008.