RIPAGlobal / scimitar

A SCIM v2 API endpoint implementation
MIT License
61 stars 43 forks source link

Refactoring #141

Closed shangsuru closed 1 month ago

shangsuru commented 2 months ago

Why

Hi! :wave: I want to use this Gem for a production system, and I would also like to contribute to this gem in the future.

What

In my first PR here, I did some refactoring and fixed code style issues. Thank you for reviewing 🙏🏻

Details

There will be a similar PR for specs later

shangsuru commented 1 month ago

@bagp1 @pond Does someone have time to review this? 🙏🏻

pond commented 1 month ago

It's just down to me now, as @bagp has moved onto an exciting new role elsewhere. I did look at this a while ago but my time is heavily divided.

First off, before I get into this, I don't want it to seem too negative and I very much appreciate the time and effort you've put into the PR. Contributions even just of code style or typo fix-ups all help improve code quality and are welcomed. Just your comment typo fixes alone here are great. Thank you for all this.

Now, onto the bits I strugged with! I think much of what you've done is personal preference, but is counter to our own preference about coding style (such as parentheses on method calls, which we include often for clarity). Much of our use of such things comes from some 20 or so years now of experience with Rails and Ruby, and seeing what can cause confusion for coders especially less used to Ruby as a language. Wrapping a multi-line "if" condition in parens is another one. Removing return just makes the code fractionally harder to grok too (a method just bluntly ending in a dumb statement foo, rather than the proactive and precise return foo, can look like a mistake or otherwise just seem odd; it's micro-aggressions that increase cognitive burden, for sake of preferring a less cluttered aesthetic to the code - to which we are sympathetic, but argue, function over form).

Since Scimitar is a hybrid of other work, this coding style is of course not 100% consistent throughout and I realise that in itself might annoy some and can make it hard to judge what is expected! We don't have a coding style doc for the gem, after all.

Anyway, this means I'm on the fence. There are some things in here (such as comment typos) that I want to keep. Another one is where you removed the == true  on if skip_next_component == true and - while I often don't like truthy-falsy comparisons (type ambiguity and when is something truthy? puts "hello" if 0 is a good one) - in this case those are all bool flags and there are subsequent examples where they're checked without the "==", so it makes sense. You also removed parens that were in that sequence which were indeed pointless if (foo) ... => if foo ..., which again, makes sense. There's no ambiguity/cognitive burden difference arising for such a simple statement. Aesthetics therefore win.

So I guess...

...and some more specific things...

shangsuru commented 1 month ago

@pond Thank you for the reply and: Sorry, this is my first open source contribution on Github :pray: I should have put the more opinionated code style adjustment in separate PRs to make it easier to review. Putting all changes in one PR makes effort to review much larger than the value the PR is giving.

Regarding the one-liner:

self.schemas.lazy.map { |schema| schema.find_attribute(*path) }.find(&:present?)

since it has no opportunity to break out of the iteration early, but instead processes the whole map

:bulb: FYI it doesn't process the whole map, because it uses lazy evaluation. I also think the one-liner is quite cute... But I agree, it is only easier to read for people familiar with functional programming. So reverted it, too.

ripa-developer commented 1 month ago

Don't worry, it's a good PR, with a good description and clear intent, and I don't generally mind larger PRs at all.

Checks all passed and it looks good -> Merging! Thank you!