Boiling out Boilerplate

Boilerplate

Boilerplate

@interface Foo : NSObject {
  Bar *_bar;
}
@property (retain) Bar *bar;
@end

@implementation Foo
@synthesize bar = _bar;

- (void)dealloc {
  [_bar release];
  [super dealloc];
}
@end

149 chars

Boilerplate

 
public final class Foo {

  private final Bar bar;

  public Bar getBar() {
    return bar;
  }

  public Foo(Bar bar) {
    this.bar = bar;
  }
}

101 chars

JSR 269

@AutoValue
public abstract class Foo {



  public abstract Bar getBar();



  public static Foo create(Bar bar) {
    return new AutoValue_Foo(bar);
  }
}

119 chars

JSR 269

@AutoValue
public abstract class Foo {



  public abstract Bar getBar();



  public static Foo create(Bar bar) {
    return new AutoValue_Foo(bar);
  }
}

119 chars

Boilerplate

 
public final class Foo {

  private final Bar bar;

  public Bar getBar() {
    return bar;
  }

  public Foo(Bar bar) {
    this.bar = bar;
  }
}

101 chars

Lombok


public class Foo {

  Bar bar;
}









23 chars

Lombok

@Value
public class Foo {

  Bar bar;
}









29 chars

Lombok

@Value
public class Foo {

  Bar bar;
}









29 chars

Groovy

 
class Foo {

  Bar bar
}









16 chars

Groovy

@Immutable
class Foo {

  Bar bar
}









26 chars

Talk is cheap,

show me the code!

Wrap up

  • Annotation Processing API

Wrap up

  • Annotation Processing API

  • Lombok & Hrisey

Wrap up

  • Annotation Processing API

  • Lombok & Hrisey

  • Groovy

Wrap up

  • Annotation Processing API

  • Lombok & Hrisey

  • Groovy

  • Talk is cheap

Wrap up

  • Annotation Processing API

  • Lombok & Hrisey

  • Groovy

  • Talk is cheap

  • Wrap up

Wrap up

Thank You && Q || A

Boiling out Boilerplate / DroidCon Zagreb 2015

By Maciej Górski

Boiling out Boilerplate / DroidCon Zagreb 2015

  • 1,881