Comment On Refactoring to the Max

As a consultant, one of Maarten De Cock's responsibilities is to analyze his client's code, identify where the developers could use improvement, and train them on how to write higher-quality code. Most of the developers that Maarten works with get it: they take in the techniques, apply them, and go back to improve the existing code. Others, not so much. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Refactoring to the Max

2006-04-04 15:15 • by Maurits
private boolean is04(String authCode)
{
if ("02".equals(authCode)) return true;

Uh... what?
[Note from Alex: This was a typo when anonymizing it -- I've corrected this]

Re: Refactoring to the Max

2006-04-04 15:16 • by l-user
04 is 02 and I am first

Re: Refactoring to the Max

2006-04-04 15:16 • by reed
66933 in reply to 66932
You are number six!

Re: Refactoring to the Max

2006-04-04 15:17 • by pinguis
I have no mouth, but i must scream

Re: Refactoring to the Max

2006-04-04 15:17 • by anon
So is he also 'training' the developers to cram as much code onto one line as possible and to avoid the use of constants?

Re: Refactoring to the Max

2006-04-04 15:19 • by Fist!
Alex Papadimoulis:




// brillant!

private boolean is01(String authCode)
{
if ("01".equals(authCode)) {
Console.Write("FIST!");
return true;
}
  else return false;
}

Re: Refactoring to the Max

2006-04-04 15:20 • by Rusty B

 I wonder how they will handle the 'Case Else' ....


 


argh


 

Re: Refactoring to the Max

2006-04-04 15:23 • by MikeMontana
Yeah, april fools. Too rediculous to be beleived - unless this is the output of some CodeWizard Tool.

Re: Refactoring to the Max

2006-04-04 15:33 • by ParkinT
private boolean isBrillant(String authCode)
{
  if ("paula".equals(authCode)) return true;
  else return false;
}

Re: Refactoring to the Max

2006-04-04 15:35 • by Manni

*snicker* You said "cock".


This code feels like burning in my special place. I work with a guy that likes to hardcode all sorts of crap like this, and he defines a function for every single thing. If he needs to create 30 different database tables, he'll make 30 separate functions to do it rather than one function that accepts a list of field names and types as parameters.

Re: Refactoring to the Max

2006-04-04 15:35 • by The Internet
What's the deal with these WTF's recently? Clearly, this is fake. We have not run out of real WTF's yet, have we?

Re: Refactoring to the Max

2006-04-04 15:39 • by Djinn
66944 in reply to 66942
Anonymous:
What's the deal with these WTF's recently? Clearly, this is fake. We have not run out of real WTF's yet, have we?


No, over functioning is a real syndrome. I have seen it myself.

Re: Refactoring to the Max

2006-04-04 15:41 • by Volmarias
66945 in reply to 66942
Gosh, I love the fact that I can't use any BBcode, or HTML tags, or anything like that, JUST BECAUSE I'M USING OPERA. (Hint: Get a better fucking board)

Maurits said:
---
private boolean is04(String authCode)
{
if ("02".equals(authCode)) return true;

Uh... what?
---

I don't see that, maybe Alex made a booboo and fixed it.

Re: Refactoring to the Max

2006-04-04 15:42 • by Volmarias
66946 in reply to 66945
Yep, mere moments later:

[Note from Alex: This was a typo when anonymizing it -- I've corrected this]

Too bad I can't edit my original post, or delete it!

Re: Refactoring to the Max

2006-04-04 15:54 • by DWalker59
66947 in reply to 66938
MikeMontana:
Yeah, april fools. Too rediculous to be beleived - unless this is the output of some CodeWizard Tool.

 

Why do so many people have trouble spelling "ridiculous"???

Re: Refactoring to the Max

2006-04-04 15:54 • by Coughptcha
66948 in reply to 66933
reed:
You are number six!
I am not a number. I am a free man!

Re: Refactoring to the Max

2006-04-04 15:57 • by GoatCheez
Stuff like this is grounds for either firing the dumbass that did this, or promoting them to management. WTF man...

Re: Refactoring to the Max

2006-04-04 15:59 • by mrprogguy
66950 in reply to 66931

Can someone please tell  me where that


if(condition) return something; else return somethingElse;


idiom came from?


Why would you need to protect a return with an else?  If the return is exercised, then the other clause is ignored! 


It's even in the original K&R book on C, written by the guys themselves, and it's no less idiotic coming from someone "authoritative."


That, to me, is a serious WTF.

Re: Refactoring to the Max

2006-04-04 16:02 • by BiggBru
Alex Papadimoulis:

As a consultant, one of Maarten De Cock's responsibilities is to analyze his client's code, identify where the developers could use improvement, and train them on how to write higher-quality code.


And that's when Maarten De Cock slapped the developer with his ... hand. [:P]

Re: Refactoring to the Max

2006-04-04 16:03 • by bullseye
66952 in reply to 66942

The Internet:
What's the deal with these WTF's recently? Clearly, this is fake. We have not run out of real WTF's yet, have we?


These comments are becoming as tiresome as the "first" posts.


If it is so outlandish, that it looks fake, then welcome to the world of code maintenance.  As I, and any other developer that works in the real world, can attest to, you see stupid stuff like this frequently.


Instead of looking like a moron (anonymously) who has never had to work with other people's code, you should sit back and be thankful that you haven't encountered this type of crap in your job.


(And yes, I am admittedly hostile about this because I have been debugging WTFs all day.  On a side note, I think this site has jaded me to bad programming tactics...)

Re: Refactoring to the Max

2006-04-04 16:04 • by Rob
66953 in reply to 66950
Eclipse even warns you that it is a mistake.
Hooray for Eclipse :)

Re: Refactoring to the Max

2006-04-04 16:05 • by ChiefCrazyTalk
66954 in reply to 66950
mrprogguy:

Can someone please tell  me where that


if(condition) return something; else return somethingElse;


idiom came from?


Why would you need to protect a return with an else?  If the return is exercised, then the other clause is ignored! 


It's even in the original K&R book on C, written by the guys themselves, and it's no less idiotic coming from someone "authoritative."


That, to me, is a serious WTF.



 


Simple - so the next guy who comes along and adds a line of code doesn't cause something to break.  This way its clear what is going on, when the intent is, and is more maintainable. 

Re: Refactoring to the Max

2006-04-04 16:06 • by Hubert Farnsworth
This is obviously machine generated, so it's ok.

Re: Refactoring to the Max

2006-04-04 16:07 • by cjd
66956 in reply to 66947
Probably because there's the E sound when they say it.  It makes perfect cents!

Re: Refactoring to the Max

2006-04-04 16:13 • by An apprentice
Alex Papadimoulis:
/**

* Method is01.
* @param authCode
* @return boolean
*/
private boolean is01(String authCode)
{
if ("01".equals(authCode)) return true;
else return false;
}

At least it's properly documented! I wouldn't know this method returns a boolean otherwise. And the name authCode is so self-explaining...

Re: Refactoring to the Max

2006-04-04 16:13 • by Joshua
66958 in reply to 66948
Hah! Ha! Ha! Hah!

(Seriously: The Prisoner was awesome.)

Re: Refactoring to the Max

2006-04-04 16:15 • by Joshua
66959 in reply to 66948
And, of course, the Real WTF is the forum software. (This coming from an anonymous bastard.) I was quoting the following...

Coughptcha:
reed:
You are number six!
I am not a number. I am a free man!


Re: Refactoring to the Max

2006-04-04 16:15 • by Tyler
66960 in reply to 66954
I agree.  I like the style:
if (condition) doStuff;

instead of
if (condition) {
    doStuff
}

I think it's more readable.  I also like the idea of not counting on the returns to avoid the else clause.  however, that's only when we are talking about long if statements (more than 5 lines at least).  it looks pretty stupid to write as much code as they did when half the code would have worked.. (and that's not getting rid of worthless functions).  And yes, people do write functions like that.  people that went to college and memorized certain techniques about coding but never really understood the underlying theory and reasoning behind modularity.

Re: Refactoring to the Max

2006-04-04 16:19 • by jackass
66962 in reply to 66944

Djinn:
Anonymous:
What's the deal with these WTF's recently? Clearly, this is fake. We have not run out of real WTF's yet, have we?


No, over functioning is a real syndrome. I have seen it myself.


I agree, I have seen this many times myself.  All you people who think this is fake are just a bunch of jackasses.

Re: Refactoring to the Max

2006-04-04 16:20 • by Digitalbath
66963 in reply to 66950
mrprogguy:

Can someone please tell  me where that


if(condition) return something; else return somethingElse;


idiom came from?


Why would you need to protect a return with an else?  If the return is exercised, then the other clause is ignored! 


It's even in the original K&R book on C, written by the guys themselves, and it's no less idiotic coming from someone "authoritative."


That, to me, is a serious WTF.



This would be much better:


private boolean is01(String authCode)
{
  boolean returnboolean = false;


  if ("01".equals(authCode) == true) {


    returnboolean = true;


    return returnboolean;


  }
 else if ("01".equals(authCode) == false) {


    returnboolean = false;


    return returnboolean;


 else {


    returnboolean = false;


    return returnboolean;


   }


  //and just to make sure, ie FileNotFound case 


  return returnboolean;
}


//end joke



Re: Refactoring to the Max

2006-04-04 16:26 • by E
66964 in reply to 66960

Or, instead of:


if(condition) return true; else return false;


How about:


return condition;

Re: Refactoring to the Max

2006-04-04 16:30 • by davewalthall
66965 in reply to 66950
The idiom:
  if(cond) return a;
  else return b;
comes from a very reasonable place.  It implies that b is being returned because cond was not true.  If you instead write:
  if(cond) return a;
  return b;
it implies that you are returning b because that is the appropriate thing to do if you reach that point, and is unrelated to cond.  I strongly believe that when code layout and structure reflects the underlying logic, that is a good thing. 

David

PS An even stronger statement of the idiom is:
  return (cond ? a : b);


Re: Refactoring to the Max

2006-04-04 16:35 • by kipthegreat
66966 in reply to 66945
Volmarias:
Gosh, I love the fact that I can't use any BBcode, or HTML tags, or anything like that, JUST BECAUSE I'M USING OPERA.


Opera is for hippies, gays, and terrorists.  Use Firefox.  It's what the cool kids are using.

Re: Refactoring to the Max

2006-04-04 16:37 • by VGR
This is sort of a cargo cult thing.  People do this because they
don't know why they're doing the things they've been instructed to
do.  As a result, they end up taking it all sorts of weird
directions.



Something like this would make a world of difference:



private boolean isAdministrator(String authCode)

{

    return "01".equals(authCode);

}



private boolean isFurniture(String productCode)

{

    return "004".equals(productCode) || "005".equals(productCode);

}



Not just because the if/else is pruned out (that's a pet peeve of mine,
and sure sign that the coder is still living in the world of C or maybe
even VB), but because the method's name now makes it an
abstraction.  So now it at least has some worth.

Re: Refactoring to the Max

2006-04-04 16:42 • by kiptheretard
66968 in reply to 66966

kipthegreat:

Opera is for hippies, gays, and terrorists.  Use Firefox.  It's what the cool kids are using.


Yeah, screw standardisation and the basis of inter-machine communication, just as long as everyone's a squealing script kiddie and using the same "kewl" browser. Hey, I hear Firefox has the best support for "Web 2.0". lolz.

Re: Refactoring to the Max

2006-04-04 16:50 • by Alun Jones
66969 in reply to 66965

davewalthall:

PS An even stronger statement of the idiom is:
  return (cond ? a : b);


Or, as I saw it in a few places while at Microsoft:


return !!cond;


Seriously.

Re: Refactoring to the Max

2006-04-04 17:05 • by Gene Wirchenko
66971 in reply to 66957
Anonymous:
At least it's properly documented! I wouldn't know this method returns a boolean otherwise. And the name authCode is so self-explaining...


Obviously, it is the Authentic Author Authority Code.  I am not sure whether it is a data value or the program code though.

Sincerely,

Gene Wirchenko



Re: Refactoring to the Max

2006-04-04 17:08 • by Enric Naval
66972 in reply to 66952
bullseye:

The Internet:
What's the deal with these WTF's recently? Clearly, this is fake. We have not run out of real WTF's yet, have we?


These comments are becoming as tiresome as the "first" posts.


If it is so outlandish, that it looks fake, then welcome to the world of code maintenance.  As I, and any other developer that works in the real world, can attest to, you see stupid stuff like this frequently.


Instead of looking like a moron (anonymously) who has never had to work with other people's code, you should sit back and be thankful that you haven't encountered this type of crap in your job.


(And yes, I am admittedly hostile about this because I have been debugging WTFs all day.  On a side note, I think this site has jaded me to bad programming tactics...)



Either it is a persistent troll, or some troll made one of this posts, and other have followed suite.



This kind of WTFs are common. Trust me, Anonymous, I know. I know because I have done them myself, and I had to refactor some of them myself :)



The sad thing here is seeing how the trolls here have run out of "brillant" trollings, and how they have to resort to bashing again and again the same trollings.



Errrr, are you sure that I can't mod myself troll?

Re: Refactoring to the Max

2006-04-04 17:12 • by rob_squared
66975 in reply to 66947
DWalker59:
MikeMontana:
Yeah, april fools. Too rediculous to be beleived - unless this is the output of some CodeWizard Tool.

 

Why do so many people have trouble spelling "ridiculous"???


Because people say it like they say words like redone remade and think an e belongs there.  Now its obviously wrong, because I've never heard of someone diculizing someone.

Re: Refactoring to the Max

2006-04-04 17:17 • by emurphy
66977 in reply to 66967
VGR:

private boolean isAdministrator(String authCode)

{

    return "01".equals(authCode);

}



private boolean isFurniture(String productCode)

{

    return "004".equals(productCode) || "005".equals(productCode);

}



Is there a good reason to avoid the following, which reads more like normal English?

private boolean isAdministrator(String authCode)

{

    return authCode.equals("01");

}



private boolean isFurniture(String productCode)

{

    return productCode.equals("004") || productCode.equals("005");

}


Re: Refactoring to the Max

2006-04-04 17:20 • by procyon112
66979 in reply to 66975
rob_squared:
DWalker59:
MikeMontana:
Yeah, april fools. Too rediculous to be beleived - unless this is the output of some CodeWizard Tool.

 

Why do so many people have trouble spelling "ridiculous"???


Because people say it like they say words like redone remade and think an e belongs there.  Now its obviously wrong, because I've never heard of someone diculizing someone.


We must not go to the same parties.

Re: Refactoring to the Max

2006-04-04 17:21 • by Gene Wirchenko
66980 in reply to 66975
rob_squared:
DWalker59:
MikeMontana:
Yeah, april fools. Too rediculous to be beleived - unless this is the output of some CodeWizard Tool.

 

Why do so many people have trouble spelling "ridiculous"???


Because people say it like they say words like redone remade and think an e belongs there.  Now its obviously wrong, because I've never heard of someone diculizing someone.


Bad reasoning.  You probably have not heard of anyone ading a book either.

Sincerely,

Gene Wirchenko

Re: Refactoring to the Max

2006-04-04 17:23 • by bovilexic
66981 in reply to 66950
mrprogguy:

Can someone please tell  me where that


if(condition) return something; else return somethingElse;


idiom came from?


Why would you need to protect a return with an else?  If the return is exercised, then the other clause is ignored! 


It's even in the original K&R book on C, written by the guys themselves, and it's no less idiotic coming from someone "authoritative."


That, to me, is a serious WTF.



Believe it or not there are some college professors who strictly enforce such garbage.  I experienced this first hand and still do not understand the full rationale behind it.  It was in fact maddening.  This specific professor always made us to do certain things for any bit of code:

1.  Always put a comment with the performance metric (big O) at the top of every method written.

2.  Always handle EVERY SINGLE case in a conditional and document it with comments.

So with #2 you had code that looked like this just so you didn't lose 10% of your assignment grade for not following instructions.  Love this WTF... (and no, not the operation performed, that is made up just to prove the point)

	// handles all negative numbers and 0
	if (i <= 0) {
    		i = i * -1.5;
	}
	// handles all numbers greater than 0 and less than or equal to 100
	else if (i <= 100) {
    		i = i * 1.5;
	}
	// handles all numbers greater than 100
	else {
    		// No operation to perform on numbers greater than 100
	}

Re: Refactoring to the Max

2006-04-04 17:23 • by John Bigboote
66982 in reply to 66975
rob_squared:


 Now its obviously wrong, because I've never heard of someone diculizing someone.




"Diculize" has actually made its way into the vernacular; it's when
somebody passes out and you duct-tape them to the couch and draw on
them with magic marker.

Re: Refactoring to the Max

2006-04-04 17:24 • by ParkinT
66983 in reply to 66947
DWalker59:

MikeMontana:
Yeah, april fools. Too rediculous to be beleived - unless this is the output of some CodeWizard Tool.

 

Why do so many people have trouble spelling "ridiculous"???


Yeah!  That is abserd!

Re: Refactoring to the Max

2006-04-04 17:24 • by Nand
66984 in reply to 66977
emurphy:


Is there a good reason to avoid the following, which reads more like normal English?

private boolean isAdministrator(String authCode)

{

    return authCode.equals("01");

}



private boolean isFurniture(String productCode)

{

    return productCode.equals("004") || productCode.equals("005");

}




Yes. That code will throw a NullPointerException when productCode == null. You'd have to check that first, or assume that it never happens and pray.


Re: Refactoring to the Max

2006-04-04 17:25 • by kipthegreat
66985 in reply to 66968
Anonymous:

kipthegreat:

Opera is for hippies, gays, and terrorists.  Use Firefox.  It's what the cool kids are using.


Yeah, screw standardisation and the basis of inter-machine communication, just as long as everyone's a squealing script kiddie and using the same "kewl" browser. Hey, I hear Firefox has the best support for "Web 2.0". lolz.



Okay, you got me, I was totally serious and you called me on it.  Thanks.  I now view the world in a different light.

PS: homooperausersayswhat

Re: Refactoring to the Max

2006-04-04 17:29 • by ammoQ
The real WTF is that they didn't write


/**
* Method is01.
* @param authCode
* @return boolean
*/

private boolean is01(String authCode)
{
if (isTrue("01".equals(authCode))) return isTrue(true);
else return isTrue(false);
}



(sorry could not resist, despite the obvious lameness of those IsTrue jokes)


Re: Refactoring to the Max

2006-04-04 17:35 • by kipthegreat
66988 in reply to 66969
Anonymous:

davewalthall:

PS An even stronger statement of the idiom is:
  return (cond ? a : b);


Or, as I saw it in a few places while at Microsoft:


return !!cond;


Seriously.



Sometimes the !! "operator" makes sense.  In the C++ code where I work, we use COM objects, and "smart pointers", which are actually objects with a pointer and a reference count.  The operators are overloaded so you can use them exactly like pointers.  So "!spObj" returns true if a smart pointer is "null".  So to see if it is NOT null, you use "!!spObj".  It threw me for a loop the first time I saw it, but once you get used to it it makes sense.

But in the case of a boolean condition like you mentioned... yeah it doesn't make much sense.

Re: Refactoring to the Max

2006-04-04 17:35 • by Tito
66989 in reply to 66969

!!cond is actually a C idiom for ensuring that the value is actually set to "true", where true =1 or -1 as the case may be for the compiler.  Since in C anything nonzero is considered "true" when used in a conditional.  (Because of the whole JNZ asm thing)  However, that can lead to strange situations like having the following two if statements not be equivalent when x=5:


if (x) // true


if(x==TRUE) // false  (and yes, this is needlessly verbose, but shouldn't be WRONG)


So, in order to clean up the possible issue with int variables (and bool's didn't exist until disturbingly recently.. #define int BOOL was normal) using the !!variable would ensure that the variable was ACTUALLY either true(1) or false(0).

« PrevPage 1 | Page 2 | Page 3Next »

Add Comment