Skip to content

Instantly share code, notes, and snippets.

@Potherca
Last active October 17, 2022 04:27
Show Gist options
  • Save Potherca/8b91a5212e29d3a8178f382de647d406 to your computer and use it in GitHub Desktop.
Save Potherca/8b91a5212e29d3a8178f382de647d406 to your computer and use it in GitHub Desktop.
Everything Wrong with the Code on That Mug

There is a post going round on facebook of a mug with some code on it. There's even a reddit post on it. The mug looks quite nice but sadly the code on it is crap.

  • The code is not placed in a separate namespace
  • A var keyword is not used when assigning the Coffee object
  • The object oriented style abstraction is broken
    • There is no container for the coffee
    • There is no dispenser for the coffee
    • There is no person to drink the coffee
    • There is no SoftwareDeveloper object
  • There are flaws in the logic
    • When the coffee is refilled it is not drunk
    • The logic is only run once
  • The comment is totally useless
  • The code style does not adhere to the C# coding standards for .NET
    • Rule 2.3. Do not create declarations of the same type (namespace, class, method, property, field, or parameter) and access modifier (protected, public, private, internal) that vary only by capitalization.
    • Rule 2.18. Try to prefix Boolean variables and properties with “Can”, “Is” or “Has”.
    • Rule 4.3.33. Avoid invoking methods within a conditional expression.
  • There is no logging, error handling or messaging

Honestly, if I came across such code in a peer review it would not pass.

Beside these issues, the code is written in C# (created by Microsoft) and not in the more suitable CoffeeScript

At a certain point I might feel like writing a better version.

Right now, my coffee mug is empty, so I'm going to get a refill first ;-)

Coffee coffee = new Coffee();
if (coffee.Empty)
{
coffee.Refill()
}
else
{
coffee.Drink()
}
//I am a software developer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment