- 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
Time is so valuable that it should be treated the same as money - use Decimal!
Admin
So he has tsDifference.Hours and tsDifference.Minutes RIGHT THERE.
I don't work in this language but surely it's just
If tsDifference.Hours > 0 then txtEstWaitHours.Value = tsDifference.Hours.toString;
txtEstWaitMinutes.Value = tsDifference.Minutes.toString;
Admin
The author of this code snippet votes, serves on jury, and drives, too. Think about that!
Admin
Yeah, sure sure, "Time to Wait" because the WTF today was delayed. TRWTF is, again, Remy.
Remy: I recommend you skim the HTML for comments. ;)
Admin
Apparently he not only had a hammer (which would mean everything is a nail), but also a screwdriver! And then proceeded to bang the hammer on the screwdriver for optimal effect...
Admin
This might stem from the author's lack of knowledge about the framework.
The .Hours and .Minutes properties of TimeSpan are never greater than 24 or 60 (respectively). They show that portion of the time span, but only the remainder which is not handled by the next-highest-order portion of the time. Probably the original author wanted .TotalMinutes which is a decimal number and can be very high because it is not exposing only "the remainder, after the whole hours have been removed".
What's really dumb as all hell though is that this could be:
var moreThanAnHour = tsDifference.Hours > 0; txtEstWaitHours.Value = moreThanAnHour? tsDifference.Hours.ToString() : String.Empty; txtEstWaitMinutes.Value = tsDifference.Minutes.ToString();
If that weren't two separate textboxes, then the whole thing could have been an overload of TimeSpan.ToString(string format).
Admin
I dread to think how they calculated dtWorkTime, which must be a future timestamp...
Admin
Still more accurate an estimate than anything a programmer can give.
Admin
I will respond angrily to your comment in 6 months, 7 days, 16 minutes and 5 seconds (roughly).
Admin
You know, C# has the handy keyword "var" which basically says to the compiler "You deal with all the type-safety stuff, 'cause I don't want to be bothered with it." (Which, it should be noted, is still very different from mushy-typed languages like Javascript & PHP). Once you get into that style of thinking, all this Hungarian nonsense tends to fall by the wayside, because it's not really so important to keep track of the exact datatypes anymore. And of course any halfway-decent IDE can tell you the type if you really want to know it. Better to name a variable for the information it represents rather than the shape it has.
Admin
I like the word "auto" more like in C++, its meaning aligns with its function. "Var" is meaningless. Does it stand for variable? Or varying type? Or varsity baseball? Who knows.
Admin
If you need a chisel, but don't have a chisel, then a hammer and screwdriver is the next best thing.
Admin
Right - because someone who is bad at one thing is automatically bad at everything else. -1 for social awareness.
Admin
It's a variable. What type? don't care, the compiler will sort that for me
Admin
If all you have is a three-headed hammer, everything looks like three nails.
Admin
I personally favour stabbing people who use that for anything other than iterators to death with the hot end of a GAU-8.
Admin
But... if TimeSpan.Minutes might equal 60, then you have to check for that and stringify and convert to "1 hour" before destringifying, so that you never display "60 minutes" in the output field. Or did you mean that TimeSpan.Minutes is strictly less than 60?
Admin
If var means variable, then surely we should prefix explicitly typed declarations with var, too? Var into x; is declaring a variable of type integer.
Admin
Are you that guy who always writes ApplicationVersionIncrementorContainerFactory x = new ApplicationVersionIncrementorContainerFactory(); ?
Admin
Estimating wait time is the WTF, any code is an afterthought.
Admin
Using Hungarian notation is all-the-more important once you start using keyword "var".
Admin
Who knows what keyword "var" stands for? According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/var, it means "an implicitly typed local variable".
According to your logic, keyword "for" could mean "fortran", "foremost", "for your eyes only", etc.
Admin
Big difference, the word "for" exists in English and its meaning in programming is very similar to its English meaning. There's no word "var" in English, and even if we accept it to be an abbreviation of "variable", it doesn't communicate at all that it's implicitly typed. The keyword "auto" in C++ on the other hand is a clear reference to "automatic", meaning the compiler automatically determines the type.
Admin
And that is the biggest WTF in my opinion: dtWorkTime is a date in the future, seemingly the date&time when the work will be completed. Where does that date&time come from? From knowing the date&time when the job was submitted and the duration for said job, So dtWorkTime was calculated using the very data that this thing is trying to figure out!
Admin
Actually, no. The value of dtWorkTime is only partly determined by how much time that kind of job takes; it's also determined by the time at which a service bay will next become free.
Admin
hungarian means the programmer has learned to code a long time ago. This could imply experience, but certainly does not indicate good code.
It's entirely obsolete in a modern IDE and just slows down the review process.
Admin
No. Using var implies that your code isn't terribly concerned with the exact type of the data you're handling and you'd rather not make it fragile. If you use Hungarian in these scenarios, you're likely to see that the variable declared as "var intMinutes = x.Minutes" now handles decimal data because someone changed a property type. It also would imply that the person changing the data type should be responsible to go find everywhere the property is used and update the variable names in those methods. Otherwise, your handy notation of telling people the type in the name would could never be trusted, and therefore be less useful (in extreme cases become more misleading than helpful).
Admin
So we all gathered here to bash and mock this code. In the meantime, the guy got paid, the code made it to production, and will work just fine until the product dies.
Admin
Seriously, that's the guy you are worried about on jury..? Can I live in your universe please? I imagine it must be very different from mine.
Admin
Yes, because the only thing that matters is that you get your paycheck and the software "works". This shows a complete lack of pride, craftsmanship, or even concern for the future of your job and your workload. How can we, as a profession, build more maintainable code when our own ranks see maintainability as a waste of time?
Admin
Sometimes he uses
.ToString
and other times he usesConvert.ToString
. Is there a difference, or is that just another in the long line of WTFs?Addendum 2019-09-17 09:38: (That wasn't meant to be a reply; sorry about that.)
Admin
Decompile of appropriate overload of Convert.ToString:
public static string ToString(int value) { return value.ToString(CultureInfo.CurrentCulture); }
So, yes, even though it uses a different overload of ToString, it boils down to the same thing when passed CultureInfo.CurrentCulture.
Admin
Or use a Greasemonkey script like https://userscripts-mirror.org/scripts/show/112851 or a bookmarklet like the one at https://what.thedailywtf.com/topic/12789/remy-s-back-a-script-for-those-who-don-t-want-to-read-the-source You might need to update the class names though: "ArticleBody" is spelled "article-body" these days.
Admin
Granted, my sarcasm was very subtle, but I still think you deserve a "whoosh".
Admin
Hungarian notation is useful in typeless (as in, without explicit type declaration) like JS, Lua, PHP or Python, but I don't see usefulness of it in C# (which this code is certainly written in) where even in editors like VS Code you can just hover over the variable to see what type it is, not to mention in full-blown 8DE.
Treating time as float though, that's inexcusable no matter the language or the library.