Noel Rappin Writes Here

Tag: ruby

Object Constellations

Last time, I talked about ways to use dynamic typing to manage objects and business logic in your code. Doing so involves leaning into the object system, going beyond just “one class for each noun” and creating objects to model different states within the business logic directly. In a basic Object-Oriented design, you might have an object called User. This object, by itself, represents the entire concept of a user within the system.

How Not To Use Static Typing In Ruby

How To Not Use Static Typing In Ruby Last time, I took a short example and examined in some detail what you would gain by adding static typing to it and what it would cost to use static typing. What I didn’t do was explain how I might handle the problem without static typing. For reference, Here’s the example again. Consider this to be part of a larger system and don’t worry too much about the rest of the world:

What About Static Typing in Ruby?

I’ve tried writing this literally a half-dozen times. And it always feels like it slips out of control and gets too abstract to be useful. So, let’s start with something concrete. And we’re going to wind up splitting this into multiple parts. Probably two, but honestly, at this point who knows? This all got started because I was discussing the use of runtime checking using Sorbet. The other person gave me a code snippet and asked how I would manage it without type checking.

Better Know A Ruby Thing: On The Use of Private Methods

Last time around, we got to Better Know access control in Ruby, and I started to write my opinion on the use of private methods in Ruby, but my position/argument/rant had gotten out of hand and so I spun it off into its own post. This is that post. It’s long enough as it is, let’s just get to it, we’ll skip the internal ad. What I think about Private Methods in Ruby In Ruby, a method without side effects should be public.

Better Know A Ruby Thing: Methods and Access Control (part 1)

I’ll be honest, I picked this topic out of the half-dozen or so Better Know A Ruby Things on my to-do list strictly because it’s maybe the only Ruby take that I genuinely argue with people about. To be even more honest, it got away from me a bit as I started writing the argument: which is why I tend to avoid declaring methods private. I know these newsletters have tended toward long, but 3100+ words was a bit much even for me, so I’ve split it in half.

Better Know A Ruby Thing #5: Block Arguments

Previously in what what I guess is now “The Argument Trilogy”, we talked about: Positional Arguments Keyword Arguments And now the trilogy now comes to its inevitable conclusion with “Return of The Jedi” block arguments. In the interest of keeping this thing within the plausible word count of a newsletter, we’re not going to talk about what blocks are or the way blocks behave here, that’ll be a future Better Know, but we do need to talk about block syntax.

Better Know A Ruby Thing #4: Keyword Arguments

Last time on Better Know A Ruby Thing, we covered positional arguments, and now we’re going to move on to keyword arguments. I really did think this was going to be shorter than the last one, and then I got to the conversion between keyword and positional arguments, and then… well, it’s not shorter. (I know I said the next newsletter was going to be Conway’s Law, that’s coming, but this one moved along faster…)

Better Know A Ruby Thing #3: Positional Arguments

Ruby has three ways to pass information from a method call to a method definition: positional arguments, keyword arguments, and block arguments. Each of these ways has: A syntax to declare an argument of that type in a method definition A syntax to declare an argument of that type in a method call A class that can can be used to convert arbitrary objects into and out of method calls A text marker that is associated with that kind of argument, *, **, or &.

The Pickaxe is out and I am Happy

I am extremely excited to say that Programming Ruby 3.3, also known as The Pickaxe Book, is now done done, finished, completely available as an ebook, and winding its way to distributors to ship to people as a genuine physical book. The PDF and ePub versions of the book are available at Pragmatic’s website. The print book should be available wherever you get print books, including Amazon and Bookshop. I’ve talked in the past about what’s in the book, what’s new, and whether you should buy it.

How To Manage Duplicate Test Setup, or Can I Interest You In Weird RSpec?

You have a series of test cases. They cover the same logic with different inputs. In order to get to that logic, there’s some overhead: objects have to be created first. Then there’s more logic needed to evaluate the result. What’s the best way to manage these tests? You want it to be easy to add new tests. You also want it to be clear what part of the test is different in each round and what part is just the common logistics.

Better Know A Ruby Thing Bonus: Contestants and Nesting

