FOLD subroutines

Previous topic - Next topic

erico

is it possible to fold subroutines in glbasic like, for example,  AMOS used to do?
Does anyone have an idea on achieving similar goal? I'm sure there must be a way but it escapes me, help?

FutureCow

If you mean is there any way to do it in the IDE to shrink your subroutine down to one line, the answer is no unfortunately.  :'( I put it in as a feature request ages ago.
There is also no way at this time to use an alternative IDE that supports code folding (eg. Eclipse) and have it integrate nicely with the compiler as the two are currently tightly coupled.

Your only current way to do this is :
* Load the project in GLBasic
* Close the source file you want to work on (but keep the project open)
* Edit your code in a compiler supporting code folding
* When you're ready to compile, switch back to the GLBasic IDE and compile. Switch back to the other IDE to do more editing of the code.
* Note that if you use the debugger it will reopen the source code window which you'll need to close again before you can go edit your code.

It's a pain but your only solution at present.

erico

thanks future crow, folding subroutines in the IDE is what I was looking for.

I'm a messy programmer, learned to use arrays just some time ago, before that I would duplicate the variables and duplicate the code to achieve let's say, a second player. Can you believe it?not to mention enemies!! I remmember my 2 player fight game on the amiga to have something like 3k lines of code! (I still have the code).

Anyway my programs tend to get really big, I try to organize it by making it modular and lot's of documentations(rem), so a lot of subroutines pop up. Problem is that if I stay away from it, let's say a week, it becomes a pain to understand it again.

Folding subroutines helped me a lot on amos on these issues, so I was looking for it.

I understand nowadays there are a lot of ways to make the code more readable and efficient, I particularly enjoy the post on TYPES that is going on right now on the forum.

It is just that I'm learning it all and sometimes I want to achieve results by whatever way I can.

I noticed you can have tabs with extra codes on the ide, are they independent? can I, say, put a subroutine in a tab and make my main program look for that? is it possible? would they share global variables?

Thanks for the help, I believe the problem here is me, I should study more on the ways to keep the code clean and organized with the so many new commands glbasic offer on that. but folding helped this poor programmer sooo muuuuch!

Moru

You can have more files, look on the right of the editor window, there is a files tab. You just right-click it and add files as you want. They are all global, the main document can call functions in the other documents

FutureCow

Erico, I'm a big one for modular programs and subroutines myself - hence why I was after code folding in the IDE too.  I found it immednsely helpful in my last programming language's IDE - I really miss it in the GLBasic one. I particularly put functions that do related activities near each other. I find it really useful to be able to see inside some functions while being able to see the names of others. Unfortunately the function list the IDE shows isn't quite the same - and I usually have it sitting as the debug window anyway so constantly changing it back to function names is a pain.

Each tab at the top of the IDE is a separate file. If you include the file as part of your project then globals will be shared between the two programs, and you can jump from a function in one file to a function in the other in your code. To add a new file go to the sub-window on the right hand side of the IDE. Click its "FILES" tab, you should see "Sources" and "Main file" in the right hand pane now. Right click in that right hand pane, click "new file" and give the file a name. The IDE will now create a new file and make a new tab for it.
To the compiler it's just like you have one long file instead of two, so anything you could normally do in one file you can do from one to the other without any changes (eg. there's no difference in calling a sub in the current file to calling a sub in another file in your project).
If however you just open a file from within the IDE while you're working on a project, anything in it is NOT accessible to your project until you include that file in the project. To do that, go to the files tab in the right hand window pane again, click "add file" and select a previously created file to add to your project.

The advantage with using multiple files is if you only change a bit in one file, it doesn't recompile any others in your project when you hit the compile button. This makes for huge time savings as your project gets bigger and gets split amongst multiple files.

Note that the Jumps tab in the right hand pane only shows you subs/functions from the currently opened file. It changes when you change to a different file tab to reflect the functions/subs in that file.

Let me know if I've explained that well enough to follow. Splitting your program amongst multiple files (eg. one for menus, one for player logic, one for CPU player logic etc) should help clean up your code considerably!

erico

Explained perfectly, thanks a lot.
I wonder if folding subs would be difficult to implement in the IDE.
I have a feeling it could make it easier for beginners to jump into glbasic.
thanks again!

bigsofty

The editor within the IDE is a third party add on, Gernot has stated in the past, that it is not within his powers to add features to this.  So rewriting the whole IDE to use another Editor component would be necessary to add features like code folding. No small undertaking for a man with such little time...
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)