forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Get lost goto!

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
dmonckton
Contributor
Contributor


Joined: 09 Aug 2002
Posts: 117
Location: Lewes, U.K.

PostPosted: Wed Nov 21, 2007 11:55 am    Post subject: Get lost goto! Reply with quote

Hi

A while back I tried to introduce VDS to a close friend who is a professional C++ developer. I was trying to get a bit of cred with him.
He just looked at the code and said "it's crap it still uses GOTO's". I was very deflated and have been trying to hint at how good VDS is ever since.

So I made this skeleton application with out using GOTO's.

Is there any reason why I shouldn't do it this way??

Code:


Title Get lost goto
DIALOG CREATE,Get lost goto,-1,0,240,160
  DIALOG ADD,BUTTON,B1,110,90,64,24,OK
  DIALOG ADD,EDIT,E1,37,75,90,19,Test,,EXIT
  DIALOG ADD,EDIT,E2,63,75,90,19,stuff
  DIALOG SHOW

rem Event Manager Loop
repeat
    wait event,4
    gosub @event()
until

:B1BUTTON
    gosub Groovey
    exit

:E1EXIT
    exit

:Timer
    exit

:Groovey
    gosub nice
    exit

:Nice
    exit
   
:Close
    stop


Thanks

David...
Back to top
View user's profile Send private message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Wed Nov 21, 2007 10:08 pm    Post subject: Reply with quote

Your friend will give you the same reaction with that code since it uses GOSUB. Reason being is that he's used to running all his code in the main loop of his programs. Or in our case all code would be in the EVENTLOOP, or in your example the "repeat" loop there.

It is an ancient belief that using GOTO and GOSUB CREATED slower code, and it did, back in the days of 8088's and maybe even 386 computers, back when the CPU was so much slower. But these days, it doesn't matter much, if at all, if you use those now since the computers are so fast that you're not going to notice any sort of speed difference using either method, unless you're getting into millions of lines of code, then, maybe then you might notice a difference.

Here's what he might better relate too here:

Code:
Title Get lost goto
DIALOG CREATE,Get lost goto,-1,0,240,160
  DIALOG ADD,BUTTON,B1,110,90,64,24,OK
  DIALOG ADD,EDIT,E1,37,75,90,19,Test,,EXIT
  DIALOG ADD,EDIT,E2,63,75,90,19,stuff
  DIALOG SHOW

REPEAT
  WAIT EVENT,"0.5"
  %E = @event()
  IF @equal(%E,B1BUTTON) 
    %E = GROOVEY
    INFO B1BUTTON
  END
  IF @equal(%E,GROOVEY) 
    %E = NICE
    INFO GROOVEY
  END
  IF @equal(%E,NICE) 
    %E = CLOSE
    INFO NICE
  END
  IF @equal(%E,E1EXIT) 
    %E = CLOSE
    INFO E1EXIT
  END
UNTIL @equal(%E,CLOSE)
EXIT
STOP


That would be more like what he's used to seeing and what he's expecting. Except he'd likely see the use of CASE instead of IF statements.

Show him this code, and if he still says "crap" then he's just full of oops himself and being ignorant, at which point, nothing you show him will open his eyes to anything. Be sure to impress upon him that you're not trying to take him away from his precious C, but merely to offer him an alternative to his C for quick hacks when needed.

~Garrett

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
WidgetCoder
Contributor
Contributor


Joined: 28 May 2002
Posts: 126
Location: CO, USA

PostPosted: Thu Nov 22, 2007 12:14 am    Post subject: Reply with quote

Personally, I like the that VDS is not a highly structured language and that it uses the familiar old DOS branching syntax “GOTO”. I think you will find this technique while looking more non-linear and structured really has no actual advantage. It creates an unnecessary level of nesting for both the REPEAT and GOSUB commands (mem usage).

If you want to test that theory create two identical programs one with the standard goto loop and one with your gosub branching. Compile them, run them both at the same time, and compare their memory usage with task manager. I’m sure the difference will be slight but the gosub branching will use more resources.
Back to top
View user's profile Send private message Send e-mail
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Thu Nov 22, 2007 9:45 pm    Post subject: Reply with quote

