Issue #4 - 1 - 7 August 2022

The one where we exchange ideas about code review and how to help Ruby juniors to get jobs

Hello,

Thank you for subscribing to this newsletter. You can read this newsletter online here. It might be too long for some email clients. No worries, even if it is long, it is easy to read 😀 as it contains tweets.

If you like it and have suggestions of people working with Ruby and sharing exciting stuff on social media, please find me on Twitter @lucianghinda and tell me about them.

This edition was created with support from @adrianthedev from Avo for Ruby on Rails (a friendly full-featured Rails admin panel) and from @jcsrb, who sent me recommendations to include.

Xavier Noria shared a thought about where to add comments explaining the why

Stanislav Katkov shared 3 git extensions that he finds very useful: git recent, git open and diff-so-fancy:

Steve Polito shared a tip about discovering the data type when using Redis gem:

He added:

Turns out, you can't always call "get" on a key. Instead, you need to call the correct method for the type of data stored in the key. (source)

Emmanuel Hayford shared a small piece of code to lint factories

CJ Avilla shared a quick tip for converting video duration in seconds:

Konnor Rogers shared a comparison between various component gems:

You might want to look also to these benchmarks, shared by Joel Drapper that includes also the Phlex library he is working on:

Junichi Ito (伊藤淳一) shared an example about the frozen_string_literal magic comment and how it applies:

<Ruby豆知識> # frozen_string_literal: true は全ての文字列がデフォルトで凍結されるわけではなく、文字列リテラルを使って生成した文字列だけが凍結されます。なので、数値や配列をto_sやjoinメソッド等で文字列化した場合は、この条件に該当しないので凍結されません。

translated to:

<Trivia of Ruby> # frozen_string_literal: true means that not all strings are frozen by default, only strings created using string literals are frozen. Therefore, if a number or array is converted to a string using the to_s or join method, it will not be frozen because it does not meet this condition.

Tim Carey asked a question about authorization in Rails and received a lot of replies. You should read them as people are sharing their experiences and limits they encountered when using CanCanCan and Pundit. There are also recommendations for Pundit, ActionPolicy and bullet_train-roles.

Brandon Weaver shared an experimental code to do deep groupings:

Ahmed shared a piece of code that uses meta-programming to implement a find or initialize by:

Nick Schwaderer shared one of the most interesting changes in Rubocop. You should read the discussion on Github as there are shared some good cases for using and/or

Jean Boussier shared that Queue#pop will accept in Ruby 3.2 a timeout argument (you can also read the the ruby-lang feature discussion):

Dmitry Tsepelev shared an experimental gem that he created to help write natural DSLs in Ruby:

Greg Molnar shared a quick tip about how to generate a Rails app with a specific version:

Pablo Orellana shared a quick tip about pipelining rails routes into fzf:

Nicolás Sanguinetti shared a piece of code describing a way to work with base exception as module:

One thing I really like about ruby, when writing a library/gem, is to make the base "exception" a module. This allows subclassing the "semantically correct" exception while still providing a base, catch-all constant that can be rescued by users of the library.

 

Vaidehi Joshi shared a learning experience about how reading the source code of a library is a game changer:

You should read the full thread as it is a great and open sharing:

Benito Serna asked a great question about solving N+1 queries problem:

How would you solve the "latest_comment" n+1 queries problem?

There are a couple of solutions shared in that thread, and he also presented the most known ones in an article:

Pascal Laliberte shared a quick tip about erb partials and CSS:

<%= render '_index', use_columns: true %> <%# in _index.html.erb, use a default of 15rem column width with 3 columns if use_columns is true, but use --column-width if defined in a parent #> <% tag.ul class: ["columns-[var(--column-width,_15rem)_3]": use_columns] do %> ... <% end %>

Josef Strzibny shared a statement about the job of the reviewer and received many replies about how people see the role of the reviewer:

Read also the replies to this retweet where I asked the question about what should be the purpose objective of a code review.

Here are some replies:

The reviewer should not be expected to run the code, that’s what tests are for. They are only there to review the logic, code structure, naming, maintainability, security, etc. The reviewer should operate with the assumption that the code works

