Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [tutorial] Procedures + Functions + Processes
Index -> Programming, Turing -> Turing Tutorials
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rizzix




PostPosted: Thu May 05, 2005 8:27 pm   Post subject: (No subject)

yes its called closures and it can be very handy at times.. Java handles the closure concept in a different way: annonymous inner classes (this ensures type safety)
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Tue May 10, 2005 6:10 pm   Post subject: (No subject)

Tony wrote:
wtd wrote:
Within languages that support it well, local functions can be quite handy.

Really? Thinking Could you show me an example? I'm quite interested..


A counter, in Perl:

code:
sub counter {
   my $start = shift(@_) || 0;
   return sub {
      my $current = $start;
      $start++;
      return $current;
   }
}

my $c = counter;
print $c->() for 1..10;
Foundation




PostPosted: Sat Sep 16, 2006 11:07 am   Post subject: (No subject)

Doh! I still don't really understand it... I'm sorry, I'm new at programming. So what can you do with a procedure? Are all the functions in the help file? And would you use procedure if you had to use a part of your code over and over again?
Ultrahex




PostPosted: Sat Sep 16, 2006 11:38 am   Post subject: (No subject)

The Idea of Procedures can be for many uses when you go into programming Classes and also to remove repetitive code, even repetitive code with minor variations, for example you could draw a card in 5 places on the screen by using one procedure and running it 5 times (which is 5 lines of code) it saves space, and also cleans up your code at the same time.

All the functions are not kept in the Help File, Infact there is procedures also in the Turing Help File, they are not all functions. The reason not all are kept in the Help File is because you can actually make functions, Functions that come in the Turing Library are in the Help File however.

You can also use procedures to loop back to another area of code. for example if you made a game and quit back to menu you can run the procedure "runGame" that you wrote to go back and start a new game, this is much more used for user interaction in that case.

There is also many other uses of Procedures that I didn't list here.

But remeber if you are planning to do something 50 times and all the same, you do not want to use a Procedure, you would want to use a loop cause it is the exact same.

I hope this clears a few things up,
Ultrahex
richcash




PostPosted: Sat Sep 16, 2006 11:49 am   Post subject: (No subject)

Man, Ultrahex beat me to it. If he didn't already mention it, procedures (and all subprograms) can also be used for neatness and readablity. For example, it's not good to have 300 lines scattered in your main loop, it's impossible to read and very difficult to edit/debug/add things. Instead you can make separate subprograms and just call an entire chunk of code with one word.

Also, not EVERY single predefined procedure and function in the Turing library is listed in the Turing Help. There are also these rare ones not listed (well, they might be in newer versions, I wouldn't know. Not as of 4.01!).

You can find these here : http://compsci.ca/v2/viewtopic.php?t=641&highlight=unlisted
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 20 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: