magic_lobster_party

  • 0 Posts
  • 73 Comments
Joined 4 months ago
cake
Cake day: August 15th, 2024

help-circle
  • Writing maintainable code is an art form. Like most art forms it can mostly only be learned by practice. So if you don’t have much experience maintaining long lived systems, it’s difficult to know what works and what doesn’t. Most universities don’t teach this as well, so it’s mostly something people learn in the industry.

    Then I believe there’s also some aspect of pride in writing overly complicated code. It’s the belief that ”other people can’t comprehend my code because they’re not as smart as me”, when it’s actually ”I suck at writing comprehensible code”.



  • I’ve haven’t had a burnout (knocks wood), but the most toxic environment I’ve worked in had tight deadlines, unclear requirements and many last minute changes on features that ultimately didn’t mattered. Combine this with long and tedious release processes and narrow release windows. If a bug slipped through our (not so robust) testing process, it was difficult to fix it.

    It felt like the priorities were all wrong. Instead of improving the product for existing customers and improve our release process, it was all about adding pointless features some ”potential buyer” asked for (they never bought the product either way).

    Now I work in a much better workplace, thankfully.



  • Basically it’s just an optimization of a double nested for loop. It’s a way to avoid running the inner for loop when it is known there will be no hit.

    This is useful when we for example want to find all product orders of customers in a particular country. The way we can do this is to first filter all customers by their country, and then match orders by the remaining customers. The matching step is the double for loop.

    Something like this:

    for order in orders:
        for customer in customers_in_country:
            if order.customer_id == customer.id:
                …
    

    Many orders won’t match a customer in the above query, so we want to single out these orders before we run the expensive inner for loop. The way they do it is to create a cache using a Bloom filter. I’d recommend looking it up, but it’s a probabilistic cache that’s fast and space efficient, at the cost of letting through some false positives. With this particular use case it’s ok to have some false positives. The worst thing that can happen is that the inner for loop is run more times than necessary.

    The final code is something like this:

    bloom_filter = create_bloom(customers_in_country)
    for order in orders:
        if bloom_filter.contains(order.customer_id):
            for customer in customers_in_country:
                if order.customer_id == customer.id:
                    …
    

    Edit: this comment probably contain many inaccuracies, as I’ve never done this kind of stuff in practice, so don’t rely too much on it.


  • I hate when coworkers tell we should do thing in a particular way because it’s ”better”. We try the thing and there’s no measurable difference. Well, it was a good idea in their mind, so it must be an improvement. Therefore, they insist it should be kept, even if it makes the code extra convoluted for no reason at all.

    And yes. Profiling is great. Often it is a surprise where most time is spent. Today there’s few excuses not to profile since most IDEs have good enough profiler included.




  • I agree with the first point. Always go for clarity over cleverness.

    I somewhat disagree with the second point. Consistency is important. Stick with the same name when possible. But I think mixing camel case and snake case should be avoided. It can make the code less ”greppable” IMO, because now you need to remember which casing was used for each variable.

    Kind of agree on the third point. I think flatness should be preferred when possible and when it makes sense. Easier to find the variables with the eyes rather than having to search through nested structures.






  • This is just so wrong. He’s too nostalgic of the Amiga days.

    First, he has no concrete proof that many lines of code is bad. He’s just saying “I feel like things are worse now and here’s a graph that correlates with my feelings”.

    And then he shows a graph of the number of lines in the Linux kernel. Yeah, Linux grew in size mid 90s because that was when people wanted to make it work on computers other than Torvald’s own!

    Secondly, no one wants to plug in an USB and grant whatever is in it full machine access. It’s a major security concern, and people want multitasking. What if I want to listen to Spotify while I play my game?

    The USB thing is likely not going to work either way because it can’t take into account for all possible configurations. Too bad, this program doesn’t recognize your specific WiFi card. You have to survive without internet.

    Unless someone manages to perfectly standardize everything that can possibly happen in a computer. That ain’t going to happen.