- 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
Let's assume somebody was born on the 1st of January 1970 (the dawn of time, after all) and now is the 1st of January 1980. According to you (1991 >= 1980 returns true) they can go order a large whiskey and a double vodka. But they can't for their 22nd birthday in 1992 (1991 >= 1992 returns false).
Admin
An incompetent java programmer.
Admin
uh, what are you talking about?
bool canDrink = DateTime.Parse(AnyCommonStringRepresentationOfABirthDay).AddYears(18) <= DateTime.UtcNow;
Admin
Lol.
canDrink = DateTime.Parse("12.02.1990").AddYears(18) <= 17.09.2014 = false
So now that I'm 23, I can't drink anymore. TRWTF.
Admin
Oh actually I may be drunk. Cannot even do simple boolean logic.
Admin
Also, there is a very good reason why the method you expected to be available isn't: a TimeSpan value is independent from start and end dates. It is exactly what it's called -- a span of time -- and no more. If it had a notion of months and years, what is it supposed to do when you add it to another date? e.g. What is TimeSpan.Months for 30 days: 0 or 1? If you add it to Jan 31, should the result be Feb 28, or March 2? Same issue applies to leap years.
Admin
Admin
People use C++ because there is no better alternative. It is the single widely used language where you can build up any number of abstraction layers to match the application domain, with zero or minimal performance penalties. Of course, having such a sharp knife makes it possible to cut off your feet, but C++ provides enough means to adapt or build your own ecosystem which is exactly as safe as you want.
I would gladly welcome a comparable language without all those C++ gotchas, but I'm afraid this might impact the sharpness.
Admin
Admin
Are you claiming that someone on TDWTF is too pedantic? Hah, that's funny.
Admin
Let's assume that I didn't make a tpyo.
Admin
Rust is aiming to be that language. I doubt it's exactly what you want currently, as the language is still being finalised. (End of 2015 is the estimated 1.0 release), but the goal is essentially to be a replacement for C++.
It's plenty sharp too. It's easy to write safe code in Rust that runs as fast as equivalent C/C++. If you can't convince Rust something is safe, you can drop down into "unsafe" mode (which really only adds the ability to deference raw pointers).
It's not gotcha-free (no language is), but the gotchas tend to result in compile-time errors rather than segfaults or memory leaks.
Admin
This was a good one!
Admin
Can someone get the author of that code to write a routine to determine whether or not a number is a prime number and post it here?
Admin
Which is the reason you never sell or buy MM contracts on Feb 29 unless you have no choice. But there is always an answer. For listed instruments the calculation will be in the standard contract used by the exchange where the instrument is listed.
Any real finance/treasury library explicitly deals with those questions. There are 3 answers that capture 90% of the contracts, and another 6 that probably capture the next 9%.
Admin
Where is this idea that C/C++ is fast coming from? Are you comparing it to Lisp? JavaScript?
The enourmous work that has been done on making optimising compilers for C/C++ is because C and C++ are languages that make it very difficult to compile fast code. Almost any other native-compiled language is going to be at least as fast as C/C++ It's not a high bar to leap.
Admin
I'm not sure what the legal drinking age is in Java. In the UK it's 18, and in (at least most of) the US it's notoriously 21 (which is of course TRWTF). I don't know where in the world C# is, so haven't a clue what the legal drinking age there is.
Admin
At least your consistent, but please learn you're grammar.
Admin
FTFY
Quite a few of the contributors are displaying more or less illiteracy in their responses to this post. I despair of the education system of the nation to which they have the misfortune to belong.
Admin
Let me guess -- here's the pseudocode:
Reasoning: everybody knows 2 is a prime, it's famous for being the only even prime, even I know that.
So let's look at the odd numbers. 3 is prime. 5 is prime. 7 is prime. 9 is prime. 11 is prime. 13 is prime. We can extrapolate from there.
Sorry, what was that, nine isn't prime? Okay, no worries, I've made a fix to isOdd so as to make sure it returns 9 as false.
Sorry, you said "what about 1"? Oh good grief, stop making so much fuss over edge cases!
Admin
Nope.
What if the Date object has a constructor?
Admin
Admin
In my mind, the real question is why was a single process allowed to allocate so much memory as to bring the machine as a whole to its knees?
Isn't it the sysadmin's responsibility to configure system limits so as to prevent this sort of thing?
I can see leaving (ulimit|Windows System Resource Manager|whatever), configured to its defaults on a dev or QA machine, but not on a business critical production server.
One badly-behaved program should not be able to bring down the server. And there will always be badly-behaved programs.
Admin
.....rowwraaawwwraowwwaooowwwdugudugudugaWHOOOOOOOOOOOOOSH!!!
Admin
Admin
Have you heard of SCALA or are you living under rock?
Admin
.net definitely has it's shortcomings, but this is not one of them.
Admin
Scotland is 5. Yes 5
http://www.adviceguide.org.uk/scotland/relationships_s/faq_index_family_scotland/faq_family_legal_age_drinking_and_smoking_scotland.htm
Admin
Not true! I've gotten plenty of dates... Before I was a programmer.
Admin
Lisp and JavaScript are not native-compiled languages; this is not a contradiction.
Admin
Admin
What people don't grasp is that the elapsed time between any two events is indeterminate. Given any two date/times, you cannot determine how much time elapsed between them without a database, for past times, and and not at all, for future times.
Prior to 1970, there were a fixed number of seconds in a year, so the calculations were simple, but the length of a second was variable. Since 1970, we've fixed the length of the second, but we change the number of seconds in a year, at regular intervals.
We base our calendars and clocks on the rotation of the Earth, but the simple fact is that the rotation of the Earth isn't constant, and its variation is not predictable.
So no, it's not simple. Or, rather, it's only simple if you ignore what is really going on.
Admin
You, sir, deserve a medal for this. (I wonder if that also explains why the Unix epoch was chosen to be Jan 1, 1970...)
Admin
Also note that the author thinks all leap years have last digit of 0, 4, or 8. But 2012 and 2016 are leap years.
Admin
Admin
I just checked and Rust does have a certain gotcha I hate: it uses C-style month numbering (0 to 11) rather than human month numbering (1 to 12).
If I complain about this, I wonder if they will fix it. C-style month numbering might -- might -- have made sense forty years ago, but by no means does it make sense today.
Admin
Admin
It was a bad example. Here are some better ones.
One month after April 15 is May 15. Easy, eh?
What is one month after April 30? Is it May 30 or May 31?
One month after March 31 is April 30. One month after April 30 is possibly May 30 or May 31.
Two months after March 31 is definitely May 31.
February 27 to March 27 is one month.
February 27 to March 28 is one month and one day.
February 28 to March 28 is less than a month.
I had to deal with end-of-month calendar issues in a client billing system I wrote and maintain.
Sincerely,
Gene Wirchenko
Admin
Months are pretty much pointless these days.
People tend to make appointments for "next Thursday" (which has its own problems), not for such-and-such a day of such-and-such a month.
Signs for annual events tend to be used year after year, but with the day of the month repainted annually. The day of the week does not change, and the new date is chosen to stay close to the anniversary of the old date.
If they get rid of months and just counted weeks instead, that would be fine by me. By the way, that's exactly what they did in Iceland in the Middle Ages.
Admin
For that matter they'd have done the same thing to the year so Unix programmers would get an extra year to fix Y2K bugs.
Admin
However, months aren't pointless when people tend to make appointments for "next month's 12th day" or predict something for "November's first third." Weeks in the old calendar were 10 days long, which isn't exactly one-third of a month, but it's still common to talk about the upper week (first third of a month), middle week (second third of a month), or lower week (third third of a month). Not much different from talking about a quarter or a half of a year.
Admin
Like I said, you could get rid of months, and people would just count weeks. A man who goes to his barber today (Monday of week 39) might make an appointment for "Monday of week 47".
Admin
Like many companies already do. I rarely hear "we expect delivery by October 24th" but "delivery has to be in week 43" or "our salesperson will contact you tuesday week 40". All our projectios of what we expect to sell/buy/... are done by week, not month.
But good luck for the layperson to change. Just look at how long england took to change from imperial to decimal measurement (and the public outcry when the pound was made decimal)
Admin
Do we know that AddYears(21) won't stumble over a DST transition and therefore result in a date that's an hour off?
Admin
Admin
Admin
Admin
Bill me on: [X] End of month [ ] __ of every month
I still don't see 9 possible variations on this...
Admin
...unless it's February?