Object-Orientation, Abstraction, and Data Structures Using Scala
eBook - ePub

Object-Orientation, Abstraction, and Data Structures Using Scala

  1. 632 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Object-Orientation, Abstraction, and Data Structures Using Scala

About this book

Praise for the first edition:

"The well-written, comprehensive bookโ€ฆ[is] aiming to become a de facto reference for the language and its features and capabilities. The pace is appropriate for beginners; programming concepts are introduced progressively through a range of examples and then used as tools for building applications in various domains, including sophisticated data structures and algorithmsโ€ฆHighly recommended. Students of all levels, faculty, and professionals/practitioners.
โ€”D. Papamichail, University of Miami in CHOICE Magazine

Mark Lewis' Introduction to the Art of Programming Using Scala was the first textbook to use Scala for introductory CS courses. Fully revised and expanded, the new edition of this popular text has been divided into two books. Object-Orientation, Abstraction, and Data Structures Using Scala, Second Edition is intended to be used as a textbook for a second or third semester course in Computer Science.

The Scala programming language provides powerful constructs for expressing both object orientation and abstraction. This book provides students with these tools of object orientation to help them structure solutions to larger, more complex problems, and to expand on their knowledge of abstraction so that they can make their code more powerful and flexible. The book also illustrates key concepts through the creation of data structures, showing how data structures can be written, and the strengths and weaknesses of each one. Libraries that provide the functionality needed to do real programming are also explored in the text, including GUIs, multithreading, and networking.

The book is filled with end-of-chapter projects and exercises, and the authors have also posted a number of different supplements on the book website. Video lectures for each chapter in the book are also available on YouTube. The videos show construction of code from the ground up and this type of "live coding" is invaluable for learning to program, as it allows students into the mind of a more experienced programmer, where they can see the thought processes associated with the development of the code.

About the Authors

Mark Lewis is an Associate Professor at Trinity University. He teaches a number of different courses, spanning from first semester introductory courses to advanced seminars. His research interests included simulations and modeling, programming languages, and numerical modeling of rings around planets with nearby moons.

Lisa Lacher is an Assistant Professor at the University of Houston, Clear Lake with over 25 years of professional software development experience. She teaches a number of different courses spanning from first semester introductory courses to graduate level courses. Her research interests include Computer Science Education, Agile Software Development, Human Computer Interaction and Usability Engineering, as well as Measurement and Empirical Software Engineering.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weโ€™ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere โ€” even offline. Perfect for commutes or when youโ€™re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Object-Orientation, Abstraction, and Data Structures Using Scala by Mark C. Lewis,Lisa Lacher,Lisa L. Lacher in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming Languages. We have over one million books available in our catalogue for you to explore.

Chapter 1

Scala Language Basics

1.1 First Application
1.2 Comments
1.3 Variables and Types
1.4 Statements and Expressions
1.4.1 Lambda Expressions/Closures
1.5 Control Structures
1.5.1 Conditionals
1.5.2 Loops
1.5.3 Error Handling
1.6 Declarations and Scope
1.7 Essential Libraries
1.7.1 Standard Input and import Statements
1.7.2 Basic Collections
1.7.2.1 Array and List
1.7.2.2 Creating Collections Using fill
1.7.2.3 Creating Collections Using tabulate
1.7.2.4 Creating Arrays Using new
1.7.2.5 Creating Lists Using Cons
1.7.2.6 Range
1.7.2.7 Methods
1.7.2.8 Higher-Order Methods
1.7.3 The Option Type
1.7.4 Text Files
1.8 Other Language Features
1.8.1 Unfinished Code
1.8.2 Named Arguments
1.8.3 Default Parameter Values
1.8.4 Curried Functions/Methods
1.8.5 Pass-by-Name
1.9 The Read, Evaluate, Print Loop (REPL)
1.10 Putting It Together
1.11 End of Chapter Material
1.11.1 Summary of Concepts
1.11.2 Exercises
This book assumes that you have previous programming experience, though perhaps not with Scala. This chapter is intended to get you up to speed on the basic syntax and semantics of the Scala language. If you have previous experience with Scala, this can be a refresher. If your previous experience is in some other language, this chapter will help introduce you to the key concepts that you need to use in later chapters.
Programming languages are generally classified by different PARADIGMS. A paradigm is an approach that a language takes to organizing code and solving problems. The four main paradigms of programming are IMPERATIVE, FUNCTIONAL, OBJECT-ORIENTED, and LOGIC. Scala is generally described as both functional and object-oriented, but it is not strictly functional, as it allows the imperative style as well. This combining of paradigms is becoming more common, and even older languages, like Java and Python, have gained features that also allow them to use aspects of all three of these paradigms. In Scala, one often prefers more functional approaches, while languages like Java and Python are naturally imperative with functional features.
Through the course of this book, and hopefully later in your education, the meanings of these terms and the features of the various paradigms will become clearer. The discussion in this book will generally explicitly say whether code is written in a way that is more functional or more imperative, and everything in Scala is fundamentally object-oriented.

