- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Translated into PHP for CLARITY?
Now THAT'S funny.
Admin
The real WTF is obviously that the application is called "the application" and not "The Application".
Admin
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Admin
You guys still seem to question whether this is java or not. Java doesn't have an ArrayList.Count so it's not java. But it does exist in the .NET ArrayList.
Admin
The first lesson I learned about XP is that it can't magically turn a bunch of average people into high performers. In retrospective, I'm embarrassed at having needed to learn that lesson again, but that's how it went.
Admin
first.. the function returns NULL or an array
I'd return an array, empty or not. But not NULL.
public ArrayList GetRoles()
{
.....
return null;
}
then we check for a not-null member?/method? and branch from there. Id probably do that too.
if (this.getRols() != null)
{
....
}
then it gets weird..
we seem to be in an instance of *this*. proven by the call to this.getRols()
which leads me to believe that instance *this* has a method getRols()
or has a member of class getRols. Probably the later.
Then there is the <<< NEVER RE-EVALUATE SOMETHING NEEDLESSLY. >>> thing within the loop
while (roles.Count < getRols().Count)
{
}
<FONT color=#0000ff>consider a generic for() loop:</FONT>
<FONT color=#0000ff> for(min;max;increment){}</FONT>
<FONT color=#0000ff>I would hope to NEVER see any function() in the second argument. like:</FONT>
<FONT color=#0000ff> for(min;max();increment){}</FONT>
unless getRols() is a moving target, it's needless re-evaluation.
so we see...
while (roles.Count < getRols().Count)
{
... where getRols() is re-tested each iteration. That sucks.
... then we re-instantiate role...or no... getRols() is a static class
RoleClass role = (RoleClass)getRols().Item[roles.Count];
... so role object can feed roles.Count via the roles.add() method ... to increment it
roles.Add(role);
}
so that we can finally return roles as an array.
return roles;
Seems to me, the WTF is that a class was built simply to populate an array. Not to mention it needs a subordinant to actually perform the population.
This is abstraction at it's finest - aside from the needless loop gymnastics.
Admin
I like PHP.. it's fun.
Bring it on Brother.
Admin
Except for maybe the part about bothering to unit test your code. ;-)
Admin
Doesn't getRols() indicate that it is a method. Which means that the underlying code for the method is executed every time it is called? Which means that whatever is in getRols() is done twice for every iteration through the loop?
Admin
Admin
Admin
better that way :
public ArrayList getRoles() {
return getRols() == null ? null : new ArrayList().addAll(getRols());
}
Admin
It'll compile in Java if you do this (note that it's ok to create a class called ArrayList as long as it's not in the java.util package):
Won't be much use, but eh :)
Admin
Hey, if you're going to just rethrow the same error, why the hell did you bother catching it in the first place?
Admin
Ummm how do you know GetRoles() returns either null or 3 items? I think you mean:
<font face="Courier New">public Bool GetRollz0rz(int SuperFluous)
{
EnterpriseTable paula = new WoodenTable();
paula.Refactor(GetRoles() == null ? null :
GetRoles().Length == 1 : (</font><font face="Courier New">new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">) :
GetRoles().Length == 2 : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1]) :
</font><font face="Courier New"> GetRoles().Length == 3 : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1])</font><font face="Courier New">.Add(GetRoles().Item[2]) </font><font face="Courier New">:
</font><font face="Courier New"> GetRoles().Length == 4 : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1])</font><font face="Courier New">.Add(GetRoles().Item[2])</font><font face="Courier New"> </font><font face="Courier New">.Add(GetRoles().Item[3]) </font><font face="Courier New"> </font><font face="Courier New">:
</font><font face="Courier New"> GetRoles().Length == 5 : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1])</font><font face="Courier New">.Add(GetRoles().Item[2])</font><font face="Courier New">.Add(GetRoles().Item[3])</font><font face="Courier New">.Add(GetRoles().Item[4])</font><font face="Courier New"> </font><font face="Courier New"> </font><font face="Courier New">:
</font><font face="Courier New"> GetRoles().Length == 6 : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1])</font><font face="Courier New">.Add(GetRoles().Item[2])</font><font face="Courier New">.Add(GetRoles().Item[3])</font><font face="Courier New">.Add(GetRoles().Item[4])</font><font face="Courier New">.Add(GetRoles().Item[5])</font><font face="Courier New"> </font><font face="Courier New"> </font><font face="Courier New"> </font><font face="Courier New">:
</font><font face="Courier New"> new Brillant());
</font><font face="Courier New"> return FileNotFound;</font>
<font face="Courier New">}</font>
Admin
hehe, that's bad, but not that bad, or, wait, that's really bad actually... hohoho ;)
Admin
I call WTF.
Dude, you're still calling getRols() twice... unless it returns null the first time. No soup for you!
Admin
It only 'works' for some value of 'works'. Suppose it calls getRols and its told there are 10 rows. And then while the loop is running someone else deletes a row from the database. Uh oh. What happens when it goes to get ist 10th row? Crashtastic. Debug that.
If you want to get something from a database get it all in one go - or use cursors and tread carefully...
Admin
For completness:
As a C programmer, I will never call a procedure or function inside
<font color="#0000ff">for ( t=0;t < (max = GetMax(screen));t++){
DrawPixel(m,t);
}</font>
but:
<font color="#0000ff">max = GetMax(screen);
for ( t=0;t < max; t++){
DrawPixel(m,t);
}
</font>
then with OOP the difference of function/method is blended
<font color="#0000ff">for (t=0;t< screen->getMax();t++){
DrawPixel(m,t);
}</font>
this code is NOT that bad. Is a step away a huge optimization, is suggested to not do that, but is not a rule.
I mean, a getter mostly is about to get existing values, but to isolate internal from external, so you can change implementations, etc.
A simple enough getter mean, the perfomance hit is neligible.
This one is ugly:
<font color="#0000ff">for (t=0;t< screen->getMaxFromDB();t++){
DrawPixel(m,t);
}</font>
This one is ugly, because mean you are doing a mayor work you can avoid.
Yet another implementation, for speed, if Max not change, is to have a global variable (but you need to fill that global first on initialization!):
f<font color="#0000ff">or (t=0;t < screenSpecs.maxx;t++){
DrawPixel(m,t);
}</font>
or even a DEFINE
<font color="#0000ff">#define SCREEN_MAXX 768
for (t=0;t < SCREEN_MAXX ;t++){
DrawPixel(m,t);
}</font>
The better optimization is to rewrite withouth a loop:
<font color="#0000ff">
DrawLine( m,0,m, SCREEN_MAXX);
</font>On a good lang , maybe you can even do that:<font color="#0000ff">
screen.line( orgX: m , orgY: 0,
endX: m, endY: screen.SCREEN_MAXX);
</font>
--Tei
Admin
Judging from the name of the submitter, "Rol" is Dutch for "Role". But since two roles are called "Rollen", this "Rols" must a mixture between English and Dutch, famously known as Denglish.
Admin
That wouldn't do any difference :)
Admin
on the contrary... people should criticize code they haven't read properly as much as they possibly can.
the entertainment they provide is far superior to the original wtf itself.
where did beanbag girl go? not as classy as fússball girl, but I'm sure she wears bigger earrings!
Admin
What might be really interesting is that, if another user removes a role from the data base when the method is just about to retrieve the last role, an ArrayIndexOutOfBounds will be thrown! Its not only preforemence, since getRols might really return different values, which will bring a variety of interesting behaviours.
Admin
I really think you should improve on your code formatting. And I don't mean the . Readability is a goal that cannot be overvalued.
Sofayeti
Admin
notice the quoting of "clever". proposed option 1 doesn't look too bad.
Admin
Oh no, you must be another non-believer! Cast your demons -- its time you convert and realize that Brooks was right: The only way its OK to use junior programmers is if you are willing to pay ten of them to do the job of one good senior developer. It has been proven time and time again.
Check out the Mythical Man Month, by Fred Brooks, for other project management gems.
dZ.
Admin
But insn't Java a blatant copy of Turtle Graphics' Logo?
-dZ.
Admin
Monkeys typically hit the database about 12 times per loop, so I think it was probably junior developers this time.
dZ.
Admin
Welcome to the Real Point of this forum!
dZ.
Admin
Roger, is that you??
How many tight-assed, obsessive "argument hi-jackers" are actually out there? You know what I mean, where conversations usually go like this:
- Could you pass me that blue pen, please?
- There is no blue pen
- But... its right there on the desk!
- Oh, that pen: its not blue.
- WTF? Its blue! I have the black one, the one over there is red, and this one is blue.
- No, its not blue. Technically, its a white cylindrical pen, with a sorta cyanish cap, with blue *ink*, but its definitely not a "blue pen".
- {clenching teeth} Could you pass me, then, the cylindrical white pen, with a sorta cyanish cap, that writes in blue ink, please?
- {grinning} Sure, here you go.
{I then stab him in the eye with the fscking blue pen}
Lighten up!
dZ.
Admin
That's what the germans thought in ww2 before their fancy tanks lost to the russian t-34's
Admin
especially when this->getRols() (Love that name by the way) already does what this->getRoles() tries to do
Admin
Actually, growing/shrinking the stack uses trivial amounts of CPU time and doesn't "allocate" memory in any sane (compiled to machine code, for the most part) language/platform (and even in Java/.NET it should be possible to JIT compile it so it doesn't allocate memory).
It looks like code written in .NET<2.0, since 2.0 has generics (which are fluffy). I think it does serve a function, though, and that's to perform the cast to RoleClass (the class name is another WTF). In .NET, you can overload both explicit and implicit casts, e.g. a = (string[])listOfStrings could be equivalent to listOfStrings.ToArray().
Nevertheless, the code is so bad it's probably a port of something in VB or so, written by someone who hasn't learned about features in .NET. I fondly remember using various hacks to get my code to run properly (except back then I used RB), but this is inexcusable with a decent set of classes (not that .NET is decent).
Captcha = zork
Admin
WTF!!
Admin
Ouch.
Admin
WTF!
Admin
Now THERE's the REAL WTF.
Admin
A coding double-play, maybe? Gates-to-Ballmer-to-Ellison
Admin
You know on a side note:
I had a debate with brooks once through email (part of which was printed in the programmer's journal) and my final conclusion was that while his theory is sound he was totally wrong in his assessment.
It basically came down to this:
He stated that adding programmers will slow down a project, end of story, finito. I countered by saying that if that were the case no project would have more than one programmer but in reality, adding programmers will reduce the time to production. He countered basically saying He was right and I was wrong and that was the way of the world. This is where our published correspondence ended, of course he was the one controlling it.
The extended version went one more step. The entire issue is about Return On Investment (ROI). One programmer will take 100% of the time to complete a project, a 3 week project takes 3 weeks. Two programmers does not cut the time in half to 1.5 weeks but rather reduces it to maybe 2 weeks. In man-hours we increased the time (making him correct in theory) but in reality we reduced the time to market (making me correct in practice). I stated that there will come a time where you start adding programmers and get a negative ROI but until such time you are shortening your time to market albiet with increased cost.
The problem with this is that most project managers either think adding someone will cut the time equally (a flat ROI) or listen to Brooks without understanding the context and always refuse to add more help when it really is needed.
Admin
I should say that the above is written with the assumption that the programmers involved are compitant; Incompitant programmers start out with a negative ROI.
Admin
My thoughts exactly.
Incidentally, the legacy portions of our system (which are still in the majority, though my boss is hoping to rectify that soon) depended on a database component which had the following helpful properties:
* It did its own connection pooling. Which was broken. It would never release connections, and it would return them to the pool without doing any reinitialization. This created some MAJOR headaches when one component did BEGIN TRANSACTION and never did a COMMIT or ROLLBACK, then the connection (still in the transaction) was returned to the pool and handed off to the next component... causing mysterious data loss, until I figured out that's what it was.
* Most of the code was written in VB6 (honestly, as bad as VB is, it's far easier to write stuff in than C++). Using parametrized SQL Server stored procedure invocations (good). But VB isn't strongly typed. Therefore, in order to avoid needing CCur() and CInt() and whatnot everywhere, the code did this:
1. Fetch all of the parameters for the stored proc from the database.
2. Take the parameters passed in from the caller, match them up to the list in #1, and use VariantChangeType to convert them automatically.
This was clever and convenient. Unfortunately, there was no caching involved here, so some procs with *lots* of parameters actually spent more time getting the parameter info than executing the proc.
Oh, incidentally, this was really only necessary because the one type conversion SQL Server won't do automatically is string -> currency (varchar -> money).
* Here's the part relevant to your message I quoted above: In a gross blunder, the component returned the recordset object through an output parameter into a variant. Futhermore, under most circumstances, instead of an empty recordset, it would return Nothing. Otherwise, it might return VT_NULL or VT_EMPTY. It wasn't consistent. This led to this beautiful code (thanks to a lack of short-circuit evaluation):
dim recordset, error as long
error = conn.ExecuteStoredProc("my_sp", recordset)
if error = 0 then
if IsObject(recordset) then
if not Recordset Is Nothing then
' code
end if
end if
end if
Admin
LOL! That's friggin' hilarious! every time you hit the top of the while loop you're running a new query!!! WTF? Do you expect new roles to be appended while you're building your ArrayList? WTF? What's wrong with the first Array List? WTF? If you have to cast to RoleClass can't you do it in the original getRols call? WTF? Why is it getRols and not getRoles?
Funniest DWTF in a long time.
Admin
Very true, since they were written by the same guy who Microsoft "Stole" away from Borland - Anders whats-his-name.
CAPTCHA = (for) shizzle!
Admin
<!--StartFragment -->
That's one of the great things with this site, and has been mentioned several times before... It's actually not impossible that Alex ('Alex') uses TDWTF as some sort of psychology experiment by presenting fabricated 'WTF stories' just to lure 'WTF people' into proving themselves to be just that. Perhaps some of us will even turn up in some academic papers, or even a book! Now THAT would be the real WTF?!?!?!?
Admin
To make matters even worse (not taht it matters a lot if the code is bad). The code doesn't seem to be very thread safe. If the database changes during the execution of this function (e.g. adding or removing a role), it is possible that the array returns contains invali entries that never have existed in such a combination. I guess it is a good thing that teh function isn't thread safe though. Imagine this function to synchronize or lock the table or whatever. That could bring the application to a grinding halt in the worst case.
Even worse, if the original GetRols function doesn't guarantee the order of the rows returned (as the SQL standard doesnt impose) it is possible that certain entries are duplicated while others are removed.
Admin
true. but I think the guy said something to that affect later on. he was just replying to the dodgy code sample at the top of page 2.
I see this pointless catchcng and throwing all the time and it drives me mad. it makes people think they are writing error handling code, but all they are doing is losing the cause of the real error.
CAPTCH: WTF
Admin
You should have read the very next message before you take my soup away. But I hope you feel better about yourself now.
Admin
Most WTFy comment ever.
Admin
Even with the addition of a second body I would expect the project to take longer to complete if it's a three week project - simply because it takes too long for bod number 2 to learn what bod number 1 is thinking.
You will also end up with a less cohesive whole.
Not that I'm agreeing with what you say Brooks said, you can reduce time to market by adding bods, but you have to bloody careful about how you do it - and I would argue that very few shops are.
I'd also claim (with nothing but my own experience to back this up) that adding bods is considerably worse than starting off with more bods - and I mean right back at the planning stage.
Admin
function getRols()
{
$sql = "SELECT * FROM `roles`";
$res = mysql_query($sql);
$retval = array();
while ($row = mysql_fetch_object($res))
$retval[] = $row;
return $retval;
}
PHP converted to XML:
<getRols>
<DeclarationBlock>
<declarevar name="sql"><[CDDATA[
SELECT * FROM `roles`
]]></declarevar>
<declarevar name="res">
<functioncall name="mysql_query">sql</functioncal>
</declarevar>
</DeclarationBlock>
<ImplementationBlock>
<while>
<iteratorrule>
<let var="row">
<mysql_fech>res</mysql_fech>
</let>
</iteratorrule>
<executerule>
<le var="retval.current">row</let>
</executerule>
</while>
<return>retval</return>
</ImplementationBlock>
</getRols>
Anyway is better to move SELECT * FROM `roles` to a DTD.