79

I received a really nice SO mug as swag for the choose your own swag contest this year. Everything was working fine until this morning. Was there a patch or update or something?

Here's the relevant code snippet:

if (owner.isCoding() && mug.isEmpty())
{
    mug.fill('coffee');
}

Here's a screenshot of what I'm seeing:

Empty SO mug with code on a monitor in the background

As I've highlighted with an orange arrow, I am coding recursive fractals using Logo. You can see also that my cup is empty. I believe this satisfies both conditions specified in the code snippet I posted above, and yet my cup remains empty.

I checked the console and there are no errors. What gives?

18
  • 18
    -1, orange arrows are soulless
    – ArtOfCode
    Apr 1, 2016 at 13:48
  • 56
    I see the problem. You assumed using Logo was coding. Apr 1, 2016 at 13:49
  • 30
    Oh no! Your password is showing!
    – Oded
    Apr 1, 2016 at 14:01
  • 7
    @Oded Oops! I'll upload a new screenshot.
    – Kit Z. Fox
    Apr 1, 2016 at 14:04
  • 1
    Oh, also, I'm not sure if it's relevant, but we just switched to Agile methodology, so I'm pair programming.
    – Kit Z. Fox
    Apr 1, 2016 at 14:15
  • 11
    It's because that if statement should be while loop, otherwise it will not fill up more than once. I really have no idea why it worked until yesterday... Apr 1, 2016 at 14:40
  • 1
    Oh, I see that you're still on Windows XP, maybe that's why it's not working ? Try formatting your hard drive and installing SoCoffeMugLinux™ 16, maybe that fixes it :-) Apr 1, 2016 at 14:43
  • 5
    I suspect owner.isCoding() is returning false. Please add a alert(owner.isCoding()) to check it's result.
    – Arulkumar
    Apr 1, 2016 at 15:15
  • 23
    Have you tried turning it off and turning it back on again?
    – Alex A.
    Apr 1, 2016 at 23:52
  • 5
    I suspect you have a bug in the mug. Have you used a debugger?
    – Spikatrix
    Apr 27, 2016 at 13:30
  • 2
    I also suspect that 1) Here owner.isCoding(), you aren't the owner. Someone else is (The guy who made/designed the mug) 2) mug.isEmpty() will always return false as the mug is never empty, it is filled with air.
    – Spikatrix
    Apr 27, 2016 at 13:33
  • You aren't coding, you are holding the mug. owner.isCoding() returns false so no wonder it isn't filling. Apr 2, 2017 at 14:51
  • The password is still in the edit history. Is it possible to remove that, maybe for diamond mods? Nov 25, 2017 at 19:06
  • 2
    @Fabian Thanks for your concern. It's actually a fake. It was intended for humorous effect.
    – Kit Z. Fox
    Nov 25, 2017 at 21:44
  • 1
    Also, what if you want tea in the cup? Or hot chocolate? Would you just switch "coffee" in the code for another beverage? Mar 24, 2019 at 20:41

9 Answers 9

104

You forgot to hook up dependency injection correctly.

You need one of these:

enter image description here

7
  • 5
    What framework should we use? I have the same problem. Apr 1, 2016 at 14:23
  • 40
    @PatrickHofman Clearly the problem is not enough jQuery. Apr 1, 2016 at 14:44
  • 1
    OK, I tried this, but now I'm getting Reference not set to an instance of an object?
    – Kit Z. Fox
    Apr 1, 2016 at 17:00
  • 4
    @KitZ.Fox - assuming you are using java-beans, did you roast and grind them as the standard requires?
    – Oded
    Apr 1, 2016 at 17:57
  • 1
    @Oded I did and appended them to the filter object. Maybe I'm invoking the brew method incorrectly.
    – Kit Z. Fox
    Apr 1, 2016 at 18:44
  • @KitZ.Fox - you may need to post your grounds on MayYourCupOverfloweth.com to get an answer on that.
    – Oded
    Apr 1, 2016 at 19:01
  • 6
    Is the proposed dependency RFC 2324 compliant?
    – SEJPM
    Apr 1, 2016 at 22:15
49

Classic beginner mistake. The code hasn't been run. So, hold the mug and run ... perhaps to the pantry, where the coffee is.

5
  • 1
    Ah, bad UX on the design then eh? :)
    – enderland
    Apr 1, 2016 at 14:25
  • 14
    Run, but don't execute the code, those things are kinda hard to ship.
    – Tim Post
    Apr 1, 2016 at 14:25
  • 1
    Tim, since [mug] isn't instantiated, which one would fill if you had two of these next to each other? Apr 1, 2016 at 14:26
  • 7
    Mug is very much instantiated, OP has it in their hand. And mine even reviews code. Apr 1, 2016 at 14:27
  • Yep, in your case isCoding() is false @Mat'sMug Apr 1, 2016 at 14:52
