Skip to content
DevMeme
5674 of 7435
Kotlin extension functions charm; JavaScript prototypes get an HR complaint
Languages Post #6225, on Sep 3, 2024 in TG

Kotlin extension functions charm; JavaScript prototypes get an HR complaint

Why is this Languages meme funny?

Level 1: Stickers vs Scribbles

Imagine you have a really nice drawing, and a friend wants to make it even better. In one case, your friend politely asks to put a cute sticker on it – you agree, and it makes the drawing even more special. That’s like the first scene: a small, friendly addition that everyone is happy about. Now think of a different friend who grabs your drawing and scribbles all over it with a permanent marker without asking. Not so nice, right? You’d probably be upset and call a teacher or parent for help. That’s the second scene. The meme is joking about these two situations: Kotlin’s way of adding something is like a harmless sticker that makes you smile, but JavaScript’s way can feel like an unwanted scribble that causes trouble. One is polite and sweet, and the other crosses the line – which is why it’s so funny that the woman goes from “Awww!” to “HELLO, HUMAN RESOURCES?!” in the comic.

Level 2: Classy vs Classless

Let’s break down the joke for those newer to these languages. Kotlin is a modern programming language (popular on Android) that builds on the Java ecosystem. It’s a class-based language (meaning it uses classes and inheritance like Java or C#). One of Kotlin’s cool tricks is extension functions – this lets you bolt on new functions to any existing class as if they were part of that class. For example, imagine you want a quick way to add a heart ♥ to any string. In Kotlin you could do:

// Kotlin: defining an extension function on String  
fun String.addHeart(): String {
    return this + " ❤️"
}

// Using the extension:
val greeting = "Hello".addHeart()
println(greeting)  // Outputs "Hello ❤️"

Here we didn’t modify the original String class in the library. We just wrote a function addHeart() that can be called on any String in our code. It’s like giving strings a temporary new ability in a safe, localized way. Other code outside our project won’t suddenly find a mysterious addHeart method on strings – it exists only because we imported/defined it in our scope. This is why it’s seen as a tidy, appropriate feature: it feels built-in when you use it, but it doesn’t actually break anything or surprise other parts of the program. In a team setting, using an extension function is usually no big deal (often encouraged for cleaner code). It’s adding functionality without stepping on anyone’s toes.

Now, JavaScript (the language of the web) has a different heritage. JavaScript is historically classless – for decades it didn’t use classes under the hood, instead relying on prototypes for objects. A prototype is basically a default object that another object uses as a fallback for properties. If you access a property that an object doesn’t have, JavaScript will look up the chain at its prototype, then the prototype’s prototype, and so on. This is called prototype inheritance. It’s flexible: you can create one object and have another object inherit from it without formal classes. And you can add new properties or methods to the prototype even after objects are created. For instance, to give all strings a new method in JavaScript, you might do:

// JavaScript: adding a method to the String prototype
String.prototype.addHeart = function() {
  return this + " ❤️";
};

const greeting = "Hello".addHeart();
console.log(greeting);  // Prints "Hello ❤️"

At first glance, this looks similar to the Kotlin example – now every string in JS can use "Hello".addHeart(). The big difference is scope and safety. We actually modified String.prototype, which is a global object that all strings refer to. This means we’ve permanently changed the behavior of strings for the entire program (and even other scripts running on the same page). All code, including third-party libraries, now finds a new function on every string. If some code isn’t expecting that extra method, it could misbehave. And if two different pieces of code each decide to add their own addHeart() method? They’ll collide – the last one wins, potentially breaking the first. You can imagine in a large team or open-source project, uncoordinated changes to built-in prototypes could become chaotic.

Because of these risks, modifying prototypes directly is often considered a bad practice except in very controlled cases. Many style guides say “don’t monkey-patch built-in objects.” (Monkey-patching means changing or extending core objects in a dynamic way, like a cheeky monkey messing with stuff that isn’t its own.) It’s powerful, but it can lead to unpredictable side effects – kind of an “enter at your own risk” zone of JavaScript. Newer JS features like class syntax (introduced in ES6) make it less common to manually tinker with prototypes, but under the hood even those classes are using prototypes – just in a safer, structured way.

So why the HR joke? In a professional workplace, there are rules about what’s appropriate behavior. Similarly, in programming teams, there are informal “work rules” for code. Kotlin’s extension functions play by the rules: they’re considered a polite way to extend functionality without upsetting the codebase. But a developer who starts messing with JavaScript’s prototypes in a shared project might be seen as breaking the rules – almost like someone saying something out-of-line at work. The top panel of the comic shows the “Appropriate” label because extension functions make the coder look helpful and charming (the colleague is flattered, saying “Awww, you’re sweet”). The bottom panel is flagged “Inappropriate” because bringing up prototypes – i.e. planning to tinker with them – sets off alarm bells (the colleague is shocked and immediately calls Human Resources, the department that handles workplace misbehavior). It’s a playful way to say: Kotlin’s feature comes across as friendly and harmless, whereas JavaScript’s old-school prototype manipulation might get you in trouble with your peers. In short, one is welcomed in the codebase, the other might earn you a stern talking-to during code review!

Level 3: Charming vs Alarming

In the developer language wars, certain language features earn affection while others draw suspicion. This meme humorously casts Kotlin’s extension functions as a charming compliment and JavaScript’s prototypes as an HR-worthy offense. It's playing on an InsideJoke among programmers: Kotlin’s tidy LanguageQuirks feel elegant, whereas JavaScript’s prototypical inheritance can feel downright sketchy in a large codebase.

To seasoned developers, the comparison is spot on. Kotlin extension functions let you add new methods to existing classes in a controlled, polite way. Under the hood, an extension function doesn’t actually change the original class at all – it’s compiled to a static utility function that only looks like a new method. This means you can extend a class’s behavior without touching its source code or globally altering its structure. It’s like offering an object a helpful tool only when needed, leaving no permanent mark. Team leads love this because it keeps codebases clean: you’re not really injecting anything sneaky into shared state. No wonder the coworker in the first panel blushes with a heart – an extension function is a respectful way to share functionality. It adheres to the “code of conduct” of maintainable design.

Contrast that with JavaScript prototypes. In JavaScript’s world, objects don’t inherit through classes but through a prototype chain – every object has a hidden link to a prototype object, forming a chain of fallbacks for property lookups. It’s powerful, but with great power comes great responsibility (and occasional chaos). When a dev proudly proclaims “Let’s use prototypes!”, experienced colleagues might wince. Why? Because adding methods via SomeConstructor.prototype.newMethod = ... actually mutates the objects’ blueprint for all instances. That’s like tattooing every employee with a new skill without asking – a bold move that might violate personal space (or coding standards). In a big project or frontend codebase with many contributors, unexpectedly changing a global prototype is just asking for trouble. It can lead to bizarre bugs: for instance, if you add a property to Object.prototype, every single for...in loop suddenly starts iterating over your new property, breaking code that never expected it. (Many of us learned this the hard way – the JavaScript equivalent of an HR nightmare.) Monkey patching built-in prototypes (slang for modifying core objects on the fly) is so notorious that most teams ban it outright. It’s considered inappropriate behavior in code, much like an off-color joke in the office.

The cartoon nails this dynamic perfectly. In the “Appropriate” panel, the Kotlin dev’s mention of “Extension Functions” is like giving a well-received compliment – it follows the social (and coding) rules, and the colleague responds warmly. But in the “Inappropriate” panel, the JavaScript dev blurts out “Prototypes”, and it’s treated like he crossed a line. The coworker grabbing the phone to call Human Resources is an exaggerated metaphor: in reality, the “HR” for code misconduct might be a stern code review or a heated engineering meeting. It’s an inside joke that anyone who’s had to untangle a gnarly prototype chain bug can relate to. We’ve all seen that one eager dev who, fresh from a Kotlin project, thinks “hey, I’ll just extend JavaScript objects like I did in Kotlin” – only to be met with immediate “HELLO, CODE POLICE?!” vibes from the team. The humor lands because it’s relatable: Kotlin’s feature feels like innocent developer charm, while JavaScript’s approach has a history of causing headaches, earning it a tongue-in-cheek reputation as a codebase HR violation.

Description

Two-panel Sunny Street comic edited for dev humor. Header reads "SUNNY STREET" with sub-banner "KNOW THE WORK RULES." Panel 1, marked "APPROPRIATE," shows a smiling male coworker whose torso is replaced by the colorful Kotlin logo; his speech bubble says "Extension Functions." A woman at her cubicle blushes and replies "AWWW, YOU'RE SWEET" with a red heart floating beside her. Panel 2, marked "INAPPROPRIATE," reuses the scene but the man now sports a bright yellow square with bold black "JS" letters; his bubble says "Prototypes." The same woman, alarmed, grabs the phone and shouts "HELLO, HUMAN RESOURCES?!" The meme contrasts Kotlin’s tidy extension-function syntax with JavaScript’s sometimes maligned prototype chain, poking fun at how certain language features feel elegant while others feel sketchy in large codebases. Cartoon style is colorful with light blue background and thick black outlines; original credit "SUNNY STREET © 2013 Max Garcia" sits in the footer

Comments

22
Anonymous ★ Top Pick Some teams call it "extending a class"; others call it "modifying Object.prototype" - one gets code review kudos, the other triggers a P0 incident and an HR lecture on boundaries
  1. Anonymous ★ Top Pick

    Some teams call it "extending a class"; others call it "modifying Object.prototype" - one gets code review kudos, the other triggers a P0 incident and an HR lecture on boundaries

  2. Anonymous

    The real HR violation here is that someone's still defending prototype manipulation in 2024 when we have proper class syntax, TypeScript, and a dozen better patterns for extending functionality without risking the entire global object chain

  3. Anonymous

    This perfectly captures the industry's collective PTSD from explaining JavaScript's prototype chain in interviews versus the relief of just adding `.also {}` to literally anything in Kotlin. Extension functions are the syntactic sugar we didn't know we needed until we stopped accidentally mutating `Object.prototype` at 2 AM and calling it 'dynamic programming.'

  4. Anonymous

    Kotlin extensions: politely augmenting classes. JS prototypes: mutating the global object graph until HR intervenes

  5. Anonymous

    Extension functions are compile-time sugar with scoped receivers; prototype patching is shared mutable state at runtime with a blast radius wide enough that your first responder is HR

  6. Anonymous

    Extension functions feel like polite, namespaced sugar; prototypes are the coworker who patches Object.prototype in prod - now the incident commander and HR both page you

  7. @SamsonovAnton 1y

    The first one was more fun.

  8. @Araalith 1y

    Implicit type conversion in JS: Eww, did you see what happens if you add an array to a string while comparing the result to a number? Weird... JS is so awful. Implicit type conversion in literally any other language: Nice! What? You didn't expect that int + float isn't the same as float + int? Learn to code!

    1. @azizhakberdiev 1y

      JS designers be like: This type conversion works in the most ridiculous and counterintuitive way? Approved and documented, next!

      1. @Araalith 1y

        Sure, these conversions are very human

        1. @azizhakberdiev 1y

          > sure > ascii code > garbage value > integer division

          1. @Araalith 1y

            Yes, it's very human... if the human was abducted and raised by wild compilers

            1. @azizhakberdiev 1y

              I'd prefer being abducted by C compiler rather than JS

              1. @azizhakberdiev 1y

                It is not like I hate JS, but I cant eat bananas anymore

    2. @x4erem6a 1y

      lmao it gets even better with floats nan == nan -> false js: eww so weird literally any other language: rtfm ieee 754 it's the basics

  9. @Araalith 1y

    Meanwhile "counterintuitive" JS...

    1. dev_meme 1y

      Don't offend believers in JS supremacy, they're also humans

    2. @hotsadboi 1y

      gee, I wonder how many people will find 1 + +"4" intuitive after getting "14" several times in a row

      1. @misesOnWheels 1y

        + is a unary operator that converts a numeric string into a (float) number, ppl should actually go over the features before criticizing the language

        1. @hotsadboi 1y

          and character literal in c is a u8 number. i am not criticizing js, i am criticizing this guy's example of js being very intuitive compared to c. you cannot in good faith complan about c bullshit and then give js bullshit as an example of completely intuitive language design

          1. @Araalith 1y

            When you "+" a string with anything, the result is a string. When you "+" two numbers, the result is a number. If you want to use a string as a number, you need to explicitly typecast or convert it, as you would in any modern programming language - JavaScript isn't unique in this behavior. However, C handles these cases in a very specific way due it's low-level nature logic. P.S. In some languages, like Perl, the "+" operator is reserved exclusively for numerical operations, so "Hello" + "World" is 0

          2. @hotsadboi 1y

            brother, nobody is asking what type conversion is. you chose the example to illustrate a point, showing that js is more "human" and "intuitive" when compared to c, and this example is at best not a strong one. nobody was arguing that c is very human and intuitive, using different logic (not converting to a number in c vs converting to a number in js) undermines your entire point, and "+" operator being used to convert strings to numbers is not intuitive to anyone who's not familiar with js and ecmascript-based languages (to be fair, chars being treated as numbers and strings being treated as pointers is also not intuitive for anyone who's not familiar with c or assembly, but that's not relevant to the discussion)

Use J and K for navigation