Sorry for skipping a week or two – I was approving copyedits on the book that is now called Programming Ruby 3.3, because we now want to be proactive about the next release. Coincidentally, the copyedit review does relate to this newsletter. I noticed a particular code sample as I was going through the book again, and it highlights a feature of Ruby’s constant lookup that I didn’t discuss last time.

Better Know A Ruby Thing #2: Constants

A fun thing about learning Ruby is that sometimes concepts that have the same name as in other languages have different behavior and purpose in Ruby. Today: constants They aren’t actually constant. They aren’t only used for small strings or magic literals. They aren’t even mostly used for that in most Ruby programs. Constants are one of the core pieces of Ruby and they aren’t super-well documented in the official site, so here we go…

Better Know A Ruby Thing #1: method_missing

Welcome to “Better Know A Ruby Thing”. In each one of these, we’re going to look at some feature of Ruby language, library, ecosystem, or culture and explain what it does, how it works, why it’s there, and any thing else that comes to mind. First up, method_missing. If I may be poetic for a second, method_missing represents both infinite potential, and the possibility of a second chance when you can’t figure out what to do the first time around.

Hi, All, It's a Pickaxe Q&A

I haven’t sent out a newsletter in 2022 – about 10% of people subscribed to this newsletter have never seen an actual newsletter in their mailbox. That seems like it should end, so… hi! I’m Noel. I write books, mostly about Ruby. I write this newsletter, which is normally about Ruby, Rails, Agile, and other topics, and is occasionally (like today) self-promotional. Under normal circumstances this comes out a few times a month.

Redundancy, Terseness, and Code

Most human communication, text or written, is wordier and more redundant than it needs to be, strictly speaking. That previous sentence, for example, would still communicate its point in about a third of the words with “Most human communication is too wordy”. You’d likely still get the idea if I used about half the characters and wrote: “hmn comms too wrdy”. There are certainly reasons why you might include words when speaking or writing that are technically not needed:

Another Refactoring Story: ActiveRecord Lists

I’ve now tried to write this post like three times, and one thing that’s clear to me again is why you don’t see more write-ups of even moderately complicated real-ish problems. It’s hard to get enough of the context across to make the code sensible without being overwhelming. But there’s a Rails and ActiveRecord structure that this example gets to that I think is useful, so I’m going to try again.

More Ruby Magic

Hey, if you like this post, you might like my recent books: “Modern Front-End Development for Rails” (Ebook) (Amazon) and “Modern CSS With Tailwind” (Ebook) (Amazon). If you’ve read and enjoyed either book, I would greatly appreciate your help by giving a rating on Amazon. Thanks! When last I talked about the Elmer project tracker, I was talking about Ruby magic and singing the praises of StringInquirer. I was expecting some pushback on the Ruby Magic™, but didn’t get any, so I threatened to do something really weird, like implementing an API for getting project history with something metaprogrammy and dynamic, like project.

Refactoring, Part Two: In Defense of Magic

A quick program note: If you like this newsletter, you might like my recent books: “Modern Front-End Development for Rails” (Ebook) (Amazon) and “Modern CSS With Tailwind” (Ebook) (Amazon). If you’ve already read and enjoyed either book, I would greatly appreciate your help by giving a rating on Amazon. Thanks! In my last post, I refactored the status field for cards in my project tracker to a more object-oriented representation that used value objects and classes to replace conditionals throughout the code.

Rails, Objects, Tests, and Other Useful Things

For the first time in quite a while, I’ve been able to spend time working on a brand-new Rails application that’s actually a business thing and not a side project. It’s small. Okay, it’s really small. But at least for the moment it’s mine, mine, mine. (What was that about collective code ownership? I can’t hear you…) This seemed like a good time to reflect on the various Object-Oriented Rails discussions, including Avdi’s book, DCI in Rails, fast Rails tests, Objectify, DHH’s skepticism about the whole enterprise, and even my little contribution to the debate.

May 9, 2012: The Random Link Post Returns

