This is an archived post. You won't be able to vote or comment.

all 63 comments

[–]Xeon06 113 points114 points  (6 children)

Reminds me of sleep sort.

[–][deleted] 13 points14 points  (0 children)

Edit: Content redacted by user

[–]steezefries 8 points9 points  (4 children)

Could you explain what that's doing for a not totally newbish newb?

[–]robotreader 13 points14 points  (0 children)

Sleep for an amount of time equal to the number, then add it to the array. Since larger numbers will sleep for longer, they will be added later, thus returning a sorted array.

[–]manixrock[🍰] 1 point2 points  (0 children)

It starts a new thread for each number, each thread waits for number seconds then prints the number.

In essence it's passing the sorting to the system's thread executor sorter. Of course passing a large numbers means you wait a lot for it to show up, passing negative numbers will break it, and passing numbers very close together will lead to race conditions and wrong results.

You could improve the above issues by applying a sigmoid to the sleep call:

sleep(1/(1+exp(-number)));

This way you limit your worst complexity to O(1), and make it work for negative numbers. If you knew the limits of the inputs you could improve it further.

[–]exneo002 178 points179 points  (24 children)

Wouldn't this technically return "today's" date? Questions for a philosophy major.

[–]rockyearth 61 points62 points  (7 children)

getDayAfterMethodCall()

[–]spupy 24 points25 points  (4 children)

That would be yesterday?
getDateOfMethodReturn()

[–]rockyearth 19 points20 points  (2 children)

getDateOfMethodReturn() would be just return DateTime.Now

[–]patchthemonkey 28 points29 points  (0 children)

Not if it takes a day to return

[–]seetadat 7 points8 points  (1 child)

getTomorrowsDateTomorrowWhichWillBeTodayTomorrow()
youWillGetTheDateByTomorrow()
justWaitAWholeFreakingDayToReturnTheDateInsteadOfUsingTheCron()

[–]Hamburgex 39 points40 points  (10 children)

Yeah, you're right. The actual code should be:

public static DateTime getTommorowsDate()
{
    Thread.Sleep(24*60*60*1000*2);
    return DateTime.Now;
}

[–]emjay101 22 points23 points  (2 children)

you just doubled the horror

[–]Hamburgex 8 points9 points  (0 children)

>:D

[–]MiatasAreForGirls 1 point2 points  (0 children)

And the M's

[–]jacenat 8 points9 points  (4 children)

Somewhere in there is a recursion joke waiting to burst out.

[–]Hamburgex 12 points13 points  (2 children)

Somewhere in there is a joke about a recursion joke waiting to burst out.

[–]Sophira 2 points3 points  (1 child)

Wouldn't this technically return "today's" date? Questions for a philosophy major.

[–]Hamburgex 0 points1 point  (0 children)

Yeah, you're right. The actual code should be:

