May 2004 - Posts
Reader Stefán Jökull Sigurðarson, whose middle name means Glacier (now, how awesome is that!), sent along this chunk of C-code, straight from Iceland.
At first, this block of code made absolutely no sense to me. What can I say? My Icelandic is a bit rusty. But Stefán was nice enough to tell me that "faersla" should really be "færsla" (as C doesn’t allow international characters), which translates to "transaction or a part of a collection". So I hope that clears it up for the rest of you.
While we’re on the subject of C, I’m a firm believer that the single greatest thing to come from C is the International Obfuscated C Code Contest, where you can get a Missle Command Game whose source code looks like a "danger – radiation" symbol or a Flight Simulator shaped like an airplane. But there still is a fine line between writing code for an obfuscation contest and writing code for a business application. And although it may seem like a good idea at the time to use "v7" instead of "IterationHitCount," programmers like myself and Stefán would really appreciate the latter.
First and foremost, thanks for the WTF submissions! Please keep 'em coming. They don't have to be code snippets or diagrams, just something technical-related that made you say or think What the F--! And now that I think about it, I'd love to see some crazy Boss Emails and Memos. I had a trove of them saved from the last company I was at, but lost them all. So let's see yours! Just use the Contact Form, and feel free to include a website to link back to.
With that out of the way ... I give you this.
Three points for checking to make sure that the built-in New() construct actually created an instance. But, WTF was the coder thinking by not putting in “If Not TypeOf objNews Is clsNewsObject” code? What happens if the type of objNews changed after checking if it was Nothing?
Cross-Posted From TheDailyWTF.com.
I received some great ideas for new features and thought I'd incorporate them in a new version. Here's what's new:
- Tab/linebreak escape choices for C#
- Verbatim Literals (optional line spanning) for C#
- Paste As StringBuilder (with optional AppendFormat usage)
- Auto Formatting After Paste (optional)
- Ability to hide Paste As options on the context menu
- Add-In Commands for adding to custom menus and keyboard shortcuts
SmartPaster is now maintained at Inedo: http://inedo.com/Downloads/SmartPaster.aspx
I'm sure we've all heard, over and over, that inline SQL is generally a bad practice, and that we should use Stored Procedures when possible. But let's be realistic for a minute. Who wants to write a stupid stored procedure for every stupid little simple query needed. Like, for example, this query from an actual, production, report-producin' web page:
See how easy that was? For cryin' out loud, do we really need to write a Stored Procedure for something like that? It's only 156 lines or so. Stored Procedurers are for suckers!
Crossposted from TheDailyWTF.com. Got a WTF you'd like to share? Just fill out the Contact form and send it in!
As a certified Überprogrammer, I get quite annoyed with inexperienced maintenance programmers looking at my code and asking questions that any coder with a clue would instinctually know. Take for example this function:
Perfectly clear to me, and I'm sure every other Überprogrammer out there. But the inexperienced n00bs ... they have to waste my time with questions like WTF does Batman() do? or Does it MANage BATch processes? or It prints out the MANual for the Business Aquisition Team, right? or even Does it invoke Silhouette_Spotlight() to create an instance of The_Dark_Knight?
C'mon people. As if it isn't clearly obvious. BatMan() returns False or a DocumentID, depending on whether or not a record with strFileName exists in the database. Jeeze, what's next, asking what JudyGarland() does?
Cross-posted to TheDailyWTF.com. If you've got anything technical-realted that makes you shake your head and say “WTF“ -- send it on in using the Contact Form! I'll cross post for a while.
Yesterday, we learned that sarcasm is officially dead. Oy. So today, let me disclaim by saying that I am not actually advocating this as a good practice. Just trying to toss in a little humor. And also, let me applogize already for having a weak example today, been too busy to dig for some real gems. And with out further ado, your Daily Cup of WTF:
Now I for one can't seem to fathom why the folks at Microsoft that engineered the framework did not think to include this as a core function. Honestly, how else are you supposed to know if an expression is true or false. See how ambiguous and confusing this is:
If myDocument.IsActive Then DoStuff()
I'm completely lost. WTF does that line of code do? Now lets see how it looks when we employ best practices and the the IsTrue function:
If IsTrue( objInstanceOfDocument.blnDocumentPropertyIsActive ) Then fn_DoStuff()
Some more ado ... Fellow blogger brady gaster suggested I start a separate blog where we all submit ideas. I did the first step, and registered TheDailyWTF.com. Any ideas on a good way to configure .TEXT for it?
I don't know about you guys (and gals), but I often find myself pasting large string literals (SQL queries or dialogs) into code. It started to become quite a hassle to fire up EditPlus, paste, replace line breaks with quote characters, copy, and paste it into Visual Studio. So, I put together an add-in to help with this task and called it Smart Paster.
It works for both VB and C#, and will wordwrap if you'd like it to. Not sure if you'll find it useful, but it's yours for the taking, along with the source code (which is installed in it's Program Files folder). If you'd like, you can grab it here: <removed, get the newer version instead, see below>
I'd really appreciate some feedback if you find it useful, or if can think of any other features to add. Oh, and if there is already one of these out there, sorry about that. I was more in a Write-An-Add-In mood than a Search-For-An-Add-In mood.
OMISSION: I forgot to give props to Jason Mauss for suggesting the Paste As Region option. Thanks Jason!
EDIT: Version 1.1 is avaiable here: http://weblogs.asp.net/alex_papadimoulis/archive/2004/05/25/Smart-Paster-1.1-Add_2D00_In-_2D00_-StringBuilder-and-Better-C_2300_-Handling.aspx
I suspect this one may be a bit less common than tblState ...
Used on an in-production, web-based staff directory of 600 or so, the idea behind tblStaffDirectory is expandability. By putting everything in one table, we don't need to worry about ever having to modify the database structure. Data in this table is stored in the following manner:
Creative, eh? While queries to retrieve the data in a useful manner may be a bit complicated (120 lines and 38 JOINS to get the equivilant of “SELECT * FROM Staff“), it's a heck of a lot better than the alternative (changing the table structures). Besides, I don't think users mind waiting 5-10 seconds for the page to load. I challenge anyone to come up with a better implementation than this.
Naturally, all tables referencing tblState link with a column “intStateID”
Now, I don't know about you, I think you'd be a fool to implement this any other way. Think about it, what happens if a state descides to change it's name and abbreviation ... and the database you moved to when this happens does support update triggers? Can you really afford to take that risk? I didn't think so!
An actual table from a production database. The client code uses it (I believe) by opening a recordset to it and extracting the field names. What's puzzling is that the system isn't a database schema tool, or anything like that. Just a plain old boring information system.
What I still can't figure out ... why are the columns not named intInt, and dtmDatetime :-)?