The problem with hard-coding string constants

What I learned today — 2 March 2018

Niel de Wet
1 min readMar 5, 2018

“The OurObject obj could not be found”

This is not a response that you like to get from a remote system that you’re integrating with, especially if there’s no reference to “OurObject” in the API.

After a lot of hunting, asking for help and tracking down the bug in the remote system it turned out that there was a hard-coded “obj” value which should have been “OBJ”, in upper-case.

Of course, the solution to this type of thing is simple. Use constants for these values, and reference them everywhere you need to pass the value. Even better, use an enum and transform that to a string at the last responsible moment.

--

--

No responses yet