• (disco)

    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?

  • (disco)

    Even without the extra variables, there’s still some redundancy:

    DateTime now = DateTime.Now;
    DateTime nowPlus30Days = now.AddDays(30.0);
    DateTime endTime = (DateTime) item["End Time"];
    DateTime startTime = (DateTime) item["Start Time"];
    if (endTime >= now) {
       if ((endTime >= now) && (startTime <= nowPlus30Days)) {
          item["DisplayThis"] = "YES";
          item.Update();
       } else {
          item["DisplayThis"] = "NO";
          item.Update();
       }
    } else if (endTime < now) {
      item["DisplayThis"] = "NO";
      item.Update();
    }
    

    I hope there’s a built-in feature in Sharepoint to do this...

  • (disco)

    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.

  • (disco) in reply to VinDuv

    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:

    var now = DateTime.Now;
    var nowPlus30Days = now.AddDays(30);
    var endTime = (DateTime) item["End Time"];
    var startTime = (DateTime) item["Start Time"];
    item["DisplayThis"] = endTime >= now && startTime <= nowPlus30Days ? "YES" : "NO";
    item.Update();
    

    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.

  • (disco) in reply to VinDuv
    VinDuv:
    I hope there’s a built-in feature in Sharepoint to do this

    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.

  • (disco) in reply to RaceProUK
    RaceProUK:
    And of course the syntax highlighter is broken

    Try java rather than csharp, since the latter isn't a thing at the moment so the highlighter is clearly guessing wrong (it picked sql.)

  • (disco) in reply to RaceProUK
    var now = DateTime.Now;
    var nowPlus30Days = now.AddDays(30);
    var endTime = (DateTime) item["End Time"];
    var startTime = (DateTime) item["Start Time"];
    item["DisplayThis"] = endTime >= now && startTime <= nowPlus30Days ? "YES" : "NO";
    item.Update();
    

    cs

  • (disco) in reply to PJH
    PJH:
    (it picked sql.)

    :wtf: Why SQL? Why highlight it like this?

    Luhmann:
    He's looping through items in a SharePoint list and setting/updating the value of the field DisplayThis to YES or NO.
    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.
  • (disco) in reply to Zowayix

    Well, it's seems a bit like a backwards version of http://en.wikipedia.org/wiki/Static_single_assignment_form

  • (disco) in reply to PJH
    PJH:
    it picked `sql`
    :wtf: May as well have guessed Martian.
    Buddy:
    cs
    Ah; fixed :smile_cat: <!-- Emoji'd by MobileEmoji 0.2.0-->
  • (disco)

    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.

  • (disco) in reply to Zowayix

    It probably helps minimize race condit--sorry, I just threw up everywhere.

  • (disco) in reply to VinDuv
    VinDuv:
    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.

    No he isn't:

    item["DisplayThis"] = "NO"; item.Update();

    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:

  • (disco)

    I kept reading SPSite as SPite.

  • (disco)
    kupfernigk:
    My guess is that this was written by a beginning coder

    Probably could have left it at that.

  • (disco) in reply to RaceProUK
    RaceProUK:
    May as well have guessed Martian.

    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)

  • (disco) in reply to chrullrich

    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.

  • (disco) in reply to ufmace
    ufmace:
    Anyone who's ever toyed with decompilers knows that they tend to create a bunch of extra, badly-named local variables.

    Which is why those variables aren't the WTF. That the source was apparently never made available, OTOH…

  • (disco) in reply to dkf
    dkf:
    That the source was apparently never made available, OTOH…
    Who says it wasn't in the printouts from the 1990s that have gone to paper recycling a decade ago, together with the (paper) files where to find which source?

    Which would be a WTF on the next level, of course ...

Leave a comment on “Variables Everywhere, But Not a Stop to Think”

Log In or post as a guest

Replying to comment #:

« Return to Article