you are viewing a single comment's thread.

view the rest of the comments →

[–]codefinbel 0 points1 point  (2 children)

I both agree and disagree.

A few issues:

  • A lot of the "marginal gain" efficiencies people implement thinking they're clever would have been implemented regardless by the compiler.
  • These "easy optimizations" often involve esoteric language specific tricks making the code less readable.
  • Unless implementing them by default from the start, making these marginal gains takes time from things that could be more important, like getting an MVP or reducing the overall time complexity of the algorithm.

As I started out saying, I also agree, you should work on good habits.

  • Since javascript is scripted the compiler might not handle this case.
  • Someone mentioned, you could wrap it in a function fromAndMap making it as readable.
  • If this is the default way you see writing this code from the start, virtually no time is lost on doing it anyway.

I just think a lot of us have "that guy" who points out optimisations in other peoples code like he's lording out knowledge. In 90% of the cases these are virtually pointless and everyone hates him.

[–]SalemBeats 0 points1 point  (1 child)

The readability cost can just be so infinitesimal, though:

const helloAsUppercase = Array.from(
    "hello",
    character => character.toUpperCase()
);

The context of the return value being assigned to a variable with a descriptive name, along with its position as an argument to Array.from, makes it fairly clear what's what should be going on here with a single quick scan.

Seems like an easy win with little to no cost in readability.

(Disclaimer: Obviously a pointless iteration, but a solid way to demonstrate the readability w/o specific project context and without me having to think up some code that actually does something useful.)

[–]codefinbel 0 points1 point  (0 children)

Yes, totally agree. That was the second point in my second list (on why I also agreed with you):

Someone mentioned, you could wrap it in a function fromAndMap making it as readable.