uwolnić się od "if"
TRANSCRIPT
Uwolni si od if
$flag="OK"; // This is the flag and we set it to OK
http://roflcopter.pl/6025
$flag="OK"; // This is the flag and we set it to OK
Tomasz Nurkiewicz
5+ lat z Jav
...Scala, JavaScript
SCJP, SCJD, SCWCD, SCBCD
60K+ rep. na StackOverflow
Commiter projektu Logback
nurkiewicz.blogspot.com
scala.net.pl
Ale dlaczego?
null twj wrg
com.google...Optionalscala.Option[T]Data.Maybe
flagi, wajchy, tryby, przeczniki
instanceof
Najlepsz dobr praktykjest zdrowy rozsdek
if(v > 10 ) size = 6;if(v > 22 ) size = 5;if(v > 51 ) size = 4;if(v > 68 ) size = 3;if(v > 117) size = 2;if(v > 145) size = 1;return size;
http://stackoverflow.com/questions/3786358
int getSize(int v) { int[] thr = {145, 117, 68, 51, 22, 10};
for (int i = 0; i < thr.length; i++) { if (v > thr[i]) return i+1; } return 1;}
public class Mapper {
private final S[] source; private final T[] target;
// Builder to enable from... to... syntax and // to make Mapper immutable public static class Builder { private final S2[] data; private Builder(final S2[] data){ this.data = data; } public Mapper to(final T2... target){ return new Mapper(this.data, target); } }
private Mapper(final S[] source, final T[] target){ final S[] copy = Arrays.copyOf(source, source.length); Arrays.sort(copy); this.source = copy; this.target = Arrays.copyOf(target, target.length); }
// Factory method to get builder public static Builder from(final U... items){ return new Builder(items); }
// Map a collection of items public Collection mapAll(final Collection