- 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
Frist of the fristest! By a new approach this time!
Admin
Cc @PJH: So @PaulaBean creates a new topic. And makes it invisible. Making it invisible creates a post. Which is visible in @PaulaBean's profile. And contains a direct link to the invisible topic...
Invisible topics are a joke. They are broken by design, and fixing them will need fiddling in many places.
Admin
Conglaturation! This topic is happy end.
Filed under: I was here an hour ago but didn't post.
Admin
Admin
Always winning is boring. I wake up really early because I take the train to work. I should have liked @PaulaBean's post, though, just to have evidence.
Admin
I don't know, is this topic visible yet? I cannot see it being displayed in topic list.
Admin
hmm. Sure that was sorted previously...
Admin
Admin
Admin
Oh, and the next bug with "invisible topics" is: as soon as anyone posts a reply to an invisible topic, that "reply" will be visible in the "replies" list of the user creating the invisible topic. Also making it more or less public.
Admin
I've heard many claims for the 51st state of the USA, including "Puerto Rico", but never have "Americas", "Europe", or "Federal" featured among them. (Nor the Canadian provinces, come to that). I'm half surprised not to see an entry for Guantánamo Bay.
Admin
Where are the remaining 24 posts?
Admin
Ok, so @aliceif can quote obscure game references at a higher rate than me, and @Arantor can match me in Red Dwarf quotes at the very least...
Hey, @PJH, if we make an "uber nerd" contest, could you make a badge for the winner? :stuck_out_tongue:
Admin
Someone found @PaulaBean's meds and she's taking them again.
I have one already. You are allowed more than one snowflake you know...
Admin
UNICODE anyone?
Admin
Actually, sounds like you're always losing.
Admin
What sort of state names do you use?
Admin
Who mixes state names with country names? Why is there a continent in there too?
Admin
Admin
Not only
strcmp
is probably already optimized to compare multiple bytes simultaneously, this “optimization” may cause the program to crash and burn if it run on an architecture requiring properly aligned reads.This code sample also screams “hashtable” (or at least
bsearch
)Admin
FTFY
Admin
Just me who's amused by the response to @PJH raising this on meta?
https://meta.discourse.org/t/links-to-invisible-topics-are-visible-in-a-users-activity-history/19080/2
filed under: Bug trackers tend to have a search
Admin
Admin
Admin
The point is that for unicode, casting to a short will only compare on the first letter!
Admin
Depends on the encoding, no? Anyways, the function takes
const char *StAbbr
, notconst wchar_t *StAbbr
Admin
Admin
The compiler might insert padding between the strings to provide multi-byte alignment anyway, and this code's author probably has a pretty high degree of certainty that the code will only run on x86 and maybe ARM.
The overhead of calling strcmp() -- or just figuring out alignment so it can decide what implementation to use -- would be substantial compared to the type-punning comparison in this code. A perfect hash function (i.e. tailored for this particular array's content, so that there are no collisions for strings in the search domain) would probably be the only algorithm that is measurably faster than the provided code: Binary search would have worse cache locality, and bsearch() in particular adds huge function call overhead for such a simple search.
If I had to put money on this, I'd be most comfortable saying that you could not reliably measure a difference in execution time between this code and a binary search, followed by this code being faster than binary search, and least comfortable claiming that binary search would be faster. Any of those would be somewhat improved by making the StAbbrs[] array an array of character arrays, rather than an array of pointers to character arrays -- that might be a bigger difference than linear vs binary search.
Admin
Here's your post reproduced (from raw) prior to memory hole action:
That is understood. But the link to the invisible topic *is in the public domain*, i.e. the topic creator's post history, and thus can be seen (and used) by anyone coming across the topic creator's post history.If that is "by design", perhaps it would be less misleading if the text were changed from "This topic is now invisible" to "This topic does now not appear in the topic list".
Admin
https://meta.discourse.org/t/links-to-invisible-topics-are-visible-in-a-users-activity-history/19080/2
"Would swear it is a duplicate but I can't find it."
I see their "bug tracker" is working well. Any bug tracker that relies on Discourse search is doomed from the get-go.
Admin
Yet another misguided optimization. And you thought you were being OT!
Admin
Admin
Just so I know what I'm being accused of, is that On or Off Topic?
Admin
Admin
Or did googlebot find it for him?
Admin
I'm not saying.
Admin
Stop undermining my Discourse dissing.
Admin
Admin
Not for searching Discourse. If he's insane enough to cram Discourse into a bug-tracker dogfood can, no way he's not using his own search.
Admin
AA, AE, etc., (Americas and Europe) are APO/FPO codes - Army Post Office and Fleet Post Office. They're abbreviations used within the US postal service for delivery to US military addresses overseas.
Admin
Ah, but Jeff has an explanation: "It depends how you define invisible, in this case it means 'invisible from topic lists'."
Discoverability. You just have to discover that invisible means invisible from topic lists.
Admin
Misleading labels (to anyone not smart enough to discover Jeff's cleverness) are kind of a Disco-trademark.
Admin
I'm pretty sure this topic is going to stay hidden. The Discourse topic is visible, though.
Admin
And the alignment-padding for the strings had better be there for it to work on the align-checking ARM architecture...
(For real fun, run almost any of the code we see on TDWTF on an x86 of the 486+ variety when some maniac has set the AC bit...)
Admin
If doing a linear search on an ordered list with only 70 or so items is the slowest part of this application, then she is a goddess among coders, and deserves not your scorn.
Never guess where to optimize.
Admin
If you wanted a fast, well-defined way to do the compare in this linear search...
Admin
If you really want speed and don't care about space, you want to encode the full names as pointers in a two-level trie of 256 elements each. Since the trie encodes the case of "." and all the invalid abbreviations as well, the only special case you need to check is whether or not a NULL pointer is passed in for
StAbbr
.Sure it takes 256 KB (assuming 32-bit pointers) plus the actual string storage, but I defy you to find a faster implementation.
Admin
About 10 years ago, the province of Newfoundland was renamed to Newfoundland and Labrador. The abbr. was changed from NF to NL. I was in the middle of a big (at least for me) database project when this happened, so I had to change the name and abbreviation, which I had used as a primary key for the "Province" table. I just had to make one change and let the UPDATE relationships convert all those NF codes to NL. I am actually glad I put the province/state information in the database, rather than hard-coding it.
I also noticed that code for Newfoundland in the look up is still NF, even though that changed 10 years ago. This could cause bad times for your mail getting to its destination in St. John, NL. I think TRWTF is not updating your list of constants when circumstances change. That is why they are there; so you only have to update them in one place, but you still have to update them.
Admin
Now that Nagesh is here, it will get open soon.
Admin
For start, this is so much easier in Python.
allIndia = {'MA': 'Maharashtra', 'AP': 'Andhra Pradesh', 'MP': 'Madhya Pradesh'} print allIndia['AP']