Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Coding Practices for Modular Code

Status
Not open for further replies.

dhazer

Programmer
Oct 20, 2006
48
I'd like suggestion from you guys on how you structure your files and code to be as flexible and as modular as possible.

For example, I was adding logging functionality to a package of scripts of mine.
However, logging functionality would be very helpful for several other Aspect scripts. So I've tried to make considerations that could allow me to "drop" my logging code into another script with little to no modifications.

Recently, to make code more modular, I am using local variables as much as possible (to reduce namespace conflicts). It's to bad you can't embed a procedure within an existing procedure, otherwise I'd be doing that also.

Second, I also try to uncouple each function or procedure from others as much as possible by avoiding calls to other func's and proc's at most costs; that way changes to other func's and proc's don't break older code.

Third, I try to strategically use the "#include" statements.
For included files that I religiously include in my scripts, I have an "includes" folder at the top of my file structure; in the same root folder are folders named for the projects they contain. That way, any scripts that need to include files just include them with the path ascending to the root folder and go into the "includes" folder. For example: #include "..\includes\stripSpaces.was"

Any best-practice suggestions of your own? (or things you don't like about my suggestions)
 
All very good suggestions and thanks for sharing with the forum. Most of the scripts I write aren't "involved" enough to the point where I have to worry about such practices, but they can be very helpful during some script development.

One thing that has helped me is using an editor that is customized for ASPECT and its syntax. I use TextPad and a syntax file that another programmer and I came up with (plus some modifications to make things easier), but have heard from other people who have done similar things in at least two other editors. Being able to see if a particular bit of code is a variable, keyword, etc. can sometimes prevent me from performing an oopsie and catching a mistake before compiling. If you (or anyone else) is interested in those editors and syntax files, they are on the resources page of my site.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top