all 12 comments

sorted by: hot top controversial new old
[–] 8 points 6 months ago (3 children)

When you start to bump into any of these concerns, I'd recommending extracting the functions themselves, rather than breaking the pipeline... which was not something mentioned or explored.

  • source
  • hideshow 3 child comments
  • [–] 5 points 6 months ago (2 children)

    One can definitely go overboard with this, though. I have had to read a lot of code where someone broke something up into several functions that only had the effective of forcing me to constantly bounce around all over source file to figure out what was going on without improving clarity at all.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 5 points 6 months ago (1 child)

    Ugh, SonarQube with the cognitive complexity check.

    "Instead of having 50 lines where all logic is right here, I'mma need you to break it up into 10 separate functions so it's a massive pain in the ass to figure out what the fuck is going on"

    I understand the reasoning but sometimes it's way more confusing to split up complex logic instead of just having it all in one place.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 3 points 6 months ago

    I disagree with this article for the same reasons as everyone else.

    I'll also add it's possible to add comments between each line of the pipeline.

    I aslo use promise chaining as pipeline pattern for non-chainable calls, as described here : https://blog.kaki87.net/promise-based-pipe-in-js/

  • source
  • [–] 6 points 6 months ago* (last edited 6 months ago) (3 children)

    Only tangentially related, but I dislike that filter and map are eager in JS. Meaning if you chain them, you allocate N-1 arrays that are being discarded right away. C#, Java and Rust have the right approach.

  • source
  • hideshow 3 child comments
  • [–] 3 points 6 months ago (2 children)

    Are they eager even with generators?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 6 points 6 months ago (1 child)

    You made me go down the rabbit hole with that question. TIL the very same methods exist on Iterator's prototype. They aren't eager, no.

    You can get an iterator out of an array with Array.prototype[Symbol.iterator]() and you can collect an iterator into an array with Iterator.prototype.toArray().

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 6 months ago

    One reason you may not have known this is that these (iterator methods, not the Iterator itself) are newish additions to Javascript and only available in all the big browsers for just over 1 year.

  • source
  • parent
  • [–] 4 points 6 months ago (1 child)

    Ugh, I absolutely hate reading code with a ton of variables that are only used once, because each introduction of a variable is a new thing that I have to first parse and then track to figure out what it does. I would much rather read a pipeline that expresses what is going on concisely without introducing extraneous elements. In particular, I thought that the pipeline at the start of the article was perfectly clear and did not need any of the subsequent modifications.

  • source
  • hideshow 1 child comment
  • [–] 2 points 6 months ago

    I think using a better variable name for the "pipeline" result is a much better approach

  • source
  • 3 comments in c/hackernews@lemmy.bestiver.se view that post
    [–] 1 point 6 months ago

    In array languages (APL -- the Dyalog variant -- not classic APL/2, BQN, J, ...) there's been a trend towards 'tacit' aka 'point-free' syntax, where many ops are combined/composed to avoid the need for named variables.

    Unpopular opinion time: I don't like it. As this article says, it's fine for short, simple chains but becomes inscrutable if overused.

  • source
  • [–] 1 point 6 months ago (1 child)

    This should have never been done in the first place.

  • source
  • hideshow 1 child comment
  • [–] 1 point 6 months ago

    Yeah glad they figured this out but largely this kinda stuff does not pass code review for me specifically because of the negligible extra work to make your code infinitely more readable and easier to debug later.

  • source
  • parent