[openstreetmap/openstreetmap-website] Prefer string interpolation to concatenation (#2921)

Tom Hughes notifications at github.com
Wed Oct 28 17:14:59 UTC 2020


@tomhughes commented on this pull request.

I think I did look at this one before but I was concerned that where some of the things being joined were non-trivial expressions it might all become a bit unreadable.

As is often the case the style guide is unfortunately lacking in any rationale as to why you should prefer interpolation - my natural assumption would be that concatenation would generally be higher performance for example not that it matters most of the time.

I notice that `format` is an acceptable approach though, which would be easier to read where some of the things being interpolated are more complicated expressions.

> @@ -6,7 +6,7 @@ def self.coder
   def set_title(title = nil)
     if title
       @title = TitleHelper.coder.decode(title.gsub("<bdi>", "\u202a").gsub("</bdi>", "\u202c"))
-      response.headers["X-Page-Title"] = ERB::Util.u(@title + " | " + t("layouts.project_name.title"))
+      response.headers["X-Page-Title"] = ERB::Util.u("#{@title} | #{t('layouts.project_name.title')}")

This is getting quite messy - might `format` be a better choice here?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/2921#pullrequestreview-518900126
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20201028/599ca994/attachment.htm>


More information about the rails-dev mailing list