5 ms·
This is, because you can't Java. How you will find out, where you use first_names = [p.first_name for p in people] ? More verbose, but right way in Java is
by exelib 14y ago
This is, because you can't Java. How you will find out, where you use
first_names = [p.first_name for p in people]
? More verbose, but right way in Java is like (you can do this better with enums and/or guava, it's just example):
class PersonTransformer implements Transformer {
public Object transform(Object o) {
return ((Person)o).getFirstName();
}
}
and then:
Collection<String> firstNames = CollectionUtils.collect(people, new PersonTransformer());
You can reuse it and, more important, you can search for it. Same for second example.
- rbanffy 14y agoWhy would you want to reuse a construction so trivial? Why would you want to search for it? A couple days back I commented Java, by making some things harder than needed, induces programmers to over-engineer and build things for needs they don't have and to think that's perfectly normal. Think about what you just wrote.
- exelib 14y agoBecause it's DRY-Principle. It's doesn't matter trivial or not. If you distribute you 'trivial' constructions over whole application, you doesn't have any chance to have consistent, robust processing. If you collect/group things logically, you can easy find out where you (re)use constructions and what you can break, if you change it. It's not over-engineering, it's just how to deal with >300 People and >6 years projects and not to have "design dead software".
- rbanffy 14y agoIt's just a list comprehension. Do you imply I should use a function instead? Why not use a very nice syntax feature every Python developer can understand? Because if you do, I'd advise you not to add integers with the "+" operator, but, instead, build a class with various add methods for different types of arguments or, better yet, build add methods into every class you define so that you can better search for them. This approach would allow you to add things that aren't integers or even not the same type on both sides of the operator.
- exelib 14y agoI give up. You're like a little kid. Codesize or verbosity doesn't matter. Quality is a keyword and it resulting in sustainable pace. If you doesn't understand this, nobody can help you. Your arguments are like as "Why I should use TDD, if I can write code directly".
- rbanffy 14y agoYou call me a kid because you claim using a single line syntactic feature of a language isn't maintainable. It's like claiming for loops are unmaintainable and that we should wrap them inside methods. It's not people hating Java: it's you afraid of looking at other tools.
- beothorn 14y agoorangecat example is type safe, your example trades a "compile time" error for a runtime error.
- exelib 14y agoPython isn't type safe (but Scala). Especially for you I wrote "you can do this better with ... guava, it's just example" :)
- runT1ME 14y agoAre you really arguing that the 'java' way in your example is superior to Scala's