NYCPHP Meetup

NYPHP.org

[nycphp-talk] Code cleanliness vs. code popularity

Kenneth Downs ken at secdat.com
Fri Sep 16 19:11:25 EDT 2005


> Hello all,
>
> I was recently reading through the phpBB source code, and had some
> observations to shares. In most of the pages / script files I looked
> through, there were 1000 - 2000 lines of PHP code, with no functions or
> comments. While the code itself is strictly procedural, it is also to
> the point, and not indecipherable.
>
> Still, some interesting questions came to me: how can one of the most
> popular PHP applications be written in eighties-style procedural code?
> Or, to rephrase it: are object-oriented design, (fancy) frameworks not
> useful in practice? How many of you have worked with commercial, open
> source or in-house frameworks? Have you found these frameworks to be
> useful in the long run, or do they just get in the way?

I don't know the developers, but if I had to guess I would say it was a
very small group that has total control of coding practice.  Most of the
"crucial advances" in programming languages of the past 20 years are meant
to make it easier for large groups to work together.  When one or a few
people work very intensely on a project, the only thing that really seems
to matter is that they stay focused and undistracted, in which case they
always know what is going on and can code it in sanskrit if they want.

>
> I have long been a fan of PEAR (and other external / third-party)
> libraries. I much prefer to save myself work, when I do not have to
> reinvent the wheel. Still, in many companies, people prefer to write
> everything from scratch, often wrapped up in laborious frameworks. In
> your collective experience, what's the best policy for code development?
> In other words: bang it out, test it, ship it, receive feedback, fix it,
> and then back to the beginning again, or: huge design upfront, OO or
> functionized code,UML diagrams, and the 'f' word: a framework.

Since opinions you desire, opnions you shall have! :)

First is the min/max principle.  Use the smallest number of technologies
to the largest benefit.  This thinking drives me away from Java and to
PHP.  One simple example is that I can do anything with a PHP Associative
Array, while Java wants me to use all kinds of different objects for
different purposes.  That violates min/max.

The reason big shops avoid 3rd party stuff is they want to keep control
and avoid having their quality rest upon somebody else's work.  This is
very important when the 3rd parties are commercial and tend to go out of
business on you.

I've written 1 LAN framework, one C/S framework, and one 3-tier framework.
 The reason people like to do them is because they are fun, a lot more fun
than coding up the invoice form.  Therein also lies their threat.  They
become complicated and random, and then everyone is working for the
framework instead of the framework working for you.

My biggest beef with frameworks is that they are usually all about
managing labor instead of eliminating it.  Why lay out 20 tasks for me to
do for every table in a database?  If they are so well known, shouldn't
the framework do them automatically for me?  My latest 3-tier framework is
as close to zero-code as I've gotten, and it's where I want to stay.

The two largest groups of unreasonable zealots you will ever meet are the
high priests of the the Two Towers, Object Orientation and Database
Theory.  The only way to work out how to handle what they say is to make
sure you understand it.  The database people see all the world as tables,
and the OO people see everything as an object.  Since everything in the
end does end up in a database, I tend to think the database people are
more correct, but they are doing nothing with this advantage.

>
> I personally cannot write strictly procedural code any more, and I
> prefer a mix of functionized and OO code. Still, real world applications
> - popular real world applications, often totally avoid this approach.
> So, what gives?

Well consider that there is nothing inherent in a web call that requires
OO.  Strictly speaking it is a procedural operation, which might be
written out as:

1) Trying to logout?  Reset their session
2) No session?  Give 'em a cookie
3) Not authenticated?  Send 'em to the login page
4) What do they want?  Any database writes to do? Do 'em
5) What will we show them?  Any database reads? Do 'em
6) Format the HTML, send it out.

There is nothing in that that requires OO.  There are repeating designs
that suggest it, such as an object for every table, but somehow I've
managed to get along just fine without that.  Instead I have a datafile
for every table that describes the table and a common library that reads
the data file to figure out what to do.

Bottom line: experiment with what feels most comfortable to you naturally,
and here and there experiment with things that do not feel so comfortable.
 Sometimes you will be glad you did because you'll learn something new,
and sometimes you'll confirm your hunch that you didn't want to go that
way.



>
> - Jay
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
>


-- 
Kenneth Downs
Secure Data Software
631-379-0010
ken at secdat.com
PO Box 708
East Setauket, NY 11733




More information about the talk mailing list