This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Scala has AOP implements?

12 replies
linzuxiong
Joined: 2011-09-09,
User offline. Last seen 30 weeks 1 day ago.

Scala has AOP implements, Like java , AspectJ or Spring AOP?

Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala has AOP implements?

On 10/27/2011 02:07 PM, zuxiong lin wrote:
> Scala has AOP implements, Like java , AspectJ or Spring AOP?
It has functional programming, which is a bit like AOP, with the caveat
that it works.

David Hall 4
Joined: 2009-08-21,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala has AOP implements?

Hi,

You should consider Scala's answers to a lot of the problems that AOP
tries to address.

For instance, see
http://blog.objectmentor.com/articles/2008/09/27/traits-vs-aspects-in-scala
. Scala has features (including FP) that help obviate a lot of the
framework-y stuff that you need in Java. Probably it would be best if
you described something specific you wanted to accomplish, maybe
including how you'd do it in AOP. Then, I'm sure people here will help
point you to the various ways to do it in Scala.

On Wed, Oct 26, 2011 at 9:07 PM, zuxiong lin wrote:
> Scala has AOP implements, Like java , AspectJ or Spring AOP?

marius
Joined: 2008-08-31,
User offline. Last seen 3 years 19 weeks ago.
Re: Scala has AOP implements?
In short, AOP and Scala does not make much sense since FP aspects already address what AOP tries to solve.


On Thu, Oct 27, 2011 at 7:07 AM, zuxiong lin <linzuxiong1988 [at] gmail [dot] com> wrote:
Scala has AOP implements, Like java , AspectJ or Spring AOP?

Anwar Rizal
Joined: 2011-07-05,
User offline. Last seen 42 weeks 5 days ago.
Re: Scala has AOP implements?
Tony,
Can you explore a little bit on this one? 
I take a classical example of AOP, which is, adding a log to invocation to a set of function by let' say using a pointcut call *.* . How functional programming can address such need ? 
Thanks,Anwar. 

On Thu, Oct 27, 2011 at 6:08 AM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
On 10/27/2011 02:07 PM, zuxiong lin wrote:
> Scala has AOP implements, Like java , AspectJ or Spring AOP?
It has functional programming, which is a bit like AOP, with the caveat
that it works.

--
Tony Morris
http://tmorris.net/



Anwar Rizal
Joined: 2011-07-05,
User offline. Last seen 42 weeks 5 days ago.
Re: Scala has AOP implements?
Because Scala codes compiled to Java byte codes, you can of course use AspectJ or SpringAOP to Scala codes.
But, of course, it's not interesting because it may no longer be functional programming.
A couple months ago, I've read couple of papers in the subject such as (Dantas et.al. 2005) or something more Haskell like (Sulzmann & Wang, 2007). I imagined then that a more scalaish aspect oriented  is possible. I imagine something like:
aspect SumPrice(val total:Int) {    def advice( _.( (x:Price, y:Price) => Int) ) = {           proceed();           SumPrice(x.amount + y.amount)    } }
that  accumulates all prices that are passed in function (Price,Price)=>Int.
Of course, it was just my wild imagination, but would love to see a real AOP in scala.
Refs:Aspect-oriented programming with type classes (Sulzman M & Wang M, 2007)PolyAML: a polymorphic aspect-oriented functional programming language (Dantas D, Walker D, Washburn G, Weirich S, 2005)
Cheers,Anwar Rizal   
On Thu, Oct 27, 2011 at 6:07 AM, zuxiong lin <linzuxiong1988 [at] gmail [dot] com> wrote:
Scala has AOP implements, Like java , AspectJ or Spring AOP?

Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala has AOP implements?

Sure. What does it mean to "add a log statement"? It means taking an
existing function (call it f) and composing it with your "log" function.
Let's call the new function g.

val g = f compose log

The problem is, of course, that now your new function doesn't compose
well because of the logging side-effect. So can we get the same effect
as "log" but without the bad bits? Absolutely, you pair the result of f
with a value that becomes the log, and so it goes on -- now you can keep
composing (orienting-your aspects-properly if you prefer to call it
that) until at the very outside of your application, you do that
side-effect that you'd been dreaming of doing all along. Except of
course, this time, your program works.

HTH
> Thanks,
> Anwar.
>
> On Thu, Oct 27, 2011 at 6:08 AM, Tony Morris wrote:
>
>> On 10/27/2011 02:07 PM, zuxiong lin wrote:
>>> Scala has AOP implements, Like java , AspectJ or Spring AOP?
>> It has functional programming, which is a bit like AOP, with the caveat
>> that it works.
>>
>> --
>> Tony Morris
>> http://tmorris.net/
>>
>>
>>

