3 Patterns for Cleaner Code
Recorded at:
This is basic programming pratice
by
Wouter Vos
Re: This is basic programming pratice
by
Olmo del Corral
Transformer -> .Select()
Classifiers -> .GrupBy()
...
msdn.microsoft.com/en-us/library/bb394939.aspx
The points have existed in Functional Programming very long time.
by
cai chao
it seems we can always get the lights from our ancestor.
Still a valuable and necessary talk apparently
by
Johanna Belanger
Re: Still a valuable and necessary talk apparently
by
rajesh parab
This is exactly what developers needs,
Many new generations of developers don't know this or not taking any pain to learn that.
I often see during code review people are not following this rules.
Good and very helpful presentation.
Excellent presentation
by
rajesh parab
code. I enjoy this presentation. It helps me to know I am on right track.
Even apache collections has library for predicates which was not mentioned in presentation.
But this is how presentation should be.
many presentation has nice title but I found them boring.
or some presentation might be for certain class.
Re: Excellent presentation
by
Sanjeev Karani
Please share these code samples as I am interested in implementing the predicate approach for filtering objects
Re: Excellent presentation
by
dharmi sarkar
-Dharmi
Re: Excellent presentation
by
Cory Maksymchuk
Cheers,
Cory Maksymchuk
Google Guava
by
Nick Talbot
Unnecessary third type parameter?
by
Søren Palmund
T3 is only ever used to declare Collection<T3>. Could you not write the declaration as Collection<T1> which would basically be the same since T3 extends T1.</t1></t3>
Re: Unnecessary third type parameter?
by
Cory Maksymchuk
The code below uses Objects and Integers (which are Objects) to keep the code small. Without the T3 parameter, the code below will not compile.
public class Test
{
public static void main(String[] args)
{
List<Object> objectList = new ArrayList<Object>();
List<String> stringList = CollectionUtil.transform(objectList, OBJECT_STRING_TRANSFORMER);
List<Integer> integerList = new ArrayList<Integer>();
stringList = CollectionUtil.transform(integerList, OBJECT_STRING_TRANSFORMER);
}
public static Transformer<Object, String> OBJECT_STRING_TRANSFORMER = new Transformer<Object, String>() {
@Override
public String transform(Object input) {
return input.toString();
}
};
}
public final class CollectionUtil
{
public static <T1, T2, T3 extends T1> List<T2> transform(Collection<T3> input, Transformer<T1, T2> transformer)
{
List<T2> output = new ArrayList<T2>();
// for some reason infoq wont allow double equals here so wrote in the word instead
if (input doubleequals null)
{
return null;
}
for (T1 t1 : input)
{
output.add(transformer.transform(t1));
}
return output;
}
...
}
</t2></t2></t1,></t3></t2></t1,></object,></object,></integer></integer></string></object></object>
Guava
by
Johan B
Predicate
Function (Transformer)
Multimaps.index (Classifier)
The classifier interface is superfluous since a Function does the same thing. It takes an object of type A and return an object of type B.
Re: Google Guava
by
Johan B
Re: Unnecessary third type parameter?
by
Søren Palmund
I found your presentation very engaging. Have you done other presentations like this?
Re: Unnecessary third type parameter?
by
Cory Maksymchuk
Cheers,
Cory




Hello stranger!
You need to Register an InfoQ account or Login to post comments. But there's so much more behind being registered.Get the most out of the InfoQ experience.
Tell us what you think