The value-add for a reviewer IMO is mainly a second-opinion on overall strategy and code readability. If the code didn’t work, the tests would show that.

For me I have to say the objective is higher confidence that the change will work and doesn't break other stuff. Practically everything else is secondary as there is no need for a long review of broken code.

Hal Brodigan shared a quick Active Record tip about using Arel instead of parameterized SQL strings:

He shared more about this:

The one I was just working on was trying to query two binary columns (SQLite3 BLOBs) that I use as min/max keys. `Model.where('min_key <= ? AND max_key ?', bin_key, bin_key)` does not work because ActiveRecord doesn't know I want bin_key converted to sqlite3's x'XX...' syntax. (source)

Where as if you use `where(arel_table[:bin_column].lteq(value).and(...))` it knows that you're comparing a value against a binary column and can thus correctly typecast/format the input value. (source)

Hiring Juniors

I feel like this was an important topic discussed a lot on Twitter this week, so I am trying to aggregate multiple discussions here:

Josef received multiple replies about how junior Ruby developers experienced this and some ideas about how to improve this.

Rose W shared a good way how to talk about hiring juniors in our teams:

Joe Masilotti identified some reasons why few companies are hiring juniors:

Among those reasons:

Businesses see junior developers as a risk.

Businesses don't have programs for the dev to grow.

Businesses need to replace a senior dev who left.

He also offers some reasonable solutions in that thread and hosted a Twitter Space conversation about the same topic.

Jacob Daddario had an interesting reply:

Greg Molnar had an interesting take on education:

If you read so far and you like the content, maybe you take into consideration sharing this and subscribe:

Articles and Videos

Courses

Jason Charnes shared that his StimulusReflex course is free. This is a great resource to grab.

Something to read

PlanetScale shared an article about deleting large quantities of data talking about destroy_async, delete vs destroy and moving delete operations to background queues.

Kelly Sutton shared an article he wrote about Scaling Sidekiq at Gusto.

AnyCable shared that they started Any Cables Monthly newsletter. Read the first issue here.

Greg Molnar shared that a new issue of This Week in Rails is out. This issue was created by Petrik de Heus

Something to watch or listen

Noah Gibbs published a discussion with Tobias Pfeiffer about education, software history, programming languages, and different Ruby implementations: listen here → Tobi Pfeiffer: So Many Languages

GoRails shared a new episode about implementing hCaptcha from scratch in Rails and making it compatible with Turbo using Stimulus. See it here → hCaptcha with RoR, Turbo and Stimulus

CJ Avilla shared a video about discussing with Chris Oliver about the Pay gem. There is also a demo, so it is worth watching. See it here → Collecting payment in Ruby on Rails with Pay

Drew Bragg shared a New Coding Coders Episode with Collin about willing to jump into source code, orienting in a new codebase and more. Listen to it here → Episode 9 -Collin Jilbert

Shopify Engineering shared a video where they asked their Ruby & Rails infrastructure team how they feel about Rails. See it here → Our Relationship with Rails

Remote Ruby shared a new episode about “Gem Mining & Advice on Mentoring Developers” with Chris Oliver - Listen to it here → Remote Ruby Episode 191

Joe Masilotti hosted a Twitter space about “On hiring junior Ruby on Rails developers”. Listen to it here → On hiring junior Ruby on Rails developers

Ruby for All published a new episode with Andrew and Julie. Listen to it here: Failures and Lessons as a Junior Developer

Adrian Marin published a video where he demos the new features from Avo. See it here → Avo 2.12 for Rails - Use custom resources for has_many

New Libraries or Updates

vscode-ruby-light

r7kamura shared that they are working on a new VSCode extension for ruby: Ruby Light

Yardspec

Also r7kamura launched a new Gem called Yardspec which will run YARD as RSpec:

Avo for Ruby on Rails

Avo published a new release v2.12:

This release has a lot of updates, and you can see all of them here in the release notes or watch the video demo Adrian did for this release.

Outro

Thank you for reading this. If you have any suggestions of people/tweets to include, please reach out to me @lucianghinda or at [email protected].

All (or almost all screenshots) were generated by using Xnapper

Reply

or to participate.