Scala

Scala编程语言。(The Scala programming language.)

Github stars Tracking Chart

一个可扩展的语言

Scala是“可扩展语言”的缩写。 这意味着Scala与你一起成长。 您可以通过键入单行表达式并观察结果来进行操作。 但你也可以依赖它来进行大型的任务关键系统,包括Twitter、LinkedIn和英特尔这样的公司。

对有些人来说,Scala感觉像一种脚本语言。 其语法简洁而低俗; 因为编译器可以推断出它们的类型, 所以它会退出。有一个REPL和IDE工作表来快速反馈。 开发者非常喜欢它,Scala在2012年JavaOne大会上赢得了ScriptBowl比赛。
同时,Scala是许多关键任务服务器系统的首选主要语言。 生成的代码与Java的一致,它的精确类型意味着许多问题在编译时被捕获,而不是在部署之后被捕获。
在根本上,语言的可扩展性是精心整合面向对象和函数性语言概念的结果。
面向对象
Scala是一种纯粹的面向对象语言。在概念上,每个值都是一个对象,每个操作都是一个方法调用。该语言通过类和特征支持高级组件体系结构。
其他语言中的许多传统设计模式已经被本地支持。例如,通过对象定义支持单例,通过模式匹配支持访问者。使用隐式类,Scala甚至允许您添加新的操作到现有的类,无论他们来自Scala还是Java!
函数式
即使它的语法相当传统,Scala也是一个完整的函数式语言。它具有您期望的一切,包括一流的函数,一个具有高效的不可变数据结构的库,以及对变异的不变性的一般偏好。
与许多传统函数式语言不同,Scala允许逐渐、轻松地迁移到更具函数式的风格。您可以开始将其用作“没有分号的Java”。随着时间的推移,您可以逐步消除应用程序中的可变状态,逐步确定安全的功能组合模式。作为Scala程序员,我们认为这一进步通常是一个好主意。同时,您可以使用任何您喜欢的风格,Scala也没有意见。
无缝Java互操作
Scala运行在JVM上。 Java和Scala类可以自由混合,无论它们是驻留在不同的项目还是在同一个。它们甚至可以相互引用,Scala编译器包含Java编译器的一个子集,以便了解这种递归依赖关系。
Java库、框架和工具都可用。构建像ant或maven这样的工具,像Eclipse、IntelliJ或Netbeans这样的IDE,像Spring或Hibernate这样的框架都可以与Scala无缝地工作。 Scala运行在所有常见的JVM上,也可以在Android上运行。
Scala社区是Java生态系统的重要组成部分。受欢迎的Scala框架包括Akka、Finagle和Play Web框架,包括用于Java和Scala的双API。
函数是对象
Scala的方法是开发一组可以灵活组合的核心结构。这也适用于其面向对象和函数式性质。双方的特点统一到一个程度,函数式和面向对象可以看作是同一个硬币的两面。
一些例子:Scala中的函数是对象。函数类型只是一个常规类。在诸如Haskell、F#或ML之类的语言中发现的代数数据类型在Scala中以类层次建模。模式匹配是可能的任意类。
面向未来
Scala特别在涉及使用并发和同步处理、多核并行利用和云中分布式处理的可伸缩服务器软件时尤为明显。
其函数式使得编写安全和执行多线程代码更容易。通常对可变状态的依赖程度较低,而参与者提供了强大的工具,用于组织高级抽象的并发系统。
乐趣

也许最重要的是,在Scala中的编程往往是非常愉快的。没有样板,快速迭代,但同时具有强静态系统的安全性。来自Guardian的Graham Tackley说:“我们发现Scala使我们能够以更少的代码来更快地提供更多的东西。这让我们团队重新焕发了生机。“

