- 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
So the for / switch paradigm but done badly.
Admin
Slight nitpick, the QueryString struct is part of ASP.NET, not normal .NET. In regular .NET you can either roll your own query building or you can use HttpUtility.ParseQueryString(string.Empty) to get an instance of the private HttpQSCollection class that overrides NameValueCollection with a ToString() that will build the query string.
Admin
yes, let's bash VBA once again, that's the real WTF. So what does a logical OR do? it takes two booleans (a bitfield of 1 bit) and does a bitwise OR. So, OR is always a bitwise OR in VBA, you just have to interpret the results correctly. As always: garbage in is foul ooze out.
Admin
So many programmers enjoy reinventing the wheel as an oblong triangle and just rolling with it.
Admin
Where's the part that checks whether
i
is0
so it can use?
before the keyword instead of&
?Admin
In most other programming languages, the logical or will not evaluate the second clause if the first one is already true (that's what's called short-circuiting). It allows to do stuff like
if( someClassInstancePtr != NULL or someClassInstancePtr->someMember ... )
Admin
Sure, but VB has history and the maintainers have a long history of making sure that everything ever written continues to work. So, since "Or" historically didn't short-circuit (from like the dinosaur days), they instead added a new keyword. Your complaint would be reasonable for a language invented in the past 20 years, but not for one that had a lot of existing code in 1990.
Admin
Nitpick. This isn't VB6 or VBA. It's VB.NET, which is its own thing, and only vaguely compatible with the other two.
Admin
There might be a reason they did it this way with integer iteration: it preserves the order of the key value pairs. Usually the order doesn't matter, but they may want to preserve it for user readability or search engine/ analytics reasons.
Also, the lack of "?" in the beginning means the query string already has some other parameters.
The only WTF is that they have an exclusion check of one key, and inside of that if, they have an inclusion check of the keys they care about; the outside if isn't needed.
Maybe the needed keys could have been put into a static readonly FrozenDictionary instance, for performance reasons, but that would be a micro optimization which would need to be tested and proven - i don't know if it would improve the performance.
Addendum 2024-10-23 11:40: Also, the useless outside if has a useless ToString call, and calls Equals instead of using == operator, which is inconsistent with the rest of the code snippet; very minor WTFs. Overall, sorry but this article falls short.
Addendum 2024-10-23 11:42: Correction, the outside if uses the <> operator, which is inconsistent with the Equals method calls elsewhere, but the point still stands - it's an inconsistency.
Admin
"When processing HTTP requests, you frequently need to check the parameters which were sent along with that request." What part of the sentence does "that request" refer to? You mean those requests, or each request, or could say an HTTP request at the start, but this is really silly. For a site making fun of bad coding, fencepost errors, mismatched types...
Admin
and
C has done short-circuit logical evaluation ever since the beginning, you know, more than 50 years ago, so that "past 20 years"(1) could easily be "past 40 years" without even raising either a sweat or an eyebrow.
(1) Heck "in the past 20 years" excludes languages invented in the 90s, or in, for example, 2000.
Admin
A reasonable algorithm you might say except that it doesn't preserve order as already noted (of course, if the collection is a
NameValueCollection
order is already not preserved) but also there is nothing in the HTTP URL standard that says keys in a query string must be unique. How the collection deals with this is dependent on the collection implementation, but I believe in this case you would get a comma separated list of all the values for the key.Admin
I didn't say that no language has had short-circuiting in the past 20 years, I said that in the past 20 years, a language designer would be oblivious to not make or short circuit by default. In the 80's and 90's, language conventions weren't so well established regardless of how old C is.
Admin
Notpick may be true, but Microsoft though very hard about getting people from VB to VB.Net and wanted to make the code work as is as much as possible. I taught a class when ASP.Net was first coming out and we gave the students a list of 10 things to do in asp pages so that they can be upgraded to ASP.Net by simply changing the file extension.
Since C# didn't exist before then, the only code-free upgrade path was Classic ASP using VBScript to ASP.Net using VB.Net. They very much thought about making that use case as simple as possible.
Admin
At least the equivalent of OrElse in early Microsoft BASIC would have obligated the programmer to format somewhat consistently.
Admin
Agree that VB.Net non-shortcircuiting Or keyword was entirely about backwards compatibility = ease of upgrade from VB6. Those of us who where there and did that certainly appreciated how well the upgrade path worked.
Nobody has yet mentioned this aspect of the system tht this code was taken from. Here's Remy's list of QS keys:
Do we notice any consistency whatsoever in how they are cased or named? No we do not. Morons.
Admin
"lot of existing code in 1990" Wow, we finally know where all these programmers with "10 years experience" in a 3-year old language come from. (VB was first released in 1991. Not VB.Net or even VB6, but VB1.)
And before that, it wasn't only C, as Steve_The_Cynic mentioned. Pascal originally had full evaluation, but Turbo/Borland Pascal, popular in the 1980s, had an option for short-circuiting (which was on by default and left on by most programmers). So the issue was well understood by then and when you say, "language conventions weren't so well established", that's certainly not true on this point in the 1990s (sounds more like the 1960s to me).
Admin
The parameters' case doesn't really matter, because the Params thing (NameValueCollection) is case insensitive when comparing key names. They probably just grabbed the names as they appeared on the URL so that searching for wherever they came from would be easier.
Admin
Hmm, or(else)...maybe they actually need these checks to be case sensitive, and because the Request.Params is a case-insensitive NameValueCollection they figuered that this was the only way to do it?