- 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
Could be I'm missing something, but if 'o' is null, wouldn't
return (ConcurrentQueue<AppointmentCuttOff>)ViewState["lstAppointmentCuttOff"]
throw an exception?
Admin
The real wtf is the coder that wants to cast null into somethiing else. Compressing the line into "Cleverness" makes the best WTF. We all want to shine with a glorious line, yet, this will crash just in time.
Admin
Gosh. Computer programmer is dyslexic. Hold the front page.
Admin
return (ConcurrentQueue<AppointmentCuttOff>)ViewState["lstAppointmentCuttOff"] causes the WTF when it crashes on a Null reference.
Admin
Re: Hungarian notation.
It's wrong on two levels. It's trying to be "Systems" Hungarian (where the wart tells you the type), which is only just barely HN at all, and it fails at being SHN because it's got the wrong wart on it.
The original HN, "Applications" HN, was a workaround for the shortcomings of C"s type system, where "flavours" of data cannot be easily indicated. Is this
unsigned
a count, an indication of size, what? Is thischar *
a pointer to a single character or to a NUL-terminated string? If it's a NUL-terminated string, does it contain raw text? HTML-encoded text? Something else?It's mostly unnecessary now, except that there is a growing number of languages where variables don't have explicit types, and it helps a lot to indicate what kind of data your variable is supposed to hold.
Also:
Should be:
The thing that there is is a queue.
Admin
This does not seem that bad to me. In some languages, typecasting null values will lead to a NPE. If in doubt, I'd probably do the same.
Admin
No, in .NET you can perform casting on a null value.
Admin
Assuming this is C#, casting null is perfectly acceptable as long as the target type is nullable. Obviously it must be nullable or we couldn't explicitly return null either.
Admin
Without the "if null" try having your average developer set a breakpoint on the the code if the element in viewstate is null, but not break if it contains something...
Since we do not see the call to the setter, we can not know anything about the instance(s) being used and if they are potentially shared across threads.
Admin
If they managed to access ViewState across threads, then that code would be the real star of this WTF. ViewState only exists for about half of the ASP.Net request pipeline, which is handled on a single thread and typically lives only a few milliseconds.
Admin
I have no idea what IDE you're using but all three I use have something called conditional breakpoints. They usually slow down the debugging process by a non negligible amount but that's something else.
Admin
The idea of anything in ViewState (conceptually objects that get sometimes serialized to the client or to a database) being used for concurrency control is both laughable and worrying. That this works at all in this application…
Admin
Until this was pointed out I assumed the variable was called "1stAppointmentCutoff" (as in "first").
Either way, this is a very mild WTF compared to what else we've seen.
Admin
To really nitpick it, you don't even need a block there. Just "get => (ConcurrentQueue<AppointmentCuttOff>)ViewState["lstAppointmentCuttOff"];"
Admin
Am I the only one to see this? I kept reading "lst" as "first", thinking that initial character was the digit 1 - until I remembered that you can't begin a variable name with a numeral. So it's really a lowercase L - which means it's an abbreviation for "last", not "first".
Hungarian notation has its usual problems, and using visually similar characters just makes it worse.
Admin
With all the talk of bad variable naming and no one is going to point out how terrible it is to have a variable named 'o'?
Admin
Admin
That is called lexical distance. Certain characters should be avoided in variable names if it can lead to confusion.
Admin
I'm just super-impressed our developer managed to spell "cutt" consistently between the typename and the viewstate keyname. I'd much sooner have expected one to be "Cutoff" and the other other "Cuttoff".
As to the ConcurrentQueue, everybody knows ASP.Net is multi-threaded to handle all those pages being "simultaneously" served to different users. So of course we need to use a concurrent data structure for our internal queue of cut(t)offs.
Admin
Another interpretation of "CuttOff" could have been "cut to FF" - "CutToFf" or "cutToFF", BeCause messingWith uPper and loWer casE 1s Fun.
Admin
Maybe the developer is a Kasabian fan.
Admin
In C#, the ConcurrentDictionary has AddOrUpdate as a method, but the standard Dictionary does not. I would be lying if I didn't say laziness has caused me to use a ConcurrentDictionary in single-threaded usage.
Admin
What I find strange is that if you put a condition on a breakpoint, it slows everything down a lot. But if you put an if (condition) // something to put a breakpoint on, it doesn't slow down at all. I guess the way it accesses the variables for evaluating the condition are completely different in each case.
Admin
That's basically it. Here's how I think of it:
In theory, in an interpreted language, the debugger could inform the interpreter of the conditional breakpoint, and the interpreter could treat the condition check as "injected" code and execute it as part of the main execution context, and only switch contexts if required. I am not sure if any interpreted language debugging environments do this, but it should result in no slowdown during execution (at the cost of a tiny overhead during the interpretation step).
Admin
Is this really a big evil or simply harmless debug code that wasn't removed?
As others have said, conditional breakpoints are expensive--there isn't really such a thing as a conditional breakpoint, the breakpoint always fires (which is an expensive operation) then the environment checks the conditional before presenting it to the user.
Add to this the fact that C# (and I think any other managed language) doesn't support the hardware-assisted breakpoints that can make certain types of conditionals fast. (I used to love break-on-write. Now you have to make something a property that isn't automatic to do this.)
Admin
Given the amount of discussion it has caused here, I wouldn't call it harmless debug code, but I wouldn't call it a big evil either.
And yeah, hardware breakpoints (especially break-on-write) were good. They were about the only good thing about Turbo Debugger 386 back in the DOS days. It was glacially slow at actually switching control to the debugger when you did hit a breakpoint, while on the same PC, Turbo Debugger 286 would do it so fast you'd miss it if you blinked at that exact moment, but TD286 didn't support hardware breaks.
Admin
You often have 'hotspots' in your code where you need to place a bereakpoint often. I see no problem in making that part of the code a little easier to debug by placing a (somewhat) unnecessary breakpoint.
I am an oldschool developer that started when the c64 was hotstuff. These days, 'if' statements like the one in the article are basically free. I keep reminding myself of this fact when I wite code 'for clarity' (not for 'speed' or minimum CPU-cycles).
Yes Tom, the 'hard cast' will bring down C#. You can use the 'soft cast', which Remy prolly meant, but he sometimes makes mistakes, like he re-wrote (incorrectly) my submission a few weeks back.
Softcast.
return ViewState["lstAppointmentCuttOff"] as ConcurrentQueue<AppointmentCuttOff>
Admin
Jamie not difficult at all.....
This is not about ViewState being accessed by multiple threads, but rather an item in viewstate....
While this is normally the result of serialization/deserialization, that is not the only way...
ViewState["mykey"] = someobject
Two lines later (same thread same request
ViewState["mykey"].Operation()....
The original someobject could be being accessed by many threads..
FYI: this is not just theory, have seen it.
Admin
Are "CutOffs" something to do with this new-fangled transgender society we live in today?
Admin
C language is over my head
Admin
wow. this triggered an OLD memory: when i saw "1st" i read it as "LIST"...on a TRS80 computer, if you type "LLIST"it tries to PRINT the current program, and if you don't have a printer connected, TOTAL SYSTEM FREEZEUP. with no way to recover but a power-cycle. WTF?!