Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Procedure too big  (Read 4674 times)

0 Members and 1 Guest are viewing this topic.

Umpal

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 37
  • Programming and graphic
Procedure too big
« on: February 28, 2018, 12:24:16 AM »

I'm encountering this problem for the... can't recall which time. Usually I reduce the procedure but this time it would be a real pain in the back. Simply Amos can't handle well a procedure with many conditionals (If and some Else If). I mean many, many conditionals. It crashes or displays nonsense errors in lines that are OK or does other circus things. If I delete just one line then it all comes back to normal (doesn't really matter which conditional I choose). Is there a declaration like Set Buffer that expands somehow capability of such procedure and/or Amos in general? Of course rising the value of Set Buffer doesn't change a bit so it would have to be something different, if exists.
Logged

adrazar

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 69
  • Generic Amiga User
Re: Procedure too big
« Reply #1 on: February 28, 2018, 11:50:21 AM »

I have a slightly random suggestion; does it help if you create a gosub routine inside the procedure and move one of the "else if"-blobs into it?
Logged

KevG

  • A600
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 87
Re: Procedure too big
« Reply #2 on: February 28, 2018, 01:13:50 PM »

Hi Umpal

It would help if you posted your code. People could then figure out what is causing the problem. Also, you say that you are using many, many If..Else..EndIf statements. Why don't you use a mapping instead? This will shorten the code AND increase the speed immensely.

Logged

Umpal

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 37
  • Programming and graphic
Re: Procedure too big
« Reply #3 on: February 28, 2018, 05:30:31 PM »

@adazar, I occasionally use Gosub in that procedure to a subroutines that repeat often, but I even if I did it with all Ifs it doesn't make sense since they would be still in the same procedure (it would even complicate the code and made it slower).

@KevG, what kind of mapping do you mean? You have my attention. I won't publicize the code since it's a part of something bigger and doesn't work alone. Anyway it's still simple If...End If and If...Else If...End If so there is no rocket science. I assure you it's not the code itself, it's the size of the procedure. Tested and confirmed not only by me. Please let me know about the mapping, how it is working and how it can replace and make faster the code (the latter is very interesting also).
Logged

KevG

  • A600
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 87
Re: Procedure too big
« Reply #4 on: February 28, 2018, 05:55:35 PM »

@Umpal

It doesn't matter if the code doesn't work on its own. Just post the procedure and people will be able to look at it and recommend improvements. People are here to help but you must give us something to work with. How do you expect me to provide a mapping example? I don't know what values I am supposed to map.
« Last Edit: February 28, 2018, 05:57:20 PM by KevG »
Logged

adrazar

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 69
  • Generic Amiga User
Re: Procedure too big
« Reply #5 on: February 28, 2018, 10:00:25 PM »

Why don't you use a mapping instead? This will shorten the code AND increase the speed immensely.
Could you give a simple example showing what a transformation of an else if-block to a mapping looks like?
Logged

KevG

  • A600
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 87
Re: Procedure too big
« Reply #6 on: March 01, 2018, 05:26:44 PM »

OK. here is an example of some very shocking code that a lot of people seem to use.

If A=1 : b=24 :end if
If A=2 : b=12 : end if
If A=3 : b=93 : end if
If A=4 : b=45 : end if
etc.etc.....

It uses a lot of condition checking which slows things down.

Here is how to do it properly and it is instant!

Rem Put this code at the beginning when you set everything up
Dim myArray(5)
myArray(1)=24
myArray(2)=12
myArray(3)=93
myArray(4)=45

Now rather than use If:endif statements, we simply map through the index in the
array to read the value.

B=myArraY(A)

That is it. That's all you have to do. What ever A is, it returns the value in B
No condition checking at all and its in one statement.


Logged

Umpal

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 37
  • Programming and graphic
Re: Procedure too big
« Reply #7 on: March 02, 2018, 12:01:32 AM »

KevG, I've read about mapping after your post but that's the best explanation I've seen so far (no need to read more, thanks, you have my applause). However, it won't work in my case (no, I won't post my code because I don't want to.) Anyway, I solved my problem as I did couple of times before - by splitting the procedure into two. I just had to pass on some variables and one local table but that's piece a cake. I just had hope there was some command that makes Amos more cooperative in that case. I've learned to live with how Amos is so I still like it ;-)
Logged

KevG

  • A600
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 87
Re: Procedure too big
« Reply #8 on: March 02, 2018, 10:34:40 AM »

Hi Umpal

A mapping is simply the process of matching one set of numbers with another set of numbers.
I use them all the time because of the speed at which they work and there is less code.

The example I gave above is a very, very simple example but effective.
Logged
Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022