- 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
I know what it does!
It hunts down and KILLs sane programmers... what else could it be used for?
Admin
Not knowing access at all:
What does IIf() do?
Admin
IIf is normally a very efficient operator in Access, but since you divided it up into multiple lines it will lose much of its efficiency, since the compiler has to execute each line individually. This is not so bad. At least he didnt use a buch of separate if statements, then we would really be saying wtf, right?
Admin
<FONT style="BACKGROUND-COLOR: #efefef">Using Access is the WTF</FONT>
Admin
IIF is like a ternary operator:
evaluate ? true expression : false expression
IIF (evaluate, true expression, false express)
Even knowing that, good luck.
Admin
Admin
Admin
From looking at the code, I get the distinct impression that it has something to do with formatting a date.
Admin
I can't believe you actually said that...ROFL
You must be joking...either that or you have no true programmatic experience with Access.
Your comment is a major WTF.
Admin
Holy Crap! [:'(] Does anyone, anyone know what this does??! Alex. I applaud you for your attempt to format this. I gather it's looking at some date criteria.. but, who the hell know what, exactly.
About it being access: No: this is certanly VB. Why they've bracked the varaible name is beyond me, but with it being on multiple lines and having too many continuations (I was going to try it in VB to see what it did... I gave up, after realising that stepping through 1 line of code would be useless and formtting this into a sensible(HAH) set of nested ifs seems to be an impossibility) I conclude that the person who wrote this should be taken behind the shed and shot.
Admin
LOL.. Yep, using Access is the best thing if you want corrupt data and unusable databases :)
BTW, the really sad thing is if this mess was trying to be efficient, it's horribly ineffecient. VB Does not have short circuit evaluations unlike other, real programming languages. So, it has to do, a couple dozen format statements, a bunch of comparisons, and a whole litany of function calls.
Admin
Looks like the code tries to find out if a date (sol_date_reqd) is within 10 weeks of today, but hasn't happened yet? Following that code hurts my brain.
If Access has a datediff() function or somesuch, this is an amazing WTF indeed :)
Admin
Admin
It appears that this function checks if the requested date is in a fiscal year that is 10 weeks off of the calendar year. (WTF if I am right...)
Eddie Garmon
Admin
WTF???? [:|]
I love how he's using + 0 to convert all the outputs of the Format functions to integers for the conversions...
Admin
Best I could do in the circumstances. I probably messed it up somehow, but I expect forgiveness, given the circumstance.
Rik
Admin
Wow the posts come fast. I meant that that pseudocode above was the best I could do. Not the original code. If I'd written that, I'd shoot myself.
Rik
Admin
Wow, I was going to say that you're brave..but...
You wouldn't have had to shoot yourself, I think the participants would have taken care of that for you [:)]
Admin
I give up. I made an attempt to discern what this does but decided that I may not want to know.
And what's with the "+ 0" sprinkled throughout the code? The "+ 10" I thought might be some type of Fiscal Year to Calandar Year conversion but W(ho)TFK(nows)
Admin
See my post above for my guess as to what they're for...
Admin
Admin
This actually looks like a lot of the MDX (similar to SQL, but for OLAP) code that I have to maintain. The difference is that in the case of MDX -- that would be considered good code.
Of course, with MDX you HAVE to do everything in-line. So yes, nested IIf loops all over the place -- and debugging is Hell!
Admin
Pseudo-Code:
To the code's credit, it does wrap weeks (though it could do the same by just adding the damn ten weeks and calling the modulo operator, which hopefully exists in this language); in doing so, it ignores carrying to the year, though, and it has issues with a week 53 (which would be 4 days of a week at the end of a year).
I have no idea why anyone would be interested in just the number of the week of a requested date, limiting it to be between this week (which might be up to six days ago) and 10 weeks (plus or minus six days) from now, particularly when throwing away the year in the process.
As for the efficiency (ha!): sometimes, trading efficiency for maintainability can be the right decision. In this case, the codemonkey chose to forego one in order to get rid of the other, so ignoring what the code actually does, that design decision strikes me as the major (WT)F-up.
Admin
Basically this code figures out when to do something, based on sol_date_reqd. If this date is equal to the current date, it returns the current week number, otherwise it returns the number of the week 10 weeks from now, wrapping around the end of the year. If the required date has passed, then just return -1.
There, that wasn't so bad after all.
Admin
Sorry to burst your anti-VB bubble but VB has short circuit evaluations now. - AndAlso and OrElse.
Admin
Admin
I do not consider VB.NET and VB the same thing.
Admin
The refactoring is called "introduce explaining variable"
Admin
I agree - the difference between VB6 and VB.NET is huge - though IMHO it should have been bigger - e.g. less 'backwards compatibility'.
Admin
Admin
<!--StartFragment --> Just to throw my 2 cents in, for a single user database I'd much rather use something like MSDE than Access since it acts like a real database instead of pretending to be like one [;)]
Admin
Sometimes, as a developer, you don't have a choice of language or backend database. You just have to make do with what's already there. Especially if you're doing maintenance work on code you didn't write.
Admin
Was this actually written out in VBA code, or was it an expression used in a query or in the "ControlSource" property of a report or form control?
If it was the latter, the use of IIF() is explained. Using a bunch of nested IIFs allows you to write the thing as one big expression. Otherwise you would have to write a VBA function.
Which is what I would have done. But I suppose it's possible -- possible -- that there is a performance difference between doing this in a function and doing it as an in-line expression. If this were part of some gargantuan report or batch update, there might be enough of a difference to make this worthwhile.
But I do think they must not have known about Year() and DateDiff().
Admin
You've accidentally changed the behavior of the code. Just think of the differences if you ran your code near midnight on New Year's or a Saturday.
Admin
This looks to me like a LISP programmer who's being forced to use Access, which is reason enough for ?him to want to kill himself. If he were a better programmer, he would have checked and found that IIF is a function, not a special form, and therefore the if-true and if-false parts get evaluated even when they're discarded.
So no - arguing against the fairly clueless (or poorly-expressed) comment about the IIF "operator", it would have been better as a bunch of IF statements.
And if I were doing it in LISP or some other functional language (Python, ML, JavaScript, etc), I'd have broken it up into subfunctions and let them document themselves...
Admin
wait.. javascript is considered a functional language? I thought it was just a normal procedural language. Then again I havn't really studied it a whole lot.
Admin
Javascript is quite an amazing language, closer to "real" languages like Python and LISP than to the pseudo-assemblers like C and C++ or the text-processing scripting languages like Perl. Unfortunately, it was so badly implemented that you never get to see a tenth of its theoretical power. Pity.
Admin
(But you're right - it's not really a functional language. I just threw that in to see if anyone was watching...)
Admin
If this were part of some gargantuan report or batch update, it ought to be implemented in something other than Access.
Admin
Come on, why are you all trying to make this CLEARER?
Let's see what it must have looked originally:
IIf(Format(Now(),"yyyy") + 0 > Format([sol_date_reqd],"yyyy") + 0,-1,IIf(Format(Now(),"yyyy") + 0 < Format([sol_date_reqd],"yyyy") + 0,IIf(Format([SOL_DATE_REQD],"ww",1,1) + 0 > IIf(Format(Now(),"ww",1,1) + 10 > 52,Format(Now(),"ww",1,1) - 42,Format(Now(),"ww",1,1) + 10,IIf(Format(Now(),"ww",1,1) + 10 > 52,Format(Now(),"ww",1,1) - 42,Format(Now(),"ww",1,1) + 10),Format([SOL_DATE_REQD],"ww",1,1) + 0),IIf(Format([sol_date_reqd],"ww",1,1) + 0 < Format(Now(),"ww",1,1) + 0,-1,IIf(Format([sol_date_reqd],"ww",1,1) + 0 > Format(Now(),"ww",1,1) + 10,Format(Now(),"ww",1,1) + 10,IIf(Format([sol_date_reqd],"ww",1,1) + 0 > 52,1,Format([sol_date_reqd],"ww",1,1) + 0)))))
Ah, now THAT'S a real WTF :)
"Um, I think there is a problem with a formula in this report. Can you check them out for me?"
Admin
A couple of good posts, especially Rikkus who done a good job of figuring it out.
One of our customers had paid many thousands of pounds to have this written and it was the "developers" choice to use Access. Which is hilarious when you consider that our software is all humming away on a HUGE MSSQL Server in their computer room and that [SOL_DATE_REQD] column is from a table that is copied into Access so this thing can process it...
Anyway, the thing stopped working around about the start of the year and they couldn't work out what was wrong, so in the end they asked my company if we could have a quick look. The experience was a realt WTF! (shouted). Having dug out some online Access manuals, the problem was that the "programmer" had used a Format for weeks ("ww",1,1) that only worked for 2004 - My understanding is that it should have been "ww",1,2 (I think).
Apparently, the guy that wrote it has changed career in the last year and now owns a pub (bar).
Says it all.
Admin
If this code was being used as an expression, other than the use of Format instead of DatePart, + 0 instead of CInt and manual modulo instead of the mod operator, I don't think it's too bad.
If I could make an educated guess I would say that the requirements are:Admin
The single line formatting is so that when this is ported to linux, the ms access parser doesn't get confused by the line endings. Simple enough once you know the reasoning behind it, no?
Admin
<FONT style="BACKGROUND-COLOR: #efefef">Do you know the spec? Maybe he was trying to build a LISP-Interpreter in Access...</FONT>
Admin
I am sitting here laughing reading these posts...I love it how people try to defend Access as a legitimate DB for the corporate environment...or how Javascript is a real programming language...you guys crack me up.
Admin
There's nothing wrong with JavaScript, especially compared to abominations like Basic and The Quick-And-Dirty PDP Assembler That Men Call "C". Its only really flaws are:
: Bat :
Admin
Admin
You know, somehow I thought this was supposed to be a place to review stupid code and comment ON THE CODE, not pick fights about "real" programming languages. In the world that I have had to work in, I all to often have to hold my nose to do the work because I am saddled with old systems and not given the time to redo things "right". As I read in a book "you don't send a regiment to squash a fly." I have even heard "real" programmers, you know the ones who work in C & Assembler, say that VB makes sense for some things. So if you don't have anything useful to contribute ABOUT THE CODE, shut up.
Admin
Isn't this post a bit hypocritcal? Part of what makes reading these threads fun is the distance elimination contests that always seem to follow..[:D]
Admin
I think I know why it was one line. It was a property of a form or something like that. It wasn't even entered in the code behind module.