How to not loose track ?

I am doing a fairly big app.
Consist of at least 5 individual pages and within each several functions and classes with touch and data events.

I am loosing track and the red line with all the different files I have put together.

What is a good system to keep the overview ?
How do you do it ?

Re Peter

Fairly broad question! There are many ways to do it, more and more complex when you go to the professionnal side (UML). I can tell you i do (or try to do) it:

Draw your Data structure and Processing Blocs : identifying them is a key point: put your data in a class with simple and clear elements. Draw you data structure on a paper with lines indicating relationships with methods (processing blocks). Check again if you haven’t forgotten any bloc or line. At that point your drawing should look like an inextricable mesh (don’t be scared that’s normal!). Redo the drawing trying to make it look nice and ordered, with minimum line crossing. If you can’t do it, then that’s what your code is: inextricable! No wonder why you loose track… Try to re-organize your blocs on paper until it looks clear, add new blocs or functional lines if needed to make it clear. And once you’re happy with it, recode it! Having the map of your code on a paper drawing allows you to remove it from you brain, leaving room to focus on details, one by one.

Example: I’ve worked on this planet simulator and i got completely lost because it was so complex i was unable to do any addition or changes at some point. I have recoded completely 3 times the projec, each time simplifying, ordering to make it easier, but each time not satisfied. Now i am in the 4rth recoding… As an example, here is my 1rst drawing on the left (i use bamboo,paper app, free and easy to draw) and the 5th version of drawing on the right (at some point i switch to graphio light free app, because is is easier to reuse the previous version than with bamboo). I have not writen code between these 5 drawings, just re-done drawings. Once i was happy with the final drawing, the recoding was easy and pleasant, because i could avoid to keep everything together in my head, and concentrate on each bloc individually.
Compactness try to make ‘compact’ classes, i mean with minimum interractions between classes: that’s the interractions that become so complex that you can’t view them all at once and you don’t understand anymore what your program is doing. Group your functions in one class by functionnalities, in such a way that you can work on this bloc without impacting the other blocs: this is a key point for easy maintenance/improvement in your code.

Top-Bottom Bloc organization divide your code in small functions that are smaller than 1 page, so can view it all at once. Make sure you can write down what this bloc is doing, and do it, at the beginning of the bloc. If the description is too long, split it in two simpler blocs. In one bloc call subfunctions that do simple things, with same rules.

unit tests Test each of your blocs. It is easy to do with dependancies: create a project for your new class, create a tab for this class. In the main tab, write a few simple functions that proove you by printing their input+output that the class methods work as expected, and the class data are correctly filled. When you’ll call this project as a dependancy in your main project, the main tab will not be loaded, so you will not be bothered by it. Oh, and i forgot that one: write and run your test function each time you finish one function, not all at the end, cause then you won’t do it!

If you follow these guidelines you can probably multiply by 10 the number of code lines you’ll be able to manage(at least that works for me). Beyond that you’ll need to read books about programming methods.

Thanks for taking a lot of time trying to this extensive explanation :slight_smile:
It helps a lot to see your thoughts put in writing.
Though my project may not be as complicated as yours, I think, I have also re-coded some times now. Mostly because I tend to break up my ideas into self containing projects and running them individually. It then gets complicated when I try to put it all together because same variables and logic is used in the parts.
It is a very good thing to “box” it and I do just that in my normal engineering work a lot.

What I have thought to be worth trying is putting the parts into classes that do everything for that part of the program.
As mentioned I have 5 pages for now with their own touch events etc. So every page goes now to a class that I can work on without interfering with the others. I have to be strict about the links in between these parts and avoid any if possible.

One thing I would wish where possible in the Codea layout, is sub file tabs, so a file could have a number of tabs, one for each function in the file. This way you could try to limit yourself to a one page function only and avoid scrolling. Maybe in 1.5, I did not check if it is planned.

Another good option is the use of iExplorer so coding takes place in TextWrangler on my MacBook. I have just made this setup and think it will help some, however ruining the good felling of coding in Codea.

Re Peter

@Jmv38 - that’s some really helpful advice, thanks for sharing.

I would also add a comment that you should try to use local variables as much as possible.

function IterateArray()
   --locally set variable. 
   -- This will be destroyed after IterateArray is done
   local max=50    
    for x = 1,max do
       --process array item here

function CountSheep()
  --At this point, max is nil and the 
  -- code will FAIL 
  --  (a good thing, you should be explicit!)
  for x=1,max do
      --count / process a sheep
  1. They stop confusion: once the function is done, they are “gone”. This stops the global use of “x” in one routine completely hsoing up another, unrelated routine.

  2. They are faster. Locals don’t use the global space in LUA, so the memory allocated globally is conserved. This gets important as your projects get larger.

  3. It’s easy to see when you are getting sloppy/hacky. If you are reusing a variable all over the place, consider making that variable a global with a CLEAR/CONCISE name, so, once again, you don’t have “x” or “loop” all over your code.

The image above by Jmv38 is why I started my Coding On Napkins project: to turn crude drawing into running code with the maximum possible help from our computers.
I also want to retain these images in the source code as documentation that stays correct when the code is changed.
A very important part of Coding On Napkins is to make understanding and maintenance of existing code easier years later when none of the orinal creators is around to help.
My ViewingCODEA project is a start in this direction but constructing a lua code reader/parser is a much bigger task than I had thought.

Writing a lua reader/parser? Have you looked at loadstring()? I think that does what you ware looking for in one line…

He wants a drawing parser, not a text parser.

Hmmm…so attach metadata to shapes, then parse the shapes as commands?

I don’t want to execute the code but to extract all the infomation in it so I can look at the code in a variety of ways to understand how it works, find errors, see if I need to “refactor” the code, etc.

For example:
– I want to see all calls to a function on one screen with the arguments in neat columns so I can see how the function is used or if I am using ir incorrectly.
– When a project uses classes, I want to see everwhere a class is used, starting with a list of all obj’s such that obj=C() for C=class().
– I want to tap on a function call to see the definition on the same screen as the call.
– I want to create 2D “minimaps” with lines showing execution flow or everywhere a variable is used. I want to use different size fonts and autohiding to see uses in context.
– I need to keep a history of what I have seen and eventually make notes and draw on the code to help retain what I learn…

Code is really a complex node/edge graph that we currently write as one long text string.
It would be better to think and write code in the graph form.

ViewingCODEA will eventually turn into an editor incorporating all these views with easy editing especiallty of large projects

What I really need is to get at all the information the CODEA/LUA interpreter/compiler creates and then throws away.

Any suggestions?

Currently ViewingCODEA is just for my own use.
A completed maintained version or incorporation into the native CODEA system will have to be done by someone else.