100 Days of Improving Coding Style
Milan Saxena
255

You shouldn’t write long names just because editors help you with that. We sure have tools that automate typing, but none that automate reading.

Most of the time you have to write something like `variableThatMeansSomethingAndAlsoSomethingDependingOfTheMoonPhase`, you should stop and reconsider. I see this patient example as faulty, because you sedate patient, not the tumor, and the tumor position has nothing to do with sedation itself. These things are orthogonal, so they should be separated.

The second thing is `patient`. What patient? If it’s a specific patient, than it should be mentioned, if not — it shouldn’t be mentioned at all. Shouldn’t it be a structure instance then, or an object if you prefer?

Now should tumor be position set as rightSideOfTheBrain or leftSideOfTheBrain. Well, of course not, but there are ways to set patient position currently used in medical software, which are similar in nature. Like `Decubitus left` meaning patient lying on the left side, or `Decubitus right`when on the right. Note that this relates to the patient, not the tumor, as you definitely want more precise way to position the tumor than left or right.

So I see patientIsSedatedWithTumorOnLeftSideOfBrain not as a boolean, but:

tumor_patient. position = DECUBITUS_RIGHT;

tumor_patient.is_sedated = true;

It is more precise, more malleable and it doesn’t require any long names.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.