3 ms·
It is mentioned in the comments, but bears repeating here- The author's example of "overly verbose" Java is rather unfair. Compare the 11-line example with loa
by RodgerTheGreat 17y ago
It is mentioned in the comments, but bears repeating here-
The author's example of "overly verbose" Java is rather unfair. Compare the 11-line example with loads of temporary variables to something like this:
Set results = new SortedSet();
for (Method m : String.Class.getMethods()) {
if (m.getName().toLowerCase().contains("index")) {
results.add(m.getName());
}
}
return results.toArray();
- AndrewDucker 17y agoI had a play with LINQ in C# to see how similar I could make it: After adding a couple of extension methods (to make the syntax more similar) I can write: from methodName in "".MethodNames() where methodName.Grep("index",RegexOptions.IgnoreCase) orderby methodName select methodName; in C#
- AndrewDucker 17y agoAnd an even simpler one: "".MethodNames().Where(m => m.Grep("index",RegexOptions.IgnoreCase)).OrderBy(m => m)