473,799 Members | 3,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help: good sturdy C procedural program design

The way I've always "designed" procedural C programs has just been to:

A. Think about what I need to do
B. Draw a flowchart with pencil and paper
C. Implement the flowchart in C from the top down
D. Compartmentaliz e chunks of code that serve some specific purpose
into functions, while filling in the framework left by the top-
down approach.
E. Refactor until I can call it pretty much done.

Though, I haven't created any large C projects myself (mostly just
programs consisting of maybe 5 to 10 source code files), so it could
be that the above process will land me in deep doo doo once my projects
start getting larger.

Any advice on procedural C program design?

Thanks.
--- if contacting via email, remove zees ---

Nov 14 '05 #1
2 1503

"John Gabriele" <jo*****@bestwe bz.net> wrote in message
A. Think about what I need to do This is vitally important. B. Draw a flowchart with pencil and paper Flowcharts are really for assembly routines. For C programs they have 2
weaknesses - if a flowchart fits on a side of A4 then it is so simple that
there's not much point, whilst if it is larger it becomes unwieldy, and
there is no accepted electronic means of storing flowcharts.
C. Implement the flowchart in C from the top down
Some people will do this, so what I say is only one opinion. Generally code
should be designed top-down in a quick pass, and then written bottom up. The
reason is that you can then test as you write.
D. Compartmentaliz e chunks of code that serve some specific
purpose into functions, while filling in the framework left by the top-
down approach.
This the problem with the top-down approach. You may have a framework of
function calls, but no code to go in them. Each function should do one
specific thing which can be described simply, and ideally can be tested.
Write scratch code to test the functions as you write them. Obviously,
higher-level functions will need to call lower-level functions, so you write
the lower level functions first. Then they get tested again as you test
their callers.
E. Refactor until I can call it pretty much done.
What's this meant to mean? If you follow a rigorous bottom-up approach and
you have a complete design, then this shouldn't happen. Reality is that with
big programs you tend to have to design and build as you go. No engineer
would tolerate such an approach to building a bridge, but with software
people are always asking "just pop in a quick "undo" function". Programmers
aren't innocent either, often playing with code until something works.
Any advice on procedural C program design?

The most important relationship in programming is dependency. Once you
realise that then everything else pretty much falls into place.
Nov 14 '05 #2
Malcolm wrote:
"John Gabriele" <jo*****@bestwe bz.net> wrote in message
A. Think about what I need to do
This is vitally important.
B. Draw a flowchart with pencil and paper


Flowcharts are really for assembly routines. For C programs they have 2
weaknesses - if a flowchart fits on a side of A4 then it is so simple that
there's not much point, whilst if it is larger it becomes unwieldy, and
there is no accepted electronic means of storing flowcharts.
C. Implement the flowchart in C from the top down


Some people will do this, so what I say is only one opinion. Generally code
should be designed top-down in a quick pass, and then written bottom up. The
reason is that you can then test as you write.
D. Compartmentaliz e chunks of code that serve some specific
purpose into functions, while filling in the framework left by the top-
down approach.


This the problem with the top-down approach. You may have a framework of
function calls, but no code to go in them. Each function should do one
specific thing which can be described simply, and ideally can be tested.
Write scratch code to test the functions as you write them. Obviously,
higher-level functions will need to call lower-level functions, so you write
the lower level functions first. Then they get tested again as you test
their callers.
E. Refactor until I can call it pretty much done.


What's this meant to mean?


I'm sorry. I should've thought more before writing that. I was thinking
of C++ where I sometimes end up with objects that need to know too much
about each other.
If you follow a rigorous bottom-up approach and
you have a complete design, then this shouldn't happen.
Right, unless/until -- as you point out -- requirements get tweaked.
Reality is that with
big programs you tend to have to design and build as you go. No engineer
would tolerate such an approach to building a bridge, but with software
people are always asking "just pop in a quick "undo" function". Programmers
aren't innocent either, often playing with code until something works.
Any advice on procedural C program design?


The most important relationship in programming is dependency. Once you
realise that then everything else pretty much falls into place.


Thanks for the insightful reply Malcolm!
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
4657
by: toedipper | last post by:
Hello, I am designing a table of vehicle types, nothing special, just a list of unique vehicle types such as truck, lorry, bike, motor bike, plane, tractor etc etc For the table design I am proposing a single column table with a field name called vehicle_type and this will contain the vehicle type. Sot it will be
9
1418
by: Angelos | last post by:
First of all I need to thank you in advance... Now I 'll try to show you what I want do and if you can, tell me how My class should be composed. I have a CMS. I add content and that Content can be Published Unpublished and Backuped. Now the content has Several Types like... pages,news,products. I am trying to write a class Content that will cover the common bits that Several Content Types have and the rest will be inherited.
4
2776
by: Mohitz | last post by:
Any pointers as to how one should go about porting procedural type code into object oriented code?? --- Mohit
5
2645
by: CK | last post by:
I have this UDF CREATE FUNCTION IsSupervisor (@empID int) RETURNS bit AS BEGIN
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.