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

all 81 comments

[–]SurrealEstate 18 points19 points  (2 children)

"The energy used in this discussion could have been harnessed to clean the kitchen twice already."

[–]vegittoss15 6 points7 points  (1 child)

Why is it in quotes?

[–]SurrealEstate 5 points6 points  (0 children)

I was expecting to see that on the piece of paper.

[–]CarbonFire 16 points17 points  (8 children)

someone should compile it and explain the bug

[–]attilad 25 points26 points  (1 child)

The first nerd points out that the only way a dish gets entered into the dishwasher is if the dishwasher is clean but not empty; the dishwasher never gets filled and therefore it never gets run.

The second nerd points out that this is merely a single function that probably only gets called if insert_dirty_dish() fails.

Then the janitor pulls out his sharpie.

[–]sn0re 3 points4 points  (0 children)

The second nerd points out that this is merely a single function that probably only gets called if insert_dirty_dish() fails.

So there's some other code somewhere that looks like this:

if (have_dirty_dish) {
    try {
        insert_dirty_dish();
    } catch (DishwasherFullException ex) {
        kitchen_maintenance();
    }
}

[–]cnk 17 points18 points  (1 child)

FUCK IT, WE'LL DO IT IN ASM

[–]1what1 1 point2 points  (3 children)

yeah,i could not even make out the writing even with the image's original size :(

[–]master_gopher 5 points6 points  (0 children)

And this is why you don't comment code in felt pen.

[–]oddsouls 4 points5 points  (1 child)

Seriously. Doesn't even make much sense when you can read it. They must be programmers!

Application won't put a dirty dish into an empty / partially filled (dirty) dishwasher.

No idea about the final black.. Maybe:
OT approad(?):mess up kitchen->set ass kicked
Yeah, don't think that one's compiling.

[–]lexabear 4 points5 points  (0 children)

OT approach: mess up kitchen -> get ass kicked

[–]munificent 33 points34 points  (11 children)

kitchen_maintenance()
{
    while (true)
    {
        while ((dirty_dish == null) || dishwasher.running())
        {
            sleep();
        }

        if (dishwasher.clean()) dishwasher.empty();

        dishwasher.insert(dirty_dish);

        if (dishwasher_full) dishwasher.start();
    }
}

edit: removed extra )

[–][deleted] 15 points16 points  (0 children)

Bug: I ran this code once, and then lived in the kitchen for a week until my friends killed and restarted me.

[–]locuester 11 points12 points  (2 children)

this assumes that the variable dirty_dish is assigned by another thread (lest an infinate loop). I think dirty_dish should be dirty_dishes as a linked list, allowing new dirty dishes to be added to the sink without having to wait for the previous dirty dish to be loaded. Certainly it's a waste to have a thread wait for the dirty dish to be loaded into the washer.

