7 ms·
I think it's a fair statement to prefer the OO paradigm, and indeed it is good for a whole load of things in programming. Nonetheless, adding lambdas to Java sh
by GlennS 15y ago
I think it's a fair statement to prefer the OO paradigm, and indeed it is good for a whole load of things in programming. Nonetheless, adding lambdas to Java should give plenty of easy wins even if you prefer your code to be broadly OO.
Look through your for and foreach loops. I bet a lot of them would be neater, more readable, and better express intent as some combination of map and filter.
Count how many classes you have with only one method and no data in them. Would you really make separate classes for all of those if you had the option to pass them around as functions?
I would also like to see something like the yield and yield! (yield every item in this collection) keywords, because those can give readability improvements in a lot of places too, but one step at a time.
- mayanksinghal 15y ago> Count how many classes you have with only one method and no data in them. I have never done this, but for the usecase that you have mentioned, would the following work? class Xyz { private Type type; private RetType type1MethodName(params) { // Do Whatever } private RetType type2MethodName(params) { // Do Whatever } public Xyz(type) { this.type = type; } public RetType methodName(params) { switch(type) { type1: return type1MethodName(params); type2: return type2MethodName(params); } } public enum Type { type1; type2; } } And then when we want to pass methods according to types, we can just instantiate the class with a proper type and pass it.