Turning off Predef

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Turning off Predef

Travis Parks
I've always been bothered by Predef (http://www.scala-lang.org/api/current/index.html#scala.Predef$). For the most part, I consider many of the implicits just part of the language. But printf and println really bother me. Calls to those functions shouldn't appear in most non-console applications. Worse, developers new to Scala end up using implicit conversations without even realizing it; this leads to confusion when they go to look up definitions but can't find them. Methods like assert and require really seem out-of-place. It'd be nice if I could make it difficult for other developers (and myself) to use these undesirable "default" features.

That said, I am okay with most of the Predef functionality... wrapping primitives, strings, collections, etc. It makes me wish Predef was broken out by responsibility: rich primitives, string wrapping, collections, testings, etc. It would be nice to then turn on only the features you wanted through a compiler flag. Obviously for backward compatibility, by default, all Predefs would be included. Perhaps this is already possible and I just don't know about it?

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning off Predef

Artúr Poór
There is a -Yno-predef flag already in the compiler, so could import the
necessary things only. That should do the trick.

Cheers,
Artúr

2016-09-19 20:38 keltezéssel, Travis Parks írta:

> I've always been bothered by *Predef*
> (http://www.scala-lang.org/api/current/index.html#scala.Predef$). For the
> most part, I consider many of the implicits just part of the language. But
> *printf* and *println* really bother me. Calls to those functions shouldn't
> appear in most non-console applications. Worse, developers new to Scala end
> up using implicit conversations without even realizing it; this leads to
> confusion when they go to look up definitions but can't find them. Methods
> like *assert* and *require* really seem out-of-place. It'd be nice if I
> could make it difficult for other developers (and myself) to use these
> undesirable "default" features.
>
> That said, I am okay with most of the Predef functionality... wrapping
> primitives, strings, collections, etc. It makes me wish Predef was broken
> out by responsibility: rich primitives, string wrapping, collections,
> testings, etc. It would be nice to then turn on only the features you
> wanted through a compiler flag. Obviously for backward compatibility, by
> default, all Predefs would be included. Perhaps this is already possible
> and I just don't know about it?
>

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning off Predef

Seth Tisue-3
There is a (WIP) PR in this area at https://github.com/scala/scala/pull/5350

Seth Tisue / Scala team / Lightbend, Inc.

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning off Predef

Travis Parks
In reply to this post by Artúr Poór
That's nuts. I've read both Odersky's and Wampler's books and have done repeated google searches, and I never heard of this option.
I'm going to start working on my import statement that excludes the stuff I don't want. I'll post it later for others benefit.

The best place for this little tidbit of information would be on that page I linked above. :-)

On Monday, September 19, 2016 at 2:56:56 PM UTC-4, Artúr Poór wrote:
There is a -Yno-predef flag already in the compiler, so could import the
necessary things only. That should do the trick.

Cheers,
Artúr

2016-09-19 20:38 keltezéssel, Travis Parks írta:

> I've always been bothered by *Predef*
> (<a href="http://www.scala-lang.org/api/current/index.html#scala.Predef$" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.scala-lang.org%2Fapi%2Fcurrent%2Findex.html%23scala.Predef%24\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGYe3Zhhk-xwfYH78ZV1MZQRS_BCg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.scala-lang.org%2Fapi%2Fcurrent%2Findex.html%23scala.Predef%24\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGYe3Zhhk-xwfYH78ZV1MZQRS_BCg&#39;;return true;">http://www.scala-lang.org/api/current/index.html#scala.Predef$). For the
> most part, I consider many of the implicits just part of the language. But
> *printf* and *println* really bother me. Calls to those functions shouldn't
> appear in most non-console applications. Worse, developers new to Scala end
> up using implicit conversations without even realizing it; this leads to
> confusion when they go to look up definitions but can't find them. Methods
> like *assert* and *require* really seem out-of-place. It'd be nice if I
> could make it difficult for other developers (and myself) to use these
> undesirable "default" features.
>
> That said, I am okay with most of the Predef functionality... wrapping
> primitives, strings, collections, etc. It makes me wish Predef was broken
> out by responsibility: rich primitives, string wrapping, collections,
> testings, etc. It would be nice to then turn on only the features you
> wanted through a compiler flag. Obviously for backward compatibility, by
> default, all Predefs would be included. Perhaps this is already possible
> and I just don't know about it?
>

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning off Predef

Travis Parks
My build.sbt file will end up looking like this on new projects:

lazy val commonSettings = Seq(
    scalaVersion
:= "2.11.8",
    scalacOptions
++= Seq(
       
"-unchecked",
       
"-deprecation",
       
"-Xfatal-warnings",
       
"–Xlint",
       
"-Yno-predef"
   
)
)

Unfortunately, the code to partially include/exclude some of the Predef stuff is ugly:

import scala.Predef.{
   
assert => _,
    assume
=> _,
   
print => _,
    printf
=> _,
    println
=> _,
   
require => _,
    _
}
import scala.Console

object Main extends App {
   
Console.out.println("Hello, World!")
}

If I could globally apply that nasty import to every .scala file, that'd be awesome to say the least.

On Monday, September 19, 2016 at 3:27:58 PM UTC-4, Travis Parks wrote:
That's nuts. I've read both Odersky's and Wampler's books and have done repeated google searches, and I never heard of this option.
I'm going to start working on my import statement that excludes the stuff I don't want. I'll post it later for others benefit.

The best place for this little tidbit of information would be on that page I linked above. :-)

