If considered harmful?


That blog post of your friend is already a good example of someone who doesn't understand the message properly and starts misrepresenting the campaign with stupid, unclear and probably wrong examples.
How so? What is the message and how does he misunderstand it?
 
I'm afraid I lol'd at the NPE blog post, mainly over the example.

  • An Integer was turned into a class - which has a larger overhead
  • this.bar.doYourThing() is never described. So you're basically just moving your If statement into there... or...
  • If you're creating three classes to deal with the different integer values supported (yet more overhead), you'll still need to If to work out which class to instantiate from your factory class.


All I can tell from this is that the if statements are just being moved about, and extra overhead created for dealing with classes.
 
How so? What is the message and how does he misunderstand it?
The anti-if campaign exaggerated the evilness of the IF-statement to make a point. They do indicate that in fact they want to eliminate bad applications of if statements which are, in object oriented languages, better solved in other ways. The blog post translates this in an all-but absolute statement.


To demonstrate this, he raises an incomplete example about eliminating branching on data values. He replaces an integer with an object to somehow magically dispatch the right doYourThing method. Without more context, the only thing that can be concluded from this example is that the if statement has moved into the object or moved towards the point where the object is created.


This type of branching on data values is exactly the type of branching where it would be appropriate to use an if-statement.


This problem is created by the campaign itself. It over-generalizes without clearly communicating which cases they are talking about. It is to be expected that many people will fill in the gaps on their own by raising poor examples.
 
I gave up on the website, unable to find a clear picture about what the hell they were talking about.


I then proceeded here to rant about how terrible it was, but you all agree. So +1 for everyone, hurrah!


How about we launch a campaign to eliminate shitty, incoherent websites from the internet? I still don't know what the hell is considered to be a "bad" IF, or what's a good one, or what the hell I'm supposed to do without IFs.
 
I still don't know what the hell is considered to be a "bad" IF, or what's a good one, or what the hell I'm supposed to do without IFs.
You're supposed to go to a course/formation to find out. This website is basically a scam to bring you to their class on high price.
 
I still don't know what the hell is considered to be a "bad" IF, or what's a good one, or what the hell I'm supposed to do without IFs.
You're supposed to go to a course/formation to find out. This website is basically a scam to bring you to their class on high price.

If so, then they've even failed at that. Useless!


I consider myself adept at avoiding "if", just pass all your variables into a SQL statement and use CASE WHEN. Example:


$Action = "Multiply";


$a = 1;


$b = 2;


$result = $mysql->query('SELECT CASE WHEN ?action = "Multiply" THEN ?a * ?b ELSE ?a / ?b END AS result', array( 'action'=>$action, 'a'=>$a, 'b'=$b ));
 
I still don't know what the hell is considered to be a "bad" IF, or what's a good one, or what the hell I'm supposed to do without IFs.
You're supposed to go to a course/formation to find out. This website is basically a scam to bring you to their class on high price.

If so, then they've even failed at that. Useless!


I consider myself adept at avoiding "if", just pass all your variables into a SQL statement and use CASE WHEN. Example:


$Action = "Multiply";


$a = 1;


$b = 2;


$result = $mysql->query('SELECT CASE WHEN ?action = "Multiply" THEN ?a * ?b ELSE ?a / ?b END AS result', array( 'action'=>$action, 'a'=>$a, 'b'=$b ));
Is offloading the check to the db any better then performing the check beforhand?


I mean mysql would still have to act on some sort of expression, so your just moving the work from PHP (or alternative) to MYSQL.


Is that saving any system resources?
 
Im personally starting a new movement that shall be named the anti-while association.


While keyword is the most vile and disgusting programming operation know to man, it will cause you program to be stuck in a loop fore......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop......loop .....loop.....
 
LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....


LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....


LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....


LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....


LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....


LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....LOL....
 
Is offloading the check to the db any better then performing the check beforhand?


I mean mysql would still have to act on some sort of expression, so your just moving the work from PHP (or alternative) to MYSQL.


Is that saving any system resources?

No, it's an utter programming abomination from the very depths of hell. But I've been known to program unnecessarily in SQL from time to time. Particularly to fudge SQL output to be compatible with my bizarre table rendering classes.


For the most part, I'd use something like:



Code:
if( class_exists( $this->providerName )  && $this->provider = call_user_func( array( $this->providerName , 'instantiate' ) ) )



Yes, it's still an if, but it's better than:





Code:
switch ( $this->providerName )

{

  case 'monkey':

	$this->provider = class_monkey::instantiate();

  case 'pirate':

	$this->provider = class_pirate::instantiate();

  break;

}
 
Back
Top