Get the code on GitHub

Preface

Computer science introductory texts are often unnecessarily long. Many exceed 500 pages, laboriously describing every nuance of whatever programming language they are using to introduce the concepts.

There is a better way: a programming language that has a low entry barrier. Preferably, the language selected should be a real, widely used language with a subset that is powerful and useful, yet mercifully small. Such a choice should arm the readers with marketable tools. The esoteric details of the programming language, however, should be ignored but with pointers for future investigation provided.

Ruby is a programming language well suited to this task. It is object-oriented, interpreted, and relatively straightforward. More so, instead of being purely educationally oriented, its popularity in industry is steadfastly growing.

Our book should be covered in sequential fashion. Each chapter assumes that the material from the preceding chapters has been mastered. To focus the discussion, we ignore gory details, such as user interface design and development issues, that we believe are ancillary to the core of computer science. Such issues should be, and are, covered in depth in a variety of subsequent courses.

Our target audience is students and practitioners who wish to learn computer science using Ruby rather than just how to program in a given language. This book consistently emphasizes why computer science is different from computer programming. Students and practitioners must understand what an algorithm is and what differentiates differing algorithms for the same task. Although we are living in an era of growing computational resources, we are also living in a world of growing data sets. Data amass every day; thus, efficient algorithms are needed to process these data.

Students and practitioners completing a course using this book possess foundational knowledge in the basics of computer science and are prepared to master abstract and advanced concepts. Second semester courses should rely on languages other than Ruby, furthering the understanding that programming languages are just interchangeable, expressive tools. We know, however, that many students and practitioners may not take another computer science course. If that is the case, this book provides them with an overview of the field and an understanding of at least one popular programming language that happens to be useful from both a practical and a pedagogical standpoint.

Concepts taught in this book provide students and practitioners with a sufficient foundation to later learn more complex algorithms, advanced data structures, and new programming languages.

Finally, we hope to instill a core appreciation for algorithms and problem solving so students and practitioners will solve problems with elegance and inspiration rather than simply plowing ahead with brute force.

The slides corresponding to this book and the source code listed in the book are available at http://ir.cs.georgetown.edu/Computer_Science_Programming_Basics_with_Ruby.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, email addresses, filenames, and file extensions

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords

Constant width bold

Shows commands or other text that should be typed literally by the user

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context

This icon signifies a tip, suggestion, or general note

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Computer Science Programming Basics in Ruby by Ophir Frieder, Gideon Frieder, and David Grossman (O’Reilly). Copyright 2013 Ophir Frieder, Gideon Frieder, and David Grossman, 978-1-449-35597-5.”

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at .

Safari® Books Online

Safari Books Online (www.safaribooksonline.com) is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

  • O’Reilly Media, Inc.
  • 1005 Gravenstein Highway North
  • Sebastopol, CA 95472
  • 800-998-9938 (in the United States or Canada)
  • 707-829-0515 (international or local)
  • 707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://oreil.ly/comp_sci_basics_ruby.

To comment or ask technical questions about this book, send email to .

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments

Gone are the days where one needs to set the stage with “computers are everywhere” or “computers are a commodity.” Clearly, computers are everywhere, are used by everyone, and permeate every daily function and activity. Unfortunately, the majority of society can only use ready-made computer applications; they cannot program computers. With this book, we intend to change that!

In authoring this book, a five-year process, we benefited from and are grateful for the help of many; here we name but a few and apologize to those whose help we inadvertently forgot to acknowledge by name.

We thank all the students who persevered through the many instantiations of this text, from those who read the initial chapters over and over and over again as part of IIT’s offerings. Their comments, suggestions, and criticisms guided our corrections through the iterations.

The entire production of this book, from the first partial drafts to the final version delivered to O’Reilly, was managed by two students, initially by Yacin Nadji (a doctoral student at Georgia Tech) and more recently by Andrew Yates (a doctoral student at Georgetown University). Without their help, we would have stumbled over one another, and we would have given up the effort many times over.

We use and envision others will use our book in the classroom. To aid instruction, we provide corresponding slides that would not exist without the help of two Georgetown University students, Candice Penelton and Sarah Chang.

We benefited from many editorial remarks; we thank the editorial changes suggested by Becca Page, the anonymous reviewers, and most notably, Mike Fitzgerald, who not only reviewed the book word by word, but also tested our code. We also thank Jason Soo for his periodic assistance with the Ruby source code and Abdur Chowdhury for his general guidance and assistance. Likewise, we thank the entire O’Reilly production team, who went way beyond what could be expected and significantly improved this book.

Finally and foremost, we thank our family members whose support and tolerance helped us through our jointly endured struggles (for David: Mary Catherine, Isaac, and Joseph; for Gideon: Dalia; and for Ophir: Nazli).

Sampler Contents: