Philipp Haller | 1 Apr 10:52
Picon
Picon
Favicon

Re: Actors performance, was: mem leak

Hi Alex,

That's a good point.

The only issue is that we'd have to make sure that it is still possible 
to override the def `scheduler` in the `Actor` trait. Also, we probably 
have to change the `SchedulerAdapter` trait, so that it wraps 
`Runnable`s into `FJTask`s.

I didn't have time to look into it in detail, yet. But, if we can make 
sure that your suggested changes integrate well with all the rest of the 
scheduler framework, I'd be very happy to integrate your patch.

Thanks,
Philipp

Alex Yakovlev wrote:
> Hi Philipp,
> 
> performance-wise, have you considered inheriting Reaction from FJTask
> instead of wrapping it? I mean:
> 
> class Reaction extends FJTask {
> ...
> }
> 
> and in Scheduler.scala:
> 
>   def execute(task: Runnable) {
>     currentThread match {
(Continue reading)

Alex Yakovlev | 1 Apr 13:40
Picon

Re: Actors performance, was: mem leak


Hi Philipp,

Philipp Haller-2 wrote:
> 
> The only issue is that we'd have to make sure that it is still possible 
> to override the def `scheduler` in the `Actor` trait.
> 

Since it is important to change actor's schedulers, I suppose it is better
to completely hide current implementation with FJTask and leave Runnable in
all *Scheduler traits and classes. So that alternative scheduler
implementations will not depend on FJTask and don't even need to know about
it.

The only overhead will be is checking in object Scheduler.execute if task is
FJTask or general Runnable. IMHO, it is small and worth avoiding of strong
binding of all scheduler framework to current FJTask-based implementation.

So what I suggest is the following:

1. in Reaction.scala:

class Reaction extends FJTask // instead of Runnable

2. in Scheduler.scala:

object Scheduler extends IScheduler {
...
  def execute(task: Runnable) {
(Continue reading)

Seth Tisue | 1 Apr 15:32
Gravatar

ProGuard incompatible with current Scala trunk build


I filed this bug report with on the ProGuard tracker:

https://sourceforge.net/tracker/?func=detail&aid=2725052&group_id=54750&atid=474704

I don't know whether it's a ProGuard 4.3 bug or a scalac (2.8.0.r17416)
bug or both.  I'll see what the ProGuard guy thinks.

In the meantime, if anyone wants to use ProGuard with the Scala trunk,
here's how.  In the ProGuard 4.3 source, at line 114 of
src/proguard/classfile/ClassPool.java, in the classesAccept method,
replace this line with:

  clazz.accept(classVisitor);

with:

  if( ! clazz.getName().equals( "scala/util/parsing/combinatorold/syntactical/BindingParsers" ) &&
      ! clazz.getName().equals( "scala/util/parsing/ast/Binders" ) )
    clazz.accept(classVisitor);

and rebuild ProGuard.  There must be something odd about those two
classes.  (Fortunately they happen to be two classes I don't need.)
Another option would be to remove those classes from scala-library.jar
before running it through ProGuard.  (Though that might cause a bunch of
missing-class warnings unless you ripped out a bunch of associated
classes, too.)

--

-- 
Seth Tisue / http://tisue.net
(Continue reading)

Andrés Testi | 1 Apr 19:38
Picon

DTO in Scala

Does Data Transfer Object pattern make sense in Scala? Are there
better options? Is there a kind of BeansUtils/Dozer API for mapping
scala objects?
Thanks in advance.

- Andrés

Lee Mighdoll | 1 Apr 21:59
Picon

aspectJ experiment: observing property changes

I tried an experiment, using aspectJ to insert property change detection into scala instances.  It works fine, at least on my small test case.  You can see what I did here on git

It's pretty neat that idiomatic scala properties can be observed for changes
with almost no changes to the scala source. (It'd be great if this could be done
in scala without resorting to aspectJ...).


The scala class needs only to add the marker trait Observable.

class Model extends AnyRef with Observable {
var prop:String = _
}

Modifications to the instance will then run the aspect, notifying the observer.

val model = new Model()
m.prop = "whee"

Run that and the test observer sees the change and prints:

change observed> example.Model <at> 6abf2d5e=>> prop:whee


I'm getting more tempted to use aspectJ because it enables such a simple and idiomatic
approach.


Lee
Dean Wampler | 1 Apr 22:32
Picon

Re: aspectJ experiment: observing property changes

While AspectJ certainly works for this, you can also achieve the same effect with traits. Something like


trait ObservedPropWrite extends Model {
  override def prop_=(x: String) {
    super.prop_=(x)
    log("change observed> " + this + "=>> prop:" +prop)
  }
}

val model = new Model with ObservedPropWrite

Where AspectJ is unique is when this kind of modification is a pervasive behavior change and there is no common trait, etc. that you can use as the single point to intercept or you don't have control over instance instantiation. Then the "pointcut language" and "advice" mechanisms are really handy.

dean

On Wed, Apr 1, 2009 at 2:59 PM, Lee Mighdoll <lee <at> underneath.ca> wrote:
I tried an experiment, using aspectJ to insert property change detection into scala instances.  It works fine, at least on my small test case.  You can see what I did here on git

It's pretty neat that idiomatic scala properties can be observed for changes
with almost no changes to the scala source. (It'd be great if this could be done
in scala without resorting to aspectJ...).


The scala class needs only to add the marker trait Observable.

class Model extends AnyRef with Observable {
var prop:String = _
}

Modifications to the instance will then run the aspect, notifying the observer.

val model = new Model()
m.prop = "whee"

Run that and the test observer sees the change and prints:

change observed> example.Model <at> 6abf2d5e=>> prop:whee


I'm getting more tempted to use aspectJ because it enables such a simple and idiomatic
approach.


Lee



--
Dean Wampler
twitter: <at> deanwampler, <at> chicagoscala
Chicago-Area Scala Enthusiasts (CASE):
-  http://groups.google.com/group/chicagoscala
-  http://www.meetup.com/chicagoscala/ (Meetings)
http://www.objectmentor.com
http://www.polyglotprogramming.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org
Lee Mighdoll | 1 Apr 23:01
Picon

Re: aspectJ experiment: observing property changes

Hi dean -- BTW, I looked at your blog post to try this experiment, thanks.

I agree it would be better to do this w/o aspectJ.  But there are some disadvantages -- mainly that overriding each property manually creates an unfortunate amount of boilerplate to write and maintain.  You have to create an override for every property, always change two places when you add/remove/change a property, and potentially edit every override if your observation api changes (e.g. to report the original state of the property). 

Overriding manually might still be the best approach on balance, but you see the temptation to mess around with aspects.  The tooling is awkward, but the net resulting api is clean.

Lee

On Wed, Apr 1, 2009 at 1:32 PM, Dean Wampler <deanwampler <at> gmail.com> wrote:
While AspectJ certainly works for this, you can also achieve the same effect with traits. Something like

trait ObservedPropWrite extends Model {
  override def prop_=(x: String) {
    super.prop_=(x)
    log("change observed> " + this + "=>> prop:" +prop)
  }
}

val model = new Model with ObservedPropWrite

Where AspectJ is unique is when this kind of modification is a pervasive behavior change and there is no common trait, etc. that you can use as the single point to intercept or you don't have control over instance instantiation. Then the "pointcut language" and "advice" mechanisms are really handy.

dean

On Wed, Apr 1, 2009 at 2:59 PM, Lee Mighdoll <lee <at> underneath.ca> wrote:
I tried an experiment, using aspectJ to insert property change detection into scala instances.  It works fine, at least on my small test case.  You can see what I did here on git

It's pretty neat that idiomatic scala properties can be observed for changes
with almost no changes to the scala source. (It'd be great if this could be done
in scala without resorting to aspectJ...).


The scala class needs only to add the marker trait Observable.

class Model extends AnyRef with Observable {
var prop:String = _
}

Modifications to the instance will then run the aspect, notifying the observer.

val model = new Model()
m.prop = "whee"

Run that and the test observer sees the change and prints:

change observed> example.Model <at> 6abf2d5e=>> prop:whee


I'm getting more tempted to use aspectJ because it enables such a simple and idiomatic
approach.


Lee



--
Dean Wampler
twitter: <at> deanwampler, <at> chicagoscala
Chicago-Area Scala Enthusiasts (CASE):
-  http://groups.google.com/group/chicagoscala
-  http://www.meetup.com/chicagoscala/ (Meetings)
http://www.objectmentor.com
http://www.polyglotprogramming.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org

Dean Wampler | 1 Apr 23:14
Picon

Re: aspectJ experiment: observing property changes

All true.


I'd like to figure out ways to get the decoupling that aspects provide, but still use traits, in some way. Java annotations provide a much better way to define "pointcuts", since method and field names can change on you, but annotations are generally more stable.

Perhaps an object factor that mixes in traits based on the annotations on the methods and fields?

dean 

On Wed, Apr 1, 2009 at 4:01 PM, Lee Mighdoll <lee <at> underneath.ca> wrote:
Hi dean -- BTW, I looked at your blog post to try this experiment, thanks.

I agree it would be better to do this w/o aspectJ.  But there are some disadvantages -- mainly that overriding each property manually creates an unfortunate amount of boilerplate to write and maintain.  You have to create an override for every property, always change two places when you add/remove/change a property, and potentially edit every override if your observation api changes (e.g. to report the original state of the property). 

Overriding manually might still be the best approach on balance, but you see the temptation to mess around with aspects.  The tooling is awkward, but the net resulting api is clean.

Lee


On Wed, Apr 1, 2009 at 1:32 PM, Dean Wampler <deanwampler <at> gmail.com> wrote:
While AspectJ certainly works for this, you can also achieve the same effect with traits. Something like

trait ObservedPropWrite extends Model {
  override def prop_=(x: String) {
    super.prop_=(x)
    log("change observed> " + this + "=>> prop:" +prop)
  }
}

val model = new Model with ObservedPropWrite

Where AspectJ is unique is when this kind of modification is a pervasive behavior change and there is no common trait, etc. that you can use as the single point to intercept or you don't have control over instance instantiation. Then the "pointcut language" and "advice" mechanisms are really handy.

dean

On Wed, Apr 1, 2009 at 2:59 PM, Lee Mighdoll <lee <at> underneath.ca> wrote:
I tried an experiment, using aspectJ to insert property change detection into scala instances.  It works fine, at least on my small test case.  You can see what I did here on git

It's pretty neat that idiomatic scala properties can be observed for changes
with almost no changes to the scala source. (It'd be great if this could be done
in scala without resorting to aspectJ...).


The scala class needs only to add the marker trait Observable.

class Model extends AnyRef with Observable {
var prop:String = _
}

Modifications to the instance will then run the aspect, notifying the observer.

val model = new Model()
m.prop = "whee"

Run that and the test observer sees the change and prints:

change observed> example.Model <at> 6abf2d5e=>> prop:whee


I'm getting more tempted to use aspectJ because it enables such a simple and idiomatic
approach.


Lee



--
Dean Wampler
twitter: <at> deanwampler, <at> chicagoscala
Chicago-Area Scala Enthusiasts (CASE):
-  http://groups.google.com/group/chicagoscala
-  http://www.meetup.com/chicagoscala/ (Meetings)
http://www.objectmentor.com
http://www.polyglotprogramming.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org




--
Dean Wampler
twitter: <at> deanwampler, <at> chicagoscala
Chicago-Area Scala Enthusiasts (CASE):
-  http://groups.google.com/group/chicagoscala
-  http://www.meetup.com/chicagoscala/ (Meetings)
http://www.objectmentor.com
http://www.polyglotprogramming.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org
Mitch Blevins | 2 Apr 01:55
Picon

Shunting Yard Algorithm

As a newbie to parser combinators, I'd appreciate feedback on this:
http://cleverlytitled.blogspot.com/2009/04/shunting-yard-algorithm.html

Especially if there is a way to eliminate my chainLeft(...) and
chainRight(...) methods with something in the std library.

-Mitch

Kristian Domagala | 2 Apr 01:58
Picon
Gravatar

Re: DTO in Scala

I haven't done anything specifically like this in Scala, but having returned recently to Java on a project that uses the DTO "pattern", I keep thinking that traits would make my life a lot simpler. The idea in my head is to have a trait that describes the common interface between the DTO object and domain model, which provides the implementation of the accessors. The domain class would extend the trait with the domain logic, and the DTO class would extend the trait with no further implementation (unless the DTOs were used in both directions, in which case you might want to have DTO specific mutators). You could have an implicit function(s) to convert between the two.

As I said, I haven't actually done this in Scala, so I'm not sure how well it would work in practice. I'm not even sure that if I was doing my current project in Scala that there would even be an explicit notion of DTOs; my thoughts above are only centered on the direct translation of that aspect of the code.

Cheers,
Kristian.

On Thu, Apr 2, 2009 at 3:38 AM, Andrés Testi <andres.a.testi <at> gmail.com> wrote:
Does Data Transfer Object pattern make sense in Scala? Are there
better options? Is there a kind of BeansUtils/Dozer API for mapping
scala objects?
Thanks in advance.

- Andrés


Gmane