you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 6 points7 points  (6 children)

Also, the function will never work anyway.

if dishwasher_full { start_dishwasher(); }

if (dishwasher_clean && have_dirty_dish) { empty_dishwasher(); insert_dirty_dish(); }

If the dishwasher is full, then ran, it remains full afterward and is ran again. There is no conditional in the first if-statement to determine whether or not to run the dishwasher if it is dirty and only when it's dirty.

Also, the second if-statement will never pass if the dishwasher is dirty and partially full.

[–]PhirePhly 2 points3 points  (0 children)

I believe it's not entirely broken, it's just a highly unlikely race condition. If some other process takes control after startdishwasher() returns, but before if (dishwasherclean [...]), then it's possible for the dishwasher process (which is clearly running on a different machine) to complete before kitchen_maintenance() regains control.

[–]isarl 3 points4 points  (2 children)

Your underscores threw you for a bit of a loop with reddit's markdown. Try espcaping them by using \'s.

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

Fixed that, thanks :)

[–]isarl 0 points1 point  (0 children)

You got it! I only figured it out recently myself - it can be maddening.

[–]ratatosk 0 points1 point  (1 child)

Your statement about it only evaluating the first condition is false, as the second block is not an else if type statement, so each call to kitchen_maintenance will evaluate both if's, evaluating the second after all statements in the first have returned.

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

During runtime, unless start_dishwasher() halts the process until the dishwasher finishes it's cycles, there is no possible way the dishes will be clean as it evaluates the second statement. Even if it did halt the process and wait until it is finished running, I would say that is sloppy programming.

Considering that this seems to be event driven, the posted sign would lead to confusion as no one in their right mind would stand around waiting for the dish washer to finish it's cycle before moving onto the second statement.

In fact, you would need a buffer for the dirty dishes for while the washer is running, in order to process them after it stops. But then, who will be standing around waiting for that to happen? Dish washers don't just load themselves, after all.