- 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
Admin
Essentially, this:
[image]Admin
Naturally one wants to do this in binary:
And like second nature in x86 Assembly:
Why do people insist on making things so hard for themselves? pffft, amateurs.
Admin
IA!! IA!! CTHULHU FTHAGN!!!!!!!
CATCHA: duis - whoever wrote that code was a real duis.
Admin
There is a reason you can transform a number into a string and vice versa. As everyone knows, that's the right way to test for the sign of a number. Here in C#:
Admin
Actualy, the date calculation is a way to go when you need to do something for each hour. Simply adding the difference between date and aimed hour is not enough to take into account daylight saving. (2 hours +1) can be 3hours, 2 hours or 4 hours depending on daylight saving ^^
Of course, considering code does nothing but changing the hour, simply calling setHour(10) would have been much easier ^^
Admin
What is wrong in doing arithmetics with while loops ? Never heard of Peano Arithmetics ? Essentially, give me '+1' and a while, and i can build up the whole integer arithmetics. TRWTF is to have a loop using minus one, instead of building subtraction with a loop using '+1'. (left as an exercise to the reader)
Admin
I'm surprised no one commented, on the reimplementing of negating a number, that in languages where overflow throws an exception instead of being silently ignored, there are some numbers that would cause overflow instead of giving you a negative value.
Of course, with two's-complement arithmetic and overflow ignored, you'll get the same results as you would from an unary minus operator.
Admin
Admin
You'll put all those poor makers of laser pointers out of work.
Hissssssssssssssssssssssss.
Admin
Admin
Everyone knows this is the correct way to turn a positive number into a negative number.
Admin
The "Early life" section on her Wikipedia page is a red flag.
Admin
That looks familiar.
Admin
The problem with date arithmetic is that people seem to want to do it on local times. This just doesn't work.
Hint - if you must roll your own date functions, ALWAYS use UTC internally.
Eg, given an 'AddHour()' function, what is the result (in the UK) of
(26 Oct 2014 02:00).AddHour(1)
Is it (26 Oct 2014 02:00) or is it (26 Oct 2014 03:00)?
Answer - both...
That's why you store and calculate in UTC, and then convert to local as necessary.
IMHO, any date class which has a 'GetHour' function is broken. There should be a 'GetUTCHour()' and a 'GetLocalHour()' function. GetHour() is ambiguous and bad design.
Admin
I remember when multiple and divide WERE done with loops on most common CPUs around...
(not quite repeated adds, but still loops - using the rather neat characteristics of binary arithmetic)
Admin
Are you sure you should ALWAYS use UTC? The WTF code seems to be trying to constrain to business hours, which can be dictated by local time. Do business hours always start exactly 10 hours after midnight and last 6 hours, or do they respect DST and begin and/or end 1 hour earlier that day? If it's the latter then we should use local time.
The .NET DateTime structure (which the given code appears to be using) is UTC. "Hour" is always UTC hour. If you want
Admin
Or two lines of shell script
#!/bin/bash
auth_server is set somewhere prior to here:
auth_server has only two versions: https: OR http:
eg: auth_server="https://thisisanUrl.com"
OR auth_server="http://thisisanUrl.com
auth_server=
echo ${auth_server/https:\/\//}
auth_server=echo ${auth_server/http:\/\//}
echo $auth_server etc, etc.
C* versions are left to the student as an exercise
Admin
Admin
Of course. If it ain't broke, don't fix it.
For one, you might introduce a bug.
You'll need someone to review your change and have a backout strategy.
You'll need to write regression tests that will run with the build and remain doing so forever, thus slowing down the build process.
You will need to write a document expressing the change and how the testing team can run tests against your change.
You'll need several managers to sign it off too.
Admin
In Helvetica yes, in "Old English Text MT" no. You must follow your code style.