47

Your computer checked Wikipedia and XKCD and discovered that "half full" and "half empty" mean the same thing. Now if

0.5*full = 0.5*empty

then

full = empty

So your code made the cup empty, on the assumption that that was the same as making it full.

3
  • 3
    It's not my code! How do I get it fixed?
    – Kit Z. Fox
    Apr 1, 2016 at 13:56
  • 5
    @KitZ.Fox Find out who wrote it and ply them with coffee until they fix it. Apr 1, 2016 at 13:58
  • 3
    Just not from this mug. Apr 1, 2016 at 14:18
21

Assuming your coffee mug isn't playing an April Fools joke on you . . .

This appears to count as undefined behavior. An official source states that (boldface mine)

While no incidents have been reported, the following scenarios might result in undefined mug behavior:

  • Owner changing, or non-owner use of mug
  • Existential difficulties of owner

I suspect that your existential difficulties have led to your working with Logo. Square fractals are recursive, meaning that any time you try to work with them, you'll get back to somewhere similar to where you started. Therefore, whenever you try to drink coffee and work with them, you'll get back to where you started. . .

Any empty mug.

14

You are most definitely missing a break statement. That thing won't get filled without a decent break.

Also, the if should be a while, obviously...

while (owner.isCoding() && mug.isEmpty())
{
    break;
    mug.fill('coffee');
}
8
  • 2
    ... but if I break; first, won't I exit before the mug gets filled?
    – Kit Z. Fox
    Apr 1, 2016 at 14:43
  • 2
    No, that is a common mistake. In this case the break doesn't cause an exit. Apr 1, 2016 at 14:43
  • 9
    Performing break with a mug might initiate garbage collection though, so you need to look out for that. Apr 1, 2016 at 15:08
  • Never heard of that before. What runtime version do you have? Apr 1, 2016 at 15:09
  • 2
    2.18.5.1.11.19.5.1.19.25 it says. Apr 1, 2016 at 15:15
  • Are you sure it is a mug then? Never actually saw a mug on that runtime. Apr 1, 2016 at 15:16
  • 4
    I couldn't update to 8.1.18.4.1.19.18.15.3.11 for some reason. Apparently it would be fixed in that version. Apr 1, 2016 at 15:20
  • 1
    @Simon I can't believe I missed your jokes last year. Here's a very late laugh: hahaha.
    – Kit Z. Fox
    Apr 3, 2017 at 12:20
12

This line:

mug.fill('coffee');

Does not state the amount of time it takes for the mug to be filled with coffee, or how it's done.

Put the mug, empty, below your pillow at night, and when you'll wake up, it will be full.

Tooth Fairies got some less known relatives, such as Coffee Fairies.

11

The && operator shorts the circuits, so owner.isCoding() is called but mug.isEmpty() is not. So if you're coding with Legos and you are the one true owner of the mug, it doesn't matter whether your mug is empty, the code will always be called.

The .fill method doesn't do any checking for .isFull() so in your case it looks like the Stack Overflowed and contents was set to 0. You can see using .contents.toLiters() how much is in mug.

I also recommend refactoring the code to make it more efficient. You can do that by reversing the indentation. I think that worked for Mat's Mug.1

You can find more information about this here.


1citation needed

4
  • 3
    I hate it when my circuits get shorted.
    – Doorknob
    Apr 2, 2016 at 0:29
  • 2
    Reversing the indentation? Geez have I been doing it wrong all this time?! Apr 2, 2016 at 23:39
  • Umm... the link wasn't broken. (can't see how any of the links is related, but that's a different matter, lol! :)) Apr 11, 2016 at 6:03
  • @ShadowWizard My esteemed colleague in moderation runs the site that I originally linked to, but unfortunately he removed the redirect for that particular URL. So I had to adapt accordingly. ¯\_(ツ)_/¯
    – Alex A.
    Apr 11, 2016 at 6:09
10

Perhaps they ignored the linker warning: mug was not correctly instantiated.

At least you didn't suffer a core dump. :)

10

I've finally found a solution for Mac OS X!

Turned out the OS X flavor of Unix doesn't ship with all the required dependencies. The easiest way to install it is via Homebrew.

$ brew install coffee

Strangely the coffee seems to be mildly alcoholic, must be a homebrew issue.


What we really need is a way to run this from a browser. Maybe I'll try porting it to Coffeescript later.

2
  • 4
    But Java should be installed automatically the first time you try to drink it.
    – Barmar
    Apr 7, 2016 at 17:34
  • Also this runs fine on ubuntu. Nov 6, 2017 at 11:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .