- 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
I do tend to like utility methods like WriteToFile that include a boolean parameter for creating the file if it doesn't exist.
Admin
Admin
Admin
Admin
Why, if C# looks exactly as Java, do method names start with upper-case? Is this some MS way of trying to be "special"? This is just retarded.
Admin
C# is proper, Java is not.
Admin
Back in my days, we called these Pokemon.
Admin
TRWTF is that the WriteToFile() method is void -- so even if IsFileLocked() returns true, the caller has no way of knowing if what he wanted to write actually got written! A void method should always do what its name says it will do, or throw an exception on failure. Correcting this ironically leads to a funny bit of refactoring, since to throw an exception on a write failure would simply involve removing the IsFileLocked() call completely and allowing any exception to bubble up to the caller :-)
Admin
I think I did this, and even used the same source, when creating a small c# utility to copy a picture to a bunch of cheap android tablets I use as digital picture frames.
The process was I copy a picture to a certain directory, it's resized and uploaded using an FTP server on the tablets. I used a FilesystemWatcher on this directory, but it had the issue where it would be triggered right away when a picture was copied, even though the copy operation wasn't done. Try a file lock, if fails, try again in 2 seconds, if fails try again in 4 seconds, up to 10 tries.
Admin
No, chatboard trolls are the most annoying thing you'll ever find. Although you can make a pretty convincing argument that trolls are not really a lifeform, and they can always be safely ignored, you still have to step over the stinking mess they leave on the carpet. No, wait; that was cats.
Admin
Admin
Suppose most of the time everything works, but occasionally the file ain't there (as described in the stackoverflow link). That would be an exceptional situation - so I don't have too much problem with testing that way....
Then again, I;m a C programmer so this concept of Exceptions is still a bit too new for me ;)
Admin
Or you could try to handle specific exceptions.
http://msdn.microsoft.com/en-us/library/system.io.filenotfoundexception.aspx
Admin
This is usually to avoid "variable may not have been initialized" warnings.
The FileStream would be read while uninitialized in the finally otherwise.
Admin
All solutions are difficult. If they were easy, we wouldn't have any problems!
Admin
No, that came from spammers, or Akismet.
Admin
Admin
Admin
But if I remember correctly, C# has using blocks specifically for this reason.
Admin
No one commenting on TRWTF: File system access in the 'BusinessLogic' layer! SoC anyone?
Admin
Gotta love how some people can turn any thread on programming choices into a political rant.
Admin
Inception FTW:
Application of recursion to do arbitrary inception depth is left as an exercise to the reader. ;-)
Admin
@Medinoc: System.Io.File doesn't appear to have an Access member, so I'm not sure what you're thinking of. There doesn't seem to be any method to check whether a file is already in use. For that matter, I don't think there's any such method in the underlying Win32 API, short of using unsupported functions to enumerate all the handles in the system.
Admin
"A few months ago she was working long hours on a migration to a new codebase, so she made up the lost sleep on the weekends"
AJ needs to find another job that doesn't raep her weekends.
Admin
Admin
Hmm, that's not the impression I got. If that's what the writer meant, then I agree 100%. I could go back and re-read the article to see if I just read it too hastily the first time and mis-interpreted. But I don't care enough to make the effort.
Admin
We should try to balance that by going to political web sites and making posts about programming.
Admin
No, the MOST annoying this is people who constantly whine about children, the neighbors, their boss, and VB programmers.
Admin
TRWTF here is the writing. Among other awkwardly phrased sentences is the following gem:
"for a princely sum": This contributes heavily to the awkwardness because of the daisy-chained use of the word 'for' later in the sentence. Worse, we don't need this information. It adds nothing to the story and it isn't relevant to the WTF. I am guessing the implication was supposed to be that because the software was expensive it should have a certain quality. However, it misses its mark. In any case, we all already know better by virtue of being on this site.
"for the project": For what project? We can conclude that the writer means the code migration mentioned at the beginning of the article, but the writer is expecting the reader to do too much work. Like above, it isn't even necessary to include the information. It isn't relevant that the software was purchased for the migration. (It really isn't even relevant that AJ was working on the migration at all if she was doing a code review on something else.) Even if the writer feels it is necessary to include that information, the use of the word "migration" instead of "project" would have been much clearer.
"that corporate bought": Corporate bought AJ's performance of a code review? They bought the software that they also licensed? Unclear.
Rewritten: "The following Monday, AJ performed a code review of some newly-licensed software."
Beyond the awkward phrasing, the general flow of the article left a lot to be desired. Specifically the transitions between the family parts and the work parts were choppy. I would leave off the bit at the end about her returning home. It adds nothing.
Admin
Admin
Known as the WTF method of double-checked locking.
Admin
I do know of at least one situation in which the "double check" makes some sense.
In Java, "File.exists()" can sometimes return FALSE, even when the file does actually exist - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5003595
This is due to improper handling of stale NFS file handles. A second call to File.exists() will usually give the correct result.
Admin
TRIsFileLocked returns a boolean: True, False, FileNotFound
Admin
In a country whose government sometimes cares about reducing racism, a company sent its programmers to a training course to teach them that different races are equally deserving of respect. (And maybe that WTFs are WTFs because they're WTFs not because of the person's race? Nah, that would be asking too much.)
So, why did the company have to send its programmers to a training course on racial relations?
Well, of course, because one time a development manager was called out of a meeting, and when he returned to the meeting he explained: "I had to deal with a race condition" ... and an HR droid heard it.
Admin
Admin
Admin
Admin
Nope...
What's "correct" is trying to open it to see if it's locked. And that's debatable.
However, this example opens it to see if it's locked. Then closes it immediately. Then still ASSUMES it's not locked and opens it again for writing.
At any time, the OS could have descheduled that program and another program could be running that also had the same file queued for opening.