David,
I am a professional programmer. I program in many languages including C/C++. I would simply ask him how he handles error checking or better yet ask him to explain how the C++ compiler handles error checking when the code is actually compiled. C++ is not a structurally sound language and even the creator of C++ said so. Structured programming is only 1 style of programming that can be applied to any language. Using goto's in a scripting language is ok as long as you use a top down approach and always return back to where the original call was made. Also ask him that if you are not supposed to use a goto then why does C++ still offer the goto statement. Normally it should be used for speed and if there is no other way to accomplish what you want to. For him to totally over look another programming language because it has the goto statement is pretty narrow minded and the fact that he claims to be a C++ programmer and does not realize that C++ has a goto statement as well is just sad. One should never think that only 1 language is the best of all languages and even the creator of C++ will not make such a bold statement as to say that C++ is the end all of all programming languages. Challenge this C++ programmer. Ask him how many lines of code would it take him to build a program that does exactly what the code I am showing below. The code below follows Structural top down programming standards. Most class based languages are not Structurally sound due to polymorphisms. For that matter C++ is actually less structural than VDS since C++ uses mostly compiler directives and MACROS from header files. Goto or no Goto; a purely procedural language like VDS can be easily programmed in a structural form.

Code:

#-----------------------------------------------------------------------------#
#                                                                             #
# Below is an example of Shockwave Flash that show how                        #
# to create the ShockwaveFlashObjects object and place it on a VDS Dialog     #
#                                                                             #
# Author:  Johnny Kinsey                                                      #
#                                                                             #
# Copyright: Copyright © 2007 DragonSphere Software                           #
#                                                                             #
#-----------------------------------------------------------------------------#
#RESOURCE ADD,BINARY,GADGETX.DLL,GADGETX

Title Create Object Examples
If @Greater(@Name(@SYSINFO(DSVER)),4)
  External GadgetX.dll,@SysInfo(DSVER)
  # GadgetX Commands
  #DEFINE COMMAND,GadgetX,DEFINE,OLE,Set
  # GadgetX Functions
  #DEFINE FUNCTION,GadgetX,OLE,Get
Else
  Warn This Example uses VDS 5 or above syntax.
  Stop
End

# The following line is required
Ole Init
# The following line is optional
# it is here for debugging your script
Ole Exceptions,SHOW
:Main
# Gets the pixels from inches
# This allows our flash player to display a
# wide screen 9" wide X 6" height just like many portable DVD players.
%%Width = @Prod(@Sysinfo(PIXPERIN),7)
%%Height = @Prod(@Sysinfo(PIXPERIN),4)
  # Shockwave Flash
  %%classname = #TFlashDemo
  DIALOG CREATE,Flash Player Demo,-1,0,%%Width,%%Height,CLASS TFlashDemo,PAINT,RESIZABLE
  #DIALOG CREATE,Flash Player Demo,-1,0,672,384,CLASS TFlashDemo
  DIALOG ADD,MENU,File,Open,Stop,Play,Loop,-,Quit
  DIALOG ADD,MENU,DragonSphere.net,DragonSphere,Clock
  DIALOG ADD,MENU,Neave.com,Space Invaders,Simon,Frogger,Hexxagon,Visit Neave.com
REM *** Modified by Dialog Designer on 3/14/2007 - 09:49 ***
    # Dialog Add,EDIT,EDIT1,0,0,672,384
    GadgetX Add,Ole,ShockwaveFlashObjects,%%classname,0,0,%%Width,%%Height,ShockwaveFlash.ShockwaveFlash,NULL
  DIALOG SHOW
  %%url = http://www.dragonsphere.net/images/dragonfly640.swf
HOTKEY ADD,ESCKEY,ESC
# property AllowScriptAccess
# Ole Set,ShockwaveFlashObjects,"AllowScriptAccess = ^b",True
# method LoadMovie
Ole Call,ShockwaveFlashObjects,"LoadMovie(^d,^B)",0,%%url
# property Loop
Ole Set,ShockwaveFlashObjects,"Loop = ^b",False
%%UserStopped =
%%IsGame = 1
:evloop
  Repeat
    wait event,0.3
    %E = @event()
    If %E
      GoSub %E
    End
  Until @Equal(%E,CLOSE)@Equal(%E,QUITMENU)
