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

pathological outcomes

3 replies
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.

I wrote a heap of code today, I wonder if I can get anyone to give me
some feedback. In the case of the second two commits I wrote every
line today, so don't consider this a completely polished work or
anything. (The first commit I wrote a couple months ago.) You might
want to look if you are interested in two or more of these things:

a) paths
b) classpaths
c) pathologies
d) empaths

Here:

https://github.com/paulp/scala-dev/tree/path-abstraction

Or in diff form:

https://github.com/paulp/scala-dev/compare/master...path-abstraction

There is no feedback guidance. You can just blast some static, it all
sounds the same through these tinny speakers anyway.

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: pathological outcomes

Is length-check + substring + equals faster than endsWith? (Guessing you wanted speed due to the @inline hint)

On Oct 1, 2011 1:52 AM, "Paul Phillips" <paulp@improving.org> wrote:
> I wrote a heap of code today, I wonder if I can get anyone to give me
> some feedback. In the case of the second two commits I wrote every
> line today, so don't consider this a completely polished work or
> anything. (The first commit I wrote a couple months ago.) You might
> want to look if you are interested in two or more of these things:
>
> a) paths
> b) classpaths
> c) pathologies
> d) empaths
>
> Here:
>
> https://github.com/paulp/scala-dev/tree/path-abstraction
>
> Or in diff form:
>
> https://github.com/paulp/scala-dev/compare/master...path-abstraction
>
> There is no feedback guidance. You can just blast some static, it all
> sounds the same through these tinny speakers anyway.
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: pathological outcomes

2011/10/1 √iktor Ҡlang :
> Is length-check + substring + equals faster than endsWith? (Guessing you
> wanted speed due to the @inline hint)

I didn't know String had an endsWith method until I inferred it from
your email. This is an illustration of the funny view of the world
one gets after long exposure to implicit conversions. Because in
those situations I'm bent on avoiding the implicit conversion from
String to Seq, and I know Seq has an endsWith method...

One might still choose to avoid it if one is averse to methods
sneakily changing target. (There are probably less contrived traps
here.)

scala> class A(s: String) { def f1(t: String) = s endsWith t ; def
f2(t: String*) = s endsWith t }
defined class A

scala> :javap -c A
Compiled from ""
public class A extends java.lang.Object implements scala.ScalaObject{
public boolean f1(java.lang.String);
Code:
0: aload_0
1: getfield #12; //Field s:Ljava/lang/String;
4: aload_1
5: invokevirtual #17; //Method
java/lang/String.endsWith:(Ljava/lang/String;)Z
8: ireturn

public boolean f2(scala.collection.Seq);
Code:
0: getstatic #29; //Field scala/Predef$.MODULE$:Lscala/Predef$;
3: aload_0
4: getfield #12; //Field s:Ljava/lang/String;
7: invokevirtual #33; //Method
scala/Predef$.augmentString:(Ljava/lang/String;)Lscala/collection/immutable/StringOps;
10: aload_1
11: invokeinterface #38, 2; //InterfaceMethod
scala/collection/IndexedSeqOptimized.endsWith:(Lscala/collection/GenSeq;)Z
16: ireturn

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: pathological outcomes

If speed is important I'd go with String.endsWith and then add a comment about it.

Cheers,
V

On Oct 2, 2011 12:16 PM, "Paul Phillips" <paulp@improving.org> wrote:
> 2011/10/1 √iktor Ҡlang <viktor.klang@gmail.com>:
>> Is length-check + substring + equals faster than endsWith? (Guessing you
>> wanted speed due to the @inline hint)
>
> I didn't know String had an endsWith method until I inferred it from
> your email. This is an illustration of the funny view of the world
> one gets after long exposure to implicit conversions. Because in
> those situations I'm bent on avoiding the implicit conversion from
> String to Seq, and I know Seq has an endsWith method...
>
> One might still choose to avoid it if one is averse to methods
> sneakily changing target. (There are probably less contrived traps
> here.)
>
>
> scala> class A(s: String) { def f1(t: String) = s endsWith t ; def
> f2(t: String*) = s endsWith t }
> defined class A
>
> scala> :javap -c A
> Compiled from "<console>"
> public class A extends java.lang.Object implements scala.ScalaObject{
> public boolean f1(java.lang.String);
> Code:
> 0: aload_0
> 1: getfield #12; //Field s:Ljava/lang/String;
> 4: aload_1
> 5: invokevirtual #17; //Method
> java/lang/String.endsWith:(Ljava/lang/String;)Z
> 8: ireturn
>
> public boolean f2(scala.collection.Seq);
> Code:
> 0: getstatic #29; //Field scala/Predef$.MODULE$:Lscala/Predef$;
> 3: aload_0
> 4: getfield #12; //Field s:Ljava/lang/String;
> 7: invokevirtual #33; //Method
> scala/Predef$.augmentString:(Ljava/lang/String;)Lscala/collection/immutable/StringOps;
> 10: aload_1
> 11: invokeinterface #38, 2; //InterfaceMethod
> scala/collection/IndexedSeqOptimized.endsWith:(Lscala/collection/GenSeq;)Z
> 16: ireturn

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