• 6 Posts
  • 113 Comments
Joined 2 years ago
cake
Cake day: July 23rd, 2023

help-circle






  • poettering is an absolute good guy here

    Agreed. But he’s also an abrasive know-it-all. A modicum of social skills and respect goes a long way towards making others accept your pet projects.

    pulesaudio protocol is used within pipewire and it works just fine.

    I wasn’t talking about the protocol, I was talking about the implementation: PulseAudio is a crashy, unstable POS. I can’t count the number of hours this turd made me waste, until PipeWire came along.



  • I totally agree. I used to hate systemd for breaking the traditional Unix philosophy, but the reality is that a tight init and service-tracking integration tool really was required. I work with and appreciate systemd every day now. It certainly didn’t make things simplier and easier to debug, but it goes a long way towards making a Linux system predictable and consistent.

    Poettering can go fuck himself though - and for PulseAudio too. I suspect half of the hate systemd attracted over the years was really because of this idiot.





  • But what is an example of where I can use it?

    Aside from operations on bitfields, a bitwise operator can be useful in several “non bits” cases. For instance:

    value & 1 evaluates to 1 if value is odd (and will evaluate to True in an if statement)
    value >> 1 divides value by 2 (integer division)

    But usually bitwise operators are for when you want to manipulate bits in values. For instance:

    value | 5 returns value with bits 1 and 3 set to True
    value & 0xffff returns the 16 least-significant bits in value (usually you do this to make sure it will fit in 2 bytes in memory for example)
    value & (0xffff ^ 5) returns the lower 16 bits of value with bits 1 and 3 set to False

    Etc.


  • Much to unpack here…

    coin == 25 | 10 | 5

    …will evaluate as True if coin is equal to the bitwise OR of 25, 10 and 5 - i.e. 31. In other word, it’s equivalent to coin == 31. That’s because the bitwise OR has precedence over the == operator. See operator precedence in Python.

    If I replace the ‘|’ with ‘or’ the code runs just fine.

    It probably doesn’t. If you replace | with or, you have the statement coin == 25 or 10 or 5 which is always True in the if statement because it’s evaluated as (coin == 25) or (not 0) or (not 0) in an if statement.

    coin == 25 | coin == 10 | coin == 5

    …will evaluate as coin == (25 | coin) == (10 | coin) == 5. Again, operator precedence.

    What you want to do is this:

    if coin in [25, 10, 5]:

    or

    if coin in (25, 10, 5):

    or simply

    if coin == 25 or coin == 10 or coin == 5:

    Don’t create problems and confusion for the next guy who reads your code for nothing. Simple and readable are your friends 🙂