FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Taking parameters into functions
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Taking parameters into functions [message #175659 is a reply to message #175658] Sun, 16 October 2011 14:16 Go to previous messageGo to previous message
houghi is currently offline  houghi
Messages: 45
Registered: September 2011
Karma:
Member
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
--
> Beware of he who would deny you access to information, <
> for in his heart he dreams himself your master. <
> Commissioner Pravin Lal: "U.N. Declaration of Rights" <
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: Editing a combobox
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Sep 19 23:55:48 GMT 2024

Total time taken to generate the page: 0.04209 seconds