Three types of programmers that I know of
I'm not sure how many types of programmers there are.
I used to work with a guy that believed that the only real programming language was assembly.
1) so we have those that believe its assembly or nothing.
I don't want to condone violence, specially against someone for something that in the grand scheme of things really is just a job.
But I did work with a guy that believed that anyone that didn't write test cases should be lined up against a wall and shot.
2) those that write tests case and those that don't.
And then we get to the crux of this post.
3) those who use constants and those that don't.
I think most developers would agree constants are good and help make the code more understandable. Of course that's not the same as saying everyone uses them.
We already have a rule that suggests that you need to convert "magic strings" into constants. We call it a "hard coded mapping". But in essence we are looking for strings that could be constants.
This means that we can help developers work out which pieces of code should be made into constants.
But then like anything, you can take it to far.
I came across code like this the other day - in 3 different files:
DECLARE AUSTRALIA CONSTANT CHAR 'AUSTRALIA';
...
DECLARE CNTRY_AUSTRALIA CONSTANT CHAR 'AUSTRALIA';
.....
DECLARE COUNTRY_AUS CONSTANT CHAR 'AUSTRALIA';
So, if you declare something as a constant, and you have a constant for the same value 3 times, by definition, is it still a constant ?
Maybe. But I think it should fit the definition of confusing.
So we added a new rule.
R361 – An ESQL CONSTANT with that value is already declared (WMB)
It's like code duplication checking but at a string level.
So I know next time I declare a constant in my code, I think i'll go searching for it with NotePad++ first. Just not to fall into the same trap. So hopefully someone next year isn't writing a LinkedIn post about me - or at least my code.
If you are interested in finding out more about our product or were interested in a demonstration, please drop me an email to:
Or contact me via the contact page on our website.
Regards
Richard