Habits to improve your control programming

Engineering and IT Insight: Control programming is programming, even if it uses ladder logic, sequential function charts, function block diagrams, and procedure function charts. Improve your programming in a dozen ways. Errors in control programs can harm people, damage equipment, and destroy products.


Control programming still is programming, even if it uses nonclassical languages such as ladder logic, sequential function charts, function block diagrams, and procedure function charts. In addition, many control programs use classical programming languages like C, C++, C#, Java, Basic, and SQL. Also, we have a whole zoo of special purpose languages developed by tool and application vendors, often developed with little regard for language consistency, structured programming constructs, and object models, and with little available training and a small user base. Control programming is hard real-time, event based, and often mission critical. Errors in control programs can harm people, damage equipment, and destroy products. Unlike business system programming where you can roll back database changes and transactions, you can't roll back a chemical process or many manufacturing steps. Despite these problems, there are specific habits you can develop that will make you a better control system programmer. There is easily a 10x difference in productivity and quality from the average to the best control programmers and a 5x difference between average and worst. The difference is often based on the habits that the good programmers have that average or poor programmers do not, and the bad habits the poor programmers have.

Control programming is not an art, where creativity is king; or science, where discovery is king. It is engineering, which is creatively applying well-understood, proven, and workable solutions to new problems. In addition, programming requires more than just experience; it requires good design, coding, debugging, implementation, and personal and group habits. Ten years of experience, where the same year is repeated 10 times, doesn't count. Even one year of experience where you develop good habits will make you a better programmer. 

Avoid a dozen bad habits

Avoid these dozen bad programming habits. Poor programmers:

  1. Repeat errors
  2. Produce inconsistent and ambiguous designs
  3. Don't leave time to update design documents
  4. Don't leave time to comment their code
  5. Don't leave time to break code into smaller manageable pieces
  6. Don't use version control or any form of source code control
  7. Don't ask for reviews, don't want them, and don't encourage them
  8. Commonly answer questions about the logic of their code by saying, "It's obvious"
  9. Never have time to do the right thing and are always patching and debugging previous work
  10. Fail to account for edge cases
  11. Spend a large percentage of time debugging their code
  12. Avoid recording their errors.

The most important programming habit to develop is the personal development habit of recording your own mistakes. Everyone makes mistakes when programming. It is intensely detailed work, where one character wrong in a 10,000-line program causes it to fail. Control programming also adds timing, real-time network communication, and data integration elements to an already complex task. Even the best programmers make mistakes in this environment, but the best programmers record their mistakes so that they learn not to repeat them. They don't just record the big mistakes, which may take days to debug, but they also record the small mistakes caught by editors, compilers, linkers, and unit tests.

Analyze and avoid

The reason for recording mistakes is to identify your weaknesses and to develop the work habits to avoid them. Some typical weaknesses are forgetting to initialize variables, using the wrong case for variable names, inadvertently changing a data type, not checking for in-range values before using them, and not checking for edge conditions.

Developing the good habit of recording your mistakes is easy; at the end of each day, or even two or three times a day, record what mistakes you made in a simple document. This includes how many times you had to run a program through a compiler or run a unit test to correct a small error. You may find that you regularly misspell variable names or don't close out conditional logic correctly. You will find over time that simply recording the mistakes makes you more aware of them and you will stop making them. 

Take time to save time

Programmers who adopt this simple habit have discovered that their productivity improves dramatically. They spend less time performing small fixes to pass unit test, and their code has fewer hidden problems that don't show up until system test or installation. Once they recognize a pattern in design, coding, or unit testing that leads to complex errors, they can address the root cause instead of fighting the symptoms.

Good control system programming is hard, but developing the correct habits-in particular learning from your mistakes, large and small-will make you a better programmer, a better engineer, and a more valuable member of any development team.

Coming up: More good programming habits

Other good habits that programmers have fall into several categories: personal development habits, group development habits, design habits, coding habits, implementation habits, and debugging habits. Future columns will address good programming habits in each of these areas.

- Dennis Brandl is president of BR&L Consulting in Cary, N.C., www.brlconsulting.com. His firm focuses on manufacturing IT. Edited by Mark T. Hoske, content manager, CFE Media, Control Engineering, mhoske@cfemedia.com.

ONLINE extra

This posted version contains more information than the print/digital edition issue of Control Engineering.

At www.controleng.com, search Brandl for more on related topics.

See other articles for 2014 at www.controleng.com/archive.

See other Manufacturing IT articles.

- See related stories from Brandl below.

Amtonio , Non-US/Not Applicable, Mexico, 07/24/14 12:05 PM:

John C , NC, United States, 08/23/14 08:05 PM:

I am a Facilities Engineer for General Electric and have been writing PLC programs and debugging other engineers programs for 30+ years. I also have been training our technicians on the basics of troubleshooting PLC based systems. I came across this article and just has to comment. I too started using a standard college binder when I first started on the Series Six PLC way back in 1979. This binder had to sections "Do's" and 'Do Not's". Dennis you hit it on the head. This simple practice over the years has made my mistakes less frequent. I have learned how to "normalize" my code with this method. Thanks
The Engineers' Choice Awards highlight some of the best new control, instrumentation and automation products as chosen by...
The System Integrator Giants program lists the top 100 system integrators among companies listed in CFE Media's Global System Integrator Database.
Each year, a panel of Control Engineering and Plant Engineering editors and industry expert judges select the System Integrator of the Year Award winners in three categories.
This eGuide illustrates solutions, applications and benefits of machine vision systems.
Learn how to increase device reliability in harsh environments and decrease unplanned system downtime.
This eGuide contains a series of articles and videos that considers theoretical and practical; immediate needs and a look into the future.
Controller programming; Safety networks; Enclosure design; Power quality; Safety integrity levels; Increasing process efficiency
Additive manufacturing benefits; HMI and sensor tips; System integrator advice; Innovations from the industry
Robotic safety, collaboration, standards; DCS migration tips; IT/OT convergence; 2017 Control Engineering Salary and Career Survey
Featured articles highlight technologies that enable the Industrial Internet of Things, IIoT-related products and strategies to get data more easily to the user.
This article collection contains several articles on how automation and controls are helping human-machine interface (HMI) hardware and software advance.
This digital report will explore several aspects of how IIoT will transform manufacturing in the coming years.

Find and connect with the most suitable service provider for your unique application. Start searching the Global System Integrator Database Now!

Infrastructure for natural gas expansion; Artificial lift methods; Disruptive technology and fugitive gas emissions
Mobility as the means to offshore innovation; Preventing another Deepwater Horizon; ROVs as subsea robots; SCADA and the radio spectrum
Future of oil and gas projects; Reservoir models; The importance of SCADA to oil and gas
Automation Engineer; Wood Group
System Integrator; Cross Integrated Systems Group
Jose S. Vasquez, Jr.
Fire & Life Safety Engineer; Technip USA Inc.
This course focuses on climate analysis, appropriateness of cooling system selection, and combining cooling systems.
This course will help identify and reveal electrical hazards and identify the solutions to implementing and maintaining a safe work environment.
This course explains how maintaining power and communication systems through emergency power-generation systems is critical.
click me