Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AS core_ext refactoring #5996

Merged
merged 4 commits into from Apr 29, 2012
Merged

AS core_ext refactoring #5996

merged 4 commits into from Apr 29, 2012

Conversation

gazay
Copy link
Contributor

@gazay gazay commented Apr 26, 2012

I want to make code inside AS core_ext more readable and understandable. Some simple stuff for starters.
Any advice?

@fxn
Copy link
Member

fxn commented Apr 26, 2012

Need to read the patch carefully for the details, but the overall refactor looks good to me. 👍 over here modulus details.

formatter.datetime_format = datetime_format if formatter.respond_to?(:datetime_format=)
if formatter.respond_to?(:datetime_format=)
formatter.datetime_format = datetime_format
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One-liner reads well here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I unwrap one-liners everywhere where they have more (or much more) then 80 symbols. Just like this style)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. You could shorten the argument name as well, from datetime_format to just format.

@jeremy
Copy link
Member

jeremy commented Apr 26, 2012

Thanks for digging in and polishing these up! Comments inline.

@larzconwell
Copy link
Contributor

Did you guys test this at all? It fails for me with 5 errors. Mostly dealing with /core_ext/time/calculations.rb

@gazay
Copy link
Contributor Author

gazay commented Apr 27, 2012

@larzconwell yep, I found it after discussion. I changed almost all already and I don't have falling tests now. I will push it soon.
Sorry for this typo - it's on https://github.com/rails/rails/pull/5996/files#L13R118, I changed a little logic and forgot rename variable

@larzconwell
Copy link
Contributor

Ah okay cool

@gazay
Copy link
Contributor Author

gazay commented Apr 28, 2012

I've fixed all what we talked about in first commit and add three commits more for discussion.
In AS core_ext refactoring pt.2 I found more similar cases as in first commit and added some changes which by my meaning can simplify readability or just looks better.
Indentation for private methods and string quotes - I know that this is not really necessary, but I thought that this style too, so maybe it makes sense to offer it for discussion too.
After discussion I can remove excess changes and merge all changes in one commit.

Thanks!

@rafaelfranca
Copy link
Member

I don't think that we need to change all the string quotes. I'm 👎 for this kind of change because it make harder to dig in the git history.

@gazay
Copy link
Contributor Author

gazay commented Apr 28, 2012

But maybe it makes sense to change quotes in strings which affected only by refactoring?

@rafaelfranca
Copy link
Member

Make sense.

dup.delete_if { |k, v| h2[k] == v }.merge!(h2.dup.delete_if { |k, v| has_key?(k) })
dup.
delete_if { |k, v| h2[k] == v }.
merge!(h2.dup.delete_if { |k, v| has_key?(k) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better as one line IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much logic for one line with non-semantic variables IMO :). And line is pretty long. That's why I decided to split this method chain

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I guess the vars are pretty cryptic haha, I think we should rename h2, to something more obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 like other

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking just simply hash or other_hash Anything is better than h2 honestly

@gazay
Copy link
Contributor Author

gazay commented Apr 28, 2012

renamed Hash#diff attribute from h2 to other https://github.com/rails/rails/pull/5996/files#L15L10

@jeremyf
Copy link
Contributor

jeremyf commented Apr 29, 2012

I ran the tests and they all pass.

There's a lot going on, but most of it is cosmetic and helps to improve the readability of the code-base.

@rafaelfranca
Copy link
Member

@jeremyf thanks for reporting this. We are helping a lot.

@@ -18,7 +18,7 @@ def in?(*args)
if another_object.respond_to? :include?
another_object.include? self
else
raise ArgumentError.new("The single parameter passed to #in? must respond to #include?")
raise ArgumentError.new 'The single parameter passed to #in? must respond to #include?'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be shortened to raise ArgumentError, '...'

@jeremy
Copy link
Member

jeremy commented Apr 29, 2012

Nice round of additional polish. Thanks @gazay

jeremy added a commit that referenced this pull request Apr 29, 2012
Active Support housekeeping and polish
@jeremy jeremy merged commit 1a4e27f into rails:master Apr 29, 2012
# "CamelOctopus".pluralize # => "CamelOctopi"
# "apple".pluralize(1) # => "apple"
# "apple".pluralize(2) # => "apples"
# 'post'.pluralize # => "posts"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quote changes are completely unnecessary imo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants