Ad
  • Custom User Avatar

    Note that this code would not work in a strict mode environment. This is not considered a best practice.
    Otherwise, clever idea

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Giving my 2 cents here.

    Keep in mind what i'm writing here for the rest of my comment : I do realise the solution is elegant, and is appropriate in the scope of codewards, aka in the case you're doing it to learn of more efficient ways to code for high performance / critical areas, or as a sandbox playground.

    But fojuth has a point, and a good one. In real world problems, where your code gets handed over to other people that will maintain it, modify it, add to it etc.. and most importantly, that you don't screen, choose or recruit to do your job after you move on, putting code like this in production is a serious case of tempting the devil and opening the gates to potential pitfalls down the line.

    A developer's job is building software, often in a team. It's not about code performance until it's specifically needed, it's more about team productivity, high velocity in task completion and a development cycle as smooth as possible.

    I feel the need to address your point about what comments should be used for. I saw this a lot with peers in university, but I digress. Comments shouldn't explain the what or the how of a certain piece of code (basically what intent + explanation means), they should explain the why, that's what truly adds value to readability without clogging your mind with unnecessary low level details, and makes code pieces literally essays.

    CS is, as its name suggests, a science. Programming on the other hand is a craft that uses CS to achieve what it wants. Please make this distinction in context while reading other comments.


    Also.. As a side but important note, do leave reddit-like comments far from dev communities. Our field is harsh enough as it is dealing with other stuff, and most of us like to help and be respectful to each other. Have some pride in what you do and leave bashing and shittalking to people with time to burn and nothing else to do.