Q – unpredictable global vars

The behaviour of the Q language can often be unpredictable and unintuitive, leading to numerous ways to shoot yourself in the foot. I think every developer has a piggy bank with such cases. Here’s one example:

As you can see, we defined function with 2 local variables, but variable b suddenly became global.

The interesting thing is if we already have global variable “b” set, it will be affected anyway, unexpected appearance/amendment of the global vars can be an unfortunate surprise. So the best way – have it initialised inside of the function.

Leave a Reply

Your email address will not be published. Required fields are marked *