• (nodebb)

    The function is also incorrectly named, because, in essence, it merges the "new" object into the "old" object. (It fails to clear the old object before adding the values from the new object to it.)

  • (nodebb)

    If you're going to re-invent the wheel, shouldn't you make one that's substantially better, not substantially worse?

    I mean, judging by this website, people tend to do the latter, but still...

  • (nodebb)

    The thing that really irks me about this though is that it pretends to be functional (in the programming idiom sense) by returning the newly modified value, but it's also just changing that value in place because it's a reference. So it has side effects, in a technical sense (changing the value of its input parameters) while pretending not to.

    To be fair, non functional style methos that mutate their single argument often return the instance. By returning the instance rather than void, the caller can chain method calls. It isn't fair to assume they meant to mimic functional programming.

  • (nodebb) in reply to Jaime

    To be fair, non functional style methos that mutate their single argument often return the instance.

    Like the built-in Array.sort.

  • my name (unregistered)

    and then you have SHAI-HULUD2 when you are using stock solutions

  • (nodebb)

    Our submitter wonders, "Is there a way to train an AI to not let people type this?" I would't think that will help - too much AI just copying published code or other "knowledge" without knowing whether the code is good, once-good but overtaken by subsequent developments, or just plain wrong. For any given relatively common topic, there will be hundreds sites repeating the same incorrect advice because the goal was advertising revenue at minimum cost, not well-curated content.

    TLDR: GIGO.

  • (nodebb)

    The thing that really irks me about this though is that it pretends to be functional

    I don't see this has even remotely trying to be functional, just using the pattern of returning the object for chaining.

    I am however irritated by the nonsensical name of the parameters -- old versus new, and it copies new into old? That makes no sense. "Src" vs "dst" would be so much more logical.

  • (nodebb)

    Further despite the name objectReplace it's not a clone operation; it's a merge operation. It amounts to old = old + new where any properties in old common to both are replaced by new's values, and the final property list of old is the union of both.

    Naming is hard. It's that much harder when your native language isn't the language of the names.

    Just illiterate garbage end to end.

  • Benjamin (unregistered)

    Always and forever, people are going to write bad code. That got a chuckle out of me, mainly because it's incredibly true. You can't train an AI to disallow people from writing bad code, but with the proliferation of AI "vibe coding", there will definitely be people using AI to write bad code until the end of this century at least. "Spaghetti-code" is and has been a recurring issue everywhere for the past few decades, I can only imagine the mess that will be the humanly incomprehensible gits of 2050.

  • giammin (unregistered)

    code that need to clone an object is the real WTF, isnt it?

Leave a comment on “Copied Homework”

Log In or post as a guest

Replying to comment #687824:

« Return to Article