Review: Metaprogramming in Ruby 2

Metaprogramming in Ruby 2: Program Like the Ruby Pros by Paolo Perrotta is delightful book on the advanced aspects of the Ruby language. It’s very approachable and written in a way that delights the user to follow along with examples and practicing in their own IRB or Rails console. The first time I read it, I couldn’t help but try the examples myself as I was reading along. Paolo writes them in a concise manner that’s easy to understand and truly captures the essence of the message.

Metaprogramming is explained as code that writes code, which also happens to be a great way to learn Ruby’s thoughtful and nuanced design implications. While it is entirely possible to get proficient with Ruby on Rails and develop applications without the lessons found in Metaprogramming in Ruby 2, but it would be difficult to find a better book to deepen those skills. Ruby on Rails’ strong conventions and focus on developer happiness is in no small part possible because of Ruby’s unique language features. Rails takes advantage of Ruby’s introspection, open classes (aka monkeypatching), methods design, inclusion of blocks, dynamic programming techniques to fulfill it’s promise of developer happiness, and convention over configuration.

If you’re looking for a way to level up your Ruby and Rails skills, you would be hard pressed to find a better book. I highly recommend it.

5 resources to level-up in Ruby on Rails

Ruby on Rails is a powerful web development framework. Mastering Ruby on Rails requires proficiency in a number of technical skills. At the most basic level, you need to be proficient with Ruby, the language that Ruby is written in. You need to be proficient in HTML, CSS and Javascript, the languages powering your browser. You need to be proficient in SQL, the database language for your data backend storage. You need to understand how to have a basic understanding of how to design, test, and deploy Rails applications to the web. And, you should need be proficient wth Git, an essential tool for modern source code version control.

While mastering the basics can be daunting task, there are many resources available focused on helping developers achieve proficiency. Developer bootcamps are growing in popularity, polished introductory video courses are widely available for a nominal fee, and there is no shortage of excellent free tutorials and books to teach you how to build your first Rails app.

Once mastery of the fundamentals is achieved, it can be easy to rest and savour the fruits of your labour and enjoying the mighty powers bestowed on the newly minted Rails developer. Junior developers often contribute to larger teams with established code bases, best practices and sensible processes, which can obscure the opportunity learn and work with new technologies, architect solutions, and deepen knowledge of advanced topics. Who wants to learn about metaprogramming when there’s a bug to be squashed? Who wants to keep up with design patterns when there’s a shiny new Javascript framework? Who wants to learn about test driven development when there are so many APIs to stitch together no-code apps?

Advancing skill sets can also be a challenge to fit in with professional responsibilities and busy personal lives. But, there has never been a better or necessary time to do so. The global literacy of software development increases each day. Access to learning resources more readily available than ever before. The consumption of technology is only increasing. And the tools and infrastructure to learn and build with have never cost less nor have ever been so easy to procure. However, the need for advanced software developers continues to remain high despite new languages and frameworks are currently popular. The concepts and experience acquired in one programming language are not surprisingly directly transferrable to others. Investing in ones skills has never been more relevant, important and rewarding.

Here are 5 resources to help you advance your Ruby on Rails programming skills to the next level.

  1. Upcase by Thoughbot is an excellent and completely free video library of intermediate to advanced Ruby on Rails developer lessons, created by Thoughtbot, a design and development consultancy behind several popular Ruby gems. Website: https://thoughtbot.com/upcase/practice
  2. GoRails by Chris Oliver is an excellent resource for learning web development, problem solving and solution-oriented learning materials. GoRails shares screencasts covering topics in Ruby, Rails, Javascript, how-to-use popular gems and much more. A large portion of the screencasts are free, while a subscription service is available for the premium content. Website: https://www.gorails.com
  3. Ruby Tapas is a subscription service of short, focused screencasts on intermediate to advanced Ruby concepts and techniques. Avdi Grimm is the head “Ruby Chef” and the author of the popular Ruby books: Confident Ruby and Exceptional Ruby. Website: https://www.rubytapas.com
  4. Practical Object-Oriented Design in Ruby book by Sandi Metz, is a widely recommended book on learning the nuances and advantages of object-oriented software with Ruby. Website: https://www.sandimetz.com/products-1-1
  5. Metaprogramming Ruby 2: Program Like the Ruby Pros book by Paolo Perrotta, focuses on writing Ruby code that is easy to maintain, change and clean with practical examples demonstrating deep and non-obvious details of Ruby. Website: https://pragprog.com/book/ppmetr2/metaprogramming-ruby-2

