Re: Taking parameters into functions [message #175662 is a reply to message #175659] |
Sun, 16 October 2011 18:32 ![Go to previous message Go to previous message](/forum/theme/default/images/up.png) ![Go to next message Go to previous message](/forum/theme/default/images/down.png) |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
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(at)attglobal(dot)net
==================
|
|
|