Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Anonymous Monk writes:

"...there still would be plenty of spaghetti left over that needs straightening out."
That is a feeling I am familiar with; but realize that part of the complexity of the code is due to not having a guiding data structure. The first thing I try to do is to enforce localization of data. Push the data to the right side of the function calls. Whether that involves closures, ties, manifests, configuration hashes or whatever, get the data separated from the control flow, the if/then/else on the left side.

Very often there is natural structure that is hidden behind the chaff. Often, to uncover it, you have to restructure the program to allow the data to lay together. For example, when dealing with multiple files, opening a group of files inside one loop then processing them inside another loop. Even multiple loops, each doing one step of the processing. This is perhaps more resource intensive but it groups the like data together. Once you have the like data grouped together you can begin to look for natural groups that can become objects. When you have groups of data together with their accessor functions, then you have an API.

"I realize that functions modifying globals is not a terribly good idea,..."
Only if the API for that data isn't well defined. This is what an object does, it associates the functions with the data and defines the scope of the interactions.

"...and don't want to rush headlong into creating classes unnecessarily."
Agreed, let the code tell you what it's objects are. That will happen as you force localization of data.

"So, what are the core points of good procedural design?"
Define the data structure first, write the code to the needs of the data.


s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}

In reply to Re: What are the core points of good procedural software design? (functions, code structuring) by starbolin
in thread What are the core points of good procedural software design? (functions, code structuring) by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-11-27 13:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?