And now, the return of the semi-occasional link post. I’m going to try to do this at least once a week, but who knows. If you are writing JavaScript, you should be looking at Justin Searls and his JavaScript testing tools. Justin posted the slides for what looks like a great talk on JavaScript testing. These slides made me happy. In random media sales, the audio book of World War Z is on sale for a mere six bucks.

July 15, 2011: Stale Links

The problem with sitting on these daily link posts is that the links go out of date. Sigh. Here are some links. Twitter I found a couple of things about this InfoQ article about Twitter’s infrastructure odd. I was expecting it to be a bit more of a Rails hit-piece, frankly, so it was nice to see a quote like this one from Evan Weaver: I wouldn’t say that Rails has served as poorly in any way, it’s just that we outgrew it very quickly.

Aug 30, 2010: Rails 3 has landed

Top Story As you probably know, both Rails 3 and Bundler went final over the weekend. The Rails 3 release notes are up, as well as extensive coverage on the Rails Guides page. I’ll also mention Jeremy McAnally’s Rails 3 Upgrade handbookhttp, and Gregg Pollack’s list of great Rails 3 documentation sources. And, just for the hell of it, here’s the post I wrote back when Rails 3 was first announced.

August 26, 2010: Some New Stuff

Book Status RSpec chapter draft handed in to edit. It’s going to need a better conclusion. A lot changed in this one, relative to the Lulu version – this is probably the chapter most affected by my own personal experience since it’s original version. Links Haven’t done a link set in a while, this is going to be kind of random. Still seats available for both WindyCityRails in general, and for my tutorial in specific.

August 11, 2010: An Abundance of Options

Book Status Shoulda chapter fixes made. The next decision is whether to push that as a beta by itself, or wait until the RSpec chapter is also done. Also Today is the last day to get early bird pricing for WindyCityRails. Book Status I did not know that Ruby 1.9 had its own coverage tool. Aaron Patterson shows how to use that tool and a little code to create useful output for coverage testing.

July 30, 2010: I Always Thought It Was An Animal Native To The Rain Forest

Book Status Beta 5 came out on Wednesday. Currently trying to figure out how to structure the Shoulda chapter in light of the direction that project has gone in since I wrote about it for the Lulu book. Friday Links One significant change in Rails 3 is that, because of the way Bundler works, the code for your gems is not part of the project. And if you are using RVM, each project might have a different gemset, and different directory to find those gems.

July 21, 2010: This Code Belongs In A Museum

Status Not much to tell, really. Spent some time getting RVM set up, since I think I’ll need it to manage simultaneously building the Rails 2 and Rails 3. Now I have a working version of the startup appendix that uses Rails 3 and Devise. I can’t speak to using Devise in practice yet, but the immediate goal of making the setup less complicated was definitely accomplished. The big question now is how much to support Rails 2 in the walk-through chapters.

July 19, 2010: Building a Legacy

And Now A Word The schedule for WindyCityRails 2010 just came out. WindyCityRails is Saturday, Sept, 11 at the Westin Chicago River North. I will be running the PM tutorial session on “Testing in a Legacy Environment”. I am frequently asked how to start testing on a pre-existing code base with no tests. In this session, we’ll start with a made-up “legacy” code base, and discuss techniques for adding tests, and fixing bug, and adding new features in a test-driven way.

July 15, 2010: An Apple Comment A Day

Book status Still writing the legacy chapter. Totally coincidentally, Michael Feathers, author of Working Effectively With Legacy Code, just wrote on an issue similar to what I’m dealing with right now: The Bad Code Kata. I imagine Feathers had a similar problem when writing his book about legacy code. An Apple Comment A Day So Apple is apparently holding a press conference Friday about iPhone 4, although they haven’t officially confirmed that it’s about the antenna issue.

July 14 2010: The Smallest Thing

Book Status Still working on the legacy chapter. The sidebar here is that deliberately writing bad legacy code for purposes of using as examples in a book is a little challenging. It’s got to be tangled enough to make the point that it’s hard to clean, but small and clear enough to work in the context of a book example. My tired brain was fighting it last night. Training! I mentioned this recently, but I want to mention it again.