Exit

:TIMER
  # method IsPlaying
  %%IsPlaying = @Ole(Call,ShockwaveFlashObjects,^b,"IsPlaying")
  If @Equal(%%IsPlaying,False)
   # property Loop
    %%IsLooping = @Ole(Get,ShockwaveFlashObjects,^b,"Loop")
    If @Equal(%%IsLooping,True)
      If @Null(%%UserStopped)
        # method Play
        Ole Call,ShockwaveFlashObjects,"Play"
      End
    Else
      # method Rewind
      If @Null(%%IsGame)
        Ole Call,ShockwaveFlashObjects,"Rewind"
      End
    End
  End
Exit

:RESIZE
:PAINT
  %%Width = @dlgpos(,W)
  %%Height = @dlgpos(,H)
  Ole Setpos,ShockwaveFlashObjects,%%classname,0,0,%%Width,%%Height
Exit

:HOTKEY
  %E = @HOTKEY()
  If %E
    GoSub %E
  End
Exit

:OPENMENU
  %%url = @filedlg("Flash Files (*.swf)|*.swf|Flash Video Files (*.flv)|*.flv",Open file)
  If %%url
       # method IsPlaying
       %%IsPlaying = @Ole(Call,ShockwaveFlashObjects,^b,"IsPlaying")
       
       If @Equal(%%IsPlaying,True)
         Ole Call,ShockwaveFlashObjects,"Stop"
         %%UserStopped = 1
       End
     
      %%IsLocal = @Substr(%%url,2,2)
      If @equal(%%IsLocal,":")
        %%url = File://%%url
      End

    # method LoadMovie
    if @Equal(@Ext(%%url),flv)
      Ole Call,ShockwaveFlashObjects,"LoadMovie(^d,^B)",0,File://@Path(%0)flvplayer.swf
      # property EmbedMovie
      Ole Set,ShockwaveFlashObjects,"EmbedMovie = ^b",True
      Ole Set,ShockwaveFlashObjects,"AllowFullScreen = ^b",True   
      Ole Call,ShockwaveFlashObjects,"SetVariable(^B,^B)",autostart,true
      Ole Call,ShockwaveFlashObjects,"SetVariable(^B,^B)",file,%%url
      #Ole Call,ShockwaveFlashObjects,"SetVariable(^B,^B)",playpause,play
      # method Play
      Ole Call,ShockwaveFlashObjects,"Play"
      %%UserStopped =
      %%IsGame =
    Else
      IF @ASK(Is this a Game?)
        %%IsGame = 1
      Else
        %%IsGame =
      End
      Ole Call,ShockwaveFlashObjects,"LoadMovie(^d,^B)",0,%%url
    End
    If %%IsGame
      # property Loop
      Ole Set,ShockwaveFlashObjects,"Loop = ^b",False
    End
   
  End
Exit

:ESCKEY
:STOPMENU
  Ole Call,ShockwaveFlashObjects,"Stop"
  %%UserStopped = 1
Exit

:PLAYMENU
  # property Loop
  %%IsLooping = @Ole(Get,ShockwaveFlashObjects,^b,"Loop")
  If @Equal(%%IsLooping,False)
    # method Rewind
    Ole Call,ShockwaveFlashObjects,"Rewind"
  End
  # method Play
  Ole Call,ShockwaveFlashObjects,"Play"
  %%UserStopped =
Exit

:LOOPMENU
  # property Loop
  %%IsLooping = @Ole(Get,ShockwaveFlashObjects,^b,"Loop")
  If @Equal(%%IsLooping,True)
    # property Loop
    Ole Set,ShockwaveFlashObjects,"Loop = ^b",False
  Else
    # property Loop
    Ole Set,ShockwaveFlashObjects,"Loop = ^b",True
  End
Exit

:DragonSphereMENU
  # This animation was originally an AVI that I had built years ago.
  # I used the avi2swf.exe from http://www.swftools.org to make it a Flash Movie.
  # Which BTW made the overall size of the animation much much smaller.
  %%url = http://www.dragonsphere.net/images/dragonfly640.swf
  Ole Call,ShockwaveFlashObjects,"LoadMovie(^d,^B)",0,%%url
