Goody
Member
I would like a discussion on programming structure and commenting.
This is more for the benefit of learners or people who have not done many full programs.
I have just recently had a horrendous experience where two separate contractors were engaged on the same project. (Well three actually if you count the electrical company who did all the wiring.)
The very short version:
A company I do work for bought some second hand plant. A concrete batching system and a block making machine.
I was given the batching plant to strip out and make a new control panel and the other company got the block making plant.
This project was ill conceived, miss-managed and a balls up from the start. The other company wanted my slice of the cake and I suppose I wanted there’s too.
The reason that two contractors were given the same project was for speed???
(If one does one half and the other, the other – it will be done twice as quick)
My panel started off with about 130 I/O (but ended up nearer 300) and a HMI Theirs was a similar number.
I was told that there would only be about 3 or 4 interconnecting signal cables between the two panels but the job got bigger and changed daily. We ended up with a 36 core cable between the two and every core is used.
To the crux of the matter:
The other company was eventually sacked before the end and I was left with both programs to finish. I am not being cruel or bitter, but the program I was left with from the others was the worst spaghetti code I have ever seen.
Page after page of internal bits with no comments or labels or anything to identify what they were doing.
Loads and loads of redundant code that should have been removed.
Lines with conditional branches after branches ( I bet even the plc itself struggled to understand what it was supposed to do)
Data manipulation that was meaningless with no particular order of registers.
The outputs and sequence was written in any random order – The first line was controlling output 85 (a small motor)
The emergency stops and safeties didn’t appear until about half way. I ended up just wiping reams of code and seeing what now didn’t work. It was very close to a re-write.
I wish I had the program on this computer; I would cut and paste a sample (I still might do tomorrow)
The point I am making is to all programmers really.
Please condition yourself to program into some sort of coherent order.
There are no set rules as to how you do this but it really helps (both you and followers to understand what is happening)
The first and most important rule is each time you do a line of code, label or comment each and every bit and add a description of what the program is doing. (even if it’s spaghetti, the comments will help)
I would like some input from the pro’s on how they structure their code. To help the learners start off on the right footing.
My way is (usually, that is – as nothing is written in stone here)
At the start a few lines of house-keeping (this is often written when the program is finished) ie resetting bits that might still be on after a power cycle. A first scan bit to put everything right and safe.
Then safety’s and E stops and the like.
Then the main program, hopefully with either the inputs or outputs in sequential order.
Then data manipulation. Ie math(s) and HMI values.
I often have none technical people look at my programs, and even they can understand what is supposed to happen.
I don’t think I can over emphasize the importance of keeping the code in order with written information all the way.
This is more for the benefit of learners or people who have not done many full programs.
I have just recently had a horrendous experience where two separate contractors were engaged on the same project. (Well three actually if you count the electrical company who did all the wiring.)
The very short version:
A company I do work for bought some second hand plant. A concrete batching system and a block making machine.
I was given the batching plant to strip out and make a new control panel and the other company got the block making plant.
This project was ill conceived, miss-managed and a balls up from the start. The other company wanted my slice of the cake and I suppose I wanted there’s too.
The reason that two contractors were given the same project was for speed???
(If one does one half and the other, the other – it will be done twice as quick)
My panel started off with about 130 I/O (but ended up nearer 300) and a HMI Theirs was a similar number.
I was told that there would only be about 3 or 4 interconnecting signal cables between the two panels but the job got bigger and changed daily. We ended up with a 36 core cable between the two and every core is used.
To the crux of the matter:
The other company was eventually sacked before the end and I was left with both programs to finish. I am not being cruel or bitter, but the program I was left with from the others was the worst spaghetti code I have ever seen.
Page after page of internal bits with no comments or labels or anything to identify what they were doing.
Loads and loads of redundant code that should have been removed.
Lines with conditional branches after branches ( I bet even the plc itself struggled to understand what it was supposed to do)
Data manipulation that was meaningless with no particular order of registers.
The outputs and sequence was written in any random order – The first line was controlling output 85 (a small motor)
The emergency stops and safeties didn’t appear until about half way. I ended up just wiping reams of code and seeing what now didn’t work. It was very close to a re-write.
I wish I had the program on this computer; I would cut and paste a sample (I still might do tomorrow)
The point I am making is to all programmers really.
Please condition yourself to program into some sort of coherent order.
There are no set rules as to how you do this but it really helps (both you and followers to understand what is happening)
The first and most important rule is each time you do a line of code, label or comment each and every bit and add a description of what the program is doing. (even if it’s spaghetti, the comments will help)
I would like some input from the pro’s on how they structure their code. To help the learners start off on the right footing.
My way is (usually, that is – as nothing is written in stone here)
At the start a few lines of house-keeping (this is often written when the program is finished) ie resetting bits that might still be on after a power cycle. A first scan bit to put everything right and safe.
Then safety’s and E stops and the like.
Then the main program, hopefully with either the inputs or outputs in sequential order.
Then data manipulation. Ie math(s) and HMI values.
I often have none technical people look at my programs, and even they can understand what is supposed to happen.
I don’t think I can over emphasize the importance of keeping the code in order with written information all the way.