Movatterモバイル変換


[0]ホーム

URL:


Packt
Search iconClose icon
Search icon CANCEL
Subscription
0
Cart icon
Your Cart(0 item)
Close icon
You have no products in your basket yet
Save more on your purchases!discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Profile icon
Account
Close icon

Change country

Modal Close icon
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timerSALE ENDS IN
0Days
:
00Hours
:
00Minutes
:
00Seconds
Home> Programming> Programming Language> Professional Scala
Professional Scala
Professional Scala

Professional Scala: Combine object-oriented and functional programming to build high-performance applications

Arrow left icon
Profile Icon HartmannProfile Icon Shevchenko
Arrow right icon
€23.99€26.99
Full star iconFull star iconFull star iconFull star iconHalf star icon4.2(13 Ratings)
eBookJul 2018186 pages1st Edition
eBook
€23.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon HartmannProfile Icon Shevchenko
Arrow right icon
€23.99€26.99
Full star iconFull star iconFull star iconFull star iconHalf star icon4.2(13 Ratings)
eBookJul 2018186 pages1st Edition
eBook
€23.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€23.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature iconInstant access to your Digital eBook purchase
Product feature icon Download this book inEPUB andPDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want
OR

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Billing Address

Table of content iconView table of contentsPreview book icon Preview Book

Professional Scala

Chapter 2. Basic Language Features

In the previous chapter, we learned the various aspects of setting up the development environment wherein we covered the structure of a Scala project and identified the use ofsbt for building and running projects. We covered REPL, which is a command-line interface for running Scala code, and how to develop and run code over the IDEA IDE. Finally, we implemented interactions with our simplechatbot application.

In this chapter, we will explore the so-called 'OO' part of Scala, which allows us to build constructions similar to analogs in any mainstream language, such as Java or C++. The object-oriented part of Scala will cover classes and objects, traits, pattern matching, case class, and so on. Finally, we will implement the object-oriented concepts that we learn to our chatbot application.

