-
Re: Good Editorial by Russell Jones
Path: news.devx.com!news.devx.com!208.186.167.111
Xref: news.devx.com vb.dotnet.discussion:16511
Hi James --
> Karl and Mike are right,
This is scary.
> but I'd like to point out that the biggest payoff
> is when that shared piece of code has LOTS of data elements that would have
> to be passed as parameters. For instance, a dozen field values from a
> table...
Right. It's an optimization technique. One that *can* be valuable.
> I avoid GoSubs as much as I possibly can, but there are a few cases where
> they are simply the best option for the situation. I agree that choice is
> the best. Anyone who thinks that bad developers will write better code
> because of language restrictions is slightly misguided. It may help, but
> people will still write lots of bad code.
What's even scarier than me agreeing with Mike, is the fact that Microsoft's product
development team apparently doesn't understand this *fundamental* optimization. Very
scary, indeed. I'd really like to hear the official rationalization on this point.
Other than driving up INTC, ...?
Later... Karl
--
http://www.mvps.org/vb
-
Re: Good Editorial by Russell Jones
Path: news.devx.com!news.devx.com!212.126.152.45
Xref: news.devx.com vb.dotnet.discussion:16531
On Mon, 29 Jan 2001 13:09:22 -0800, "Karl E. Peterson" <karl@mvps.org>
wrote:
>Jeeez, I can't believe I'm saying this, but "What Mike said", (in a nutshell). It
>was a good option, when used appropriately. Unfortunately, they hosed it in VB4, and
>it never really did recover fully. This made the potential pay-off much less, and
>the justification requirements much more rigorous. But if you (generic "you") don't
>know *why* it might be useful, then you obviously shouldn't be commenting on whether
>this is a construct that's outlived its usefulness.
>
So, tell me, Karl, when did they stop hitting you with the rubber
hoses, or was the Visual Fred editing solely *your* idea???!!!
MM
-
Re: Good Editorial by Russell Jones
Can't say.
--
http://www.mvps.org/vb
"Mike Mitchell" <kylix_is@hotmail.com> wrote in message
news:3a7601a9.10045962@news.devx.com...
> On Mon, 29 Jan 2001 13:09:22 -0800, "Karl E. Peterson" <karl@mvps.org>
> wrote:
>
> >Jeeez, I can't believe I'm saying this, but "What Mike said", (in a nutshell). It
> >was a good option, when used appropriately. Unfortunately, they hosed it in VB4,
and
> >it never really did recover fully. This made the potential pay-off much less, and
> >the justification requirements much more rigorous. But if you (generic "you")
don't
> >know *why* it might be useful, then you obviously shouldn't be commenting on
whether
> >this is a construct that's outlived its usefulness.
> >
>
> So, tell me, Karl, when did they stop hitting you with the rubber
> hoses, or was the Visual Fred editing solely *your* idea???!!!
>
> MM
-
Re: Good Editorial by Russell Jones
Path: news.devx.com!news.devx.com!63.112.197.60
Xref: news.devx.com vb.dotnet.discussion:16573
> Jeeez, I can't believe I'm saying this, but "What Mike said", (in a
nutshell). It
> was a good option, when used appropriately. Unfortunately, they hosed it
in VB4, and
> it never really did recover fully. This made the potential pay-off much
less, and
> the justification requirements much more rigorous. But if you (generic
"you") don't
I have seen no reason, including the example that justifies using Gosub.
Especially one that we have been warned about for years is going away. Just
because an obsolete construct exists, does not imply that it is "useful" or
should be used?
I can still write code in C that directly writes to Video Ram. Does this
mean it is useful? Does that mean I do it? No...not in the Windows world.
Is it "cool"? Sure. So what? Should I write articles or teach new
programmer's about it? **** no.
-
Re: Good Editorial by Russell Jones
Path: news.devx.com!news.devx.com!63.112.197.60
Xref: news.devx.com vb.dotnet.discussion:16574
> they are simply the best option for the situation. I agree that choice is
> the best. Anyone who thinks that bad developers will write better code
> because of language restrictions is slightly misguided. It may help, but
If you didn't want language restrictions, you would be writting your code in
another language. VB was designed to be a RAD tool....not get under the
covers and tweek the CPU.
-
Re: Good Editorial by Russell Jones
Hi Steve --
> I have seen no reason, including the example that justifies using Gosub.
Okay then. You've certainly made a point. Not the one you were going for, but
that's okay. We understand.
> Especially one that we have been warned about for years is going away.
Cite?
Thanks... Karl
--
http://www.mvps.org/vb
-
Re: Good Editorial by Russell Jones
"Karl E. Peterson" <karl@mvps.org> wrote in message
news:3a76f6fd$1@news.devx.com...
> Hi Steve --
>
> > I have seen no reason, including the example that justifies using
Gosub.
>
> Okay then. You've certainly made a point. Not the one you were going
for, but
> that's okay. We understand.
>
> > Especially one that we have been warned about for years is going away.
>
> Cite?
>
> Thanks... Karl
> --
> http://www.mvps.org/vb
>
<quote>
Gosub/Return
Gosub was useful in the bad old days when all variables were global and
Select Case didn’t exist. But why Gosub, Return, and On Gosub remain in
Visual Basic is beyond me. Perhaps they were left in for compatibility of
some kind, although I find it hard to imagine a procedure using these
statements that one could port from an earlier Basic.
I’ve heard it argued that it’s more efficient to use Gosub and Return than
to use subs and functions. Well, yes, but technically you could write all
your code using only If, Then, and Goto—that would be more efficient
still, if you ever got it debugged. If Gosub is what it takes to write
efficient code in Basic, I’ll take C. Fortunately, it’s not.
</quote>
from
http://www.mvps.org/vb/hardcore/
;o)
Roberto
-
Re: Good Editorial by Russell Jones
LOL! Bruce is a cantankerous old fart, and *never* spoke MS policy.
Good try, though. :-)
--
http://www.mvps.org/vb
"Roberto Martinez-Brunet" <rmbrunet@hotmail.com> wrote in message
news:3a76f965$1@news.devx.com...
>
> "Karl E. Peterson" <karl@mvps.org> wrote in message
> news:3a76f6fd$1@news.devx.com...
> > Hi Steve --
> >
> > > I have seen no reason, including the example that justifies using
> Gosub.
> >
> > Okay then. You've certainly made a point. Not the one you were going
> for, but
> > that's okay. We understand.
> >
> > > Especially one that we have been warned about for years is going away.
> >
> > Cite?
> >
> > Thanks... Karl
> > --
> > http://www.mvps.org/vb
> >
>
> <quote>
> Gosub/Return
> Gosub was useful in the bad old days when all variables were global and
> Select Case didn’t exist. But why Gosub, Return, and On Gosub remain in
> Visual Basic is beyond me. Perhaps they were left in for compatibility of
> some kind, although I find it hard to imagine a procedure using these
> statements that one could port from an earlier Basic.
>
> I’ve heard it argued that it’s more efficient to use Gosub and Return than
> to use subs and functions. Well, yes, but technically you could write all
> your code using only If, Then, and Goto—that would be more efficient
> still, if you ever got it debugged. If Gosub is what it takes to write
> efficient code in Basic, I’ll take C. Fortunately, it’s not.
>
> </quote>
>
> from
>
> http://www.mvps.org/vb/hardcore/
>
> ;o)
>
> Roberto
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
-
Re: Good Editorial by Russell Jones
From the VB6 MSDN on Gosub:
"Tip Creating separate procedures that you can call may provide a more
structured alternative to using GoSub...Return."
If that's not a hint... what is?
-
Re: Good Editorial by Russell Jones
Yet, Bruce's book was published by Microsoft Press, featured on Microsoft's
website and even distributed on millions of Microsoft Developer Network CD-ROMs....
/Pat
"Karl E. Peterson" <karl@mvps.org> wrote:
>LOL! Bruce is a cantankerous old fart, and *never* spoke MS policy.
>
>Good try, though. :-)
>--
>http://www.mvps.org/vb
>
>
>"Roberto Martinez-Brunet" <rmbrunet@hotmail.com> wrote in message
>news:3a76f965$1@news.devx.com...
>>
>> "Karl E. Peterson" <karl@mvps.org> wrote in message
>> news:3a76f6fd$1@news.devx.com...
>> > Hi Steve --
>> >
>> > > I have seen no reason, including the example that justifies using
>> Gosub.
>> >
>> > Okay then. You've certainly made a point. Not the one you were going
>> for, but
>> > that's okay. We understand.
>> >
>> > > Especially one that we have been warned about for years is going away.
>> >
>> > Cite?
>> >
>> > Thanks... Karl
>> > --
>> > http://www.mvps.org/vb
>> >
>>
>> <quote>
>> Gosub/Return
>> Gosub was useful in the bad old days when all variables were global and
>> Select Case didn’t exist. But why Gosub, Return, and On Gosub remain in
>> Visual Basic is beyond me. Perhaps they were left in for compatibility
of
>> some kind, although I find it hard to imagine a procedure using these
>> statements that one could port from an earlier Basic.
>>
>> I’ve heard it argued that it’s more efficient to use Gosub and Return
than
>> to use subs and functions. Well, yes, but technically you could write
all
>> your code using only If, Then, and Goto—that would be more efficient
>> still, if you ever got it debugged. If Gosub is what it takes to write
>> efficient code in Basic, I’ll take C. Fortunately, it’s not.
>>
>> </quote>
>>
>> from
>>
>> http://www.mvps.org/vb/hardcore/
>>
>> ;o)
>>
>> Roberto
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
-
Re: Good Editorial by Russell Jones
PRB: Poor Performance with the GoSub Statement
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for
Windows, versions 5.0, 6.0
--------------------------------------------------------------------------------
SYMPTOMS
A project compiled in native code shows poor performance. This behavior occurs
because the project contains calls to subroutines using the GoSub statement.
CAUSE
The GoSub statement has not been optimized in Visual Basic.
RESOLUTION
Instead of using sub-routines, use functions in a module or place your code
inside an event.
STATUS
This behavior is by design.
MORE INFORMATION
The GoSub statement is still provided for backward compatibility to older
versions of Visual Basic. However, the GoSub statement was not optimized
because of potential problems it can cause with the stack. Therefore, you
should not use subs of functions in your project. You will get much better
performance by calling a function in a module or placing the code inside
an event.
The following section contains instructions on how to create a sample program
that demonstrates the performance differences between inline code, calling
a function in a module, and calling a sub-routine using the GoSub statement.
For each method, the values of two variables are swapped 1,000,000 times
and the time to perform this task is shown on a message box. Each method
is in a project that is compiled to native code. The following are the results
when this project was run on a Pentium 200Mhz computer with 64Mb of memory
running Windows NT Server version 4.0:
Inline code .016 seconds
Function call .031 seconds
GoSub Statement 2.260 seconds
Your results may vary depending on the system configuration used to run this
test. Note that the time differences will not be evident if you run the projects
from within the Visual Basic IDE. To see the performance difference, you
need to compile each project as a native code executable file.
To create the sample project, you will need to create four projects:
Inline Code project - contains inline code. This project will be compiled
to a native code executable file.
Function Call project - contains a project that calls a function in a module.
This project will be compiled to a native code executable file.
GoSub Statement project - contains a subroutine that is called within the
Click event using the GoSub statement. This project will be compiled to a
native code executable file.
Sample project - contains the code to call the first three executable files.
This project can be run within the Visual Basic IDE.
Create the Inline Code Project
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
Copy the following code to the Code window Form1:
Option Explicit
Private Sub Form_Load()
Dim lngCounter As Long, x As Long, y As Long, tmp As Long
Dim tmrStart As Double
Dim strMsg As String
tmrStart = Timer
For lngCounter = 1 To 1000000
x = 100
y = 500
tmp = x
x = y
y = tmp
Next lngCounter
strMsg = "Inline took " & Str(Timer - tmrStart) & " seconds."
MsgBox (strMsg)
End
End Sub
Add the following code to the module for Form1:
Sub Form_Load()
Swap
End Sub
From the File menu, click Make Project1.exe to display the Make Project dialog
box. Name the executable "Inline" and click OK. The default compilation option
in Visual Basic is native code.
Close the project.
Create the Function Call Project
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
From the Project menu, click Add Module to add a module to the project. The
Add Module dialog box appears. Click OK. The Module1 code window is displayed.
Copy the following code to the Code window of Module1:
Option Explicit
Dim x As Long, y As Long, tmp As Long
Public Sub Swap()
Dim lngCounter As Long
Dim tmrStart As Double
Dim strMsg As String
tmrStart = Timer
For lngCounter = 1 To 1000000
x = 100
y = 500
tmp = x
x = y
y = tmp
Next lngCounter
strMsg = "Function Call took " & Str(Timer - tmrStart)
strMsg = strMsg & " seconds."
MsgBox (strMsg)
End
End Sub
From the File menu, click Make Project1.exe to display the Make Project dialog
box. Name the executable "FunctionCall" and click OK. The default compilation
option in Visual Basic is native code.
Close the project.
Create the GoSub Statement Project
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
Copy the following code to the Code window of Form1:
Option Explicit
Private Sub Form_Load()
Dim lngCounter As Long, x As Long, y As Long, tmp As Long
Dim tmrStart As Double
Dim strMsg As String
tmrStart = Timer
x = 100
y = 500
For lngCounter = 1 To 1000000
GoSub Swap
Next lngCounter
strMsg = "GoSub took " & Str(Timer - tmrStart) & " seconds."
MsgBox (strMsg)
End
Swap:
tmp = x
x = y
y = tmp
Return
End Sub
From the File menu, click Make Project1.exe to display the Make Project dialog
box. Name the executable "GoSub" and click OK. The default compilation option
in Visual Basic is native code.
Close the project.
Create the Sample Project
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
Add three CommandButtons to Form1.
Copy the following code to the Code window of Form1. Enter the pathname of
each executable file you created earlier in the sections marked with <<<.
Option Explicit
Private Sub Form_Load()
Command1.Caption = "Inline"
Command2.Caption = "Go Sub"
Command3.Caption = "Function Call"
End Sub
Private Sub Command1_Click()
Shell ("<path>inline.exe")'<<< Change <path> to the path of
' inline.exe
End Sub
Private Sub Command2_Click()
Shell ("<path>Gosub.exe") '<<< Change <path> to the path
' of GoSub.exe
End Sub
Private Sub Command3_Click()
Shell ("<path>FunctionCall.exe") '<<< Change <path> to the path
' of FunctionCall.exe
End Sub
Press the F5 key to run the program. Click each CommandButton to see the
results of inline coding, calling a function in a module, and using the GoSub
statement to call a subroutine.
(c) Microsoft Corporation 1997. All Rights Reserved. Contributions by Arsenio
Locsin, Microsoft Corporation
Additional query words:
Keywords : kbCompiler kbVBp kbVBp500 kbVBp600 kbGrpVB kbDSupport
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbprb
Technology :
Last Reviewed: April 19, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
"Karl E. Peterson" <karl@mvps.org> wrote:
>Hi Steve --
>
>> I have seen no reason, including the example that justifies using Gosub.
>
>Okay then. You've certainly made a point. Not the one you were going for,
but
>that's okay. We understand.
>
>> Especially one that we have been warned about for years is going away.
>
>Cite?
>
>Thanks... Karl
>--
>http://www.mvps.org/vb
>
>
-
Re: Good Editorial by Russell Jones
It's honest. A hint? I don't think so.
--
http://www.mvps.org/vb
"Sjoerd Verweij" <nospam.sjoerd@sjoerd.org> wrote in message
news:3a770399$1@news.devx.com...
> From the VB6 MSDN on Gosub:
>
> "Tip Creating separate procedures that you can call may provide a more
> structured alternative to using GoSub...Return."
>
> If that's not a hint... what is?
>
>
-
Re: Good Editorial by Russell Jones
It was also removed from MSDN and their web, which is why it's at my site now.
--
http://www.mvps.org/vb
<Patrick Troughton Patrick> wrote in message news:3a77060d$1@news.devx.com...
>
> Yet, Bruce's book was published by Microsoft Press, featured on Microsoft's
> website and even distributed on millions of Microsoft Developer Network CD-ROMs....
>
> /Pat
>
> "Karl E. Peterson" <karl@mvps.org> wrote:
> >LOL! Bruce is a cantankerous old fart, and *never* spoke MS policy.
> >
> >Good try, though. :-)
> >--
> >http://www.mvps.org/vb
> >
> >
> >"Roberto Martinez-Brunet" <rmbrunet@hotmail.com> wrote in message
> >news:3a76f965$1@news.devx.com...
> >>
> >> "Karl E. Peterson" <karl@mvps.org> wrote in message
> >> news:3a76f6fd$1@news.devx.com...
> >> > Hi Steve --
> >> >
> >> > > I have seen no reason, including the example that justifies using
> >> Gosub.
> >> >
> >> > Okay then. You've certainly made a point. Not the one you were going
> >> for, but
> >> > that's okay. We understand.
> >> >
> >> > > Especially one that we have been warned about for years is going away.
> >> >
> >> > Cite?
> >> >
> >> > Thanks... Karl
> >> > --
> >> > http://www.mvps.org/vb
> >> >
> >>
> >> <quote>
> >> Gosub/Return
> >> Gosub was useful in the bad old days when all variables were global and
> >> Select Case didn’t exist. But why Gosub, Return, and On Gosub remain in
> >> Visual Basic is beyond me. Perhaps they were left in for compatibility
> of
> >> some kind, although I find it hard to imagine a procedure using these
> >> statements that one could port from an earlier Basic.
> >>
> >> I’ve heard it argued that it’s more efficient to use Gosub and Return
> than
> >> to use subs and functions. Well, yes, but technically you could write
> all
> >> your code using only If, Then, and Goto—that would be more efficient
> >> still, if you ever got it debugged. If Gosub is what it takes to write
> >> efficient code in Basic, I’ll take C. Fortunately, it’s not.
> >>
> >> </quote>
> >>
> >> from
> >>
> >> http://www.mvps.org/vb/hardcore/
> >>
> >> ;o)
> >>
> >> Roberto
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
>
-
Re: Good Editorial by Russell Jones
Pat, if you'd care to *stop* repeating what I've already said, and actually get to
the point...? That info also applies to VB4, fwiw, because that's when we first
reported this issue.
--
http://www.mvps.org/vb
> CAUSE
> The GoSub statement has not been optimized in Visual Basic.
-
Re: Good Editorial by Russell Jones
Karl,
If you can ever manage to take your blinders off for more than a minute you
would *clearly* see where Microsoft advises people to *not* use GoSubs....
"The GoSub statement is still provided for backward compatibility to older
versions of Visual Basic. However, the GoSub statement was not optimized
because of potential problems it can cause with the stack. Therefore, you
should not use subs of functions in your project."
You wanted a cite. You got one. Don't get mad at me if your ego is to fragile
to handle it.
/Pat
"Karl E. Peterson" <karl@mvps.org> wrote:
>Pat, if you'd care to *stop* repeating what I've already said, and actually
get to
>the point...? That info also applies to VB4, fwiw, because that's when
we first
>reported this issue.
>--
>http://www.mvps.org/vb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks