News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

program with a lot of code. How to do ??

Started by krizpin, Jan 15, 2022, 05:33 PM

Previous topic - Next topic

krizpin

good morning.
I have a question about how to proceed...
I have a program with about 3500 lines of code, the problem is that having so much code makes me go crazy trying to find things and I'm always scrolling up-down. How can I separate the code into different files??? should I separate it into INC files???? because the problem with that is that there are different pieces of code that share the same variables and there I have a problem also when creating the INC files. Please can you tell me how to proceed when the programs have a lot of code?
Thanks

trastikata

If you don't want to use INC files, create functions at the bottom of the code and organize them according some arbitrary rules.

Even if the function is being called only once in the main program, it will help with improving the program's readability.


krizpin

is that I was not very clear if it was correct to use INC files to place code of the main program, also the problem is that in that inc file I have to include the variables that are used in that part of the code. So when you were variables or symbols are shared with another part of the code, it gives me an error when compiling it because either I have the variables in one part or another. but it tells me that the variable is duplicated

Yves

I normally use a lot of blablabla.inc files each of them can be tested individually. You can then call them individually either by a gosub or proc so the main program is directing the various sequences  to obtain desirable flow. When a subroutine works you don't want it to clutter with other subroutines and they are easily reusable. I also use an Variables_constances.inc file where I declare all variable and constants and one that do all the declarations for the pic in question. all those inc(s) are placed at the beginning of the  main code. Some needs to be jumped over. The main program can be kept quite short and act like a Maestro in an orchestra.  That is my 5 cents contribution   

regards,

Yves
Yves

TimB

If you use Positron studio you can add bookmarks. I find them invaluable to jump around between subs.

krizpin

Many thanks to everyone for the replies. Personally I had opted for the inc files, it seems to me the most comfortable option but I will also have the bookmarks account and possibly also use them. Thanks to all for the help

JohnB

Positron Studio also provides a Project Manager where you to maintain a list of include files and other data files, PDFs etc in a collection.
JohnB

Stephen Moss

Krizpin,
in the original Mechanique IDE if you have used a label to define the start of a code section, or a Subroutine (no sure about Procedure) they should be listed in the Code explorer, even those in the include file (under the includes subfolder). Clicking on the one relevant for the code you want to jump to should take you there.

I am not sure if the same applies if using FineLine, I have not looked at it recently but as I recall the same applies to the Positron Studio IDE if the include files are part of a project. As Tim said the Positron Studio IDE also allows you to add bookmarks for additional navigation which is useful if you only have one large file.
Personally I would try and avoid having a single large file as I find it easier to maintain when split in to several several files.

krizpin

The truth is that these days I have been thinking about the code and it seems to me that dividing it into several inc files is the best option, everything is very tidy and very easy to access. thanks for your comments