Looking at the history of programming paradigms, we will notice that the first generation of high-level programming languages (Fortran, C, Pascal...

Objects, Classes, and Traits

Scala is a multiparadigm language, which unites functional and OO programming. Now, we will explore Scala's traditional object-oriented programming facilities: object, classes, and traits.

These facilities are similar in the sense that each one contains some sets of data and methods, but they are different regarding life cycle and instance management:

  • Objects areused when we need a type with one instance (such as singletons)
  • Classes areused when we need to have many instances, which canbe created with the help of the new operator
  • Traits areusedfor mix-ins into other classes

Note that it is not worth navigating through code, as this is exposed in examples.

Object

We haveseenan object in the previous chapter. Let's scroll through our codebase and open the file namedMain inLesson 2/3-project:

object Chatbot3 {val effects = DefaultEffectsdef main(args: Array[String]): Unit = {   ….}   def createInitMode() = (Bye or CurrentDate or CurrentTime...

OO in Our Chatbot

Now that you know the theoretical basics, let's look at these facilities and how they areused in our program. Let's openLesson 2/3-project in our IDE and extend our chatbot, which was developed in the previous chapter.

Decoupling Logic and Environment

To do this, we must decouple the environment and logic, and integrate only one in themain method.

Let's open theEffectsProvider class:

Note

For full code, refer toCode Snippets/Lesson 2.scala file.

trait EffectsProvider extends TimeProvider { def input: UserInput def output: UserOutput}object DefaultEffects extends EffectsProvider{ override def input: UserInput = ConsoleInput override def output: UserOutput = ConsoleOutput override def currentTime(): LocalTime = LocalTime.now() override def currentDate(): LocalDate = LocalDate.now()}

Here, we encapsulate all of the effects into our traits, which can have different implementations.

For example, let's look atUserOutput:

For full...

Function Calls

Now, we'll look at how function calls are implemented in Scala.

Syntax Goodies

Scalaprovides flexible syntax and it is worth dedicating a few minutes to this concept.

Named Parameters

The following isa function,f(a:Int, b:Int). We can call thisfunction using the named parameter syntax:f(a = 5, b=10). If we swap the parameters but leave the correct names, the method will still be correct.

It is possible to combine positional and named function calls—the first few arguments can be positional.

For example:

def f(x:Int, y:Int) = x*2 + yf(x=1,y=2) // 4f(y=1,x=2) // 5

Default Parameters

When specifying a function, wecan set default parameters. Then, later, when we call this function, we can omit parameters and the compiler will substitute defaults:

def f(x:Int, y:Int=2) = x*2 + yf(1) // 4

It is possible to create a comfortable API with the help of the combination of named and default arguments. For example, for case classes with N components, the compiler generates...

Summary

We have now reached the end of this chapter. In this chapter, we covered the object-oriented aspects of Scala such as classes, objects, pattern matching, self-types, case classes, and so on. We also implemented object-oriented concepts that we learned in our chatbot application.

In the next chapter, we will cover functional programming with Scala and how object-oriented and functional approaches complete each other. We will also cover generic classes, which are often used with pattern matching. We will also cover how to create user-defined pattern matching and why is it useful.

Left arrow icon

Page1 of 5

Right arrow icon

Key benefits

  • Expert guidance that shows you to efficiently use both object-oriented and functional programming techniques
  • Understand functional programming libraries, such as Cats and Scalaz, and use them to augment your Scala development
  • Perfectly balances theory and hands-on exercises, assessments, and activities

Description

This book teaches you how to build and contribute to Scala programs, recognizing common patterns and techniques used with the language. You’ll learn how to write concise, functional code with Scala. After an introduction to core concepts, syntax, and writing example applications with scalac, you’ll learn about the Scala Collections API and how the language handles type safety via static types out-of-the-box. You’ll then learn about advanced functional programming patterns, and how you can write your own Domain Specific Languages (DSLs). By the end of the book, you’ll be equipped with the skills you need to successfully build smart, efficient applications in Scala that can be compiled to the JVM.

Who is this book for?

This is an ideal book for developers who are looking to learn Scala, and is particularly well suited for Java developers looking to migrate across to Scala for application development on the JVM.

What you will learn

  • Understand the key language syntax and core concepts for application development
  • Master the type system to create scalable type-safe applications while cutting down your time spent debugging
  • Understand how you can work with advanced data structures via built-in features such as the Collections library
  • Use classes, objects, and traits to transform a trivial chatbot program into a useful assistant
  • Understand what are pure functions, immutability, and higher-order functions
  • Recognize and implement popular functional programming design patterns

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date :Jul 31, 2018
Length:186 pages
Edition :1st
Language :English
ISBN-13 :9781789534702
Category :
Languages :

What do you get with eBook?

Product feature iconInstant access to your Digital eBook purchase
Product feature icon Download this book inEPUB andPDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want
OR

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Billing Address

Product Details

Publication date :Jul 31, 2018
Length:186 pages
Edition :1st
Language :English
ISBN-13 :9781789534702
Category :
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99billed monthly
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconSimple pricing, no contract
€189.99billed annually
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick iconExclusive print discounts
€264.99billed in 18 months
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick iconExclusive print discounts

Frequently bought together


Modern Scala Projects
Modern Scala Projects
Read more
Jul 2018334 pages
eBook
eBook
€28.99€32.99
€41.99
Professional Scala
Professional Scala
Read more
Jul 2018186 pages
Full star icon4.2 (13)
eBook
eBook
€23.99€26.99
€32.99
Scala Programming Projects
Scala Programming Projects
Read more
Sep 2018398 pages
Full star icon3.8 (5)
eBook
eBook
€28.99€32.99
€41.99
Stars icon
Total116.97
Modern Scala Projects
€41.99
Professional Scala
€32.99
Scala Programming Projects
€41.99
Total116.97Stars icon

Table of Contents

9 Chapters
1. Setting up the Development EnvironmentChevron down iconChevron up icon
1. Setting up the Development Environment
Simple Program
Structure of a Scala Project
Base Syntax
Unit Testing
Summary
2. Basic Language FeaturesChevron down iconChevron up icon
2. Basic Language Features
Objects, Classes, and Traits
OO in Our Chatbot
Function Calls
Summary
3. FunctionsChevron down iconChevron up icon
3. Functions
Functions
Exploring Pattern Matching
Partial Functions in Practice
Summary
4. Scala CollectionsChevron down iconChevron up icon
4. Scala Collections
Working with Lists
Abstracting on Sequences
Other Collections
Summary
5. Scala Type SystemChevron down iconChevron up icon
5. Scala Type System
Type Basics and Polymorphism
Variance
Advanced Types
Summary
6. ImplicitsChevron down iconChevron up icon
6. Implicits
Implicit Parameters and Implicit Conversions
Ad Hoc Polymorphism and Type Classes
Summary
7. Functional IdiomsChevron down iconChevron up icon
7. Functional Idioms
Introduction to Functional Programming Concepts
Functional Design Patterns
Popular Libraries
Summary
8. Domain Specific LanguagesChevron down iconChevron up icon
8. Domain Specific Languages
DSLs and Types of DSLs
ScalaTest – A Popular DSL
Language Features for Writing DSLs
Writing a Small DSL
Beyond This Book
Summary
IndexChevron down iconChevron up icon
Index

Recommendations for you

Left arrow icon
Debunking C++ Myths
Debunking C++ Myths
Read more
Dec 2024226 pages
Full star icon5 (1)
eBook
eBook
€20.99€23.99
€29.99
Go Recipes for Developers
Go Recipes for Developers
Read more
Dec 2024350 pages
eBook
eBook
€20.99€23.99
€29.99
50 Algorithms Every Programmer Should Know
50 Algorithms Every Programmer Should Know
Read more
Sep 2023538 pages
Full star icon4.5 (68)
eBook
eBook
€26.98€29.99
€37.99
€37.99
Asynchronous Programming with C++
Asynchronous Programming with C++
Read more
Nov 2024424 pages
Full star icon5 (1)
eBook
eBook
€22.99€25.99
€31.99
Modern CMake for C++
Modern CMake for C++
Read more
May 2024504 pages
Full star icon4.7 (12)
eBook
eBook
€26.98€29.99
€37.99
Learn Python Programming
Learn Python Programming
Read more
Nov 2024616 pages
Full star icon5 (1)
eBook
eBook
€20.99€23.99
€29.99
Learn to Code with Rust
Learn to Code with Rust
Read more
Nov 202457hrs 40mins
Video
Video
€56.99
Modern Python Cookbook
Modern Python Cookbook
Read more
Jul 2024818 pages
Full star icon4.9 (21)
eBook
eBook
€28.99€32.99
€41.99
Right arrow icon

Customer reviews

Top Reviews
Rating distribution
Full star iconFull star iconFull star iconFull star iconHalf star icon4.2
(13 Ratings)
5 star53.8%
4 star23.1%
3 star15.4%
2 star0%
1 star7.7%
Filter icon Filter
Top Reviews

Filter reviews by




Sviatoslav KsondzykMay 01, 2020
Full star iconFull star iconFull star iconFull star iconFull star icon5
Udemy Verified reviewUdemy
Alex KalinichevNov 26, 2022
Full star iconFull star iconFull star iconFull star iconFull star icon5
Udemy Verified reviewUdemy
Parthasarathy ChakravarthyNov 17, 2021
Full star iconFull star iconFull star iconFull star iconFull star icon5
Udemy Verified reviewUdemy
Mikhail KaluginFeb 06, 2021
Full star iconFull star iconFull star iconFull star iconFull star icon5
Udemy Verified reviewUdemy
Paritosh sharmaDec 10, 2019
Full star iconFull star iconFull star iconFull star iconFull star icon5
Udemy Verified reviewUdemy
  • Arrow left icon Previous
  • 1
  • 2
  • 3
  • Arrow right icon Next

People who bought this also bought

Left arrow icon
50 Algorithms Every Programmer Should Know
50 Algorithms Every Programmer Should Know
Read more
Sep 2023538 pages
Full star icon4.5 (68)
eBook
eBook
€26.98€29.99
€37.99
€37.99
Event-Driven Architecture in Golang
Event-Driven Architecture in Golang
Read more
Nov 2022384 pages
Full star icon4.9 (11)
eBook
eBook
€26.98€29.99
€37.99
The Python Workshop Second Edition
The Python Workshop Second Edition
Read more
Nov 2022600 pages
Full star icon4.6 (22)
eBook
eBook
€27.99€31.99
€38.99
Template Metaprogramming with C++
Template Metaprogramming with C++
Read more
Aug 2022480 pages
Full star icon4.6 (14)
eBook
eBook
€25.99€28.99
€35.99
Domain-Driven Design with Golang
Domain-Driven Design with Golang
Read more
Dec 2022204 pages
Full star icon4.4 (19)
eBook
eBook
€23.99€26.99
€33.99
Right arrow icon

About the authors

Left arrow icon
Profile icon Hartmann
Hartmann
Mads Hartmann is a software engineer with a fondness for automation and programming languages, especially statically typed functional ones. He holds a masters degree in computer science from the University of Copenhagen and he is currently working as a full-stack engineer at Family. He is active in the Copenhagen developer scene and has organized a meetup group for people interested in Scala.
Read more
See other products by Hartmann
Profile icon Shevchenko
Shevchenko
Ruslan Shevchenko is a system architect and a software developer who is focused on building reliable software systems. During his career patch, he was involved in projects using many languages, from Scala, Java to C++, C, Perl, and Tcl in numerous areas, such as telecommunications, OSS/billing systems, finance, code analysis, social integration, system utilities. In terms of architecture, his specialist domains are large-scale software systems and distributed processing.
Read more
See other products by Shevchenko
Right arrow icon
Getfree access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook?Chevron down iconChevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website?Chevron down iconChevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook?Chevron down iconChevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support?Chevron down iconChevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks?Chevron down iconChevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook?Chevron down iconChevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.


[8]ページ先頭

©2009-2025 Movatter.jp