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

Clean up use of LoDash #1404

Merged
merged 1 commit into from
May 6, 2020
Merged

Clean up use of LoDash #1404

merged 1 commit into from
May 6, 2020

Conversation

tvst
Copy link
Contributor

@tvst tvst commented May 2, 2020

While reviewing #1295 I noticed we're using LoDash's flowRight for apparently no reason. So I'm removing it here.

@arraydude : I don't know LoDash well. Is there a reason why flowRight is preferable over pure function composition?

@tvst tvst requested a review from arraydude May 2, 2020 06:19
@tvst tvst requested a review from a team as a code owner May 2, 2020 06:19
@@ -13,32 +13,32 @@ twine = "*"
wheel = "*"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just sorting things.

@@ -16,7 +16,7 @@
*/

import React from "react"
import * as _ from "lodash"
import without from "lodash/without"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to import the whole thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I didnt test it but it should be the same as create-react-app already includes lodash within it, but I'm agree with you

withMapboxToken,
withFullScreenWrapper
)(DeckGlChart)
export default withMapboxToken(withFullScreenWrapper(DeckGlChart))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is much more readable than using LoDash's flowRight. Is there are reason to use it here instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

From my point of view is more readable using a compose function as it is very common in the react world, actually redux expose their own compose function and it is also mentioned in the react documentation

Copy link
Contributor

@tconkling tconkling May 5, 2020

Choose a reason for hiding this comment

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

I am a bit of an anti-JavaScript partisan, so take this with a grain of salt, but: I strongly disagree that the compose function is more readable in this case. What's the benefit of a separate function that just composes already-composable functions (and essentially obfuscates that process - I need to go into compose() to see what it's actually doing)?

It feels to me like it adds cognitive overhead; adds debugging overhead (I have to step into the compose function if I'm stepping through this code; and stack traces are going to be less meaningful); it may add runtime overhead, probably not but I have to go read the code to find out; and its functionality isn't worth those overheads.

Unless there's a huge code savings, I will almost always come down on the side of explicit being much more desirable than implicit.

(Apologies for the rant; and of course I hope it goes without saying that I definitely think reasonable people can disagree here, and also I might be simply not seeing some fundamental win here. And finally, this is quite a small issue; it's more the underlying philosophy it belies that rubs me the wrong way :))

Copy link
Contributor Author

@tvst tvst May 6, 2020

Choose a reason for hiding this comment

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

Yeah, I'm with Tim on this one (minus the rant! 🤣 )

foo(bar(baz)) is 100% clear to anyone reading it, while compose(bar, foo)(baz) is not. In fact, I don't even know if it should be compose(foo, bar)(baz) — and that actually proves the point that the compose notation is confusing!

I'll go ahead and push this change for now. It's not a huge issue either way 😉

@tvst tvst merged commit 81d8a36 into streamlit:develop May 6, 2020
@tvst tvst deleted the clean-lodash branch May 6, 2020 19:39
tconkling added a commit that referenced this pull request May 11, 2020
* develop:
  Add "make mini-devel" to install minimal dev dependencies (i.e. doesn't install all the test dependencies) (#1407)
  Fixing date_input | min and max selectable date issues (#1426)
  Torch Tensorbase hash func (#1394)
  Change list() cast (#1401)
  Add geo layers to DeckGlJsonChart (#1306)
  Clean up use of LoDash (#1404)
  Replace st.beta.*/st.experimental.* with st.beta_*/st.experimental_* (#1403)
  Release 0.59.0 (#1405)
  Setting textarea height and unit tests (#1411)
tconkling added a commit to tconkling/streamlit that referenced this pull request May 11, 2020
* feature/plugins:
  black reformatting
  Add "make mini-devel" to install minimal dev dependencies (i.e. doesn't install all the test dependencies) (streamlit#1407)
  Fixing date_input | min and max selectable date issues (streamlit#1426)
  Torch Tensorbase hash func (streamlit#1394)
  Change list() cast (streamlit#1401)
  Component template tweaks
  Components: alpha 2 cleanup (streamlit#1425)
  Fix dataframe support
  Add geo layers to DeckGlJsonChart (streamlit#1306)
  Clean up use of LoDash (streamlit#1404)
  Replace st.beta.*/st.experimental.* with st.beta_*/st.experimental_* (streamlit#1403)
  Release 0.59.0 (streamlit#1405)
  Setting textarea height and unit tests (streamlit#1411)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants