Home  >  Article  >  Backend Development  >  [TOUR OF Scala] 1-Introduction - TOUR OF SCALA

[TOUR OF Scala] 1-Introduction - TOUR OF SCALA

不言
不言Original
2018-03-30 14:19:181446browse

Welcome

This journey contains some concise introductions: introducing the most commonly used functions of Scala. It is designed to help newbies learn the language.

This is just a brief introduction, not a complete language tutorial. If you can, consider buying this book or checking out other resources.

What is Scala?

Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant and type-safe way. It smoothly integrates features of object-oriented and functional languages.

Scala is an object-oriented language

Scala is a pure object-oriented language, in a sense all values ​​are objects. Object types and behaviors are described by classes and traits. Classes are extended through subclassing and a flexible mixin-based composition mechanism to become a complete replacement for multiple inheritance.

Scala is a functional language

Scala is still a functional language. In a sense, all functions are values. Scala provides a lightweight syntax for defining anonymous functions, supports higher-order functions, allows function nesting, and supports currying. Scala's sample classes and its built-in support for pattern matching model algebraic types are used in many functional programming languages. Singleton objects provide a convenient way to group functions that are not members of a class.

Furthermore, Scala's pattern matching concepts naturally extend to XML data processing by means of ignoring right sequence patterns, through the general extension via extractor objects. In this case, the for comprehension helps in formulating the query. These features make Scala ideal for developing applications such as web services.

Scala is a statically typed language

Scala is equipped with an expression type system that statically enforces the use of abstractions in a safe and consistent manner. Specifically, the type system supports:

  • Generic classes

  • Deformation annotations

  • ## Upper type boundary and lower type boundary

  • Inner classes and abstract types as object members

  • Composite types

  • Explicit type self-reference

  • Implicit parameters and implicit conversions

  • Polymorphic methods

Type inference means that users do not need to annotate code with redundant type information. Taken together, these features provide a strong foundation for safe reuse of programming abstractions and type-safe extension of software.

Scala is extensible

In practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in the form of libraries.

In many cases this can be done without using metaprogramming tools such as macros. For example:

  • Implicit classes: allow extension methods to be added to existing types.

  • String interpolation: Users can extend it with custom interpolators.

Scala is interoperable

Scala is designed to interoperate well with popular Java Runtime Environments (JREs). In particular, interaction with the mainstream object-oriented Java programming language is as smooth as possible. Newer Java features such as SAM, lambdas, annotations and generics have direct analogues in Scala.

Those Scala features that have no Java analogues, such as default parameters and named parameters, are compiled as close to Java as possible. Scala has the same compilation model as Java (separate compilation, dynamic class loading) and allows access to thousands of existing high-quality libraries.

TODO Related links in the text will be replaced after all translations

The above is the detailed content of [TOUR OF Scala] 1-Introduction - TOUR OF SCALA. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn