Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


The 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.


Especially since modern compilers will warn about the problem you are trying to prevent by putting the constant on the left side.


It 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...


your C compiler will also throw an error on that if you're using -Wall -Werror. Which you are, right?


Heavy handed, sure... maybe even micromanaging, but not an unreasonable idea.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: