Re: Formatting -- defining sections of code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 14, 2012 at 10:48:05AM -0500, Andy McKenzie wrote:

> Hey folks, kind of a strange question here.
> 
> Basically, I've been trying to move my style from "self taught" to "Oh
> yeah, there IS a standard for this."  One of the things I frequently
> want to do is define sections of my code:  to take a simplistic
> example, "this outputs everything that needs to be in file A, this
> outputs what needs to be in file B," and so on.
> 
> Up until now, I've used my own standards (generally "####
> SectionName", since it's easy to search for).  But it occurs to me to
> wonder;  IS there a standard for this?  Most likely, the programming
> world being what it is, there either isn't one or there are lots of
> competing standards, but I'd be interested to know...

A *standard* for something? ROTFL! Yeah, like there's a standard for
herding cats! [guffaw]

Seriously, no I know of no such standards. It sounds like you're
thinking of the kind of thing that's more common in languages like COBOL
than anything modern. Plus, it's near impossible on any significantly
sized project to segregate code in such a way.

That said, I would recommend PHPDoc or similar. It's a package for
generating code documentation from the comments embedded in your code.
You adhere to certain conventions in the format of your comments, and
PHPDoc can scan your code and produce pretty docs. Plus, the comments
themself serve as a sort of discipline in explaining what functions and
sections of code do. If you keep your functions to singular, small tasks
(as you should), the comments are invaluable when you come back later to
try to figure out what you were thinking when you wrote this or that
block of code.

I don't know how extensive your experience is with coding or PHP. So in
case you're a relative newbie, I'd also suggest that you keep classes in
their own files (one file per class) in a "libraries" directory or
somesuch. In fact, I'd suggest downloading something like CodeIgniter,
and studying the way they structure their code physically. They may not
be the optimum example, but for a well-known framework, their code base
is relatively slim and well-organized. Also, obviously, study the MVC
(model-view-controller) paradigm. It's a very useful way of dividing up
your code's functionality.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux