- 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
TRWTF here is if FileName is the empty string, we carefully format that empty string into the error message.
Admin
I'm slightly tempted, but only slightly, to think this is joke code.
Admin
You might want to consider changing your name to Steve_The_Gullible
Admin
My guess is that the check was originally doing something else more complicated but later got trimmed away. I once ran into something similar in old code where a condition was basically like: condition && long terniary && even longer tern with multiple function calls && are you bloody serious mate? && yes, apparently you are && seriously even more terniaries and nested conditions and () and stuff && false. And it was all in one unformatted line with the false tacked onto the end where you'd newer see it.
The worst part was, it was my old code.
Admin
Hm. Code being in existence, looking busy, doing nothing. Oh wait, that was the HPC I once met.
Admin
It really is looking for the name of the file which it already has in FileName
Admin
Speaking of random questions here is one. A couple days back I was reading through the backlog of posts on this site and ran into a comment quoting some ancient computer scientist from back in my day complaining about C. It was basically something along the lines of "C is mallware. Assembly is good." But now I can't find that quote. And google gives me nothing.
So like does anyone know what I am talking about and can you help me find it?
Admin
I did say I was only slightly tempted. My experience of reality does speak strongly in favour of there being some history that might even once have been good reasons, maybe (but probably not), that led the code to be that.
Admin
Look more closely. It is looking at the Name property of the FileInfo that was constructed from FileName, but in doing so, it overwrote FileName with that Name property ...
Conclusion: it's just nonsense.
Admin
BTW, this code actually does something. The constructor for FileInfo takes a path, and the Name property returns the filename portion. If the path ends with a backslash, then the Name property will be an empty string and the exception will be thrown.
Admin
This is a variation of yesterday's "getStreet" method: string getFileName(string filename) { return filename; }
Admin
I'm slightly tempted, but only slightly, to think this is joke code. Nice Article, thanks Author.
For unique business ideas related articles please click on below link
Remy: LOL, bots are just trying to steal lines from other comments, like we wouldn't notice that.
Admin
_name (the backing field for Name is initialized with
So the code actually does do something (i.e. strip off path information)
Addendum 2021-06-03 08:32: Jamie was 100% right, I just missed that comment when I posted.
Admin
I'm a pro at this. I've looked at hundred of stupid code fragments that the rest of my team said "just delete it, it's useless". In the end, most of them actually do something that's hard to see and is often an important step in some convoluted process.
It's sad that in 2021, the majority of programmers still think that if code works, it's done. This results in code like today's submission. Enough code like this and debugging and enhancing become incredibly difficult.
Someone recently asked me about the effort to replace our ball-of-mud line of business software. I told them it would take thousands of hours just to figure out what it does, and that would have to be step #1 of any plan to replace it. No one likes that answer, so they usually respond with "well, we probably don't need all that anyways"... and they're almost always wrong.
Admin
Is it possible that the code continues on, checking existence and creating a file if it doesn't? If so, this is just a way to not create a file with an empty string for its name.
Probably not a great way to handle that scenario, but maybe they're trying to accomplish that?
Admin
Think I've seen that on here before, but usually it's posts that get tagged on days after we all got bored arguing over the WTF of the day.
Now where did I put that link to geunine cheep lewis vitong handbags on sale here legit site gauranteed?
Admin
The reason that "the majority of programmers still think that if code works, it's done" is because the majority of programmers don't have the time to make the code as maintainable as they should.
Admin
Hey carpenter, why did the old lady fall through the stairs you made?
"I didn't have the time to put all the nails in. Blame the general contractor that asked me to do it cheaper."
Admin
Well, let's consider four groups of programmers.
a) Grizzled veterans
b) Sprightly young things, fresh out of university
c) Incompetent imbeciles
d) Masters of the Universe
Group (d) might well have the time, but don't care. Group (c) shouldn't even be given the time, because they will only make things worse. Group (b) actually do have the time, and should be encouraged to use that time, but they're shit scared of losing their first job.
Leaving us with group (a). I will maintain, as a member of group (a), that other such programmers always have the time to make code more maintainable. Because if you're in group (a), you are more than likely the poor sod who has to maintain it.
There is of course an interesting discussion to be had around the concept of "maintainable code." In my small company, I can just about maintain the math guy's code. I can just about maintain the code of the two "domain specialists." But all three of them have wildly different notions of what "maintainable" means, so it involves a lot of cognitive dissonance.
But all four of us try. Because all four of us get hit when things go wrong.
Admin
One other thing? Manufacture the time out of thin air.
Maintain a set of problems/features you have fixed/developed, which happen to be far down the Kanban board (or other measure). Stick them in your private Git repository, or on a shelf in MS Team, or wherever. My actual preference is to have an entire new parallel environment for this purpose, because I can update it daily to ensure it is ready for testing/deployment. This isn't great, but it's an easy win against management by committee diktat.
Need a couple of hours to make something more maintainable? Draw from the bank. Nobody even knew that bank was there, so no loss. Then just fix the bloody stuff so that nobody in the next five years, including you, will need to fix it again.
Admin
So many people here have obviously never had a real job.
Admin
Somewhat depends upon your concept of what a real job is, doesn't it?
I mean, I've earned other people about $10M or so in thirty years. I've saved other people (a different thing) $50M. And I'm being paid very expensive peanuts.
But in those thirty years, I've at least been able to fix things early, put tests in place, fix disasters after things go wrong (thus the $50M), and so on. Ya kinda have to be adaptable. If we all took your attitude that "nobody will give me the time to make this maintainable" then ... yes, we'd have a Real Job.
Luckily, we don't have to. That Real Job is all yours!
Admin
Sticking code in a private repository on the side is a good way to be invited to a chat with whom ever handles security.
Admin
Don't be absurd. You aren't important. :D