Comment On The Phony

"My first impression of my predecessor was a positive one," writes Michal Ochman, "he was well-spoken, sharply dressed, and seemed to be an all-around nice guy." [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: The Phony

2012-02-22 09:04 • by Mikey (unregistered)
/* Frist function **
** Just for consistency and
** ease of maintenance, let's declare our own function **/
function frist() {

// Initialise output variable
$output = "frist";

// output the output
echo $output;
}

Re: The Phony

2012-02-22 09:04 • by GotCred (unregistered)
Frist - and not SPAM

Re: The Phony

2012-02-22 09:05 • by veggen
Did he reimplement PHP in the end?

Re: The Phony

2012-02-22 09:05 • by Myth (unregistered)
Frist?

Akismet thinks this is spam. It probably is.

Re: The Phony

2012-02-22 09:06 • by Myth (unregistered)
375101 in reply to 375100
Myth:
Frist?

Akismet thinks this is spam. It probably is.


Damn you Akismet. Three other comments while I battled you.

Re: The Phony

2012-02-22 09:15 • by Ben Jammin (unregistered)
You're a phony

Askimet is a phony too.

Re: The Phony

2012-02-22 09:16 • by Anon (unregistered)
That's... somewhat pointless but not totally stupid.

PHP is a notorious mess, and he's trying to build an abstraction layer on top of it. To improve the tool, really. It's the same thing framework developers are trying to do, just on a much smaller scale.

Re: The Phony

2012-02-22 09:21 • by XXXXX (unregistered)
I had a coworker who wanted to wrap everything. Our company has a set of common shared libraries for common functions. My coworker thought we should wrapper any calls to the company's common libraries from our project in our project's own utility functions. That way, if our company's internal software (our project) was ever moved to another company, it would be easy to swap in a different library.

Re: The Phony

2012-02-22 09:25 • by Manadar (unregistered)
And in the end it turns out they actually needed a variant of base64. The new programmer only has to edit those two functions with the correct implementation.

That's sometimes how those things work out. If you suspect your implementation of base64 is not what PHP offers, please please please, do something like this. Even if that means your implementation of base64 is not base64.

Re: The Phony

2012-02-22 09:27 • by Ronan (unregistered)
He should have made it generic.

function call_php_function($function, $parameter){
//Initialisation of return value
$return_value = '';

//Call of the php function
$return_value = $function($parameter);

//let's return te result
return $return_value;
}


of course, you'd have to do that multiple times to account for the number of parameters for different php function.
function call_php_function_1_parameter($function, $parameter)
function call_php_function_2_parameters($function, $parameter1, $parameter2)
etc...

Re: The Phony

2012-02-22 09:28 • by Jeff (unregistered)
Looks like he wrapped the function to make it easier to fix if php updates end up changing the name or the method of calling it. Seems pretty standard to me. #ifdefs do this ALL THE TIME in C/C++ code to handle differences in compiler and architecture.

Re: The Phony

2012-02-22 09:30 • by HatWieldingManiac (unregistered)
It's a good start but not enough - what if his interface changes? Sure, he says it's for ease of maintenance but you can't trust other people.

Thus my solution to this WTF:

<?php

/* Base 64 Encoding function **
** For even more consistency and
** ease of maintenance, let's declare
** a wrapper around our base64Encode.
**
** Allows for partial refactoring and other
** enhancements if needed in the future. **/
function base64EncodeWrapper($plain) {

// Initialise output variable
$output = "";

// Do encoding
$output = base64Encode($plain);

// Return the result
return $output;
}

/* Base 64 decoding function **
** For even more consistency and
** ease of maintenance, let's declare
** a wrapper around our base64Encode.
**
** Allows for partial refactoring and other
** enhancements if needed in the future. **/
function base64DecodeWrapper($scrambled) {

// Initialise output variable
$output = "";

// Do encoding
$output = base64Decode($scrambled);

// Return the result
return $output;
}

?>

Re: The Phony

2012-02-22 09:30 • by MB (unregistered)
This is not a WTF, if this is what a WTF looks like for you, then you are lucky, a true WTF would be him implementing his own base64decode / encode, each time, everywhere, incorrectly...

Re: The Phony

2012-02-22 09:32 • by Ec (unregistered)
So wrapped the native function in a CamelCase name. Sounds sensible to me. And he even commented it with sort of that explanation!

Re: The Phony

2012-02-22 09:38 • by steve (unregistered)
seems like a great way to fix deprecated methods in the future....

Re: The Phony

2012-02-22 09:38 • by Rootbeer

I can respect the intent to apply some consistency to the calling conventions for PHP's internal functions: some are underline_separated, some are camelCased, some lead with the subject, some with the verb, and no two functions that take haystack and needle parameters take them in the same order.

These new function definitions still aren't very good, though. The code's needlessly explicit in a way that makes me believe the coder doesn't understand how 'return' works, and the comments are completely useless.

Re: The Phony

2012-02-22 09:40 • by Tractor (unregistered)
375113 in reply to 375103
Anon:
That's... somewhat pointless but not totally stupid.

PHP is a notorious mess, and he's trying to build an abstraction layer on top of it. To improve the tool, really. It's the same thing framework developers are trying to do, just on a much smaller scale.


Agreed, this is actually quite a sane thing to do. It keeps the function names consistent, god knows the PHP developers didn't.

Re: The Phony

2012-02-22 10:07 • by foo (unregistered)
375114 in reply to 375099
veggen:
Did he reimplement PHP in the end?


#!/bin/sh

### PHP interpreter ###
### PHP runs natively but just for consistency and ###
### ease of maintenance, let's declare our own script ###

callPHP ()
{
# Initialise output variable
exit_status=42

# Call PHP
php "$@"

# Get the result
exit_status=$?

# Return the result
return $exit_status
}

# Initialise output variable
return_status=42

# Call PHP calling function
callPHP "$@"

# Get the result
return_status=$?

# Return the result
exit $return_status

Re: The Phony

2012-02-22 10:23 • by corroded (unregistered)
375115 in reply to 375111
steve:
seems like a great way to fix deprecated methods in the future....


Bingo. I've seen a sysadmin trawling through code to fix PHP removing a method that was used throughout the system. Now, admittedly he shouldn't have upgraded PHP without checking better... but having a wrapper for the function would have meant a single change rather than searching the entire code base for the method.

Re: The Phony

2012-02-22 10:28 • by PedanticCurmudgeon
375116 in reply to 375113
Tractor:
Anon:
That's... somewhat pointless but not totally stupid.

PHP is a notorious mess, and he's trying to build an abstraction layer on top of it. To improve the tool, really. It's the same thing framework developers are trying to do, just on a much smaller scale.


Agreed, this is actually quite a sane thing to do. It keeps the function names consistent, god knows the PHP developers didn't.
And you know a language is really bad when even the trolls about it raise good points.

Re: The Phony

2012-02-22 10:32 • by operagost
I applaud this guy for not using any magic functions.

Re: The Phony

2012-02-22 10:35 • by Anon (unregistered)
375118 in reply to 375098
GotCred:
Frist - and not SPAM


Wrong and wrong again.

Re: The Phony

2012-02-22 10:37 • by foo (unregistered)
375119 in reply to 375115
corroded:
steve:
seems like a great way to fix deprecated methods in the future....


Bingo. I've seen a sysadmin trawling through code to fix PHP removing a method that was used throughout the system. Now, admittedly he shouldn't have upgraded PHP without checking better... but having a wrapper for the function would have meant a single change rather than searching the entire code base for the method.
By the logic, why not wrap everything, functions, variables, constants, files, networks, character sets, just everything. Anything might change some day, after all, and spending some effort to adjust later is certainly worse that spending 10 times the effort now. Fuck performance, Moore's Law will take care of that, right?

Re: The Phony

2012-02-22 10:38 • by Anon (unregistered)
375120 in reply to 375116
I resent that. I've never raised a good point in my life.

Re: The Phony

2012-02-22 10:41 • by frits
Clean code, new shoes
And I don't know where I am goin' to.

Standard functions wrapped tight,
I dont need a reason why

They leave running just as fast as they can.
Cause every manager's crazy bout a sharp
dressed man.

Re: The Phony

2012-02-22 10:45 • by Not Bob (unregistered)
375123 in reply to 375106

of course, you'd have to do that multiple times to account for the number of parameters for different php function.
function call_php_function_1_parameter($function, $parameter)
function call_php_function_2_parameters($function, $parameter1, $parameter2)
etc...

That's not nearly difficult enough to debug. Why not use call_user_func_array? Then you can implement all PHP classes with a single class:

<?php

class allPHP{
public function __call($name,$args){
return call_user_func_array($name,$args);
}
}
?>

Re: The Phony

2012-02-22 10:53 • by gizmore (unregistered)
375124 in reply to 375123
Not Bob:

of course, you'd have to do that multiple times to account for the number of parameters for different php function.
function call_php_function_1_parameter($function, $parameter)
function call_php_function_2_parameters($function, $parameter1, $parameter2)
etc...

That's not nearly difficult enough to debug. Why not use call_user_func_array? Then you can implement all PHP classes with a single class:

<?php

class allPHP{
public function __call($name,$args){
return call_user_func_array($name,$args);
}
}
?>

You should at least break backwards compatibility with PHP4 by using type hinting. We have to move on!

Similis: A mixture of an illness and a smiling doctor.

Re: The Phony

2012-02-22 11:06 • by corroded (unregistered)
375125 in reply to 375106
Ronan:
He should have made it generic.

function call_php_function($function, $parameter){
//Initialisation of return value
$return_value = '';

//Call of the php function
$return_value = $function($parameter);

//let's return te result
return $return_value;
}


of course, you'd have to do that multiple times to account for the number of parameters for different php function.
function call_php_function_1_parameter($function, $parameter)
function call_php_function_2_parameters($function, $parameter1, $parameter2)
etc...


Tsk, that's not enterprisey enough... and you can do it without duplicating function calls.

function evil($function) {
$args = func_get_args();
unset($args[0]); //removes function name

foreach($args as $k => $a) {
$var = 'var_'.$k;
$$var = $a;
$par[] = '$' . $var;
}

$list = implode("'",$par);
return eval($function.'('.$list.');');
}

echo evil('echo','lies'); //lies
echo evil('echo',3+3); //6
echo evil('echo','3+3'); //3+3

I apologise in advance for the current vomit coming out of your face.

Re: The Phony

2012-02-22 11:17 • by fritters (unregistered)
375126 in reply to 375106
Ronan:
He should have made it generic.

function call_php_function($function, $parameter){
//Initialisation of return value
$return_value = '';

//Call of the php function
$return_value = $function($parameter);

//let's return te result
return $return_value;
}


No. The better way is to set up a mapping using an Excel spreadsheet, then generate an XML configuration file.

Then your code just needs to parse the XML file and follow the translations. This way if you ever need to change them or add more, you don't even have to make code changes!

It's brillant!

Re: The Phony

2012-02-22 11:17 • by iToad (unregistered)
375127 in reply to 375125

Tsk, that's not enterprisey enough...


Do not speak aloud of enterprisey PHP. By doing so, you could accidentally call up that which you cannot put back down. Some elder horrors must be left to slumber undisturbed.

Re: The Phony

2012-02-22 11:18 • by my little phony (unregistered)
375128 in reply to 375119
foo:

By the logic, why not wrap everything, functions, variables, constants, files, networks, character sets, just everything. Anything might change some day, after all, and spending some effort to adjust later is certainly worse that spending 10 times the effort now. Fuck performance, Moore's Law will take care of that, right?


So, you've basically just described Java.

Re: The Phony

2012-02-22 11:21 • by PedanticCurmudgeon
375129 in reply to 375120
Anon:
I resent that. I've never raised a good point in my life.
...until now. For what it's worth, it's not really your fault. You didn't name the PHP functions, right?

Re: The Phony

2012-02-22 11:23 • by Dr Doom (unregistered)
In any other programming language this would definitely be a WTF but seen as it's PHP he's actually adding value by standardising the naming convention.

<?wtf
echo "the real WTF is PHP";
?>

Re: The Phony

2012-02-22 11:28 • by Tasty (unregistered)
375132 in reply to 375128
my little phony:
foo:

By the logic, why not wrap everything, functions, variables, constants, files, networks, character sets, just everything. Anything might change some day, after all, and spending some effort to adjust later is certainly worse that spending 10 times the effort now. Fuck performance, Moore's Law will take care of that, right?


So, you've basically just described Java.


Java, and C++ before it, are compiled languages so that performance can be optimized. Modern compilers can fold the wrappers as in-line code, and C++ has a qualifier for that.

Also, Moore's Law is far less important than properly using the CPU's instruction set. Computers will change speed, materials and architecture that interpreters and compilers have to suit.

Re: The Phony

2012-02-22 11:32 • by Daniil S. (unregistered)
Seriously, this is the very first time on WTF that everyone is actually agreeing with the perp. The world has gone mad!!!

Re: The Phony

2012-02-22 11:37 • by FragFrog (unregistered)
375134 in reply to 375106
Ronan:
of course, you'd have to do that multiple times to account for the number of parameters for different php function.
function call_php_function_1_parameter($function, $parameter)
function call_php_function_2_parameters($function, $parameter1, $parameter2)
etc...

At the risk of taking a troll serious: fun_get_args allows you to create functions which take a variable number of parameters. I would generally advice against using it (having a function which behaves differently depanding on how many arguments you give it, is a sure way to make any consecutive developer blow his brains out), but there are a few situations where it can really make things easer.

Ontopic: while I hate to admit it, PHP's own naming conventions are non-existent at best, and deliberately confusing at worst. I do not condone writing code for the sake of writing code either, but this is not necessarily a bad idea. I have seen far, far worse PHP.

Re: The Phony

2012-02-22 11:48 • by Yoshord (unregistered)
Even if the wrapper function is neccessary, the number of lines isn't. It could surely be shortened to
function base64Encode($plain) {

return base64_encode($plain);
}

Re: The Phony

2012-02-22 11:51 • by Richard (unregistered)
375136 in reply to 375134
Just what PHP needs: Perl like functions.

Re: The Phony

2012-02-22 11:51 • by Nagesh-saki (unregistered)
375137 in reply to 375133
Daniil S.:
Seriously, this is the very first time on WTF that everyone is actually agreeing with the perp. The world has gone mad!!!


Nah, just the first time all commenters are trolls. BTW, I agree with the perp.

Re: The Phony

2012-02-22 11:51 • by frits (unregistered)
Seriously guys, what software dev isn't a phony?

Re: The Phony

2012-02-22 11:58 • by Jonathan (unregistered)
$meToo++;

Seriously, whose kneecaps do I break for DEPRECATING split()? I'm a little surprised that Rasmus made it out of Penguicon with all his extremities a couple of years back. Anyone starting a new project in PHP in this day and age is either drunk or mismanaged.

Re: The Phony

2012-02-22 12:08 • by bart (unregistered)
375140 in reply to 375109
Agreed.

I am often shocked at those that are quick to judge.

Re: The Phony

2012-02-22 12:10 • by frits
375141 in reply to 375139
Jonathan:
$meToo++;

Seriously, whose kneecaps do I break for DEPRECATING split()? I'm a little surprised that Rasmus made it out of Penguicon with all his extremities a couple of years back. Anyone starting a new project in PHP in this day and age is either drunk or mismanaged.

Direct string manipulation is so 1990s. Everyone knows the extra level of indirection added by using regular expressions adds more value.

Re: The Phony

2012-02-22 12:23 • by foo (unregistered)
375143 in reply to 375135
Yoshord:
Even if the wrapper function is neccessary, the number of lines isn't. It could surely be shortened to
function base64Encode($plain) {

return base64_encode($plain);
}
Haven't you read the coding standards?

- Everything must be wrapped (also wrappers, if possible)

- Every variable must be initialized (even if the first thing you do with it is set it)

- Never do two things in one line/statement (not even a function call and return)

- Every line must be commented (even if self-explanatory)

And that's just the start. The other 42000 rules get really absurd.

(Yeah, would be more funny if it weren't so common.)

Re: The Phony

2012-02-22 12:30 • by Nagesh-saki (unregistered)
There is no programming problem that can't be solved by adding another level of indirection, except of course, too many levels of indirection.

Re: The Phony

2012-02-22 12:46 • by Anonymous (unregistered)
375145 in reply to 375107
Jeff:
Looks like he wrapped the function to make it easier to fix if php updates end up changing the name or the method of calling it. Seems pretty standard to me. #ifdefs do this ALL THE TIME in C/C++ code to handle differences in compiler and architecture.
This excuse doesn't add up when you notice the insistence in not just wrapping the function call and instead add a variable and assignments and lame stuff.

Worse, because in php, you can make "just-in-case wrappers" by just doing:

base64Encode = base64_encode

Not like making wrappers for each php function before it gets changed is quite unnecessary. Regardless of the mess fanboys call php to be.

Re: The Phony

2012-02-22 12:58 • by ubersoldat
375146 in reply to 375139
Jonathan:
$meToo++;

Seriously, whose kneecaps do I break for DEPRECATING split()? I'm a little surprised that Rasmus made it out of Penguicon with all his extremities a couple of years back. Anyone starting a new project in PHP in this day and age is either drunk or mismanaged.


Shit! Didn't know this. Haven't touched PHP with a pole since version 3 and believe me, I'm not turning back.

Anyway, if anyone thinks this is a good idea, it's because we're talking about PHP here people. In any other sane language you wouldn't have to worry about lossing base64... shit, Java have had Vector deprecated for 20 years but you can still use it.

Re: The Phony

2012-02-22 13:01 • by Jim (unregistered)
375147 in reply to 375144
Nagesh-saki:
There is no programming problem that can't be solved by adding another level of indirection, except of course, too many levels of indirection.


I'm pretty sure if you create enough indirection, you summon Cthulu, or create a black hole, in which case you've solved every problem on Earth.

Re: The Phony

2012-02-22 13:04 • by tweek
375148 in reply to 375141
frits:
Jonathan:
$meToo++;

Seriously, whose kneecaps do I break for DEPRECATING split()? I'm a little surprised that Rasmus made it out of Penguicon with all his extremities a couple of years back. Anyone starting a new project in PHP in this day and age is either drunk or mismanaged.

Direct string manipulation is so 1990s. Everyone knows the extra level of indirection added by using regular expressions adds more value.


What's that old chestnut?
Some people, when confronted with a problem, think
“I know, I'll use regular expressions.” Now they have two problems.

Re: The Phony

2012-02-22 13:07 • by derk (unregistered)
somebody has some $plain-in' to do!
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment