Mr. Lott has been involved in over 70 software development projects in a career that spans 30 years. He has worked in the capacity of internet strategist, software architect, project leader, DBA, programmer. Since 1993 he has been focused on data warehousing and the associated e-business architectures that make the right data available to the right people to support their business decision-making. Steven is a DZone MVB and is not an employee of DZone and has posted 118 posts at DZone. You can read more from them at their website. View Full User Profile

The Curse of Procedural Design

05.18.2011
| 4395 views |
  • submit to reddit

After reverse engineering procedural code in C, VB or even Python, I'm finding that procedural programming inevitably leads to bad, bad code-rot. Consider some of the common design patterns.

Strategy. Confronted with alternative strategy choices, a purely procedural code solution is either

  • If-statements everywhere the strategy is involved.
  • Block comments. (Pre-processor #if statements are the logical equivalent of block comments plus a tool to move them around just prior to compilation.)

These lack flexibility and seem to devolve into a quagmire of mystery. The if-statements often become tangled and complex. More importantly, some strategy choices — which are unused — may not be maintained at all. Of course, the block comments are never maintained.

Command. Often a command design requires a "code" or "label" and a big-old sequential switch (BOSS™) statement to select among the procedures which implement the various commands. Once "composite" commands are introduced, this devolves into nonsense. Ideally, it's a simple recursion, where a composite command simply invokes the sub-commands. However, folks get nervous about recursion and try to write weird loops.

State. A state design always seems to involve labels or codes for the state names and a slightly different big-old-state-switch (BOSS™, no accident that this is the same acronym) to sort out the variant behaviors in the distinct states. This shouldn't become too confusing. After all, Turing machines and other mathematical abstractions give us a strong hint on how we should proceed.

The problem with stateful procedural programming is that the state changes can be hidden everywhere. In the Really Bad Languages, variables can change values without an assignment statement! In the Not Bad Languages, we can track down the various assignment statements and try to reason out the state changes. Procedural code—without a lot of adult supervision—never seems to encapsulate state change with the the same in-your-face clarity that OO programs do.

I Could Go On

The point is this. While procedural programming could be done well, there appear to be a lot of obstacles inherent in the paradigm.

The best procedural programming I've seen has always been very object-oriented. Each procedure or function had a distinct data structure it worked with; they were all closely related by virtue of naming or file structure; much like a class definition.

I'm starting to wonder if my Building Skills books are taking the right approach. I start with the procedural aspects of Python. I'm beginning to feel that this may be a disservice to the n00bz.

Perhaps it's better to swap the order of the sections and start with the various Pythonic data structures and introduce the various statements sort of "casually" as part of demonstrating how a data structure is supposed to be used.

From http://slott-softwarearchitect.blogspot.com/2011/05/curse-of-procedural-design.html

Published at DZone with permission of Steven Lott, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Tom Gardner replied on Thu, 2011/05/19 - 5:14am

General principle: choose the right horse for the right course, and don't be dogmatic. Simple counter-examples are that there are better (i.e. faster and/or more understandable) ways of writing these codes than simple object-oriented programming:
  • fast fourier transforms (as an example of mathematical operations)
  • moderately complex finite state machines
  • pattern matching or backtracking algorithms
and there are many other examples.

Nicolas Bousquet replied on Thu, 2011/05/19 - 10:11am

I have a strong point against the allmighty OOP movement we have since 15-20 years.

Many time we just really need data structures and a set of functions that work on theses datastructures. As experimented developpers know it both support polymorphism and is a natural fit for the visitor pattern.

With OOP hype and everybody saying it's better, beginners tend to use it for everything even when it give nohing or worse when it complicate things. OOP trainer as full of stupid and useless example like Pets/Dog/Cat or Vehicule/Car/Plane that have rarelly any real usage.

A common example, beginners tend to fail to understand that data management and OOP doesn't do well together. Relationnal Databases don't like OOP at all (ORM doing more harm than good) and NoSQL don't take benefit of it. In many applications we are just moving and converting data. The business layer being really thin we don't really use much OO concepts.

Don't get me wrong a modern language is likely better with OOP support, and it has it's uses. But we really tend to overhype it.

For me Computer Science basics are data and algorythms, things you can get with functionnal or procedural programming. It has strong roots in mathematics and is good for the comprehension of what computer science is about.

The fact that you link data to code and will perform an action with a.b(x) instead of b(a, x) or even (b a x) is more an engineering consideration than a theoritical thing.

Emma Watson replied on Fri, 2012/03/30 - 12:27pm

The intro to Java programming class I took many moons ago emphasized object oriented design and tail recursive algorithms. Java for/while loops weren't introduced until near the end of the class.

Swing

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.