Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jroesch/learnyouascala
A light-weight Scala tutorial with examples.
https://github.com/jroesch/learnyouascala
Last synced: 23 days ago
JSON representation
A light-weight Scala tutorial with examples.
- Host: GitHub
- URL: https://github.com/jroesch/learnyouascala
- Owner: jroesch
- Created: 2012-02-28T00:37:51.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-02-28T03:55:18.000Z (over 12 years ago)
- Last Synced: 2023-03-14T05:31:03.464Z (over 1 year ago)
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This is a companion work to a talk I was giving on Scala, and all examples are provided in the source tree.
# Introduction
>Scala is a general purpose 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. It is also fully interoperable with Java.- [Scala's Webpage](www.scala-lang.org)
## References
Scala's reference's come in two flavors, mutable and immutable. The keywords ```var``` and ```val``` define these respectively. Variables in Scala are declared and defined at the same time. The only difference between the two is the mutablitity of the references themselves. ```var``` can be re-assigned to while ```val``` cannot.```Scala
/**
* String Objects are immutable themselves we are just mutating the references here.
*/
var a: String = "hello"
val b: String = "world"
// we can reassign to a
a += b
// but not to b
b = a + b
```## Literals
Scala formation of literals is nearly identical to Java's, in fact String is just an alias for java.lang.String.
The biggest difference is that we can treat everything in Scala as an object, unlike Java where there are primatives, aka value types, Integers, Doubles, Characters, Bytes, Booleans.\```Scala
// Integer Literals
val hexLiteral: Int = 0xFF
val octalLiteral: Int = 0377
val decimalLiteral: Int = 255// String Literal
val stringLiteral: String = "Hello World!\n"
```## Classes and Objects
```Scala
/**
* You can easily define classes in Scala in one line.
*/
class A
/**
* We can add data, and methods easily, and inherit with the extends keyword.
*/
class A extends B {
val a: Int
def times5 = a * 5
}
val a = new A { val a = 5 } // => a: Int = 25