3 ms·
I was told not to use constants on the left hand side of an expression e.g., if("hello"==strVar) and was made to change it throughout my code. Needless to say I
by sarvesh 17y ago
I was told not to use constants on the left hand side of an expression e.g., if("hello"==strVar) and was made to change it throughout my code. Needless to say I quit after making that change.
- inimino 17y agoThe alternative 'if(str=="hello")' is so much more common as to be a de facto standard, and if a shop decides to enshrine this common convention in their coding standards and enforce it, I don't see that as unreasonable. Certainly not something you should quit over.
- brl 17y agoEspecially since modern compilers will warn about the problem you are trying to prevent by putting the constant on the left side.
- solutionyogi 17y agoIt makes sense if you are using C. If you are using something like C#, compiler will throw an error (not warning) if you write if(str = "hello") See: http://stackoverflow.com/questions/655657/0-variable-or-null-obj-an-outdated-practice-in-c http://stackoverflow.com/questions/655657/0-variable-or-null...
- kscaldef 17y agoyour C compiler will also throw an error on that if you're using -Wall -Werror. Which you are, right?
- Oxryly 17y agoHeavy handed, sure... maybe even micromanaging, but not an unreasonable idea.