Exit

:ClockMENU
  # This clock was donated by Marty
  %%url = http://www.dragonsphere.net/images/clock.swf
  %%IsGame = 1 
  Ole Call,ShockwaveFlashObjects,"LoadMovie(^d,^B)",0,%%url
  If %%IsGame
    # property Loop
    Ole Set,ShockwaveFlashObjects,"Loop = ^b",False
  End
Exit


:Space InvadersMENU
  %%url = http://www.neave.com/games/invaders/invaders.swf
  %%IsGame = 1
  Ole Call,ShockwaveFlashObjects,"LoadMovie(^d,^B)",0,%%url
  If %%IsGame
    # property Loop
    Ole Set,ShockwaveFlashObjects,"Loop = ^b",False
  End
Exit

:SimonMENU
  %%url = http://www.neave.com/games/simon/simon.swf
  %%IsGame = 1
  Ole Call,ShockwaveFlashObjects,"LoadMovie(^d,^B)",0,%%url
  If %%IsGame
    # property Loop
    Ole Set,ShockwaveFlashObjects,"Loop = ^b",False
  End
Exit

:FroggerMENU
  %%url = http://www.neave.com/games/frogger/frogger.swf
  %%IsGame = 1
  Ole Call,ShockwaveFlashObjects,"LoadMovie(^d,^B)",0,%%url
  If %%IsGame
    # property Loop
    Ole Set,ShockwaveFlashObjects,"Loop = ^b",False
  End
Exit

:HexxagonMENU
  %%url = http://www.neave.com/games/hexxagon/hexxagon.swf
  %%IsGame = 1
  Ole Call,ShockwaveFlashObjects,"LoadMovie(^d,^B)",0,%%url
  If %%IsGame
    # property Loop
    Ole Set,ShockwaveFlashObjects,"Loop = ^b",False
  End
Exit

:Visit Neave.comMENU
  Shell Open,http://www.neave.com
Exit

:QUITMENU
:CLOSE
  # method IsPlaying
  %%IsPlaying = @Ole(Call,ShockwaveFlashObjects,^b,"IsPlaying")
  If @Equal(%%IsPlaying,True)
    # method Stop
    Ole Call,ShockwaveFlashObjects,"Stop"
  End

  # The lines below are required to be called
  # before your script exits
  If @Get(ShockwaveFlashObjects)
    # Remove the object from the Dialog
    Ole Remove,ShockwaveFlashObjects,%%classname
    # Free the Object variable
    Ole Free,Object,ShockwaveFlashObjects
  End
  # The following line is optional
  # it is here for debugging your script
  # Ole Exceptions,HIDE
  # The following line is required to be
  # the very last executed line in your script
  Ole UnInit
Exit



Also the reason you want to use the Structural Programming Paradigm is not for speed or more efficiently running code but for readability and re-usability. If you are programming large projects it does make it easier to trace bugs and is less likely to form bugs. For simple examples of what the language can and cannot do it should not be needed to go to such extremes to prove a language's worth. VDS is a rapid development scripting language. It would be akin to shell scripting. It is not really made to be a full blown systems language like C/C++ but we have found ways to close that gap over the years of using the language and developing for the language. Anyway don't worry about proving to others the worth of VDS. Build really cool and unique programs with VDS and let the language speak for itself.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
ShinobiSoft
Professional Member
Professional Member


Joined: 06 Nov 2002
Posts: 790
Location: Knoxville, Tn

PostPosted: Fri Nov 23, 2007 1:09 am    Post subject: Reply with quote

dragonsphere wrote:
Anyway don't worry about proving to others the worth of VDS. Build really cool and unique programs with VDS and let the language speak for itself.


Here here!!!!!! From another C/C++ programmer. Well said Johnny Worship

On another note, I've been an active martial artist for 30 years. One thing
that has always been taught and sticks in my mind is -> 'Never limit
yourself to one style, and to keep an open mind'.

_________________
Bill Weckel
ShinobiSoft Software

"The way is known to all, but not all know it."
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group