11
potata
5y

I've lost hope in my precision at this point:

We've updated our website to have X feature. The X feature was implemented, tested and even had unit tests... The worst part when I've lost hope? Both unit and the actual code had the same mistake in them. What was the mistake? Well...

if($variable = 'something') {}

Yeah... Read it carefully... We've always had the same case and only noticed it after 3 months when it was attempted to extend.

Funny enough, few users were harmed but no actual reports of an issue came to us.

Since then, I'm always triple checking that I have the correct amount of `=` to avoid further fuck-ups

Comments
  • 3
    If the language itself permits assignments in an if-clause, i'ts rather a fact of bad language or compiler / interpreter design. If it is an intended feature , the compiler atleast should give you a warning, or introduce a new syntax to make it more verbose.
  • 5
    Try to use fira code font or similar. It displays double and triple equal very differently from single to make it easier to spot such mistakes.
  • 2
    @TheCPPanda To bad they did not go with pascals := for assignment, it would have made it harder to do wrong.
  • 1
    @TheCPPanda Yeah, It's true but still - shit happens :D
  • 0
    @Voxera Using it but you know, mistakes happen nonetheless
  • 2
    Ah, I've been there before 😂

    Although a coworker in used to work with use to do callback hell in if() statements

    If( ($x = json_decode(callSomeAPi($args), true) ) !== false){
    //welcome to hell
    SendXSomewhereElse($x);
    }

    I get so lost looking at these, and when there is multiple conditions and an assignment 😱🔫

    Fuck I hate php some days, but fuck I love php.
  • 0
    @TheCPPanda if we're speaking about modern practices, then you are probably right. There are some really clever uses of it in C though.
  • 1
    @C0D4 To be fair, I've had such cases:

    while($variable = DB_QUERY !== null) {}

    and it's pretty great after all but... At other times you can fuck up so much :D
Add Comment