473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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. Compartmentalize 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 1475

"John Gabriele" <jo*****@bestwebz.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. Compartmentalize 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*****@bestwebz.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. Compartmentalize 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
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...
9
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...
4
by: Mohitz | last post by:
Any pointers as to how one should go about porting procedural type code into object oriented code?? --- Mohit
5
by: CK | last post by:
I have this UDF CREATE FUNCTION IsSupervisor (@empID int) RETURNS bit AS BEGIN
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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,...

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.