July 13, 2010: I Guess It Isn't A Dynabook Yet

Status Back to link posts today. The book is still lurching forward on the legacy chapter. Thanks to those couple of you that asked questions on the forum and made it look a little less lonely over there. Quick Review Quick iPhone 4 impressions, but understand that I haven’t actually, you know, used it yet, just took it home and set it up. The screen sharpness really is notice able.

July 1, 2010: Screencasts and Road Maps

A lot fewer links today. Yesterday, by the way, the most clicked on link was the “Don’t do this” like to the method_missing nil post. Book Status Handed another draft of the Rcov and Style/Test Quality chapters in. Expecting that to be the next beta next week, but we’ll see. Links Kent Beck has a screencast series on TDD from Pragmatic. I linked to the rough version of this some time back.

June 30, 2010: The Triumphant Return of the Monster Link Post

The end of the repair story At the end, a very positive experience with Apple support. The repair was free, done when they said it would be done, and all told, I spent less than fifteen minutes in the store between both halves of the visit. Plus, they replaced the top part of my pre-unibody MacBook, which was worn down and discolored from my gunky hands, almost as though they didn’t want an ugly Mac in the field.

June 18, 2010: Links Ahoy

I think a link post today… Book Status Still working on the style section, for some reason it’s going grindingly slow. The plan for beta 4 is the new style chapter, probably the legacy coding chapter. Also on the slate is updating the sample app to use Devise, which had a large constituency when I floated the idea the other day. Oh, and I haven’t had the link up in a while.

June 8, 2010: iPhone, iPhone, it's off to work iPhone

Okay, There’s a New iPhone Don’t really have a whole lot to say beyond what’s already been said. It looks very slick, and if anybody can actually pull off getting people to use video chat, it’s Apple. The form factor of video chat from a phone seems at first glance to be significantly better than from either a laptop or the iPad, in that it seems easier to hold the phone in a position to get a good angle.

June 4 2010: Okay, here's a link post

Quick links post: Gregory Brown is looking for comments and donations for a proposal for a Ruby Mendicant University, basically a rolling online Ruby course. Charles Nutter is interviewed by InfoQ on the state of JRuby. Yehuda Katz has a long post on various kinds of extensions in Rails 3 – gems, plugins, generators. This one I need to look at in some detail. The new RubyMine 2.5 beta integrates with Pivotal Tracker.

May 28, 2010: Friday Friday Friday

Short today, but preparing some longer, more rant-y bits for the future… Book status Not much forward motion for the next few days, as I have a lot of other stuff to do, including preparing for Chicago Ruby on June 1 and doing a bit of touch-up on Obtiva’s 4-Day Ruby on Rails/TDD boot camp. All fun, but time consuming. Some Links A quick tutorial by Peter Cooper on setting up JQuery in Rails 3.

May 27, 2010: Random stuff today

I think we’re going to be even more random then usual today. Here goes: If you downloaded the epub version of Rails Test Prescriptins beta 3, then you may have noticed that the promised Cucumber chapter isn’t there. The PDF is fine, and I have no idea about the mobi version one way or another. If you were affected by this, please go back to the Prags site and grab the file again, it appears to have been fixed.

May 25, 2010: Betas

Top Story Beta 3 should be out today. The main change in this Beta is the inclusion of the Cucumber chapter, which has been updated both in terms of new tech, and also in terms of conclusions about how to use Cucumber. And In Rails news… When last we met, Rails 2.3.6 had just been released. Well, in the intervening 24 hours, we’ve bumped all the way to 2.3.8, with two bug fix releases, explained by Jeremy Kemper here and here.

May 24, 2010: Martin Gardner

Top Story Rails 2.3.6 released, with more changes than I expected, taking it just a little bit beyond a bug-fix release. Follow the link for the full release notes. Things that caught my eye: Looks like they made an official plugin to give Rails 2.3.6 the default HTML safe behavior of Rails 3. Although the note is vague and I could be misunderstanding. Alert and notice are now separate methods rather than just being keys on the flash.

May 20, 2010: Fontastic

