I don't see a difference in functionality — both code snippets I gave do exactly the same thing.
As for brevity, I think clarity is more important. We should optimise for the time it takes to read and understand the code (clarity), not just read (brevity).
The best abstractions and programming language features are both brief and clear, like Python's list comprehensions. I find
[name.uppercase() for name in names if name.startswith("a")]
to be clearer than Java's
List<String> uppercaseNames = new ArrayList<>();
for (String name: names) {
if (name.startsWith("a")) uppercaseNames.add(name.toUpperCase());
}
So, the best programming language features enhance both brevity and clarity. When that's not possible, I'll take slightly longer but clearer code over short but confusing one.
As for brevity, I think clarity is more important. We should optimise for the time it takes to read and understand the code (clarity), not just read (brevity).
The best abstractions and programming language features are both brief and clear, like Python's list comprehensions. I find
[name.uppercase() for name in names if name.startswith("a")]
to be clearer than Java's
List<String> uppercaseNames = new ArrayList<>();
for (String name: names) {
if (name.startsWith("a")) uppercaseNames.add(name.toUpperCase());
}
So, the best programming language features enhance both brevity and clarity. When that's not possible, I'll take slightly longer but clearer code over short but confusing one.