<commit_before><!doctype html>
<html lang="en">

	<head>
		<meta charset="utf-8">

		<title>Scala Traits</title>

		<meta name="description" content="Rough notes...and still not much useful">
		<meta name="author" content="<NAME>">

		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<link rel="stylesheet" href="css/reveal.min.css">
		<link rel="stylesheet" href="css/theme/beige.css" id="theme">

		<!-- For syntax highlighting -->
		<link rel="stylesheet" href="lib/css/zenburn.css">

		<!-- If the query includes 'print-pdf', include the PDF print sheet -->
		<script>
			if( window.location.search.match( /print-pdf/gi ) ) {
				var link = document.createElement( 'link' );
				link.rel = 'stylesheet';
				link.type = 'text/css';
				link.href = 'css/print/pdf.css';
				document.getElementsByTagName( 'head' )[0].appendChild( link );
			}
		</script>

		<!--[if lt IE 9]>
		<script src="lib/js/html5shiv.js"></script>
		<![endif]-->
	</head>

	<body>

		<div class="reveal">

			<!-- Any section element inside of this container is displayed as a slide -->
			<div class="slides">
				<section>
					<h1>Scala Traits</h1>
					<h3>Rough notes...and still not much useful</h3>
					<p>
						<small>Created by <a href="http://blog.jaceklaskowski.pl"><NAME></a> / <a href="http://twitter.com/jaceklaskowski">@jaceklaskowski</a></small>
					</p>
				</section>

				<section data-transition="linear" data-background-transition="slide">
					<h2>Friendly Heads-Up</h2>
					<div style="position: relative">
					<p>
						This presentation is
						<span style="display:inline-block;position:relative">
							a mere summary
							<span style="position:absolute;display:inline-block;padding:4px;border-radius:10px;top:-4px;left:-4px;background-color:#eee8d5;color:#1B2C3D;font-weight:bold" class="fragment">a mere summary</span>
						</span>
						of what I could learn from the many sources available on the Internet.
						<br>
						I wholeheartedly apologise for being incompetent to yield added value besides the presentation itself.
					</p>
					</div>
				</section>

				<section data-markdown>
					<script type="text/template">
					## Traits

					* Traits are useful for mixing functionality into a class.
					* traits are used to define object types by specifying the signature of the supported methods.
					* Scala allows traits to be partially implemented; i.e. it is possible to define default implementations for some methods.
					* Traits can inherit from other traits or from classes.
					* Mixin composition in Scala occurs at compile time.
					</script>
				</section>

				<section data-markdown>
					<script type="text/template">
					## Trait inheritance vs self-types (1 of 2)

* `A` cannot be mixed into a concrete class that does not also extend `B`, i.e. `A` *uses-a* `B`:

```
trait B
trait A { this: B => }
```

