Take a moment to reflect on how bad your code once was
gist.github.com
gist.github.com
If this feeling ever stops it means I've stopped learning and stopped personal progress. I'll stop coding that day.
Thankfully it didn't go away for the last 30 years I was programming, so it will probably stay with me a little longer.
P.S. Oh man, I found it. OK, here's the code: http://pastebin.com/Hi2wYSmW and I think this is a data file for it: http://pastebin.com/eF1WuhVb
Also, it looks like at some point I learned about z-buffers while writing the thing. I seem to have a couple different versions on backups.
For reference I wrote this when I was a teenager and it ran on a 286 (IBM PS/1).
I would advise never assuming this, and would always get explicit permission, in writing.
I have worked on projects where even accidentally leaking the language being used would have revealed something my employer considered secret at the time.
http://www.intridea.com/blog/2011/4/18/-refactormycode-lives...
PLAY "T180 DF#A L2 A L4 O4 AA P4 F#F# P4 O3 D"
and draw simple shapes with a statement like: LINE (0,0)-(100,175),2,BF
Code in BASIC might have not been the most well-written. But it was certainly fun to program in! 10 PRINT "KEYFRAME"
20 GOTO 10
also, on c64 i always made sure to do this first, just to make sure it looks like a terminal to a big machine (for unknown reasons): POKE 53280,0 : POKE 53281,0So - here are my lessons - maybe someone will find them useful (keep in mind this is C code for attiny chip - it's really minimal stuff):
signed short int P[P_NUM]={0}; // real points
unsigned short int A[P_NUM]={0}; // meas points
Never name global variables with single letters. Even these are "the" global variables everything else in the code uses. Also comments do not have character limit - if it's "measured points", spell it out. It's useful for grepping. unsigned char last=0; // last point+1
I have no idea what +1 means at this point, since it starts at 0. Was the last point -1? I don't think so - again, always add details to comments. if(lcd_buff[j]&_BV(i))
PORT_LED|=_BV(PIN_AB);
else
PORT_LED&=~(_BV(PIN_AB));
PORT_LED|=_BV(PIN_CLK);
PORT_LED&=~(_BV(PIN_CLK));
Horizontal whitespace matters - code above is barely readable. Defines for constants are good, but could be more descriptive than "PIN_AB". At least PIN_CLK is self-explanatory. eeprom_busy_wait(); eeprom_write_byte((uint8_t *) 0x00+1, last);
eeprom_busy_wait(); eeprom_write_word((uint16_t *)(2+setup_pos*4), A[setup_pos]);
eeprom_busy_wait(); eeprom_write_word((uint16_t *)(4+setup_pos*4), P[setup_pos]);
If some function repeats so often that you end up prepending it before "actual work", you're probably missing a level of abstraction. a*=2;
a/=dif;
if(a&1)
a++;
a/=2;
Even if some code is specific to that project and crucial to the way it works - comment on "how" and "why". I guess it tries to round the division... but it could be a lot clearer. //#define CORRECT(a,b) ((A[b]-A[a])/(P[b]-P[a]))
//#define CORRECT2(a,b) ((A[b]-A[a])/(P[b]-P[a])>>1)
Never comment out unneeded code. Delete it and let the version control keep the old things. Now I'm not sure if that was commented out for testing, or was it never needed...Also found out that any in-line state machine will grow until it fills the memory (not hard on attiny ;) ). If you don't design proper macros to construct it, it will become a single function with lots and lots of copy-paste code. It doesn't matter that it was clear at the start and only had 4 states that fit on the screen. Code grows on it's own :)
Also I found a CVS folder in that project. There's one issue with it - I only have the client part - so I can't see any history anymore. DVCSs are a really cool idea.
And for the end -> writing code for a very small chip doesn't mean you have to make the code itself really short, but somehow it seems I was trying to do that. It's the resulting binary that is supposed to be small. Keep in mind how separated are you from the end-result.