sanjar-notes / programming

A high level view about programming. Its use, need and implementation scenarios.
Creative Commons Zero v1.0 Universal
0 stars 0 forks source link

Use generators for drop-in and non-ugly optimization? #11

Open sanjarcode opened 11 months ago

sanjarcode commented 11 months ago

Code like

const wordInSentence = 
  sentence
    .split(' ')
    .find(word => _someCriteria)

This is O(n) memory solution. But the problem could be solved in O(1) memory using a loop.

Generator behavior - like in Python, JS could solve this.

  1. Why don't we have such code then?
  2. Would it impact ability to debug, inspect running code?
  3. Would doing this from the start affect barrier to entry?
  4. Can this optimization be done as a drop-in (syntactic) action to a codebase? If yes, what part (percentage) cannot be automated by a tool that does this syntactic migration.

Think