You are here: Re: how do professional PHP developers handle defaults for function parameters? « PHP Programming Language « IT news, forums, messages
Re: how do professional PHP developers handle defaults for function parameters?

Posted by Ivαn Sαnchez Ortega on 07/07/07 09:13

pangea33 wrote:

> As another "professional" PHP programmer I have to disagree with the
> responses the OP has been getting.

And now I have to disagree with you ;-)

> An unchanging set of arguments makes sense when you're working with a
> small codebase, but sometimes one might want to call a function from
> multiple locations that have different requirements.

Wrong approach, IMHO. That sounds like building a big, ugly monolithic
function, at which you can throw everything you want.

The "right" way to go is to go modular. Abstract complexity in small
modules.

> Suppose you have a PHP function that creates and executes a MySQL select
> query.

Yes, it's called Zend_Db::query() ;-)

> A search page might be designed to support text matches on a couple
> columns, only to find out that additional fields need to be supported for
> generating reports.

Then you should have one fnuction that gets a 'search text' as its only
parameter, and calls the generic (and private) query-building function. For
additional fields, use another function that receives different parameters
and calls the generic query-building function...


> There are two options here. You can create your function with a static
> set of arguments that fails when it is called with missing parameters,
> then counter with the retort that the dude who called it was a "bad
> programmer." [...] The second option is to pass in a
> structure and simply check for various optional arguments.

OK, suppose I call fopen() with the wrong arguments. The two options here
are:
- I was a bad programmer for not reading the fopen() documentation
- The guys that programmed fopen() (and libc) are stupid for not accepting a
variable list of arguments


> When I need to expand the capabilities of an existing function to
> support new requirements, I simply have to make a modification to the
> UDF rather than to all existing code.

When I need to expand the capabilities of the existing *system*, I create
new functions that call the underlying ones. Monolithic is bad, modular is
good, right?

> You might disagree with me, but I can guarantee it's a lot easier to
> maintain a site when you don't have to touch all references to a function
> whenever you want to improve it.

It's much easier to add things at the top and not touching the working code
at all :-D

--
----------------------------------
IvΓ‘n SΓ‘nchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Habit is habit, and not to be flung out of the window by any man, but coaxed
down-stairs a step at a time.
-- Mark Twain, "Pudd'nhead Wilson's Calendar

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация