Cześć,
Pracuję ostatnio nad poprawą czytelności mojego kodu, mam więc pytanie. Jak oceniacie czytelność kodu zamieszczonego poniżej
public static String swapEveryTwoLetters(final String wordIn) {
if (wordIn != null) {
if (wordIn.length() == 0) {
return "Error: The word is epmty!";
} else if (wordIn.length() == 1) {
return wordIn;
} else if (wordIn.length() >= 2) {
char[] wordOut = wordIn.toCharArray();
int firstLetterIndex = 0;
int secondLetterIndex = firstLetterIndex+1;
int lettersDistance=2;
do {
swapLetters(wordOut,firstLetterIndex,secondLetterIndex);
firstLetterIndex += lettersDistance;
secondLetterIndex = firstLetterIndex + 1;
} while (secondLetterIndex < wordIn.length());
if (wordLengthIsOdd(wordIn)) {
wordOut[firstLetterIndex] = wordIn.charAt(firstLetterIndex);
}
return new String(wordOut);
}
} else {
return "Error: The word is null!";
}
return "Why?"; //1
}
Jeszcze jedno pytanie odnośnie kodu:
Dlaczego nie kompiluje się jeżeli usunę linię z komentarza 1?