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

A few questions...

7 replies
Aishwarya Singhal
Joined: 2011-09-09,
User offline. Last seen 42 years 45 weeks ago.

Hi All

I see that runtime annotations can not be written in Scala (or atleast
I haven't found a way yet). In the Java world, I used annotations
heavily esp for data binding with external streams and hence I find
this apparent limitation troublesome. My question is - is this an
actual problem or my ignorance, and if its an actual problem, is it
being worked upon?

Also, incompatibility of byte code between major releases seems to be
a major problem. I am doing an open source project and have to publish
binaries for both 2.8.1 as well as 2.9.1 as either doesn't work with
the other version.

Also, are there any plans of the building into the compiler an ability
to warn against unused imports or poor programming practices?

Lastly, I know the first page of the manual warned me of this, but the
lack of "break" in loops gets troublesome as well at times. I do
"return" instead of break, but I would have preferred and found the
code more readable with "break". A simple (rather crude) example is as
follows:

for (i <- 0 to (tabPane.peer.getTabCount - 1)) {
if (tabPane.peer.getToolTipTextAt(i) == name) {
tabPane.pages.remove(i)
return
}
}

What do you think about "break"?

Thanks and Best regards
Aishwarya

amulya rattan
Joined: 2011-09-15,
User offline. Last seen 42 years 45 weeks ago.
Re: A few questions...
Not so sure about the rest, but break is a part of the libraray .. http://scalex.org/#scalautilcontrolBreaksbreakUnit

On Fri, Oct 14, 2011 at 5:53 AM, Aishwarya Singhal <asinghal79 [at] gmail [dot] com> wrote:
Hi All

I see that runtime annotations can not be written in Scala (or atleast
I haven't found a way yet). In the Java world, I used annotations
heavily esp for data binding with external streams and hence I find
this apparent limitation troublesome. My question is - is this an
actual problem or my ignorance, and if its an actual problem, is it
being worked upon?

Also, incompatibility of byte code between major releases seems to be
a major problem. I am doing an open source project and have to publish
binaries for both 2.8.1 as well as 2.9.1 as either doesn't work with
the other version.

Also, are there any plans of the building into the compiler an ability
to warn against unused imports or poor programming practices?

Lastly, I know the first page of the manual warned me of this, but the
lack of "break" in loops gets troublesome as well at times. I do
"return" instead of break, but I would have preferred and found the
code more readable with "break". A simple (rather crude) example is as
follows:

for (i <- 0 to (tabPane.peer.getTabCount - 1)) {
       if (tabPane.peer.getToolTipTextAt(i) == name) {
         tabPane.pages.remove(i)
         return
       }
}

What do you think about "break"?

Thanks and Best regards
Aishwarya

H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
Re: A few questions...

in scala, you usually use "find" on a travesable for this and won't need break. in fact, i rarely use primitive loops at all.

if you insist on using break, use a breakable block. look into the traversable classes, they use it at some places

-------- Original-Nachricht --------
> Datum: Fri, 14 Oct 2011 02:53:28 -0700 (PDT)
> Von: Aishwarya Singhal
> An: scala-debate
> Betreff: [scala-debate] A few questions...

> Hi All
>
> I see that runtime annotations can not be written in Scala (or atleast
> I haven't found a way yet). In the Java world, I used annotations
> heavily esp for data binding with external streams and hence I find
> this apparent limitation troublesome. My question is - is this an
> actual problem or my ignorance, and if its an actual problem, is it
> being worked upon?
>
> Also, incompatibility of byte code between major releases seems to be
> a major problem. I am doing an open source project and have to publish
> binaries for both 2.8.1 as well as 2.9.1 as either doesn't work with
> the other version.
>
> Also, are there any plans of the building into the compiler an ability
> to warn against unused imports or poor programming practices?
>
> Lastly, I know the first page of the manual warned me of this, but the
> lack of "break" in loops gets troublesome as well at times. I do
> "return" instead of break, but I would have preferred and found the
> code more readable with "break". A simple (rather crude) example is as
> follows:
>
> for (i <- 0 to (tabPane.peer.getTabCount - 1)) {
> if (tabPane.peer.getToolTipTextAt(i) == name) {
> tabPane.pages.remove(i)
> return
> }
> }
>
> What do you think about "break"?
>
> Thanks and Best regards
> Aishwarya

Aishwarya Singhal
Joined: 2011-09-09,
User offline. Last seen 42 years 45 weeks ago.
Re: A few questions...

thanks for the traversable find tip Dennis, it looks pretty neat!

Best regards
Aishwarya

On Oct 14, 3:08 pm, "Dennis Haupt" wrote:
> in scala, you usually use "find" on a travesable for this and won't need break. in fact, i rarely use primitive loops at all.
>
> if you insist on using break, use a breakable block. look into the traversable classes, they use it at some places
>
> -------- Original-Nachricht --------
>
>
>
>
>
>
>
> > Datum: Fri, 14 Oct 2011 02:53:28 -0700 (PDT)
> > Von: Aishwarya Singhal
> > An: scala-debate
> > Betreff: [scala-debate] A few questions...
> > Hi All
>
> > I see that runtime annotations can not be written in Scala (or atleast
> > I haven't found a way yet). In the Java world, I used annotations
> > heavily esp for data binding with external streams and hence I find
> > this apparent limitation troublesome. My question is - is this an
> > actual problem or my ignorance, and if its an actual problem, is it
> > being worked upon?
>
> > Also, incompatibility of byte code between major releases seems to be
> > a major problem. I am doing an open source project and have to publish
> > binaries for both 2.8.1 as well as 2.9.1 as either doesn't work with
> > the other version.
>
> > Also, are there any plans of the building into the compiler an ability
> > to warn against unused imports or poor programming practices?
>
> > Lastly, I know the first page of the manual warned me of this, but the
> > lack of "break" in loops gets troublesome as well at times. I do
> > "return" instead of break, but I would have preferred and found the
> > code more readable with "break". A simple (rather crude) example is as
> > follows:
>
> > for (i <- 0 to (tabPane.peer.getTabCount - 1)) {
> >         if (tabPane.peer.getToolTipTextAt(i) == name) {
> >           tabPane.pages.remove(i)
> >           return
> >         }
> > }
>
> > What do you think about "break"?
>
> > Thanks and Best regards
> > Aishwarya

Kevin Wright 2
Joined: 2010-05-30,
User offline. Last seen 26 weeks 4 days ago.
Re: A few questions...


On 14 October 2011 10:53, Aishwarya Singhal <asinghal79 [at] gmail [dot] com> wrote:
Hi All

I see that runtime annotations can not be written in Scala (or atleast
I haven't found a way yet). In the Java world, I used annotations
heavily esp for data binding with external streams and hence I find
this apparent limitation troublesome. My question is - is this an
actual problem or my ignorance, and if its an actual problem, is it
being worked upon?

Also, incompatibility of byte code between major releases seems to be
a major problem. I am doing an open source project and have to publish
binaries for both 2.8.1 as well as 2.9.1 as either doesn't work with
the other version.

Also, are there any plans of the building into the compiler an ability
to warn against unused imports or poor programming practices?

Lastly, I know the first page of the manual warned me of this, but the
lack of "break" in loops gets troublesome as well at times. I do
"return" instead of break, but I would have preferred and found the
code more readable with "break". A simple (rather crude) example is as
follows:

for (i <- 0 to (tabPane.peer.getTabCount - 1)) {
       if (tabPane.peer.getToolTipTextAt(i) == name) {
         tabPane.pages.remove(i)
         return
       }
}

What do you think about "break"?



Stop thinking in loops!Sadly, JTabPage doesn't expose tabs as a collection, but it's easy enough to fake:
    val namedTabs = (0 until tabPane.peer.getTabCount) map {       i => i -> tabPane.peer.getToolTipTextAt(i)    }    val idx = tabs collectFirst { case (i, txt) if txt == name => i }    tabPane.pages remove idx

 
Thanks and Best regards
Aishwarya



Aishwarya Singhal
Joined: 2011-09-09,
User offline. Last seen 42 years 45 weeks ago.
Re: A few questions...

Thanks Kevin, I am just a fairly long time java developer so its
taking time to get over the hangover :-)

The following is what I thought of the code with "find"

(0 until tabPane.peer.getTabCount).find { i =>
(tabPane.peer.getToolTipTextAt(i) == name)} match {
case Some(i) => tabPane.pages.remove(i)
case None =>
}

I actually wanted to know of a way to avoid iterating over the entire
collection if I find a match in between, so "find" seems to be fine...

Any idea of runtime annotations or byte code compatibility?

Best regards
Aishwarya

On Oct 14, 3:35 pm, Kevin Wright wrote:
> On 14 October 2011 10:53, Aishwarya Singhal wrote:
>
>
>
>
>
>
>
>
>
> > Hi All
>
> > I see that runtime annotations can not be written in Scala (or atleast
> > I haven't found a way yet). In the Java world, I used annotations
> > heavily esp for data binding with external streams and hence I find
> > this apparent limitation troublesome. My question is - is this an
> > actual problem or my ignorance, and if its an actual problem, is it
> > being worked upon?
>
> > Also, incompatibility of byte code between major releases seems to be
> > a major problem. I am doing an open source project and have to publish
> > binaries for both 2.8.1 as well as 2.9.1 as either doesn't work with
> > the other version.
>
> > Also, are there any plans of the building into the compiler an ability
> > to warn against unused imports or poor programming practices?
>
> > Lastly, I know the first page of the manual warned me of this, but the
> > lack of "break" in loops gets troublesome as well at times. I do
> > "return" instead of break, but I would have preferred and found the
> > code more readable with "break". A simple (rather crude) example is as
> > follows:
>
> > for (i <- 0 to (tabPane.peer.getTabCount - 1)) {
> >        if (tabPane.peer.getToolTipTextAt(i) == name) {
> >          tabPane.pages.remove(i)
> >          return
> >        }
> > }
>
> > What do you think about "break"?
>
> Stop thinking in loops!
> Sadly, JTabPage doesn't expose tabs as a collection, but it's easy enough to
> fake:
>
>     val namedTabs = (0 until tabPane.peer.getTabCount) map {
>       i => i -> tabPane.peer.getToolTipTextAt(i)
>     }
>     val idx = tabs collectFirst { case (i, txt) if txt == name => i }
>     tabPane.pages remove idx
>
>
>
>
>
>
>
> > Thanks and Best regards
> > Aishwarya

Kevin Wright 2
Joined: 2010-05-30,
User offline. Last seen 26 weeks 4 days ago.
Re: Re: A few questions...
Performing side effects inside a find block is a bad idea.  Established Scala programmers won't expect it, so you're breaking the principle of least surprise.
A preferable solution is to first pull out the target index, then remove the tab page in an explicit step.



On 14 October 2011 11:50, Aishwarya Singhal <asinghal79 [at] gmail [dot] com> wrote:
Thanks Kevin, I am just a fairly long time java developer so its
taking time to get over the hangover :-)

The following is what I thought of the code with "find"

(0 until tabPane.peer.getTabCount).find { i =>
(tabPane.peer.getToolTipTextAt(i) == name)} match {
         case Some(i) => tabPane.pages.remove(i)
         case None =>
     }

I actually wanted to know of a way to avoid iterating over the entire
collection if I find a match in between, so "find" seems to be fine...

Any idea of runtime annotations or byte code compatibility?

Best regards
Aishwarya

On Oct 14, 3:35 pm, Kevin Wright <kev [dot] lee [dot] wri [dot] [dot] [dot] [at] gmail [dot] com> wrote:
> On 14 October 2011 10:53, Aishwarya Singhal <asingha [dot] [dot] [dot] [at] gmail [dot] com> wrote:
>
>
>
>
>
>
>
>
>
> > Hi All
>
> > I see that runtime annotations can not be written in Scala (or atleast
> > I haven't found a way yet). In the Java world, I used annotations
> > heavily esp for data binding with external streams and hence I find
> > this apparent limitation troublesome. My question is - is this an
> > actual problem or my ignorance, and if its an actual problem, is it
> > being worked upon?
>
> > Also, incompatibility of byte code between major releases seems to be
> > a major problem. I am doing an open source project and have to publish
> > binaries for both 2.8.1 as well as 2.9.1 as either doesn't work with
> > the other version.
>
> > Also, are there any plans of the building into the compiler an ability
> > to warn against unused imports or poor programming practices?
>
> > Lastly, I know the first page of the manual warned me of this, but the
> > lack of "break" in loops gets troublesome as well at times. I do
> > "return" instead of break, but I would have preferred and found the
> > code more readable with "break". A simple (rather crude) example is as
> > follows:
>
> > for (i <- 0 to (tabPane.peer.getTabCount - 1)) {
> >        if (tabPane.peer.getToolTipTextAt(i) == name) {
> >          tabPane.pages.remove(i)
> >          return
> >        }
> > }
>
> > What do you think about "break"?
>
> Stop thinking in loops!
> Sadly, JTabPage doesn't expose tabs as a collection, but it's easy enough to
> fake:
>
>     val namedTabs = (0 until tabPane.peer.getTabCount) map {
>       i => i -> tabPane.peer.getToolTipTextAt(i)
>     }
>     val idx = tabs collectFirst { case (i, txt) if txt == name => i }
>     tabPane.pages remove idx
>
>
>
>
>
>
>
> > Thanks and Best regards
> > Aishwarya



H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
Re: Re: A few questions...

you can do "foreach(tabPane.pages.remove)" instead of your match. foreach does nothing if none is returned and executes if an option comes back

-------- Original-Nachricht --------
> Datum: Fri, 14 Oct 2011 03:50:14 -0700 (PDT)
> Von: Aishwarya Singhal
> An: scala-debate
> Betreff: [scala-debate] Re: A few questions...

> Thanks Kevin, I am just a fairly long time java developer so its
> taking time to get over the hangover :-)
>
> The following is what I thought of the code with "find"
>
> (0 until tabPane.peer.getTabCount).find { i =>
> (tabPane.peer.getToolTipTextAt(i) == name)} match {
> case Some(i) => tabPane.pages.remove(i)
> case None =>
> }
>
> I actually wanted to know of a way to avoid iterating over the entire
> collection if I find a match in between, so "find" seems to be fine...
>
> Any idea of runtime annotations or byte code compatibility?
>
> Best regards
> Aishwarya
>
> On Oct 14, 3:35 pm, Kevin Wright wrote:
> > On 14 October 2011 10:53, Aishwarya Singhal
> wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > Hi All
> >
> > > I see that runtime annotations can not be written in Scala (or atleast
> > > I haven't found a way yet). In the Java world, I used annotations
> > > heavily esp for data binding with external streams and hence I find
> > > this apparent limitation troublesome. My question is - is this an
> > > actual problem or my ignorance, and if its an actual problem, is it
> > > being worked upon?
> >
> > > Also, incompatibility of byte code between major releases seems to be
> > > a major problem. I am doing an open source project and have to publish
> > > binaries for both 2.8.1 as well as 2.9.1 as either doesn't work with
> > > the other version.
> >
> > > Also, are there any plans of the building into the compiler an ability
> > > to warn against unused imports or poor programming practices?
> >
> > > Lastly, I know the first page of the manual warned me of this, but the
> > > lack of "break" in loops gets troublesome as well at times. I do
> > > "return" instead of break, but I would have preferred and found the
> > > code more readable with "break". A simple (rather crude) example is as
> > > follows:
> >
> > > for (i <- 0 to (tabPane.peer.getTabCount - 1)) {
> > >        if (tabPane.peer.getToolTipTextAt(i) == name) {
> > >          tabPane.pages.remove(i)
> > >          return
> > >        }
> > > }
> >
> > > What do you think about "break"?
> >
> > Stop thinking in loops!
> > Sadly, JTabPage doesn't expose tabs as a collection, but it's easy
> enough to
> > fake:
> >
> >     val namedTabs = (0 until tabPane.peer.getTabCount) map {
> >       i => i -> tabPane.peer.getToolTipTextAt(i)
> >     }
> >     val idx = tabs collectFirst { case (i, txt) if txt == name => i }
> >     tabPane.pages remove idx
> >
> >
> >
> >
> >
> >
> >
> > > Thanks and Best regards
> > > Aishwarya

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