php suggestion

php.internals

Ante Drnasin

21 years ago
Hi again guys.... I would just like to hear you oppinions about something like this...(please don't shoot me :) ) ex1: function AddToDb(mysql_scape_string($text)) { //enter $text to db } which would be the same as function AddToDb($text) { $text = mysql_escape_string($text); //enter $text to db } or ex2: function removeDigitsFromText($text) { //return the text striped from digits } function AddTextToDB(removeDigitsFromText($text)) { //add text to db; } This could be very usefull although I do understand that it could cause problems (references for example) .... I know this concept looks a bit strange but just wanted to hear oppinions from the experts... :) Thanx Ante

David Kingma - Jool.nl

21 years ago
Quoting Ante Drnasin <ante.dfg@moj.net>:
> ex1: > function AddToDb(mysql_scape_string($text)) { > //enter $text to db > } > which would be the same as > function AddToDb($text) { > $text = mysql_escape_string($text); > //enter $text to db > } > > ex2: > > function removeDigitsFromText($text) { > //return the text striped from digits > } > > function AddTextToDB(removeDigitsFromText($text)) { > //add text to db; > } > > This could be very usefull although I do understand that it could cause > problems (references for example) ....
Why could this be usefull? You're putting logic into the parameter list, I can't think of a reason why you would like to do this. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.

Nicholas Telford

21 years ago
David Kingma | jool.nl wrote:
> Quoting Ante Drnasin <ante.dfg@moj.net>: > >>ex1: >>function AddToDb(mysql_scape_string($text)) { >> //enter $text to db >>} >>which would be the same as >>function AddToDb($text) { >> $text = mysql_escape_string($text); >> //enter $text to db >>} >> >>ex2: >> >>function removeDigitsFromText($text) { >> //return the text striped from digits >>} >> >>function AddTextToDB(removeDigitsFromText($text)) { >> //add text to db; >>} >> >>This could be very usefull although I do understand that it could cause >>problems (references for example) .... > > > Why could this be usefull? You're putting logic into the parameter list, I can't > think of a reason why you would like to do this. > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program.
This could never be useful. Trying to condense as much code as you can down to as few lines as possible doesn't actually speed up the execution, nor does it make it more readable. Having logic in the parameter list removes the possibility of properly documenting it and would be executed no quicker than having it done separately. If you're developing a public API as it seems you are, then the need for proper documentation far outweighs the need to condense all the code down, even for processes that are as obvious as escaping a string. In short, there's no good reason for this to exist in any language (as far as I can see) and would probably add more overhead to the processing of parameter lists. Nicholas Telford

Nicholas Telford

21 years ago
David Kingma | jool.nl wrote:
> Quoting Ante Drnasin <ante.dfg@moj.net>: > >>ex1: >>function AddToDb(mysql_scape_string($text)) { >> //enter $text to db >>} >>which would be the same as >>function AddToDb($text) { >> $text = mysql_escape_string($text); >> //enter $text to db >>} >> >>ex2: >> >>function removeDigitsFromText($text) { >> //return the text striped from digits >>} >> >>function AddTextToDB(removeDigitsFromText($text)) { >> //add text to db; >>} >> >>This could be very usefull although I do understand that it could cause >>problems (references for example) .... > > > Why could this be usefull? You're putting logic into the parameter list, I can't > think of a reason why you would like to do this. > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program.
This could never be useful. Trying to condense as much code as you can down to as few lines as possible doesn't actually speed up the execution, nor does it make it more readable. Having logic in the parameter list removes the possibility of properly documenting it and would be executed no quicker than having it done separately. If you're developing a public API as it seems you are, then the need for proper documentation far outweighs the need to condense all the code down, even for processes that are as obvious as escaping a string. In short, there's no good reason for this to exist in any language (as far as I can see) and would probably add more overhead to the processing of parameter lists. Nick

Nicholas Telford

21 years ago
This message was cancelled from within Mozilla.

Nicholas Telford

21 years ago
This message was cancelled from within Mozilla.

George Schlossnagle

21 years ago
> > I know this concept looks a bit strange but just wanted to hear > oppinions from the experts... :)
This concept looks strange (and non-standard - do any other languages support this semantic?). It doesn't save you much typing either. George

Christian Schneider

21 years ago
Hey Ante, Ante Drnasin wrote:
> I would just like to hear you oppinions about something like > this...(please don't shoot me :) ) > > ex1: > function AddToDb(mysql_scape_string($text)) {
I'd say it's not too useful but opens up a can of worms: - You're adding code to a declaration, IMHO confusing - How complicated code is allowed, e.g. what happens with function foo(bar($p1, $p2)) { or function foo($p2->bar($p1), $p1->bar($p2)) { I think we should keep the language simple and stay with $text = mysql_scape_string($text); at the beginning of the function. That way everybody understands what's going on. - Chris