Just for fun...
Spire_Jeff
Posts: 1,917
I was showing some code to a programmer-in-training within our company and he was amazed at this statement:
I tried to explain that such a statement is not that uncommon in large systems, but he still thinks I'm doing something crazy. So, for fun, I figured I'd post to see if anyone has anyone other lines of code they'd like to post that are as complicated in appearance as this one
Here is the English description of the above bit of code: Make the light graphics on the touch panels indicate the current status of the lights in each room.
Jeff
FOR(nFB_CNTR = 1;nFB_CNTR<=MAX_NUMBER_OF_ROOMS; nFB_CNTR++){ IF(uROOM[nFB_CNTR].nLIGHT_ID && uLIGHT_BUTTON[uROOM[nFB_CNTR].nLIGHT_ID][1].nIS_ACTIVE) [dvTP_LIGHT, (100+nFB_CNTR)] = nHWI_BUTTONS[uLIGHT_BUTTON[uROOM[nFB_CNTR].nLIGHT_ID][1].nLINK][uLIGHT_BUTTON[uROOM[nFB_CNTR].nLIGHT_ID][1].nKEYPAD][uLIGHT_BUTTON[uROOM[nFB_CNTR].nLIGHT_ID][1].nBUTTON]; }
I tried to explain that such a statement is not that uncommon in large systems, but he still thinks I'm doing something crazy. So, for fun, I figured I'd post to see if anyone has anyone other lines of code they'd like to post that are as complicated in appearance as this one
Here is the English description of the above bit of code: Make the light graphics on the touch panels indicate the current status of the lights in each room.
Jeff
0
Comments
that's true for sure. I have a system with 20 TPs with as many audio zones. Each zone has up to 15 audio sources. For the devices with storable presets (AM/FM/XM/Siruis, etc...) each panel has 10 presets per source that are user assignable) The presets store channel name/number/genre. Each panel has its own set of presets. I store all the presets in one structure. You have to have those long, convoluted statements to get it done.
It reminds me of the days when I was working on Neve and SSL recording consoles. Newbees would stare at them in horror noting that it had over a thousand buttons and knobs. I'd try to calm them down and show them that it's easy if you break it down by the channel.
Here were the two longest statements with two systems I just skimmed through: and... I should note that the second code posted was written quite some time ago (several years) and I only keep this because it works. If i were re-writing it (which I may) I would do it differently.
I just like to keep things simple, I hate having to scroll to view a statement. Ugh - bad form in my opinion. But there's a gazillion and a half ways to skin a cat.
See? No square brackets
And what's with all the magic numbers up there (500,1400 etc)???
I was looking at some code my boss wrote and it had a line like this:
PULSE[dvHDTV, 11 + GET_LAST(SAT_NUM) - 4 ]
Of course, I asked him what was the significance of the 4 and 11 were, and why he didn't just add 7 rather than add 11 and then subtract 4. He said he couldn't remember what the magic numbers represented any more
Paul
Nice - I like that idea. Kudos to you!
Thanks, although I think I am in the minority as far as code style is concerned. People are probably thinking "I hope our company never has to take over one of this guys jobs"
Paul
Nice job Paul!
Code should not only work, but also should be highly readable and efficient. Those of you that have seen a well-dressed equipment rack verses a spaghetti mess knows what I mean.
It make me cringe to see the same function on the same expression called more than once in the same evaluation or event.
Perhaps a few coders could use some neatness lessons.
Many thanks,
Paul
FYI, the lenght string will evaluate a different element of the structure on every pass.
hence i & y!
what function? Have you been smoking?
In other words my code sucks but it might not be my fault cuz maybe my dog died that day or something. Pretty arrogant aren't you!
Fill in the blank here_______where my response should be!
I use stack_vars to first gather deep nested info:
It is easier to read not only for the next guy but for me. I have some code from years ago (that I'm not very proud of), it took me an hour just to follow the worm holes. I also use structures to keep all the info in one spot and to avoid naming many different arrays.
You'll only ever really need to deal with this in large installs, but the key is to plan it out on paper first.
(This is just an example, please don't hold me to the code )
I really wish we'd be able to post our ENTIRE code to actually see what some of us do. Now - I know I can't do that with my code, and I'm sure most - if not all - of you can't either, I think we're missing a whole lot whenever we just post one or two lines.
Next question - when you do have such long statements, PLEEEEEASE tell me you all use comments to remind yourself what is going on.
nAD_out_loc[18];
nAD_out_nSrc[18];
nAD_out_eq[18][10];
If you look at my AP18x18 structure you'll see all the info for all locations are in one place, when you use debug everything is there for you, just by typing AD_out. With arrays you'd have to type each variable one at a time. If you need to see location 5, 3rd band of eq: AD_out[5].eq[3]; - It keeps thinks much more organized.
I have structure for everything: tp-audio-video-shades-security-event timers-kids-fish-ect.
Hope this help!