Number of lines of code in user_routines.c

Hey guys!

   My code is HUGE!! .. i mean huge.. well at least i think it is:D just an overall question for all u guys out there programming this year.. my code is nearly 800 lines of code... including comments.. My question to u guys is.. 'How many lines of code does ur program have just for user_routines.c (including side files)?'

  Just cuz im working on my camera code.. and went from 400 to 700...:eek:.... ima bad programmer... well not really... i just write long code! but then i end up breaking it down... if yu could let me noe:) that would be great!

I wouldn’t worry about it. Our “user” code from last year was 7000 lines, and that was the simplest robot we’ve had in years.

wow! 7000? ok im good:) thxs getting scared that mine was gettin too long:yikes:

Yeah under a 1000 isnt bad. Also it has to do with how you code. Theres all sorts of ways to cut number of lines in half without changing anything.

Example


for(blah){
junk();
}

instead of


for(blah)
{
junk();
}

cuts out 1 line. Its all how you liek to do it.

I mostly do it this way… and i also include all the brackets… even though sometimes you dont have too…

Yeah, depending on your style of coding and how many comments you actually add, the lines can vary tremendously. What’s more important is the actual amount of data space you use. If you’re using MPLAB (and I’m assuming you are), go to View->Memory Usage Gauge, and this will tell you both the amount of code and variable space you’re using.

We overflowed the 2005 processor trying to get the camera and a driver perspective drive system with a gyro working. Last year we ended up using about 1/5 of the available space.

So assuming some one uses a very inefficient coding style i.e something like this:


int values[3];
for(int i =0; i<=2; i ++)
{
    switch i
    case 0:
    values[0] = 0;

    case 1:
    values[1] = 0;

    case 2:
    values[2] = 0;
}


versus:


for (int i =0; i<=2, i++)
{
     values* = 0;
}

The modern compiler should still spit out the same machine code correct?*

In an ideal world, yes, the compiler should do about the same thing. However, we’re talking about MPLAB’s compiler here, and it’s far from “ideal”. Something tells me even GCC would have difficulty optimizing it. My best bet goes to Intel’s super-optimizing compiler. It’s too bad we can’t have something like that for our PICs.

As for code length in user_routines.c? It’s only about 400-500. That’s because I split my code up into multiple files. In all, I think I’ve written about 2000 in the pre-season this year. I’ve also taken the time to write my own camera code as opposed to Kevin’s (it’s good, just a little drawn out, IMHO).

The # of lines is kinda irrelevent, they could be blank lines, or comments or stuff

The code from my team last year for FIRST is slightly over 900 lines, and that’s before the precompiler includes all the files and stuff.

Don’t worry if your code’s really large, maybe it’s huge cuz it needs to be cuz it does a lot, who knows.

The current code I have for user_routines.c is 111 lines long.

I gutted it (all those Limit_ functions are gone; I never used them) and I haven’t put the drive code back in since the rewrite. That’s why it’s so short. Plus I have the code spread into other files I created, too.

Don’t worry about it being long. Worry about it being readable. Being up late in the shop night before ship date you may be tempted to just keep writing, but when you have to decipher it to figure out why autonomous mode did nothing, you will smack yourself if it isn’t readable.

JBot

It’s not code length… it’s code functionality.

i believe ours was about 1,200 lines long… and i code in the most space saving style imaginable.

Code length in C varies drastically based on style. If you use alot of functions your user_routine.c will be much shorter but you may have a huge header file some where.

Basically if your worried about space just remember to use the right data type. No reason to be keeping a counter that goes from 1 to 10 in an int.