- 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
site.AllowUnsafeUpdates = true;
This is the the code equivalent of
// Here be dragons
. If you see this: run, don't walk.Filed under: I think this CodeSOD hides anything which is more than 30 days in the future?
Admin
Even without the extra variables, there’s still some redundancy:
I hope there’s a built-in feature in Sharepoint to do this...
Admin
I always like to find a plausible reason (if not excuse) for all WTFs, the more stupid they are the more fun that is, so...
Coding style standard where you are only allowed to refer to a variable once? Though that raises even more questions as to why such a standard would exist.
Admin
Even @VinDuv's rewrite is giving me an aneurysm. And it's WTF-factor is four orders of magnitude less than the original.
I have to rewrite it:
And even then, there's probably a better way to do it.
And of course the syntax highlighter is broken. I'd summon @discoursebot, but it won't respond here.
Admin
No. He's looping through items in a SharePoint list and setting/updating the value of the field DisplayThis to YES or NO. There are no OTB ways to do this automatically.
Admin
Try
java
rather thancsharp
, since the latter isn't a thing at the moment so the highlighter is clearly guessing wrong (it pickedsql
.)Admin
cs
Admin
:wtf: Why SQL? Why highlight it like this?
The point of this code is to only show events that will occur within 30 days. That sounds like something that could be configurable within SharePoint itself.Admin
Well, it's seems a bit like a backwards version of http://en.wikipedia.org/wiki/Static_single_assignment_form
Admin
Admin
So where's the WTF?
That code was decompiled. The "now" and "now + 30" variables might be real, because the author would not have wanted the meaning of "now" to change from iteration to iteration. The other seven were introduced by the compiler to hold values that were known to be constant over a single iteration, to avoid repeated evaluation of the "Start Time" and "End Time" fields.
Admin
It probably helps minimize race condit--sorry, I just threw up everywhere.
Admin
No he isn't:
Means he sets the value of column with the (silly) name of 'DisplayThis' to 'NO' for the current item.
If it was only about the view then yes it would be unnecessary. Following took me less then 5 minutes.
[image]Translation for my Dutch SharePoint interface: Filter where column Enddate is bigger or equal to [Today] AND column Begindate is smaller or equal [Today] + 30.
If the requirement was only 'display those records' then yes it is a gigantic overkill. Giving the code quality it might be safer to assume it's totally unnecessary. :grin:
Admin
I kept reading SPSite as SPite.
Admin
Probably could have left it at that.
Admin
I've searched for "martian programming language" and the most relevant results pointed to D (because developed at Digital Mars), and a language called "Mars"; but both would be too similar to any C flavored language to omit all syntax highlighting.
It might make sense to assume it was meant as one of the languages the Mars rovers' software gad been developed in.
Nevertheless, it would be really interesting to see a sample of a program written in a language developed from an independent IT culture.
Just for curiosity. (No pun intended)
Admin
Yup. Anyone who's ever toyed with decompilers knows that they tend to create a bunch of extra, badly-named local variables. The original code, Sharepoint, and not putting the original code in a repo somewhere and documenting where may all be WTFs, but this decompiled code doesn't tell us much.
Actually, I'm not even sure if any of the .NET decompilers/reflectors will produce ternary expressions. It may well be that the IL is always just if-elses, and it can't reasonably do anything but decompile them into if-elses, even if the original was a ternary expression.
Admin
Which is why those variables aren't the WTF. That the source was apparently never made available, OTOH…
Admin
Which would be a WTF on the next level, of course ...