dorony
dorony

Reputation: 1072

Naming convention for parameters with/without, causing confusion bugs?

I have two parameters in a class called: textWithHeader and textWithoutHeader and they are very confusing names! adding the fact that the get method is getTextWithoutHeader() + the IDE autocomplete it's pretty easy the mixed between them.

In a few places in the code, some developers got mixed between them causing some really difficult bugs in the systems.

Is there any naming convention for this type of parameters?

Good, but no cigar:

Upvotes: 0

Views: 158

Answers (2)

noamdayan
noamdayan

Reputation: 173

I'd suggest calling them headerlessText and textWithHeader You keep the meaning, but the names are different enough, not to confuse.

Upvotes: 2

Bathsheba
Bathsheba

Reputation: 234635

Well they don't look confusing: to me at least.

They follow Java's "camelCase" conventions for variables and are sufficiently descriptive. There's not much else you can do.

Although if you want to stop implicit conversion of the two things you could always wrap them in separate classes:

class TextWithHeader
{
    public final String s;
}

class TextWithoutHeader
{
    public final String s;
}

Perhaps then, your TextWithHeader class could even provide a method getTextWithoutHeader()?

Upvotes: 1

Related Questions