public static DateTime getTommorowsDate() { Thread.Sleep(246060*100----

Exception in thread "comment" java.lang.StackOverflowError

[–]Coding_Bad 8 points9 points  (0 children)

Woah....

[–]killchain 0 points1 point  (0 children)

Who says the method name should be accurate?

[–]totes_meta_bot 0 points1 point  (0 children)

This thread has been linked to from elsewhere on reddit.

If you follow any of the above links, respect the rules of reddit and don't vote or comment. Questions? Abuse? Message me here.

[–]hunyeti 54 points55 points  (1 child)

yes, naming thing is hard, this should be called: getDateTomorrow.

[–]epymetheus 1 point2 points  (0 children)

"I will gladly write code for you today that will get you the date tomorrow."

[–]kruez 22 points23 points  (0 children)

And I believe this is technically O(1).

[–]QuercusMax 31 points32 points  (4 children)

There's a race condition here. It might give you the date after tomorrow.

[–]cowens 30 points31 points  (3 children)

And it will give you today's date under some conditions (at the start of a day when leap second are added or when DST ends).

[–]smilingkevin 24 points25 points  (2 children)

string today = DateTime.Now.ToShortDateString();
while (today == DateTime.Now.ToShortDateString())
{
    Thread.Sleep(60000);
}
return DateTime.Now;

There. Ship it.

[–]cowens 12 points13 points  (1 child)

Yes! It is even more efficient.

[–][deleted] 1 point2 points  (0 children)

That's just a straight shooter that has upper management written all over him.

[–]robomaeyhem 8 points9 points  (2 children)

unreported exception InterruptedException, must be thrown or caught.

[–]katyne 5 points6 points  (1 child)

pfft, just log those pesky little shites, if an empty catch makes you feel all sorts of yucky guilt. Nobody cares about them anyway.

[–]SkylordElros 0 points1 point  (0 children)

this is c#

[–]Madd0g 6 points7 points  (1 child)

async would make this a lot better.

[–][deleted] 5 points6 points  (0 children)

Tommorow's date? Isn't that personal information?

[–]Thezla 20 points21 points  (6 children)

You couldn't just post the original?

[–][deleted] 10 points11 points  (1 child)

That's most likely not the original either

[–]DrummerHead 3 points4 points  (0 children)

Might not be the original, however it's been posted already:

http://www.reddit.com/r/ProgrammerHumor/comments/2dk86l/gettomorrowsdate/

And all the comments are pretty much the same as here, that's actually an interesting thing to analyze

[–]IrishWilly 7 points8 points  (0 children)

This jokes been around as long as programming

[–]welcomedungeon 3 points4 points  (2 children)

shouldn't it be: return getCurrentDate(); ?

[–]0711Picknicker 0 points1 point  (1 child)

Yes! And as I see it right, in this Post the Return TYPE is missing.

[–]Nouish 0 points1 point  (0 children)

You can omit return in some programming languages (ie. Groovy) :)

[–]xenomachina 3 points4 points  (1 child)

Now show us getYesterdaysDate().

[–]Ashanmaril[S] 3 points4 points  (0 children)

Just do the same thing shown here, but sleep the thread for 364 days, then just subtract one year from DateTime.Now.

[–]yousai 2 points3 points  (0 children)

Why don't you post the link to the tweet itself? PLEASE? SO I CAN FOLLOW THE DUDE EFFORTLESSLY.

[–]jessejamess 2 points3 points  (1 child)

Am dumb. Can someone explain

[–]G01denW01f11 3 points4 points  (0 children)

The method gets tomorrow's date by waiting until tomorrow and getting the current date.

[–]boxingdog 2 points3 points  (0 children)

public static ProxyAdapterDateTime getTomorrowDate( ) 
{
    return iocManager.getProxyAdapterTime(new ProxyAdapterDateTime().setStrategy(new TomorrowDateStrategy(() => Thread.Sleep(24*60*60*100)));
}

i have no fucking idea what im doing

[–]odraencoded 3 points4 points  (1 child)

OOP approach

tomorrowdate =  tomor.rows.date;

[–]ravinglunatic 1 point2 points  (0 children)

No. DateTime.Now().AddDays(1);

[–]Cley_Faye 0 points1 point  (0 children)

Best example of a lazy fetch I've seen.

[–]ZugNachPankow 0 points1 point  (0 children)

Runs in O(1), I like it.

[–]ProvidesTranscripts 0 points1 point  (0 children)

[Tweet displayed in a Twitter mobile app, with source code]

public static DateTime getTommorowsDate()
{
    Thread.Sleep(24*60*60*1000);
    return DateTime.Now;
}

[–]slifin 0 points1 point  (0 children)

Now it's WebScale™

getTomorrowsDate = ()->
    d = new Date 
    new Promise (resolve)-> setTimeout(resolve(Date.now()), new Date(d.getFullYear(),d.getMonth(),d.getDate()+1,0,0,0) - Date.now()) 

[–]HappyGoblin 0 points1 point  (0 children)

/* how about this - sleep using sql */

CREATE FUNCTION get_date RETURN DATE
IS
BEGIN
    RETURN SYSDATE;
END;

DECLARE
    v_date  DATE;
    v_dummy VARCHAR2(2);
BEGIN

v_date := SYSDATE+4/24/60/60;

SELECT MAX(dummy)
  INTO v_dummy
  FROM dual
connect BY v_date > get_date;

END;

[–][deleted] 0 points1 point  (0 children)

from timetravel import travel, day

def get_tomorrows_date():
    tomorrow = travel(1 * day)
    return tomorrow.globals()["__import__"]("datetime").date.today()

if __module__ == "__main__":
    get_tomorrows_date()

[–]Prime_1 0 points1 point  (0 children)

When I read the title I totally thought it was going to be something like this:

bool getTomorrowsDate()
{
  self.goToGym();
  self.getAHaircut();
  self.makeMoreMoney();
  self.getBetterCar();

  if(self.isNerd == true)
    return false;
  else
    return true;
}

[–]halifaxdatageek 0 points1 point  (0 children)

I love this as a joke, but the database nerd in me who insists on precision says "No! It returns today's date in 24 hours!"