News for hackers. Stuff that matters.
Re:Write More Classes by benrhughes on Tuesday February 12, 2013 @12:26AM (#5205340)
FWIW, with C#'s object initialisation syntax you can cut that down to once too. eg

  public class Foo
  {
     public string Bar { get; set;}
  }

  var foo = new Foo { Bar = "Hey there" };
Re:Write More Classes by Uchikoma on Tuesday February 12, 2013 @01:38AM (#5205531)
I've come to love Scala case classes:

  case class Foo(bar: String, foo: String = "hello")
  new Foo(bar = "Hey there")
  new Foo(foo = "Hey there", bar = "Hello")
  new Foo("Hey there")
Re:Write More Classes by hythloday on Tuesday February 12, 2013 @10:12AM (#5207249)
Case classes, I believe, have a companion object with an apply method build for them, so you can get it down to:

  case class Foo(bar: String, foo: String = "hello")
  val f1 = Foo(bar = "Hey there")
  val f2 = Foo(foo = "Hey there", bar = "Hello")
  val f3 = Foo("Hey there")
Re:Write More Classes by Uchikoma on Tuesday February 12, 2013 @11:39AM (#5207843)
You're right!