-
Notifications
You must be signed in to change notification settings - Fork 455
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
Awesome Print vN.... (was v2, but not anymore..) #193
base: master
Are you sure you want to change the base?
Conversation
AwesomePrint supports Ruby 1.9.3 or later. This remove lot of conditional check against Ruby prior to 1.9.3.
Since we support only rails greater than 3.2 we don't need this init files.
This ways we need to require always awesome_print
Just split in 2 responsabilities. Maybe configuration is not a good name. Just a begin to learn more about the code.
Moved from the Formatter to a single class that do the Array formatation.
Moved from the Formatter to a single class that do the Hash formatation.
Moved from the Formatter to a single class that do the Object formatation.
Since we have some methods on formatter that is used only on the array and hash moved to a module.
@alexch thanks for the review and join the discussion! I will remove this About the plugin structure the main changes are:
I think you can take a look at this commit michaeldv/awesome_print@4d6e963 all the types follow this same line of thinking. I will update to create the Again @alexch thanks for the review, wait for more feedback ❤️ |
@michaeldv no, I never wrote a line in Java. But I like the idea of OOP and Design pattern in the Ruby World. For example in the master version of the hash formatter we have all the logic in a single method and some helpers method like the This idea of a class to each is followed on rails for example on the Action View where all the tags have a single class. So basically we moved from a single method that handle a formatter to a specific class, wich is better to we apply some good practices like SRP, small classes, small methods and pass little params. |
@maurogeorge: this is pretty epic. thanks! 👍 However... I don't think it should be one PR, and I vote not to land it. It's just too big to review as one piece; too many things going on. Can we break out a separate PRs for:
I know it sounds like a bunch of work, but I think it'll be much easier to review, allowing all of these PRs contribute to the 2.0 milestone. :) |
@imajes thanks ❤️ I understand, in this specific case I prefer do all the work in a single PR because I have some dependencies, for example a class that I created one the earlier commits are used on the last ones. So it is not possible I made N PR in a single time. The good thing is, since I am on a single branch, if we have some fix to do on the I think If I create some diffs grouped by feature/fix can be better take, a look.
I think this way is more easy to do the review, if we treat a diff like a PR. Hope thats helps 😄 Beside that @alexch will do a review too. |
@maurogeorge Thanks for all your hard work. I guess we have some major differences on this one. First, I don't want to turn the core gem into one monstrosity with all the formatters under one roof. awesome_print should provide formatters for basic Ruby types, everything else could be made available as plugins/extensions. Ideally I would move all /ext formatters into separate gems with their own tests, maintainers, etc. Second, what's wrong with method-based Third, you seem to think removing so-called "monkey patching" is a good thing, whereas I think it lets us separate custom extensions from the core gem, and load them as necessary without maintaining explicit list of supported custom types. Fourth, you can add your own copyright but don't remove somebody else's. You just don't. Anyway, I am all for refactoring and making the code better, however writing more code with no apparent benefit doesn't seem like a right approach. I am always in favor of reducing the codebase, not growing it. |
Yeah- @michaeldv, i think that comment is exactly why this PR is too big to move on :) It'd be nice to talk about some of these things and review approach/strategy. For example i am not entirely sure that the idea of having many separate gems is super great - one of ap's biggest wins for me is that it's basically ready to go- you don't have to bring more gems into the mix to just 'get it to work'. definitely worth talking about -- because your point about the custom extensions makes sense too :) |
I'm going to wait until I review the entire PR before I weigh in on the complexity debate, but I thought I'd give my 2c on this:
He didn't remove your copyright. He removed some superfluous comments from the source code. The code still retains your copyright via the README and LICENSE files. And it's just a PR; if you feel strongly that individual source files need a copyright line, you can make that case in a less hostile way. (Please forgive me if I'm misinterpreting your tone, but "you just don't" sounds pretty harsh, especially in light of the effort @maurogeorge put into this PR.) Personally I agree with the points made here: http://opensource.com/law/14/2/copyright-statements-source-files -- and I'd like to know if you've got some compelling arguments to the contrary. |
Also: http://hackerboss.com/get-rid-of-templates/
|
@alexch I made your suggestions please take a look.
This our situation today on master or this branch. Maybe is a good idea to move to external gems, like the rspec did. But IMHO this is a big step, so maybe we need to do a baby step first.
Nothing! In the early days of the project probably make a lot of sense, but today we have a lot of formatters. So the code grows and we need to refactoring and thinking on a better solution. I sugested classes because it is better to we apply some good practices like SRP, small classes, small methods and pass a few params. The focus is on clarity, example if I want change the hash formatter, just open the
Good catch! Let`s try find together a better solution to that.
Why we need to load custom extensions? All the extensions today are inside the AP.
Sorry for that.
Again as my answer on 2, my focus here is on clarity. |
Thanks for all your feedback! Let me step back a little to provide some context. When I had first built awesome_print it only covered basic Ruby types. Very quickly I realized I want custom formatter for ActiveRecord types. So I've extended type dispatch to make the following possible:
Back then I was using Rails on daily basis so I've added my ActiveRecord extension to the gem itself (in retrospect though I should have created separate "awesome_print_rails" gem). Anyway, I think preserving "drop-in" mechanism without explicitly hardcoding a list of available custom formatters has a value. My goal in v2 branch was to 1) make dispatch chaining more DSL-ish and less explicit, and 2) document the interface so that people could create extensions outside of awesome_print gem. I am willing to give this PR a benefit of a doubt and run some benchmarks (and I encourage you to do the same). However if we are throwing in more code that is slower and doesn't add new features (and in fact removes dynamic loading I've described above) then I am highly doubtful this is the right way to go. As for the copyright, I didn't mean to sound harsh ;-) Ironically though the license itself states that the copyright notice shall be included in substantial portions of the software -- so you know who to blame ;-) |
From the 4.2.0 to 4.2.1 the internals of AR have change.
@michaeldv I understand. But I dont think we need this "drop in" mechanism, since today we have lot of formatters like the To handle this external's extensions, first we need to expose a set of methods that we define as a public API, doing a RDoc to this, this way all extensions know how method they can use to built a AP extension. Beside that the actual "drop in" it is not so "drop in", since we need to check and require the formatters. Probably the idea of have like:
It is a good thing. But I think it is a big step, to me this PR is a first step, before the next step of define a public API and later extract externals gems. I think we can treat the AP like the devise, devise has 10 modules to handle a specific part of authentication, but all that is bundle in a single gem. My idea of this PR is to fixes the #189 #187 #188 and try to enhance the code quality. As you can see on Code Climate this PR enhance the GPA in +0.89 now we do not have a single F class, since now we have more classes it is more easy to refactor and reach a better quality. About the copyright we can remove from each file right? |
@michaeldv I updated the code to preserving the "drop-in" mechanism michaeldv/awesome_print@aef581d. |
@michaeldv any feedback on that? |
@maurogeorge I run some benchmarks on my MacBook Air and the results are discouraging: it's more than 15 times slower in my test. To run it I set
I suspect it's all because of class-based dispatch: you basically look up and create new class for each formatter call, and that's a lot of overhead (even more than I anticipated). Also, your code even with custom type detection might break gems like https://github.com/estum/awesome_print-carrierwave which follow current extension loading pattern. |
@michaeldv I suspected that is slow too. But in this case I prefer code quality over speed, since the Awesome Print, I think, is used only in development/test. Let's compare the "qualities" on two branches we have, in my opinion: mg-v2
master
IMHO with a better quality I think will be more easy to start some refactorings and close some issues. Obviously be faster is always a good thing, but I don't think this will be noted when people are on a console. Maybe we can improve speed even using classes and autoload, I don't think that we need lost code quality to gain speed. Yeah probably with this PR will break gems like the one you mentioned, but the mentioned gem do not follow a public API to make extensions, today AP do not have that. And this will be the 2.0 so we are good to break things. Clearly we diverge in opinion here, but the final decision is yours 😃 |
I still don't understand why you are unwilling to break up this PR. Land the easy stuff first. I think this approach has been a bit irresponsible and you are kind of forcing it with the all or nothing approach. As a committer I would have to vote no, because this just isn't good dev practice. Sorry Mauro, but this can't be the best way to do this! ☺
|
I agree with @imajes -- if we could extract new hash syntax and then drop legacy support for older Ruby and Rails that would be great way to move forward. I agree that many developers are using awesome_print in their local dev/test environments only. However we simply don't know who and how is using it in production. Knowingly releasing something that is so much slower feels somewhat irresponsible to me. |
@imajes I explain my decision about make a single PR about V2 on the comment.
@michaeldv I understand your point. |
It seems still no tool (ap/pp/whatever) to print hashes with new syntax. Strange. |
Will break this stuff up into smaller PRs, as a lot of it is worth saving! |
Hi @michaeldv @imajes this is a big commit, with tons of refactorings and close the issues to we bump a version 2.0.
Since we have a lot of changes, I think it is better take a look on the branch at https://github.com/michaeldv/awesome_print/tree/mg-v2
To fix the #187 I create N formatters, so all new formatter can have a single place to format the object like this. Removed the monkey patch on the plugins too 🤘.
To fix the #188 I create a new option, false by default. Since the default on ruby is to use the hash rocket.
To fix the #189 I droped the Ruby 1.8.x and Rails 2.x from the code and specs.
Beside the issues, I change the structure a lot. Since in the last commits we have more code coverage, I feel more confident to make this changes.
Since this is a big step I think we can release a
2.0.0.beta
first, and wait a little before release the2.0.0
this way we can fix some possible bug on this. We can define a number of downloads on Rubygems to the beta, and after the downloads we release the final version.Please review guys, I hope you guys enjoy. Lets work together to release a new awesome_print 🎆
@michaeldv thanks for bring the awesome_print to the world. On my first studies with Ruby/Rails I used the AP and love it. Today I work about 4 years with Ruby/Rails and use AP on my daily basis. It is so awesome I can contribute to this project 😊
closes #189 #187 #188