Paul Hudson
Joined: 2011-01-08,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala has AOP implements?

I would prefer not to wait until the end of a complete transaction before making the logs available externally. Or at least to have this option

I understand the attraction of building up all the information as you go along and performing the side effect at the end. But I don't see right now how best to structure these long running kinds of things - having some side effects (like logging, and like sending a response to the device) as you go along seems to be required.

I guess similar issues occur for GUI applications, with various events being triggered at unpredictable times? I looked at WinGHCi to see how a fairly simple GUI app might be done. But it's written in C :(

Any information (or pointer to reading matter) gratefully received. And apologies for not-really-scala-specific questions :)
DaveScala
Joined: 2011-03-18,
User offline. Last seen 1 year 21 weeks ago.
Re: Scala has AOP implements?

I also would see an AspectJ supporting scala syntax (AspectS ?).
I have seen some AOP with mixin compositions workarounds, but I don't
like that because the target source code knows about the aspect.
What I like about AOP (i.e. AspectJ) is that the target source code
knows nothing about the aspect and that aspect compiler ajc works on
the bytecode, so you can decide after compiling the target source with
scalac whether you want to add the aspect functionality or not with
ajc. It is this workflow what I like besides the capturing the cross-
cutting concerns.
How to combine AOP with FP in a mathematical pure way I don't know,
but now when I want to use AOP I use AspectJ and that is probably not
pure too.

Todd Vierling
Joined: 2011-04-27,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala has AOP implements?
On Thursday, October 27, 2011 12:48:10 AM UTC-4, David Hall wrote:

Scala has features (including FP) that help obviate a lot of the
framework-y stuff that you need in Java. Probably it would be best if
you described something specific you wanted to accomplish, maybe
including how you'd do it in AOP.

Mixin traits serve to provide _a lot_ of what AOP is used for in practice.
Matter of fact, at a JBossWorld some years ago, I got a notable person to admit publicly that his use for AOP was almost entirely to work around Java's lack of multiple inheritance.

Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: Scala has AOP implements?
So while Scala has the features to make AOP unecessary, it doesn't mean you have to give it up.   You can still use some AOP with Scala, it's just by at large not what most of us do, unless working with existing AOP-using systems.
- Josh

On Thu, Oct 27, 2011 at 2:18 PM, Todd Vierling <tv [at] duh [dot] org> wrote:
On Thursday, October 27, 2011 12:48:10 AM UTC-4, David Hall wrote:

Scala has features (including FP) that help obviate a lot of the
framework-y stuff that you need in Java. Probably it would be best if
you described something specific you wanted to accomplish, maybe
including how you'd do it in AOP.

Mixin traits serve to provide _a lot_ of what AOP is used for in practice.
Matter of fact, at a JBossWorld some years ago, I got a notable person to admit publicly that his use for AOP was almost entirely to work around Java's lack of multiple inheritance.


Jonas Bonér
Joined: 2008-12-19,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala has AOP implements?
Wrote this post some years ago. Mixin composition + AspectJ pointcut parser. http://jonasboner.com/2008/12/09/real-world-scala-managing-cross-cutting-concerns-using-mixin-composition-and-aop.html

On Thu, Oct 27, 2011 at 6:07 AM, zuxiong lin <linzuxiong1988 [at] gmail [dot] com> wrote:
Scala has AOP implements, Like java , AspectJ or Spring AOP?



--
Jonas Bonér
CTO
Typesafe <http://www.typesafe.com/> - Enterprise-Grade Scala from the
Experts
Phone: +46 733 777 123
Twitter: @jboner <http://twitter.com/jboner>
Google+: http://gplus.to/jboner



geir
Joined: 2010-06-29,
User offline. Last seen 34 weeks 4 days ago.
Re: Scala has AOP implements?
torsdag 27. oktober 2011 kl. 06:08:44 UTC+2 skrev Tony Morris følgende:
On 10/27/2011 02:07 PM, zuxiong lin wrote:
> Scala has AOP implements, Like java , AspectJ or Spring AOP?
It has functional programming, which is a bit like AOP, with the caveat
that it works.

Aspectj and Scala in combination works just fine, thank you.

We use it here, but only for the one remaining use case of AOP that Scala doesn't address: Adding functionality to a bunch of other functions without naming them explicitly, and without changing the function contract.

My AOP literature talks about "The tyranny of the dominant decomposition", meaning the lack of multiple inheritance. Perhaps the FP world has a similar problem, which would be something along the lines of "the tyranny of the dominant functional decomposition"?

Geir

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland