logo      
Custom Search

Re: Maps in scala --> PLEAC --> Literals

Date: December 31, 2006
From: Jamie Webb <j@xxxxxxxxxxxxxxx>

In-reply-to: <45976DC8.1030103@xxxxxxxxxxxxxx>
References: <20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx> <8071592.post@xxxxxxxxxxxxxxx> <5ba551214e573327ebc72e87ad1779a2@xxxxxxxxxx> <45964CE9.4060109@xxxxxxx> <45976DC8.1030103@xxxxxxxxxxxxxx>

On Sun, Dec 31, 2006 at 07:59:04AM +0000, Andy Dwelly wrote:
> Panel p = new Panel(new FlowLayout());
> JButton b = new JButton("Press me!");
> b.setEventListener(somethingOrOther);
> p.add(b);
> JSomething foo = new JSomething(blah, blah);
> foo.setAttribute();
> foo.setOtherAttribute();
> foo.soGladIDontDoThisKindOfThingAnymore();
> p.add(foo);
> 
> of course solving this needs more than just literals for maps. 

Yes, it's possible to come up with much more elegant ways to write 
stuff like that in Scala. IMO the biggest limitation is that there's 
no nice way to refer to declaratively constructed objects that are 
deeply nested. Consider:

  var myLabel = null
  val myWindow = new Window {
      title = "My Title"
      content = VBox(
          new Label {
              text = "A"
              myLabel = this
          },
          new Button {
              text = "Click Me"
              onClick = { event =>
                  myLabel.text = "B"
              }
          }
      )
  }

It's all pretty neat and should be a good way to do things in Scala, 
apart from the horrible hack I used to get hold of a reference to the 
Label object. Of course I could have just constructed the label on 
that first line instead, but then I'd be heading back in the direction 
of the unstructured Java code.

/J




Custom Search
home | non blog view