The Weird and The Wonderful

The Weird and The Wonderful forum is a place to post Coding Horrors,
Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid
workarounds and developers just not quite getting it. And then somedays we come across - or write -
the truly sublime.

Post your Best, your worst, and your most interesting. But please - no
programming questions . This forum is purely for amusement and discussions on code snippets. All
actual programming questions will be removed.

Did you know you could do that? I didn't - I knew you could use unicode identifiers (though I never see them in real code), but this is a whole other level of madness.

Obviously that variable is being used but is uninitialized. Try to guess what the compile error will be.
It's not "Use of unassigned local variable '\u0066\u006F\u006F'".

At least it is consistent though, it seems that identifiers written in that style are considered to be identical to the decoded version, so you can mix it with simplify writing it down, and it shows up in intellisense in decoded form and so on.

It gets better. int is a keyword, so it's blue and you can't use it as a name for a local variable except with the @-prefix. So, this works:

int \u0069\u006E\u0074 = 0;
@int++;

That second line can be typed with intellisense auto-completion! That clever bastard knows about the variable called "int" and knows it had better put the @-prefix in front too, just typing "i" calls it up in the pop-up menu. On the other hand, the tool tip for the "int" entry also shows "(local variable) int int", but this is an entry with the value type icon. (this was all in VS2010, it may have changed since then)

In total, I'm not sure whether to feel impressed or disgusted, or a bit of both.

I just found and fixed this in a half-dozen places whilst reviewing event logs for an Azure web app. TBF, this web app is for a strictly M-F organization, so there should be no activity at all on a Sunday...but it does seem to be happening from time to time.

btw, yes the datetime variable is a utc tz and dst adjusted datetime for the client. This code was basically just for display. I'm sure there are better ways to do it, but i'm not asking.

The problem happens when the myCurrentDate variable represents a Sunday where myCurrentDate.DayOfWeek returns a 0. The WeekdayName function expects the first parameter to be between 1 and 7...0 throws an exception.

Good find by the hackers, just reading the code made me really cringe, mainly because I'm nowhere near awake enough to parse it correctly. Whether it's a gross missnaming or the devs not checking what isValidURL() actually validates one can be certain oversights were made.

I'm in the middle of refactoring some css to make it clear and this article is yet another validation to striving to name things to the best of ones ability. My issue is naturally trivial in comparison and there is zero possibility of failing in such an impactful way, but clear code speaks for itself.

After finding this ultra-cool Bootstrap `DateTimePicker`, I thought I could simply select all my date-pickers by class, and apply the relevant code for the `DateTimePicker`, and I’d have elegant and working date-time pickers all over.

That was during that usual “honeymoon” period when you’ve just found a really cool hammer and can only see nails. That period passes quite quickly and then we’re left to deal with little niggly wrinkles to iron out on your new widget.

The first and biggest is that MVC “has already” turned one of my date-time inputs into a built-in browser native date picker. On Edge and Chrome the built-in picker is usable, but not good UX and somewhat unintuitive. I don’t know how other browsers present date and time pickers. If a model property is of `DateTime`, MVC scaffolds an input with type `datetime-local`, and lets the browser deal with the rest.

The code to initialize the DateTimePicker is normally simple, just call on your date-time input, like this:

$(".date-picker").datetimepicker();

Now when I did that, something weird happened. When I clicked any date-picker (input with class `date-picker`), I’d see two date-pickers: My new fancy one in the background, and overlaid on top of that, the browser date-picker – in my case Edge.

I have to first make the input a normal text input, and then the fancy DateTimePicker, for things to work as wanted, with the 3rd party date-picker in charge:

Now I have one last “little” problem. When I click on one of my date-picklers, I get a history dropdown of recently used dates, but I suspect it is the browser’s date-picker doing this, because it drops down over my date-picker rendering it useless. Fortunately, a second click shows my date-picker without the dropdown.

"'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself."
—Aleister Crowley