News:

Function Finder  Find all the functions within source code files

Main Menu

Program too long to edit

Started by Kman1011, February 04, 2007, 01:02:44 PM

Previous topic - Next topic

Kman1011

I get the same problem every time. The program code gets too long and cumbersome to edit. When you get to 600 lines of code, you tend to lose subs in the vastness of the program. :o

I've tried different navigation tecniques but then best I could find is bookmarking. Awesome idea. Problem is, the bookmarks disappear after you exit the program.

What are some tips on overcoming this problem. All replies welcome  ;D

(What might be nice is collapsable if/endif, gosub/return segments just like Psub & Functions)

Thanx.
Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA

empty

Use multiple source codes. Put your functions, subroutines etc in different files grouped by their task.

kevin

#2
QuoteI get the same problem every time. The program code gets too long and cumbersome to edit. When you get to 600 lines of code, you tend to lose subs in the vastness of the program.

   I think that depends upon upon your definition of 'vast'  :)

QuoteI've tried different navigation tecniques but then best I could find is bookmarking. Awesome idea. Problem is, the bookmarks disappear after you exit the program.


* Use meaningful (predictable) Functions/Subs/Labels/Array/Type etc   names.  

* Indent code.  So the flow of the program is more obvious. When the indents get too large  break them up into subs/functions were possible.   Again using meaningful function/sub names.

* Break the code into Multiple sources.    ( Declarations area, Image loading/creating/anim functions,  Player, Aliens, etc etc, Main)   Where each source  holds a focused collection of functions/types/ sub routines (whatever) about this particular theme.  

* Use 'Find Declaration" (right click over the keyword you looking for) to find declarations arrays/functions etc in your program
 
* Use Built in functions where-ever possible.   Making code smaller/simpler & faster!



  New to coding ?  - Dont forget to read the   PlayBASIC Help Files



Ian Price

#3
Perhaps you should examine your programming style?

My current PB game, Sorcery is coming up to nearly 10 times the 600 you mentioned - 5759 lines of code and I know exactly where everything is and what it does. Meaningful naming of variables and functions and everything as mentioned above saves time and confusion as to what each is/does. Admittedly, my code is constantly being refined and cut back, and I do also use lots of spacing (two lines between functions etc.) and lots of comments.

[EDIT] Added screenshot
I came. I saw. I played some Nintendo.

kevin


Ian,

   Just looking at your piccy and you might wanna check this :)


Dim Stuff(2)
for lp=0 to 10
inc stuff(1)
stuff(2)=stuff(2)+1
next
print Stuff(1)
print Stuff(2)

sync
waitkey


Ian Price

Just reading your code Kevin, I couldn't understand what the difference between "inc stuff(1)" and then "stuff(2)=stuff(2)+1" bit, then I ran it in PB and realised exactly what was happening and why my code wasn't working correctly at that point. Will it be possible to inc arrays at some point?

Cheers :)
I came. I saw. I played some Nintendo.

Kman1011

Thanks for you help guys

QuoteI think that depends upon upon your definition of 'vast'

OK I exaggerate, but it does get tricky to manage after 1000 lines of you have to admit.

Quote* Use meaningful (predictable) Functions/Subs/Labels/Array/Type etc   names.

That I do. Although I think I have some studying to do. I have problems getting some of the variables to return from the subroutine.

Quote* Indent code.

If I didn't do that I would totally be lost.

Quote* Break the code into Multiple sources.    ( Declarations area, Image loading/creating/anim functions,  Player, Aliens, etc etc, Main)   Where each source  holds a focused collection of functions/types/ sub routines (whatever) about this particular theme.   

empty said
QuoteUse multiple source codes

OK. I've seen this but not sure I understand how it works. Is this where you use the Incude# directive? I didn't see anything in detail in the docs about this or is this something every programmer should already know.

I'll try to convert my many gosub routines to Psubs and Function to start.

Thanx

Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA

kevin

#7
  
Update: Modern Editions of PlayBASIC support various C styled short cuts such as ++,--,+=,-=, *=  etc etc



QuoteWill it be possible to inc arrays at some point?  

 Probably.   Supporting INC/DEC Requires changing how data is returned from arrays() structures.   The PB1.50->2.00 design doc lists a few more C ism's within assignments to come, which fit better with how PB works.  ie.

 Stuff(10)=Stuff(10)+5

 Could be,

 Stuff(10)+=5

 So that's probably the road i'll take.

