26

We lo race conditions ve

Comments
  • 0
    @AndSoWeCode Say that to linux and the cowroot-Bug. 😂
    It's not that easy with multi-cores.
  • 1
    @AndSoWeCode I am JS dev by trade, so single threaded all the way.

    Learning C on the side, I did a project at uni and enjoyed it, so having a crack at it again
  • 1
    @AndSoWeCode there aren't really any race conditions like the one I mentioned above. It is kind of annoying that things aren't so deterministic with async code though.

    Also Async code in NodeJS is non-blocking. I can easily consume apis and read files at the same time. With promises and async/await this can even be coded in synchronous style.
  • 1
    @AndSoWeCode not sure what you mean specifically (maybe provide a code example if you have time?). If you're talking about aysnc code then that's a pretty shitty way to code JS.

    Using immutable data functions is an easy way to avoid that sort of problem
  • 1
    @AndSoWeCode premature optimisation is the spawn of the devil. Modern CPUs are blazingly fast. Code readability and maintainability should take priority.
  • 0
    With that being said, if optimisation is required, no doubt locks could be useful for async code
  • 0
    The app I work on is non-trivial. The stack is mostly functional style.

    Functional has many advantages over imperative, namely async code is a breeze to deal with without resorting to locks. Pure functions are reasonable, maintainable and highly testable. Same input, same output, every time. I can compose functions independly, pipe them though each other, map, reduce, filter.

    Sure there are some overheads, but that's a good price for what I get
  • 0
    Build the app, and then profile it, and one sees where the real bottlenecks are.

    Or else it's probably just a waste of time
  • 0
    @AndSoWeCode

    In fairness my knowledge of locks are from a few embedded systems lectures back at uni

    sounds like you work with very different kinds of projects.

    I tell you what, next time I'm programming a resource intensive async on low memory I will endeavour to learn imperative style and locks.

    For the moment though, unfortunately React can't really be coded without maps or functional style. But hey, benchmarks are still good so I'm happy.
  • 0
    @AndSoWeCode

    Say I want to remove all odd numbers from an array

    Exibit a:

    function removeOdds(nums) {
    const newArr = [];
    for (let i = 0, l = nums.length; i < l; i+=1) {
    if (nums[i] % 2 === 0) {
    newArr.push(nums[i]);
    }
    }
    return newArr;
    }

    Exibit b:

    const isEven = num => num % 2 === 0;
    const removeOdds = arr => arr.filter(isEven)
Add Comment