Book Status Starting to sound repetitive. Still working on the Cuke chapter, this time focusing on cleaning up the parts where I recommend ways to use Cucumber. Still hoping for a beta early next week. Other things This week in Yehuda, there’s a very long article about text encodings and what problems they have, and in particular how Ruby’s implementation is shaped by the complicated relationship between Unicode and Japanese.

May 6, 2010: The day of promoting stuff

Top Story I’ll mention somebody else’s book, but don’t worry, I plan on doing it in a totally self-absorbed kind of way. Pragmatic released Using JRuby into beta yesterday, by the core JRuby team. Looks good, interested to see where they go with it. Because I’m me, I can’t help but compare the structure of the book with the Jython book I did. Biggest structural difference so far is that we were unable to assume a Python-savvy audience, so we felt we had to awkwardly teach Python for 100 pages at the start of the book, where as the JRuby book is able to teach Ruby in an Appendix.

April 23, 2010: Still Alive

Top Story If you think the top story is going to be anything other than the continued launch of Rails Test Prescriptions, well, you probably don’t know me very well. I may not be a marketing genius, but I do know the value of repetition. I mean, if there’s one thing I know, it’s the value of repetition. Thanks to everybody who made yesterday fun: those of you who bought the book, those of you who blogged or tweeted about the announcement, and anybody who read this.

April 19, 2010: The Week Begins

Top Story/Book Status This is the week – Rails Test Prescriptions should go on beta sale on Wednesday. In a related story, railsrx.com now points to here, railsprescriptions.com also will shortly. I’ll be adding some basic about information and static pages here. At some point, I’ll probably bring over any blog content from the previous site that still seems relevant. I’m not sure if the original free version of Rails Test prescriptions will still be available (it’s becoming out of date, and there will be free samples available at Pragmatic), but I will make it available if anybody is still interested.

April 15, 2010: The Library of Congress Recommends the Following Tweets

Top Story As part of the Chirp conference, Twitter and the Library of Congress jointly announced that the Library will be storing Twitter’s entire public archive. I’m sure your expecting an easy joke about how many sandwiches the LoC now knows about in their archive, or about how scholarly papers about the archive will be limited to 140 characters. (Or, for a more academic joke, limited to 140 authors…) All that aside, though, I think archiving and making all this available is pretty neat.

April 13, 2010: iAd, youAd, weAll Ad

Top Story iPads. Lots of them popping up in and around work. Probably some more coherent impressions coming later. Wait, once again, Twitter has a big announcement after I start writing this. This time, they are going to start placing ads in the Twitter stream in various ways to be announced today. My quick reactions: a) I long suspected this day was coming, b) if the ads in clients are any guide, they aren’t particularly burdensome, c) implementation details will decide how irritating this is.

Notes and Notes

A couple of recent life, the universe, and everything notes: I realize I’ve been away from here for most of the last couple of weeks – a side project has been eating up a lot of time. I should be done with in next week, and back to posting here more regularly. I know, I always say that. I’ll be at RailsConf 08 later this month, and I’ll probably have some number of copies of Professional Ruby on Rails to do something promotional with, but I haven’t exactly decided what.

My Favorite Monkeys

New post at Pathfinder on monkey patching.

Shipping!?

