9
Mb3leb
5y

Do you all look for code complexity O(n) while coding? Or you make sure that your code runs and never look back what's happening ?

Because as per code review no one looks for code complexity and that's so sad

Comments
  • 5
    I tend to make the most efficient code all the time, I'm still trying to make stuff run smoothly in every occasion, my websites get awesome score on page speed.

    But when I have to run stuff in the backend, OMG, I put so much shit in there...
  • 2
    Only when I’m refactoring
  • 3
    I almost always go for readable code, both coding and in CR.
  • 10
    Real world problems are not that elementary that you could put them in a simple O-notation.

    You have dependencies, sequential processes, parallel workloads, etc.

    And there are also just the practical things like tools that run once a day or once a week where no one ever cares if that thing runs 2 seconds or 2 minutes.

    Also, most use cases do not process the content of a Google Data Center, so O(n) and O(n²), maybe even O(2^n) doesn't make a big difference.
  • 3
    When i started to work as dev i was always trying to make efficient code. But now... man. If it runs i'm satisfied. It depends on the project and the environment too.
  • 2
    @jorgeMachado hahahahah well i feel you
  • 2
    Yeah if I have stuff where complexity applies, I don't over-optimise early on, but I will still choose a decent base algo so that this won't become a bottleneck later. It's way too often that shit has to handle much more data than the devs had anticipated.

    I even avoid stcrcat() in loops on the same string because that's a hidden n^2. Instead, I use a custom strcpy that returns a pointer to the end of the string.

    Or, last month when I used qsort and bsearch to get to n*log(n) where the naive implementation would have has n^2.
  • 1
    @Fast-Nop that's the correct way but don't you think that this structure might take more time to find a solution where O complexity is N
  • 2
    @Mba3gar you just can't always reac O(n). But at least, you should avoid O(n^2) or worse.

    I once had a thing at work where shit was done in PHP on XML on the server, and it worked with a few dozen items, but for several thousand ones, it failed after 1.5 hours. So I rewrite that shit properly and in C, then it took 7 seconds. Prime example where the original devs should have given more thought.

    Here is the rant: https://devrant.com/rants/1993396/...
  • 2
    @Fast-Nop what you do is smart
  • 1
    Test, implement, optimize.
Add Comment