QuoteOK I exaggerate, but it does get tricky to manage after 1000 lines of you have to admit.

 Only if you add a few more 00's to the end of that.  

 
QuoteOK. I've seen this but not sure I understand how it works. Is this where you use the Incude# directive? I didn't see anything in detail in the docs about this or is this something every programmer should already know.  

See -> IDE FAQ

  All code in PlayBASIC is build around the Project concept.  Each project can have various source files attached to it.  

  When you add extra sources to the project that will be appear in include order.   Say if you have a project with 3 sources.

  [ declares ]   [Functions  [Main]

  The IDE will batch (join) this code out to the compiler in the following form.

[ Declares ]
      Code here

[ Functions]
     Function code here

[ Main]
   Program main loop




QuoteI'll try to convert my many gosub routines to Psubs and Function to start.

  If you have lots of Labels, You can use the source inspector to browse to whatever point you like.    




Ian Price

I've used C++ in the past (I wrote a few bits and bobs with it) , and I like the +=, ++ etc. system and would welcome that with open arms into PB. This was also used in Div to good effect.
I came. I saw. I played some Nintendo.

Kman1011

#9
100000 lines of code!! :o. Is there any limit to what the editor can hold. Yes i think at this point I need to use Source files.

Thanx for the FAQ link. It answered my question.

I think it was a matter of navigation though the program. It seemed to take longer and longer to find the code or routines I was looking for. Mind you it was just starting to. I was concerned that when my program got to be as big as ... well maby as Ian's project -5759 lines of code- that it would take forever to seek out routines. But as he showed the screen shot, I noticed the list to the right. These are the subs or source files?

My project might come in at 4000, but there's no way to tell. I still have to draw in enemy sprites and move them differently by type. An intro, and so on.

I'll keep you posted on the progress

L8R!
Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA

Ian Price

Those are all functions on the right (in my screenshot) - I place all necessary code relating to a certain part of the program in it's own function, then call it when it is needed. Eg - the "load_data" function is only used to load the data that the game needs. It's not part of the main code, but a completely seperate entity, that only does one thing and only when I need (and call) it. That function does not run independendntly on it's own (no function should do that), but onl when I want it to run. All the other functions are the same.

The "render_XX" commands are the enemy routines, which control their animation, movement and AI. These are all called for in my "Main" function, the main loop of my program.

I've managed to optimise my code a bit now (approx. 5496 lines now), but it is a full game, containing 75 levels, nearly 200 doors, 180 objects, 120 enemies and other elements etc. It also includes a title screen, full options menu, redefine keys routines, joypad routines, load/save game routines, working high-score table etc. And thankfully, it's nearly done now (code-wise). I've just started adding graphic effects to it and will soon be updating all of the original graphics. That's where the hard work comes in! :P
I came. I saw. I played some Nintendo.

Kman1011

WOW :o

I'm impressed. I was wondering if you had a finish date on this game. Mind me asking just how long it took you to write?

I'm hoping my game (either Mecha or BlackIce havn't decided) is done by the end of the year. My graphics are 90% done. I'm using AutoCad2006 3D rendering to create the mapgraphics as well as the enemies and some of the items. I suck at drawing by hand. Here is a small sample of artwork of a green gate key
I have several routines myself I've converted into Psubs. A bulk of the program I'm writing consists on a long Joypad and map collision checking If/endif structure based on a very important variable I called 'Actionmode'. Each actionmode ie-running,climbing,swimming ect. has an Actionmode number because the rules (joypad and mapcollision) is different for each action.
Now that I used these Psubs I can see it in the Source inspector and use IT the navigate. It'll help alot
in my programming. Although is passing arrays really as easy just

MYSUB(MyArray())

PSUB MYSUB(MyArray())

I have alot of routines with arrays in them.

Anyway I'll be plugging away!! Thanx
Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA

Ian Price

Gameplay-wise, it's done, with only bug hunting/fixing to do now and adding any extras that I want to include. Doing the graphics will take longer than doing the code (I started at the end of December).

Your game sounds interesting - fully 3D rendered images in a PB game will probably be a first. Look forward to seeing more of this :)
I came. I saw. I played some Nintendo.

Kman1011

Well good luck fixing the bugs.

I hate that task. I have a few of my own already >:(

L8R
Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA