Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Polished Ruby Programming
  • Table Of Contents Toc
Polished Ruby Programming

Polished Ruby Programming - Second Edition

By : Jeremy Evans
close
close
Polished Ruby Programming

Polished Ruby Programming

By: Jeremy Evans

Overview of this book

Most successful Ruby applications become more difficult to maintain as the codebase grows in size. Polished Ruby Programming, 2nd Edition provides you with the skills and advice you need to design Ruby programs and libraries that are robust, performant, scalable, and maintainable. The book takes you through possible implementation approaches for many common programming situations, discusses the trade-offs inherent in each approach, and explains why you may sometimes choose to use different approaches. You'll start by learning fundamental Ruby programming principles, such as correctly using core classes, class and method design, variable usage, error handling, and code formatting. Then you’ll move on to higher-level topics such as library design, metaprogramming, domain-specific languages, and refactoring. Finally, you'll learn about the pros and cons of different approaches to concurrency, what you should consider when deciding whether to use static types in your Ruby code, and how best to optimize your Ruby code. The 2nd edition of Polished Ruby Programming has been updated to include relevant changes between Ruby 3.0 and 4.0. While most principles discussed in the book apply to all recent Ruby versions, some of the content in the book is specific to Ruby 4.0, the latest release at the time of publication.
Table of Contents (20 chapters)
close
close
18
Other Books You May Enjoy
19
Index

Preface

The purpose of this book is to teach useful principles for intermediate to advanced Ruby programmers to follow. The focus is not generally on how to implement solutions, but on different implementation approaches, the trade-offs between them, and why some approaches are better in certain situations. While the main focus of the book is teaching principles, in some cases this book also teaches advanced Ruby programming techniques.

This book starts by teaching some fundamental principles, such as how best to use the core classes, when and how best to use each variable type, and how best to use the different types of method arguments. After building on the fundamental principles, the book teaches principles for better library design, such as how best to design extensible plugin systems, trade-offs when using metaprogramming and DSLs, and how best to approach testing, refactoring, concurrency, static typing, and optimization.

Who this book is for

The target audience for the book is intermediate to advanced Ruby programmers who are interested in learning principles to improve their Ruby programming.

What this book covers

Chapter 1, Getting the Most out of Core Classes, focuses on the optimal usage of the built-in classes.

Chapter 2, Designing Useful Classes, focuses on when it makes sense to implement a class, applying SOLID design to classes, and the trade-offs between having large classes and having a large number of classes.

Chapter 3, Proper Variable Usage, focuses on how best to use each of Ruby's variable types.

Chapter 4, Methods and Their Parameters, focuses on method naming principles, the best usage of each of the method argument types, and choosing proper method visibility.

Chapter 5, Handling Errors, focuses on the trade-offs between using exceptions and return values for handling errors, handling transient errors, and designing exception class hierarchies.

Chapter 6, Formatting Code for Easy Reading, focuses on different viewpoints on the importance of syntactic complexity and the downsides of arbitrary limits.

Chapter 7, Designing Your Library, focuses on designing your library around the user experience and complexity trade-offs when designing methods for your library.

Chapter 8, Designing for Extensibility, focuses on designing useful plugin systems to allow for extensibility in libraries.

Chapter 9, Metaprogramming and When to Use It, focuses on the pros and cons of abstraction, avoiding redundancy, and trade-offs between the two approaches Ruby has for metaprogramming.

Chapter 10, Designing Useful Domain-Specific Languages, focuses on when and how best to design DSLs.

Chapter 11, Testing to Ensure Your Code Works, focuses on why testing is so important, how to approach testing and manage complexity during testing, and the importance of code coverage.

Chapter 12, Handling Change, focuses on when and how best to implement refactoring in libraries, and deprecation strategies.

Chapter 13, Using Common Design Patterns, focuses on principles for the best usage of five common design patterns.

Chapter 14, Choosing Your Concurrency Approach, focuses on different concurrency approaches in Ruby and their trade-offs, how to approach CPU-bound and IO-bound applications, and making code ractor compatible.

Chapter 15, Static or Duck, focuses on what static typing means in Ruby, the trade-offs involved in statically typing Ruby code, and whether it makes sense to use static types in your code.

Chapter 16, Optimizing Your Code, focuses on determining when optimization is needed and how to approach optimization if it is needed.

To get the most out of this book

This book assumes intermediate to advanced knowledge of the Ruby programming language. There are sections of the book that are accessible to those with only basic knowledge of Ruby, but most of the book assumes you already understand how Ruby works and tries to teach principles for more productive usage of Ruby.

While most of the ideas and principles discussed in the book, and most of the code examples used in the book, apply to any version of Ruby, some of the examples and principles are specific to Ruby 4.0, the latest release at the time of publication.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Polished-Ruby-Programming-2nd-Edition. In case there's an update to the code, it will be updated on the existing GitHub repository.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example: "There are a few cases where you will want to return true or false and not other objects."

A block of code is set as follows:

class Foo
  def self.bar = :baz
end

Any command-line input or output is written as follows:

# Warming up --------------------------------------
#         MultiplyProf    72.655k i/100ms
# Calculating -------------------------------------
#         MultiplyProf    738.559k (_ 0.8%) i/s

The reason for the # in the command-line input or output sections is that all code blocks in this book must be valid Ruby code (sometimes heredocs are used instead of #).

Bold: Indicates a new term, an important word, or words that you see on the screen. For instance, words in menus or dialog boxes appear in the text like this. For example: " There are many good options for profiling Ruby code, from older profilers such as ruby-prof and stackprof, to newer profilers such as Vernier and rbspy."

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book or have any general feedback, please email us at [email protected] and mention the book's title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you reported this to us. Please visit http://www.packt.com/submit-errata, click Submit Errata, and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packt.com/.

Share your thoughts

Once you've read Polished Ruby Programming, Second Edition, we'd love to hear your thoughts! Scan the QR code below to go straight to the Amazon review page for this book and share your feedback.

Image

https://packt.link/r/1803243643

Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Polished Ruby Programming
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon