20

A friend got me a stack overflow mug and its amazing - but one thing has always troubled me.

Is the code written in a real world language? The code seems like it could be improved slightly.

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

enter image description here

It appears to me that isCoding and isEmpty are methods but could possibly be properties on an object to save checking the conditions each time.

Also wouldn't it be safer for the fill method on mug to expect a parameter with a type other than string.

15
  • 4
    where can i get that mug? Jul 5, 2012 at 12:49
  • 1
    I was going to link to the shop shop.stackexchange.com/password but it seems it been closed? Jul 5, 2012 at 12:52
  • 7
    Meh. Looks like Java.
    – slugster
    Jul 5, 2012 at 12:52
  • 1
    @benni_mac_b What happened to the Stack Exchange store?
    – AakashM
    Jul 5, 2012 at 12:55
  • 4
    I think you drank one too many cups... ;)
    – Lix
    Jul 5, 2012 at 12:55
  • 7
    The single quotes around 'coffee' wouldn't compile in Java. Jul 5, 2012 at 13:10
  • I first thought too that it looks like Java. Well, it is not C#...could be JavaScript. On the other hand, wouldn't it be better if 'coffee' would be extracted into an Enum (if the language supports it)? I always at those "magical strings", as they are the same for me as "magical numbers"... Jul 5, 2012 at 13:14
  • What, you don't like my coding style? My suggestion was the basis for what's on the mug, with some editing by others if I recall, but I can't find the post where I suggested it. I think it's now been deleted. At least they sent me a free mug for using my idea. It's currently full of pistachio shells. ;) Jul 5, 2012 at 16:50
  • 1
    Have at the source meta.stackexchange.com/questions/14253/… @gno
    – random
    Jul 5, 2012 at 16:59
  • @random that's a 404 for me. Deleted page?
    – Servy
    Jul 5, 2012 at 17:00
  • @gnostradamus amazing, I was hoping the author would appear. Would love to see the other suggestions Jul 5, 2012 at 17:03
  • 1
    Here's a screenshot of the original suggestion, with its comments... probably not as exciting as you're expecting it to be. It was an answer to "What types of Stack Overflow schwag would you like to see?"
    – Pops
    Jul 5, 2012 at 19:03
  • The string coffee should be enclosed in double quotes instead of single quotes, thereby adding at least C and C++ to the list of languages in which the code is legal.
    – Alnitak
    Jan 21, 2015 at 15:43
  • looks like javascript 8)
    – Dan
    Jan 7, 2016 at 20:26
  • 1
    I'm working remote now, and needed a quick image to show to my coworkers of one of my most prized possessions. Thanks for providing it. Apr 18, 2022 at 16:36

3 Answers 3

43

As the owner of such a mug, I can assure you that the code definitely works; when I'm coding and drinking from that mug, the ingredients are always coffee (at least in the duck-typing sense: it looks like coffee, smells like coffee, and tastes like coffee).

So any objection would purely be regarding the code style, but as they say: If it ain't broke, don't fix it :)

3
  • 24
    Mine is filled with water right now. What compiler are you using? Jul 5, 2012 at 13:13
  • 38
    @BilltheLizard The answer "CoffeeScript" would be too obvious, wouldn't it?
    – balpha StaffMod
    Jul 5, 2012 at 13:14
  • 12
    Ever got a bug in your coffee? Now that's nasty. Nov 21, 2013 at 20:42
17

I'm sorry, this just won't work for me. There should be a while loop and an instruction to suspend the current thread until the mug becomes empty again, at which point the producer is woken up by the consumer to put more coffee in the buffer (mug).

1
  • 9
    Just hope it's not a ring buffer, that'll make a mess on your desk.
    – balpha StaffMod
    Jul 5, 2012 at 17:38
2

Its not effing C#, which offends me.

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