(原文:http://www.scala-lang.org/what-is-scala.html,WRITTEN BY: Martin Odersky)

Overview

Name With Ownerscala/scala
Primary LanguageScala
Program languageShell (Language Count: 11)
PlatformAndroid, BSD, Linux, Mac, Solaris, Windows
License:Apache License 2.0
Release Count161
Last Release Namev2.13.13 (Posted on 2024-02-21 12:27:22)
First Release Namev1.0.0-b5 (Posted on )
Created At2011-12-01 05:02:34
Pushed At2024-04-21 17:18:36
Last Commit At
Stargazers Count14.3k
Watchers Count723
Fork Count3.1k
Commits Count39.7k
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count8287
Pull Requests Open Count25
Pull Requests Close Count2380
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Welcome!

This is the official repository for the Scala Programming Language
standard library, compiler, and language spec.

How to contribute

To contribute in this repo, please open a pull request from your fork of this repository.

We do have to ask you to sign the Scala CLA before we can merge any of your work, to protect its open source nature.

For more information on building and developing the core of Scala, make sure to read
the rest of this README!

In order to get in touch with other Scala contributors, join
scala/contributors (Gitter) or post on
contributors.scala-lang.org (Discourse).

Reporting issues

Please report bugs at the scala/bug issue tracker. We use the scala/scala-dev tracker for coordinating bigger work items.

Get in touch!

If you need some help with your PR at any time, please feel free to @-mention anyone from the list below, and we will do our best to help you out:, username, talk to me about..., --------------------------------------------------------------------------------------------------, ----------------------------------------------------------------, ---------------------------------------------------, , @adriaanm, type checker, pattern matcher, infrastructure, language spec, , @SethTisue, getting started, build, developer docs, community build, Jenkins, library, , @retronym, compiler performance, weird compiler bugs, Java 8 lambdas, REPL, , @szeiger, collections, build, , @lrytz, back end, optimizer, named & default arguments, , @Ichoran, collections library, performance, , @viktorklang, concurrency, futures, , @axel22, concurrency, parallel collections, specialization, , @dragos, specialization, back end, , @janekdb, documentation, , @sjrd, interactions with Scala.js, P.S.: If you have some spare time to help out around here, we would be delighted to add your name to this list!

Repository structure

scala/
+--build.sbt                 The main sbt build script
+--lib/                      Pre-compiled libraries for the build
+--src/                      All sources
   +---/library              Scala Standard Library
   +---/reflect              Scala Reflection
   +---/compiler             Scala Compiler
   +---/intellij             IntelliJ project templates
+--spec/                     The Scala language specification
+--scripts/                  Scripts for the CI jobs (including building releases)
+--test/                     The Scala test suite
   +---/files                Partest tests
   +---/junit                JUnit tests
   +---/scalacheck           ScalaCheck tests
+--build/                    [Generated] Build output directory

Get ready to contribute

Requirements

You need the following tools:

  • Java SDK. The baseline version is 8 for both 2.12.x and 2.13.x. It may be possible to use a
    later SDK for local development, but the CI will verify against the baseline
    version.
  • sbt (sbt 0.13 on the 2.12.x branch, sbt 1 on the 2.13.x branch)

MacOS and Linux work. Windows may work if you use Cygwin. Community help with keeping
the build working on Windows is appreciated.

Tools we use

We are grateful for the following OSS licenses:

Build setup

Basics

During ordinary development, a new Scala build is built by the
previously released version. For short we call the previous release
"starr": the stable reference release. Building with starr is
sufficient for most kinds of changes.

However, a full build of Scala (a bootstrap, as performed by our CI)
requires two layers. This guarantees that every Scala version can
build itself. If you change the code generation part of the Scala
compiler, your changes will only show up in the bytecode of the
library and compiler after a bootstrap. See below for how to do a
bootstrap build locally.

For history on how the current scheme was arrived at, see
https://groups.google.com/d/topic/scala-internals/gp5JsM1E0Fo/discussion.

Using the sbt build

Once you've started an sbt session you can run one of the core commands:

  • compile compiles all sub-projects (library, reflect, compiler, scaladoc, etc)
  • scala / scalac run the REPL / compiler directly from sbt (accept options /
    arguments)
  • dist/mkBin generates runner scripts (scala, scalac, etc) in build/quick/bin
  • dist/mkPack creates a build in the Scala distribution format in build/pack
  • test runs the JUnit test, testOnly *immutable.ListTest runs a subset
  • partest runs partest tests (accepts options, try partest --help)
  • scalacheck/test runs scalacheck tests, scalacheck/testOnly *FloatFormatTest runs a subset
  • publishLocal publishes a distribution locally (can be used as scalaVersion in
    other sbt projects)
    • Optionally set baseVersionSuffix := "-bin-abcd123-SNAPSHOT"
      where abcd123 is the git hash of the revision being published. You can also
      use something custom like "-bin-mypatch". This changes the version number from
      2.12.2-SNAPSHOT to something more stable (2.12.2-bin-abcd123-SNAPSHOT).
    • Note that the -bin string marks the version binary compatible. Using it in
      sbt will cause the scalaBinaryVersion to be 2.12. If the version is not
      binary compatible, we recommend using -pre, e.g., 2.13.0-pre-abcd123-SNAPSHOT.
    • Optionally set publishArtifact in (Compile, packageDoc) in ThisBuild := false
      to skip generating / publishing API docs (speeds up the process).

If a command results in an error message like a module is not authorized to depend on itself, it may be that a global SBT plugin (such as ENSIME) is
resulting in a cyclical dependency. Try disabling global SBT plugins (perhaps by
temporarily commenting them out in ~/.sbt/1.0/plugins/plugins.sbt).

Sandbox

We recommend to keep local test files in the sandbox directory which is listed in
the .gitignore of the Scala repo.

Incremental compilation

Note that sbt's incremental compilation is often too coarse for the Scala compiler
codebase and re-compiles too many files, resulting in long build times (check
sbt#1104 for progress on that front). In the
meantime you can:

  • Use IntelliJ IDEA for incremental compiles (see IDE Setup below) - its
    incremental compiler is a bit less conservative, but usually correct.

Bootstrapping locally

To perform a bootstrap using sbt

  • first a build is published either locally or on a temporary repository,
  • then a separate invocation of sbt (using the previously built version as starr)
    is used to build / publish the actual build.

Assume the current starr version is 2.12.0 (defined in
versions.properties) and the current version is 2.12.0-SNAPSHOT
(defined in build.sbt). To perform a local bootstrap:

  • Run publishLocal (you may want to specify a custom version suffix and skip
    generating API docs, see above).
  • Quit sbt and start a new sbt instance using sbt -Dstarr.version=<version> where
    <version> is the version number you published locally.
  • If the version number you published is not binary compatible with the current
    starr, set every scalaBinaryVersion := "2.12.0-M4". This is not required if
    the version you published locally is binary compatible, i.e., if the current
    starr is a 2.12.x release and not a milestone / RC.

The last step is required to resolve modules (scala-partest, etc). It
assumes that the module releases for the current starr work (in terms of binary
compatibility) with the local starr that you published locally. A full bootstrap
requires re-building the all the modules. On our CI this is handled by the
bootstrap script, but it (currently) cannot
be easily executed locally.

IDE setup

You may use IntelliJ IDEA (see src/intellij/README.md),
or ENSIME (see this page on the ENSIME site).
(Support for Eclipse has decayed and been removed, but could be resurrected by
a volunteer.)

In order to use IntelliJ's incremental compiler:

  • run dist/mkBin in sbt to get a build and the runner scripts in build/quick/bin
  • run "Build" - "Make Project" in IntelliJ

Now you can edit and build in IntelliJ and use the scripts (compiler, REPL) to
directly test your changes. You can also run the scala, scalac and partest
commands in sbt. Enable "Ant mode" (explained above) to prevent sbt's incremental
compiler from re-compiling (too many) files before each partest invocation.

Coding guidelines

Our guidelines for contributing are explained in CONTRIBUTING.md.
It contains useful information on our coding standards, testing, documentation, how
we use git and GitHub and how to get your code reviewed.

You may also want to check out the following resources:

Scala CI

Build Status

Once you submit a PR your commits will be automatically tested by the Scala CI.

If you see a spurious build failure, you can post /rebuild as a PR comment.
The scabot README lists all available commands.

If you'd like to test your patch before having everything polished for review,
feel free to submit a PR and add the WIP label. In case your WIP branch contains
a large number of commits (that you didn't clean up / squash yet for review),
consider adding [ci: last-only] to the PR title. That way only the last commit
will be tested, saving some energy and CI-resources. Note that inactive WIP PRs
will be closed eventually, which does not mean the change is being rejected.

CI performs a full bootstrap. The first task, validate-publish-core, publishes
a build of your commit to the temporary repository
https://scala-ci.typesafe.com/artifactory/scala-pr-validation-snapshots.
Note that this build is not yet bootstrapped, its bytecode is built using the
current starr. The version number is 2.12.2-bin-abcd123-SNAPSHOT where abcd123
is the commit hash. For binary incompatible builds, the version number is
2.13.0-pre-abcd123-SNAPSHOT.

You can use Scala builds in the validation repository locally by adding a resolver
and specifying the corresponding scalaVersion:

$ sbt
> set resolvers += "pr" at "https://scala-ci.typesafe.com/artifactory/scala-pr-validation-snapshots/"
> set scalaVersion := "2.12.2-bin-abcd123-SNAPSHOT"
> console

Note that the scala modules are currently not built/published against the
tested version during CI validation.

Nightly builds

The Scala CI builds nightly download releases (including all modules) and publishes
them to the following locations:

The CI also publishes nightly API docs:

Using a nightly build in sbt is explained in
this Stack Overflow answer

Scala CI internals

The Scala CI runs as a Jenkins instance on scala-ci.typesafe.com,
configured by a chef cookbook at scala/scala-jenkins-infra.

The build bot that watches PRs, triggers testing builds and applies the "reviewed" label
after an LGTM comment is in the scala/scabot repo.

Community build

The Scala community build is an important method for testing Scala
releases. A community build can be launched for any Scala commit, even
before the commit's PR has been merged. That commit is then used to
build a large number of open-source projects from source and run their
test suites.

To request a community build run on your PR, just ask in a comment on
the PR and a Scala team member (probably @SethTisue) will take care of
it. (details)

Community builds run on the Scala Jenkins instance. The jobs are
named ..-integrate-community-build. See the
scala/community-builds
repo.

To the top