Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3439

Re: Taking parameters into functions

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Taking parameters into functions
Date 2011-10-16 14:32 -0400
Organization A noiseless patient Spider
Message-ID <j7f809$8dr$2@dont-email.me> (permalink)
References <slrnj9ll4o.3ru.houghi@penne.houghi> <j7em50$knr$1@dont-email.me> <slrnj9lpq5.3ru.houghi@penne.houghi>

Show all headers | View raw


On 10/16/2011 10:16 AM, houghi wrote:
> Jerry Stuckle wrote:
>> Parameters are good things to pass to functions, and you should strive
>> to use them as much as necessary, not get rid of the for "cleaner code".
>>    Your code will end up much "dirtier" in the long run.
>
> With cleaner I mean I won't have several (around 15 for now. This will
> increase) lines where I might need to edit $File to $FILE or whatever if
> I change some code. For sure I will forget at least one line somewhere.
>
> I do not need it here. I could as easily use:
> function write_fifo($data) {
>    $File = "test.txt";
>    echo $data."<br>".$File."<hr>";
>    $fh = fopen($File, 'w') or exit("can't open file -".$File."= .");
>    fwrite($fh, $data);
>    fclose($fh);
> }
> write_fifo("Something Here");
>
> Or write it in full and not use a parameter at all for $File.
>
> write_fifo("Something Here"); is much more logical then
> write_fifo("Something Here";"some_file"); as it involves an action,
> rather then just writing to a file. The real name will not be
> write_fifo, but rather mplayer
>
> It will steer mplayer that is running in slave mode. e.g. one will be:
> Some of them:
> mplayer("pause");		// Pause/Play
> mplayer("quit");		// Quit
> mplayer("volume -10");		// Louder
> mplayer("volume +10");		// Softer
> mplayer("loadfile $film 0");	// Start playing a movie
>
> So the $File part is not something I would like to have there as it does
> not make thing more clear, but instead will make it less clear what is
> going on or what the code is supposed to do at that point.
>
>
> houghi

But what are you writing TO?  That's part of the action, also.  Or in 
the case or mplayer - which mplayer are you talking to?

In your example you have an action - and an object that action is 
applied to.  The object is just as important as the action.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Taking parameters into functions houghi <houghi@houghi.org.invalid> - 2011-10-16 14:56 +0200
  Re: Taking parameters into functions Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-16 09:27 -0400
    Re: Taking parameters into functions houghi <houghi@houghi.org.invalid> - 2011-10-16 16:16 +0200
      Re: Taking parameters into functions Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-16 14:32 -0400
  Re: Taking parameters into functions "Peter H. Coffin" <hellsop@ninehells.com> - 2011-10-16 11:57 -0500
    Re: Taking parameters into functions houghi <houghi@houghi.org.invalid> - 2011-10-16 20:15 +0200
  Re: Taking parameters into functions "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-10-17 10:10 +0200

csiph-web