Let your code speak – I

I want to make an attempt at extending the excellent review of Confident Ruby by Avdi Grimm from Viget Labs here which is best described by the below excerpt.

Confident Ruby makes the case that writing code is like telling a story, and reading code littered with error handling, edge cases, and nil checks is like listening to a bad story. The book presents techniques and patterns to write more expressive code with less noise—to tell a better story.

And, My favorite in the review list is BRE GTFO LOL where “BRE” stands for begin/rescue/end

In our day to day Rails coding routine, we come across lot of methods which use Rails arel methods directly like save, update_attributes, update_all etc. and sometimes the code story telling gets a back step in logic of arel chaining.

Here is a way which I came across to surface it up right in front and that too without loosing the coolness of arel chaining.

Before:
class Post
  # update callback
  def refresh_cache
    if publishability_changed?
      refresh_categories_cache_timestamp
    end
  end

  def refresh_categories_cache_timestamp
    categories.update_all(last_cache_refreshed_at: Time.current)
  end
end

Here, reading code littered with update_all breaks the story telling flow, yet again, and could be better expressed with below snippet.

After:
class Post
  # update callback
  def refresh_cache
    if publishability_changed?
      refresh_categories_cache_timestamp
    end
  end

  def refresh_categories_cache_timestamp
    categories.refresh_cache_timestamp!
  end
end
class Category
  def self.refresh_cache_timestamp!
    update_all(last_cache_refreshed_at: Time.current)
  end
end

Comparing the two snippets, After scores extra points on story telling as compared to Before.

We would be happy to respond to queries/questions in comments.

Tried on: Rails 3.2.16 with Ruby 1.9.3

 

[Press Release] VinSol Releases Four Spree Commerce Extensions

The following is a press release announcing launch of open source Spree commerce extensions from our eCommerce team.

New Delhi, October 10, 2013 – VinSol, a New Delhi, India based premier Ruby on Rails studio and Spree Commerce premier partner, today announced the release of four useful extensions for the Spree Commerce community. The extensions include Spree Wallet, Spree Favorite Products, Spree Bank Transfer and Spree Admin Roles. VinSol believe that the extensions would provide substantial return of investment to Spree Commerce Developers as well as Store Owners.

When contacted, Manik Juneja from VinSol said, “The open source model of Spree Commerce allows VinSol to offer tools and methodologies that have proven successful for us while also encouraging feedback and contributions from the Spree Commerce community.”

Spree Wallet extension would enable the option of digital wallet. Using the same, the customers are able to make a purchase using the money stored on the website for their account.

Spree Bank Transfer extension creates an additional payment method for the stores that allows customers to pay via bank transfers.

The Spree Favorite Products extension allows users to tag their favorite products. Customers can create a list of their favorite products which motivates them to come back to your website and place more orders.

The Spree Admin Roles extension will be particularly useful for stores that need to allow various store admins with restricted permissions.

VinSol confirmed that they tested the extensions before releasing it for the open source community. In addition, these extensions are compatible with 2.0.x version of Spree commerce, easy to use and can be further customized in accordance to ones requirements and preferences.

Akhil Bansal, Rails business unit head of the company added, “In more than eight years of building eCommerce application with the Ruby on Rails framework, we have learnt the ins and outs of the required development patterns and platform. Our goal is to spend our time on high-value features for our client’s stores, and our team has evolved several frameworks and utilities in Spree Commerce that allow us to be the utmost efficient with our development process.”

About VinSol

Based in New Delhi, India, VinSol is a Ruby on Rails development studio specializing in e-commerce, native mobile application and web development.  The company is also recognized as a Premier Spree Commerce Partner.

Contact Number: +1-415-839-0057

Email:  info at vinsol dot com

Website: http://vinsol.com/spree-commerce