Need for language library?
http://svn.slightlymagic.net/websvn/dif ... &peg=20728
I was looking at all that beautiful string builders, and realzied that if we always build such pretty texts, we'll either copy-paste hundreds of lines or write a special library to perform common tasks.
1. Join homogeneous parts of the sentence.
Let me name advantages of use of a library: less duplicate code, easier localization to different languages - a single change of rules for text compisition for italian or whatever, will be better than any action on currently scattered texts.
Disadvantages: more complicated texts composition (one will have to look for a method for propper conjuction of lexical forms instead of just typing the strings),
This will be effective only if every developer adopts the system.
I was looking at all that beautiful string builders, and realzied that if we always build such pretty texts, we'll either copy-paste hundreds of lines or write a special library to perform common tasks.
1. Join homogeneous parts of the sentence.
- Code: Select all
final StringBuilder fetcherSB = new StringBuilder();
for (int i = 0; i < fetchers.size(); i++) {
fetcherSB.append(fetchers.get(i).getName());
fetcherSB.append((i + 2) == fetchers.size() ? " and " : (i + 1) == fetchers.size() ? "" : ", ");
}
final String fetcherNames = fetcherSB.toString();
- Code: Select all
sb.append(" search").append(choosers.size() > 1 ? " " : "es ");
- Code: Select all
String fetchPlayer = fetcherNames;
if (chooserNames.equals(fetcherNames)) {
fetchPlayer = fetchers.size() > 1 ? "their" : "his/her";
}
Let me name advantages of use of a library: less duplicate code, easier localization to different languages - a single change of rules for text compisition for italian or whatever, will be better than any action on currently scattered texts.
Disadvantages: more complicated texts composition (one will have to look for a method for propper conjuction of lexical forms instead of just typing the strings),
This will be effective only if every developer adopts the system.