I’d love to hear your thoughts and what you do to advance your skill sets. Feel free to leave comments below

Advice for learning programming with Ruby on Rails

With the growing number of coding schools, web tutorials, online courses, paper books, ebooks and traditional computer science courses, it can be incredibly confusing for a new student to get started and to be confident that they are efficiently investing time into learning relevant skills at the appropriate depth. With the growing number software libraries it can additionally add to the stress and anxiety of learning how to program. So, here’s my take on learning programming with Ruby on Rails.

Ruby on Rails is a framework created in the Ruby language that makes web programming easier. It does so by following conventions, and encouraging re-use of code, and the use of abstractions. The Ruby language is easy to use because it was designed to help programmers to be productive, to enjoy programming, and to be happy. Over time computing power has increased and become less expensive, allowing programming languages have become more abstract and specialized. Ruby was a step towards a more natural and expressive programming language than it’s predecessors. Ruby removes the need for a programmer to worry about lower level concerns such as memory allocation, pointers, compilation, and string manipulation.

I have personally used Ruby and Ruby on Rails for nearly a decade and because I find it intuitive and expressive. I first started learning programming in Pascal and C, moved on to Modula-3, C++, Java. Over time I’ve also taken side-trips of varying lengths into C#, Objective-C, Bash, Python, Lisp, Node and Javascript but find continue to find myself wanting to work in Ruby.

Having used a number of different languages, I believe that there are fundamental concepts that all programmers should understand, which are abstracted and simplified in modern languages and frameworks. Learning different programming languages has many benefits beyond simply having the ability to read code in a new language. Different programming languages can help a user learn new concepts, solidify understandings of existing concepts, and introduce new paradigms on how to solve problems.

As a veteran programmer, I often catch myself taking my own programming skills for granted, not in a way that is boastful or self-applauding, but in a way that acknowledges that truly learning to program is a long journey. I appreciate and offer that learning how to program is more than simply learning one language and a web framework. I would even go so far as to suggest learning a lower level language first and struggling with those concepts, and working through exercise problems of string manipulation, loop control structures, and data structures. It’s important to appreciate that learning programming is a journey and not a destination marked by a final exam or job offer.

So, start with which ever language you’d like, but don’t stop there. Having a continual learner’s mindset will expand your mind and is a necessary step to becoming a better and well-rounded programmer.

How to propagate data in a Ruby on Rails Microservices environment?

Microservices encapsulate business logic in separate applications and allow independent scaling of these services. For example, an HR solution might have several micro-services split up between codebases, operating systems, geographic locations, or service providers. Having microservices, also commonly referred to as Service-Oriented Architecture, allows each service to be managed and developed independently.

In a Ruby on Rails Microservices environment, sharing data and propagating events between services does not come out of the box. However, several tools are readily available to handle these cases, ranging from Ruby background job libraries, like Sidekiq and Delayed Job, to queuing solutions, to enterprise-scale solutions designed for high volume throughput, dynamic scaling and redundancy. Let’s look into a few use cases.

For an environment with one-to-one server communication, asynchronous API calls from one service to another maybe sufficient. For example, when a Ruby on Rails Service A receives a request and needs to update a Ruby on Rails Service B, a background worker can be called by Service A to handle the asynchronous API call to Service B.

For an environment of one-to-many, one worker per recipient per separate service may be reasonable for a small number of services. For example, Service A might make API calls to Service B and Service C using a background job.

In more complex service environments, posting to intermediaries might be more useful. Services such as Amazon SQS (Simple Queue Service) and RabbitMQ allow services to publish and subscribe (producer-consumer) to queues, effectively decoupling your services from each other. For example, service A could publish data to Queue B for Service B, and publish to Queue C to be consumed by Service C. For enterprise-grade messaging services Apache Kafka and Amazon Kinesis are among several solutions.

Which solution works for you will ultimately depend on your resources and your particular situation. Time, costs, throughput and complexity are considerations when choosing how to communicate between microservices.