- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Scala has AOP implements?
Thu, 2011-10-27, 05:57
#2
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?
Thu, 2011-10-27, 07:57
#3
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@gmail.com> wrote:
On Thu, Oct 27, 2011 at 7:07 AM, zuxiong lin <linzuxiong1988@gmail.com> wrote:
Scala has AOP implements, Like java , AspectJ or Spring AOP?
Thu, 2011-10-27, 10:07
#4
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@gmail.com> wrote:
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@gmail.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/
Thu, 2011-10-27, 11:27
#5
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@gmail.com> wrote:
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@gmail.com> wrote:
Scala has AOP implements, Like java , AspectJ or Spring AOP?
Thu, 2011-10-27, 11:37
#6
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/
>>
>>
>>
Thu, 2011-10-27, 14:47
#7
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 :)
Thu, 2011-10-27, 15:27
#8
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.
Thu, 2011-10-27, 19:37
#9
Re: Scala has AOP implements?
On Thursday, October 27, 2011 12:48:10 AM UTC-4, David Hall wrote:
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.
Mixin traits serve to provide _a lot_ of what AOP is used for in practice.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.
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.
Thu, 2011-10-27, 19:47
#10
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@duh.org> wrote:
- Josh
On Thu, Oct 27, 2011 at 2:18 PM, Todd Vierling <tv@duh.org> wrote:
On Thursday, October 27, 2011 12:48:10 AM UTC-4, David Hall wrote:Mixin traits serve to provide _a lot_ of what AOP is used for in practice.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.
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.
Fri, 2011-10-28, 16:27
#11
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@gmail.com> wrote:
--
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
On Thu, Oct 27, 2011 at 6:07 AM, zuxiong lin <linzuxiong1988@gmail.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
Thu, 2011-11-17, 15:07
#12
Re: Scala has AOP implements?
torsdag 27. oktober 2011 kl. 06:08:44 UTC+2 skrev Tony Morris følgende:
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
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
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.