7
cprn
357d

Yesterday I had a questionable pleasure of interviewing a young software engineer who (while answering one of earlier questions) used a principle of polymorphism but made a mistake. So I asked her to explain what polymorphism is.

She couldn't. When she said "let me start from the beginning" for the 3rd time I jestfully noted that if she's more used to virtual communication she can text me the answer, and she not only thought I was being serious but also thought it's a good idea, then texted me a duck emoji, a dog emoji... And got stuck again.

Obviously when we were discussing potential salary she had an answer for every question. Ridiculous answer but no communication issues whatsoever.

Comments
  • 4
    I'll just assume that there were more things this candidate performed poorly on...
  • 0
    @ScriptCoded There were. But to this one she tried to answer with emoji. Emoji!!!
  • 2
    Where is the pleasure in doing this? And why was salary discussed when the candidate didn't meet the expectations?
  • 2
    Been at least 7 years since anyone interviewed me about OOP, lets see how well i remember the concepts without googling or cheating

    Polymorphism is a concept where a class can have many different forms (poly-morph meaning many-forms) (actually now that i think about it terra-form also means many-forms so whats going on here?!) Anyways lets head on to an example

    Lets say we have an

    interface Orgasm {
    void cum();
    }

    So now we wonder well who can cum? A man can cum and woman can cum. Lets implement it

    @Slf4j
    class Man extends Orgasm {
    public void cum() {
    log.info("jizz jizz");
    }
    }

    @Slf4j
    class Woman extends Orgasm {
    public void cum() {
    log.info("squirt squirt");
    }
    }

    @Slf4j
    class HiringDepartment extends Orgasm {
    public void cum() {
    log.info("shitty shit");
    }
    }

    Basically doing the same shit but in their own unique ways
  • 1
    @Nanos A simplified and modified example from Wikipedia. You can pass Cat or Dog or Duck to `letsHear()` because all three have the `speak()` method implemented. The function `letsHear()` can act on anything that has a method `speak()`. The function `letsSwim()` can act on anything that has a method `swim()`.

    From a point of view of `letsHear()` all 3 classes are the same (have the required "shape", required members/parameters).

    From a point of view of `letsSwim()` only Dog and Duck are the same and Cat is a different type that isn't handled.
  • 1
    @cprn

    @cprn

    While I don't don't the candidate didn't meet expectations, your definition, or rather, example, of polymorphism is quite contrived and not quite exact.

    Any correct definition of polymorphism must explain the concept of runtime dispatch.

    You have a base class defining a common interface. Then each subclass can implement that interface differently, and the key thing is that you can pass a subclass to a function/method expecting the base class, and the compiler won't compile in the call, but defer to runtime to know the "runtime type" of the argument, and thus call the correct implementation.
  • 1
    @asgs I talk salary with every candidate. If it's reasonable for their skill I'm often allowed to hire them, sometimes for lower position, but it's possible.
  • 1
    @cprn

    Oh, I didn't doubt discussing salary expectations. In fact, I'd appreciate if it was discussed first, not gonna lie.
  • 1
    @CoreFusionX I apologize, I'm tired...

    You're assuming a strong typed language with interfaces and inheritance and while this is where use of polymorphism is the most prominent it can happen in almost any language, including those without the aforementioned traits. But you're absolutely right it's resolved at runtime and in my example calling `letsSwim()` on a Cat class object would result in an error (on compilation if it was a compiled language and the call wasn't dynamic although nowadays we have advanced static analysis tools that can sometimes catch even that).
  • 0
    ...so, wait, is polymorphism not the act of re-encoding or re-compiling the code segment of an executable in varying situations to avoid detection and/or reverse engineering? this has a new definition now?

    i'm younger than a lot of you and apparently i'm too old for this shit
  • 1
    @Parzi You are thinking of polymorphic code I believe which is an entirely different concept.
  • 1
    @TheSilent once again, the terms are exactly the same, and are completely different. why must you all do this to me
  • 1
    @ostream Check out my earlier example - no inheritance. You know some of what polymorphism gives you - that's great, that's more than what she knew - and I'd totally accept that as an answer.

    This rant was supposed to be more about her trying to explain an abstract concept with emojis, which made me question my faith in the future of humanity, not about her not knowing what the concept was exactly, but I guess I shouldn't write when tired because most comments seem to focus on the latter.

    I promise you, it was a nice interview. She wrote some code on her own laptop, shown some of her own projects, I asked a few questions and provided detailed answers to any she didn't know. The polymorphism question was asked because it was related to one of the mistakes she made and my attempt at humour was related to something she said before.

    And the ChatGPT prompt made me smile so kudos for that. 🙂
  • 0
    @jestdotty

    The fact that languages implement and express it differently doesn't preclude from being able to define the concept of polymorphism, which is that of hierarchical runtime dispatch.

    You could do away with the "hierarchical" part if you want but then what you really have is duck typing.
  • 0
    @CoreFusionX I just had another look at that example and, yeah, you're right. It's just duck typing. To be truly polymorphic it'd need `extends Animal` in each class declaration and both global functions would need to require `Animal` type parameter. Those are somewhat related concepts, though.

    [edit] Wait, that's still not true. The Cat would also need a `swim()` method because it has to be abstract in the parent. Man, it got complicated quickly.
Add Comment