1.1 First Application

In this book, we are writing our programs as applications in Scala. If you happened to use Introduction to Programming and Problem Solving Using Scala[9] previously, most of that book used the REPL and the scripting environment. Applications were only introduced at the very end of that book. Here they will be the standard, though simple expressions can be entered and tested using the REPL as well. The appendices, which are available on the book website1 introduce some options for how you might want to work with Scala. Pick the tool that you like best. The rest of this book is generally tool agnostic and code is presented independent of the way in which you will compile and run it.
Applications in Scala are created by putting a main method in an object declaration. The following code shows the traditional "Hello World" program.
object HelloWorld {
def main(args:Array[String]):Unit = {
println("Hello world!")
}
}
Depending on your background, different things here might look unfamiliar, so we will go through the elements one at a time and compare them to what you might have seen previously. For comparison, and to aid the following discussion, here are similar programs written in Java and Python.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!")
}
}
def main():
print("Hello world!")
main()
This Python code is more complex than is really required. The definition of a function is included to make it more similar to the others for comparison purposes.
The main code of the Scala application is inside of an object declaration. We will discuss the meaning of the object declaration more in chapter 3 where we will also contrast it to the more commonly seen class declaration. For now, we will just say that this creates what is called a SINGLETON OBJECT. An object is something that combines both data and functionality. This declaration begins with the keyword object followed by the name we want to give our singleton object, then there is a block of code enclosed in curly braces. It is customary to use the CAMEL CASE naming scheme in Scala, where each word begins with a capital letter. The names for objects also start with a capital letter.
All declarations in Scala begin with a keyword. The object keyword declares singleton objects. The only thing we have put inside the body of our object is a METHOD called main. Methods are declared with the def keyword. That is followed by the name of the method, then the PARAMETER LIST with types in parentheses, the result type after a colon, then an equal sign and the body of the method. The names of methods should also use camel case naming, but they should begin with a lowercase letter.
The body of the main method is identified by curly braces. Inside is a single line that calls the println method and passes it the String that we want to print.
If you are coming to Scala from Java, a lot of this will look familiar. You are used to seeing class instead of object, and while you would not use def, you would have public static on your main method. In Java, you put the types before the things they modify, like the method result and the type of the argument, args. In Scala, types come after things such as methods, variables, etc., when they are specified, and they are separated by a colon. If you see a colon in Scala, the thing to the right of it will be a type that is attached to the thing to the left of it. You also notice that the type is Array[String] in Scala instead of the String[] that is used in Java. Unlike Java, there is also no semicolon at the end of the line calling println. Like Java, Scala does use semicolons to separate statements, the difference is that Scala will infer semicolons at the end of lines where the...

Table of contents

  1. Cover
  2. Half Title
  3. Title Page
  4. Copyright
  5. Contents
  6. List of Figures
  7. List of Tables
  8. Preface
  9. 1 Scala Language Basics
  10. 2 Basics of Object-Orientation and Software Development
  11. 3 Details of Object-Orientation in Scala
  12. 4 Abstraction and Polymorphism
  13. 5 GUIs and Graphics
  14. 6 Other Collection Types
  15. 7 Stacks and Queues
  16. 8 Multithreading and Concurrency
  17. 9 Low-Level Multithreading and Java Libraries
  18. 10 Stream I/O and XML
  19. 11 Networking
  20. 12 Linked Lists
  21. 13 Priority Queues
  22. 14 Refactoring
  23. 15 Recursion
  24. 16 Trees
  25. 17 Regular Expressions and Context-Free Parsers
  26. 18 Binary Heaps
  27. 19 Direct Access Binary Files
  28. 20 Spatial Trees
  29. 21 Augmenting Trees
  30. 22 Hash Tables
  31. Bibliography
  32. Index