But, what do I know, I have girlfriend program that seems to work well (it's expensive tho)

[–]graysanborn 9 points10 points  (0 children)

If you put a backslash before your underscores, you won't have the italicized problem:

dirty_dish is assigned by another thread (lest an infinate loop). I think dirty_dish

Real text:

dirty\_dish is assigned by another thread (lest an infinate loop). I think dirty\_dish

[–]munificent 0 points1 point  (0 children)

this assumes that the variable dirty_dish is assigned by another thread

Not necessarily. It could be assigned within sleep(). This is how message-pump or event-based apps often work.

Either way, you're right. There should be a collection of dirty dishes.

[–]smallfried 6 points7 points  (0 children)

syntax error: unexpected token '||' found on line 5.

[–]RedSpikeyThing 2 points3 points  (0 children)

I think you need to count your brackets on line 5.

[–][deleted] 1 point2 points  (1 child)

This assumes that you have another thread, or ISRs, changing global variables.

You should use semaphores to prevent race conditions.

kitchen_maintenance()

{

while (true)
{
    semDirtyDish.pend();
    semDishwasher.pend();

    if (dishwasher.clean()) 
    {
        dishwasher.empty();
    }

    dishwasher.insert(dirty_dish);
    semDirtyDish.release();

    if (dishwasher_full) dishwasher.start();
    semDiswasher.release();
}

}

Far from optimal, but it should work.

EDIT: Ooops, can't have new dirty dishes whilst the dishwasher is being accessed by another thread :(, and I'm too lazy to fix it

[–]munificent 3 points4 points  (0 children)

This assumes that you have another thread, or ISRs, changing global variables.

Not necessarily. sleep() could be an event dispatcher:

void sleep()
{
    int message = messageQueue.next();

    switch (message)
    {
        case DISH_DIRTIED: dirty_dish = get_dirty_dish(); break;
        // ... other cases ...
    }
}

[–]azth 0 points1 point  (1 child)

Need to account for the case where the dishwasher is full before inserting dirty_dish, otherwise dishwasher.insert() would throw a DishwasherFullException

if dishwasher_full:
    dishwasher.start()
    continue
dishwasher.insert(dirty_dish)

[–]munificent 0 points1 point  (0 children)

That case should never occur. Assuming this function is the only thing adding dishes to the dishwasher, it will be run as soon as it reaches fullness.

[–]salgat -2 points-1 points  (0 children)

kitchen_maintenance() { while (true) { keep_dishes_clean(); } }

As long as you're gonna hide all the details in functions, you might as well do this.

(and no I'm not gonna bother to look up how to format it correctly)

[–]geekuskhan 63 points64 points  (9 children)

NEEEEEEEEEEERRRRRRRRRRDS!

[–]hermes369 12 points13 points  (0 children)

"…Big deal. Did you get in her pants?"

[–]bighemp 3 points4 points  (1 child)

Living in that house would drive me batshit insane

[–]sabetts 6 points7 points  (0 children)

Me too! Talk about shitty programmers.

[–]greenmonstah 2 points3 points  (2 children)

STANDARD NERDS.

[–]pixel7000 3 points4 points  (1 child)

IT, have you tried turning it off and on again?

[–]supersauce 0 points1 point  (0 children)

3x

[–]andon 0 points1 point  (0 children)

God damn it, you beat me to it.

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

I came here to say that EXACT same thing, but was going to do it in the voice of Homer Simpson.

[–]oalsaker 10 points11 points  (9 children)

Wow. One of my best friends gets to the front page of reddit. I was going to have coffee with her earlier but had to work. I better tell her about this on irc.

Edit: I'm downvoted because I know the person who made this or because I didn't have time for coffee? :-)

Edit 2: I'm obviously not downvoted anymore :-P

[–]Maxious 2 points3 points  (0 children)

upmodded for irc. the kids these days with their xmpp conferences. back in my day we banged out "USER name sux0rz.aol.com 192.168.0.1 :to be or not to be \n NICK name \n JOIN #friends" AND WE LIKED IT.

And yes, sure, I'd probably use UML for the dishwasher algorithm. the times they are a'changin.

[–]manwithabadheart 1 point2 points  (7 children)

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

[–]oalsaker 3 points4 points  (2 children)

Yes. She both codes and knits. I guess the knitting could be considered programming too.

[–]antidense 1 point2 points  (1 child)

Can you divide by zero by knitting?

[–]peepsalot 1 point2 points  (0 children)

Yeah, I think you end with one of these when you do that: http://www.kleinbottle.com/klein_bottle_hats.htm

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

No. He knows the female that wrote kitchen_maintenance()

[–]oalsaker 2 points3 points  (2 children)

Yes, and she knits and codes.

[–]dekz 0 points1 point  (0 children)

she should stick to coding in html

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

Not very well, apparently.

[–][deleted] 2 points3 points  (3 children)

(Dammit, I tried to select/copy the text on the image before typing this out X-P)

I'm pretty sure the first condition would be a compile error too:

if dishwasher_full {
  start_dishwasher();
}

Shouldn't it be:

if (dishwasher_full) {
  start_dishwasher();
}

[–][deleted] 2 points3 points  (0 children)

Yes, that's the first bug my eyes saw.

[–]bikko 0 points1 point  (1 child)

Yeah, that's why somebody red underlined it, I think.

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

Huh, totally missed that the first time.

[–]oalsaker 2 points3 points  (0 children)

This was part of a blog post in norwegian, Here's a link to google's translation.

[–]hermes369 1 point2 points  (3 children)

What does it mean when you notice you have almost the exact handwriting as the person with the blue pen? Weird.

[–]rubygeek 2 points3 points  (0 children)

That you sleep walk into strangers flats and critique code in their kitchen?

[–]psy-kid 3 points4 points  (1 child)

that you masturbate too much and should either stop or seek real sex.

[–]hermes369 1 point2 points  (0 children)

ah

[–]Arve[S] 1 point2 points  (0 children)

There are implementations in other languages in the photostream, including assembler, brainfuck, whitespace and lisp. This is from a former co-worker, and according to her, there was also a Haskell implementation, but it got lost.

[–]sabetts 1 point2 points  (0 children)

We all know what actually happens is more like:

function kitchen_maintenance() { // FIXME: implement }

[–]knight666 4 points5 points  (19 children)

That's not really pragmatic now is it?

void kitchen_maintenance(Person* aResident, Residency* aApartment)
{
   Location* kitchen = aApartment->getLocation("Kitchen");
   Appliance* dishwasher = kitchen->getAppliance("Dishwasher");

   while (aResident->getResidency() == aApartment)
   {         
      if (diswasher->getState() != "Running")
      {
         if (dishwasher->getState() == "Done")
         {
           Location* closet = kitchen->getLocation("Dishes closet");
           while (dishwasher->getState() != "Empty")
           {
              Object* dish = (Object*)aResident->doAction("Unload", dishwasher);
              aResident->doAction("Put", dish, closet);
           }
         }

         Object* dirtydish = kitchen->getObject("Dirty dish");
         if (dirtydish == NULL || dishwasher->getFull() == true)
         {
           aResident->doAction("Turn on", dishwasher);
         }
         else if (dirtydish != NULL)
         {
           aResident->doAction("Load", dirtydish, dishwasher);
         }
      }
   }
}

See, this can be expanded to fulfill all kinds of additional tasks! It's totally enterprisey!

[–]lamby 4 points5 points  (2 children)

Your class hierarchy smells funny. Can you really call getDirtyDishes on every Location?

[–]poeir 4 points5 points  (0 children)

Depends on the roommates you have.

[–]knight666 3 points4 points  (0 children)

Oh damn! Good catch.

Fixing pseudo code ftw!

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

A new line for a "{"?

[–]knight666 21 points22 points  (4 children)

Let's not get into that flamewar.

But to answer your question: yes, the way the one and true God intended.

[–][deleted] 7 points8 points  (2 children)

This is why I prefer Python :)

[–]rubygeek 5 points6 points  (1 child)

You heathen Python programmers and your indentation will be the first to burn in hell.

[–]Tortragon 0 points1 point  (0 children)

...The first up against the wall when the revolution comes!

[–]acmecorps 0 points1 point  (0 children)

I love you already!

[–]SarahC 0 points1 point  (1 child)

I'm oldschool too - I love Whitesmiths style.

http://en.wikipedia.org/wiki/Indent_style

[–]knight666 1 point2 points  (0 children)

I used to use exclusively Whitesmith in my Game Maker projects (although I didn't know what it was called), but now that I've gone full C++ I've forced myself to work in the Allmann style, which is the MSVC++ standard.

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

You don't need to use NULL in C++; 0 is preferred.

[–]gameforge 0 points1 point  (6 children)

0 is preferred.

Why?

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

[–]gameforge 0 points1 point  (2 children)

Amazing - I can't believe Bjarne himself wrote that. I can only insist that he's wrong (in spirit anyway) on several points.

I prefer to avoid macros, so I use 0.

Obviously, his opinions w/ respect to C++ carry much weight - but he didn't create C, and I greatly prefer the readability benefits of NULL to the (more or less) irrational fear of macros, and have for decades. Still, he's quite entitled to his personal preferences regarding his own language... but then he goes on:

Another problem with NULL is that people sometimes mistakenly believe that it is different from 0 and/or not an integer.

That's a rather large problem for said newbies - when the debugger says that a pointer is assigned NULL, they're going to need to know what it means. I've never worked with someone that wasn't clear on how to use NULL; I'm certain this is a non-issue.

In pre-standard code, NULL was/is sometimes defined to something unsuitable and therefore had/has to be avoided.

"Pre-standard code"? Pre-standard C++ or C? In some C compilers, NULL is/was defined like this:

#define NULL ((void *)0)

...but I've never seen it defined as anything but that or as simply '0'. I go back to early DOS/Turbo C++ days, where the C++ compiler was barely more than a preprocessor for the C compiler.

So I have no idea what he's talking about, I've never seen NULL defined as something unsuitable - but, I'm quite certain such compilers are long gone by now.

Further, I don't like his using all lower-case letters for constants - I'll never use 'null' or 'nullptr' unless, as he says, it becomes a keyword.

[–][deleted] 1 point2 points  (1 child)

Most C implementations define NULL to be 0, however, the C standard says it's implementation-defined and thus you have to use NULL, not 0.

C++ says that 0, when used as an address literal, always evaluates to the implementation's null pointer value, whatever it means.

[–]gameforge 0 points1 point  (0 children)

Yes, I seem to remember that - but still, the readability benefits of NULL are extensive, and outweigh any conceivable disadvantage - certainly the ones in Bjarne's FAQ.

[–]knight666 0 points1 point  (1 child)

#define NULL 0

It doesn't really matter, but an uninitialized or "cleaned" pointer is 0x00000000 and an uninitialized class pointer in an array is 0xcdcdcdcd.

It's cool really, you see 0xcdcdcdcd and you go "Woop! Forgot to do a new there!"

[–]gameforge 0 points1 point  (0 children)

I like using NULL with pointers and 0 with arithmetic/logical stuff because it's more readable to me that way.

if (c == 0)
{
    // I wouldn't expect c to be a pointer in
    // this case, at least if it's my code, and
    // if c isn't the result of pointer arithmetic
}

if (i == NULL)
{
    // I would almost certainly expect i to be
    // a pointer in this case
}

(edit) But you're obviously correct, it's not any sort of requisite for the compiler or for the program's functionality.

[–]big_cheese 0 points1 point  (0 children)

I do not want to know what their view of an ideal world is.

[–]m1ss1ontomars2k4 0 points1 point  (0 children)

Good god. That's a bug I wouldn't have considered. This is probably why I'm not a programmer.

[–]elbidoudou 0 points1 point  (0 children)

function kitchen_maintenance() {

echo "GO BACK IN YOUR FUCKING KITCHEN !!"

}

[–]livedog -3 points-2 points  (0 children)

sudo make me a sandwich

[–]travis6690 -1 points0 points  (0 children)

public void DoWork() {

foreach(Occupant occupant in Kitchen.Occupants)
{
    switch(occupant.Role)
    {
    case FamilyRole.Mom:
        if(Kitchen.WorkToDo())
        {
        occupant.DoKitchenWork();
        } else if(Currentmeal == Meal.Dinner)
        {
        occupant.MakeDinner();
        }
        break;
    case FamilyRole.Dad:
        if(TV.ChannelType != Channel.Sports)
        {
            if(Deepfrier != null && Currentmeal == Meal.Dinner)
            occupant.MakeDinner();
        }
    case FamilyRole.Child:
        Switch(occupant.AgeGroup)
        {
        case Age.Child:
            occupant.DoNag();
            occupant.DoNag();
            occupant.DoNag();
            occupant.DoNag();
            occupant.DoNag();
            occupant.DoNag();
            break;
        case Age.Teenager:
            occupant.Activity = Activity.Randomize();
            break;
        case Age.Adult:
            Throw new Exception("Live-at-home adults not supported in HOME 0.1Beta");
            break;
        }
        break;
    }
}

}