« Return to Thread: Thoughts about RichObjects, Implicit convertions and performance

Re: Re: Thoughts about RichObjects, Implicit convertions and performance

by Ricky Clarkson :: Rate this Message:

Reply to Author | View in Thread

How about keeping the syntax we have but in those limited cases making
it equivalent in bytecode to C#'s extension methods?

2009/3/24 Jesper Nordenberg <megagurka@...>:

> If this language addition is to be considered I would very much prefer a C#
> extension method syntax:
>
> def newStringMethod(this str : String)(arg1 : T1, arg2 : T2) = ...
>
> Note the use of the "this" keyword on the first parameter.
>
> /Jesper Nordenberg
>
> Viktor Klang wrote:
>>
>>
>> On Tue, Mar 24, 2009 at 9:36 AM, Viktor Klang <viktor.klang@...
>> <mailto:viktor.klang@...>> wrote:
>>
>>    I'd like:
>>
>>    object MyImplicits
>>    {
>>    //Syntax
>>    //      implicit[targetType] def methodName[type params](params) :
>>    returnType = { expr }
>>
>>
>>    //i.e
>>             implicit[String] def isAllDigits = this.matches("^\\d+$")
>>
>>             implicit[Z <: AnyRef] def asInstanceOf[T](implicit clasz :
>>    Manifest[T]) : clasz.cast(this)
>>
>>
>> implicit[Z <: Any*Val*] def asInstanceOf[T](implicit clasz : Manifest[T])
>> : clasz.cast(this)
>>
>>
>>    }
>>
>>    //usage:
>>
>>    import MyImplicits._
>>
>>    "0000".isAllDigits
>>
>>    5.asInstanceOf[Fajita] //Yes, this example is the very definition of
>> WTF
>>
>>
>>    On Tue, Mar 24, 2009 at 7:42 AM, Johannes Rudolph
>>    <johannes.rudolph@...
>>    <mailto:johannes.rudolph@...>> wrote:
>>
>>        On Tue, Mar 24, 2009 at 7:23 AM, David Hall
>>        <dlwh@... <mailto:dlwh@...>> wrote:
>>         > Second observation, your benchmarking (below) is the "wrong"
>>        way to
>>         > benchmark JVM code because of the peculiarities of hotspot.
>>        You should
>>         > wrap these calls in a method and call it at least 10,000
>>        times in a
>>         > method before clocking speeds. HotSpot can do amazing things
>>        when you
>>         > give it a chance.
>>         >
>>         > That said, my understanding* is that HotSpot does not (yet**)
>>        do a
>>         > great job removing object creations, which is what is needed
>>        to really
>>         > make implicits faster.
>>
>>        Right, see
>>        http://wikis.sun.com/display/HotSpotInternals/MicroBenchmarks
>>        for some tips how to fix microbenchmarks with the Hotspot
>>        compiler of
>>        the OpenJDK. You can use -XX:+PrintCompilation VM option (with
>>        OpenJDK
>>        or Sun JVM) to see when methods get JIT-compiled. In this
>> particular
>>        case my tries showed, that the method is compiled just after
>>        (while?)
>>        the first run, so doing 10 iterations of the whole method should
>>        suffice.
>>
>>        Johannes
>>
>>        -----------------------------------------------
>>        Johannes Rudolph
>>        http://virtual-void.net
>>
>>
>>
>>
>>    --    Viktor Klang
>>    Senior Systems Analyst
>>
>>
>>
>>
>> --
>> Viktor Klang
>> Senior Systems Analyst
>
>

 « Return to Thread: Thoughts about RichObjects, Implicit convertions and performance