Amazon is now saying that Professional Ruby On Rails is in stock! I haven’t seen my copies yet, and I suspect Amazon purchases will actually go out next week, but it’s a real page and everything. The link to purchase is right here. I’ve also added a [running list of errata and updates](https://docs.google.com/Doc?docid=ah2szrczrmxv_26z j8npddd&hl=en). Check back on that every now and then. Much more on the book over the next week.

Hey, Free Book Samples!

As I’ve mentioned here a few times, I have a book coming out, “Professional Ruby on Rails”, available later this month. If you’d like a sneak peek, Wrox has put some samples online as PDF files. You can also just buy the book. Chapter 1 – This sets up the sample project used in the book, and talks about the new REST features in Rails. Table of Contents – Take a look at this to see if your favorite topic is covered.

Professional Rails Online?

In response to the commenter who asked if there was going to be a beta book. UPDATE: Clearly I should ask about these things before I post. Jim Minatel from Wrox added the following in comments: There will be a PDF about six weeks after the print book, meaning end of March or thereabouts. There will also be an Amazon Kindle version, eventually. Also after 6 weeks, the book will be available via Wrox’s online subscription service: http://wrox.

Things I Learned

Some things I learned about Rails and writing while working on this book: The great benefit of working on a project like this book is that it enabled me to compress about two years worth of research into Ruby and Rails tools into six months. In my case, this was a great opportunity to really dig into some tools to find that I’ve only been using a fraction of their power and also really get a sense of how elegant and flexible the tools are.

Two Pathfinder Blog Posts

Two things on the Pathfinder blog. Agile Publishing, on publishing experiences and agile methods. Live Ruby: Testbed, an attempt to work through a small test and metaprogramming problem live and on the blog. Enjoy.s

Pro Rails Book Related Things

A few things I forgot to put in the last book update: The Amazon listing has the book at 600 pages. That’s almost certainly optimistic. The contract calls for 400-500. As far as the schedule goes, I’m currently hoping to turn the complete draft in on October 26th, which is about ten days after the original date. The publisher says that pushes publication out to April, six to eight weeks after the original date.

The Rails Edge

I was fortunate enough to attend Pragmatic’s Rails Edge mini-conference here in Chicago last week. I have two blog posts up on this at Pathfinder, the first is made up of quotes from my notebook, and the second is some general thoughts. Enjoy.

And Now, A Special Announcement

Sorry for the radio silence for the last week or so, but I was waiting to be able to announce this: Today I started a new job at Pathfinder Associates, as a senior software engineer in charge of Ruby on Rails projects. Needless to say, I’m thrilled to be back in the Web game professionally, and even more thrilled to be working on Rails projects. Everybody at Pathfinder has been super great so far, and I’m looking forward to doing exciting and fun things.

Didn't I Say I Wouldn't Compare Languages?

I posted a version of this to JJ Behrens’ Blog post about Ruby, and decided it was probably worth also posting here. I use and like both Ruby and Python, here’s why… Things I like about Ruby with respect to Python I think Ruby is the only language that gets accessors right. The thing you want to do 95% of the time – simple access – is trivial, and the thing you want to do 5% – something fancy in your accessor – of the time is a pretty easy override.

from internet import *

Three posts that caught my eye today. Ruby School Gregory Brown over on O’Reilly net has an article about using Ruby in Computer Science courses, at least in later algorithm classes. It’s not a bad argument, but I think it’d be more convincing if the Ruby example was a little cleaner and easier to read compared to the pseudo-code. Let’s see… The last time I had to care about this issue was about eight years ago when my grad institution was going through a somewhat controversial revamp of the CS curriculum.

Posting to Blogger via Ruby

TextMate has what seems to be a very nice blogging bundle for programmatically sending posts to your blogging engine of choice. Except that it doesn’t work for the new Blogger API. Or at least it didn’t the last time I checked. Mostly I just wanted to see if I could write my own script to send to Blogger. This is a Ruby script based on the Python script located at http://djcraven.

Rubies in My Coffee

Now two of the big Java IDE’s are promoting Ruby language tools as a big thing. IntelliJ has a plugin in early beta, and NetBeans is also making a big deal of their new early beta support. Eclipse has had a Ruby/Rails plugin for about a year or so. This is weird, weird, weird, that suddenly all the Java tools would feel the need to grow into somewhat ill-fitting Ruby IDE’s (Eclipse has always styled itself as more of a meta-IDE, so that’s a little less strange).

Languages I Use

Continuing in the getting to know you kind of vein, I thought I’d ground some of what I say by talking about the three programming languages that have made up the bulk of my professional and hobby work for the past five years or so – Java, Python, and Ruby. Java: I’ve been programming Java since either just before or just after the 1.0 release… can’t quite remember at this point.



Copyright 2024 Noel Rappin

All opinions and thoughts expressed or shared in this article or post are my own and are independent of and should not be attributed to my current employer, Chime Financial, Inc., or its subsidiaries.