* any (concrete or abstract) class mixing in `A` will also be mixing in `B`, i.e. `A` *is-a* `B`:
<commit_msg>Notes from Chapter 12 of Programming in Scala, First Edition<commit_after><!doctype html>
<html lang="en">

	<head>
		<meta charset="utf-8">

		<title>Scala Traits</title>

		<meta name="description" content="Rough notes...and still not much useful">
		<meta name="author" content="<NAME>">

		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<link rel="stylesheet" href="css/reveal.min.css">
		<link rel="stylesheet" href="css/theme/beige.css" id="theme">

		<!-- For syntax highlighting -->
		<link rel="stylesheet" href="lib/css/zenburn.css">

		<!-- If the query includes 'print-pdf', include the PDF print sheet -->
		<script>
			if( window.location.search.match( /print-pdf/gi ) ) {
				var link = document.createElement( 'link' );
				link.rel = 'stylesheet';
				link.type = 'text/css';
				link.href = 'css/print/pdf.css';
				document.getElementsByTagName( 'head' )[0].appendChild( link );
			}
		</script>

		<!--[if lt IE 9]>
		<script src="lib/js/html5shiv.js"></script>
		<![endif]-->
	</head>

	<body>

		<div class="reveal">

			<!-- Any section element inside of this container is displayed as a slide -->
			<div class="slides">
				<section>
					<h1>Scala Traits</h1>
					<h3>Rough notes...and still not much useful</h3>
					<p>
						<small>Created by <a href="http://blog.jaceklaskowski.pl"><NAME></a> / <a href="http://twitter.com/jaceklaskowski">@jaceklaskowski</a></small>
					</p>
				</section>

				<section data-transition="linear" data-background-transition="slide">
					<h2>Friendly Heads-Up</h2>
					<div style="position: relative">
					<p>
						This presentation is
						<span style="display:inline-block;position:relative">
							a mere summary
							<span style="position:absolute;display:inline-block;padding:4px;border-radius:10px;top:-4px;left:-4px;background-color:#eee8d5;color:#1B2C3D;font-weight:bold" class="fragment">a mere summary</span>
						</span>
						of what I could learn from the many sources available on the Internet.
						<br>
						I wholeheartedly apologise for being incompetent to yield added value besides the presentation itself.
					</p>
					</div>
				</section>

				<section>
					<section data-markdown>
						<script type="text/template">
							## Programming in Scala, First Edition

							### Chapter 12 Traits
							by <NAME>, <NAME>, and <NAME><br>
							December 10, 2008<br>
							http://www.artima.com/pins1ed/traits.html
						</script>
					</section>
					<section data-markdown>
						<script type="text/template">
							## Introduction

							* Traits are **a fundamental unit of code reuse** in Scala.
							* A trait encapsulates **method and field definitions**.
							* Reused by **mixing** them into classes
							* A class can mix in **any number of traits**
							* **Two** of the most common ways they are useful
								* widening thin interfaces to rich ones
								* defining stackable modifications
						</script>
					</section>
					<section data-markdown>
						<script type="text/template">
							## 12.1 How traits work

							`trait` keyword defines a new trait

```scala
// example from the Akka project
trait Actor {

  def receive: Actor.Receive

  type Receive = Actor.Receive

}
```
						</script>
					</section>
				</section>

				<section>
					<section data-markdown>
						<script type="text/template">
							## Spray-Swagger project

							Spray-Swagger brings [Swagger](https://github.com/wordnik/swagger-core) support for [Spray](http://spray.io/) APIs.<br>
							https://github.com/gettyimages/spray-swagger
						</script>
					</section>
					<section data-markdown>
						<script type="text/template">
							## SwaggerHttpService

							* The `SwaggerHttpService` is a trait extending Spray's `HttpService`
						</script>
					</section>
				</section>

				<section data-markdown>
					<script type="text/template">
					## Traits the very beginning

					* Let's start with 
					* traits are used to define object types by specifying the signature of the supported methods.
					* Scala allows traits to be partially implemented; i.e. it is possible to define default implementations for some methods.
					* Traits can inherit from other traits or from classes.
					* Mixin composition in Scala occurs at compile time.
					</script>
				</section>

				<section data-markdown>
					<script type="text/template">
					## Traits

					* Traits are useful for mixing functionality into a class.
					* traits are used to define object types by specifying the signature of the supported methods.
					* Scala allows traits to be partially implemented; i.e. it is possible to define default implementations for some methods.
					* Traits can inherit from other traits or from classes.
					* Mixin composition in Scala occurs at compile time.
					</script>
				</section>

				<section data-markdown>
					<script type="text/template">
					## Trait inheritance vs self-types (1 of 2)

* `A` cannot be mixed into a concrete class that does not also extend `B`, i.e. `A` *uses-a* `B`:

```
trait B
trait A { this: B => }
```

* any (concrete or abstract) class mixing in `A` will also be mixing in `B`, i.e. `A` *is-a* `B`:

{'fraction_non_alphanumeric': 0.140303738317757, 'fraction_numerical': 0.007710280373831775, 'mean_word_length': 3.1040268456375837, 'pattern_counts': {'":': 0, '<': 161, '<?xml version=': 0, '>': 163, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4953779', 'n_tokens_mistral': 3367, 'n_tokens_neox': 2611, 'n_words': 799}