On Monday, September 19, 2016 at 2:56:56 PM UTC-4, Artúr Poór wrote:
There is a -Yno-predef flag already in the compiler, so could import the
necessary things only. That should do the trick.

Cheers,
Artúr

2016-09-19 20:38 keltezéssel, Travis Parks írta:

> I've always been bothered by *Predef*
> (<a href="http://www.scala-lang.org/api/current/index.html#scala.Predef$" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.scala-lang.org%2Fapi%2Fcurrent%2Findex.html%23scala.Predef%24\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGYe3Zhhk-xwfYH78ZV1MZQRS_BCg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.scala-lang.org%2Fapi%2Fcurrent%2Findex.html%23scala.Predef%24\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGYe3Zhhk-xwfYH78ZV1MZQRS_BCg&#39;;return true;">http://www.scala-lang.org/api/current/index.html#scala.Predef$). For the
> most part, I consider many of the implicits just part of the language. But
> *printf* and *println* really bother me. Calls to those functions shouldn't
> appear in most non-console applications. Worse, developers new to Scala end
> up using implicit conversations without even realizing it; this leads to
> confusion when they go to look up definitions but can't find them. Methods
> like *assert* and *require* really seem out-of-place. It'd be nice if I
> could make it difficult for other developers (and myself) to use these
> undesirable "default" features.
>
> That said, I am okay with most of the Predef functionality... wrapping
> primitives, strings, collections, etc. It makes me wish Predef was broken
> out by responsibility: rich primitives, string wrapping, collections,
> testings, etc. It would be nice to then turn on only the features you
> wanted through a compiler flag. Obviously for backward compatibility, by
> default, all Predefs would be included. Perhaps this is already possible
> and I just don't know about it?
>

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning off Predef

Simon Schäfer



 ---- On Mon, 19 Sep 2016 21:56:53 +0200 Travis Parks <[hidden email]> wrote ----
 > My build.sbt file will end up looking like this on new projects:
 >
 > lazy val commonSettings = Seq(
 >     scalaVersion := "2.11.8",
 >     scalacOptions ++= Seq(
 >         "-unchecked",
 >         "-deprecation",
 >         "-Xfatal-warnings",
 >         "–Xlint",
 >         "-Yno-predef"
 >     )
 > )
 > Unfortunately, the code to partially include/exclude some of the Predef stuff is ugly:
 >
 > import scala.Predef.{
 >     assert => _,
 >     assume => _,
 >     print => _,
 >     printf => _,
 >     println => _,
 >     require => _,
 >     _
 > }
 > import scala.Console
 >
 > object Main extends App {
 >     Console.out.println("Hello, World!")
 > }
 > If I could globally apply that nasty import to every .scala file, that'd be awesome to say the least.

Just write your own Predef, which contains only the definitions that you want. This way you only have to import your own Predef.

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning off Predef

Marconi
In reply to this post by Travis Parks
Try

$ scalac -help
$ scalac -X
$ scalac -Y

You are going to discover quite a few goodies there.

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.