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

withCmds is more understandable than ! #661

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@willnwhite

willnwhite commented Jul 14, 2016

damn haha, just realized what ! from Platform.Cmd does, amazing 😍

Maybe ! has a history, but I think it could do with a more descriptive name.
I've avoided using it so far because it's harder to understand than the alternative.
I guess shorthand is useful, but I always feel like I never know who's going to need to understand my code quickly.

maybe withCmds as an alias for (!). you could do
{ ...model... }withCmds[cmdA, cmdB]
. but then again that's something people might have to look up once and remember then too

Though that might be an even better "basic" way because it gets rid of the tuple syntax too.

I was wondering if ! was used for anything else because I think withCmds like this is the most readable.

and since this is a thing... http://package.elm-lang.org/help/design-guidelines#avoid-infix-operators

withCmds is more understandable than !
A: damn haha, just realized what `!` from `Platform.Cmd` does, amazing 😍

Z [2:59 PM]  
Enlighten us, what does it do?

A [3:05 PM]  
takes a model and a list of commands, and gives you a tuple that you can use

[3:05]  
its definition is straightforward enough:

[3:05]  
(!) model commands = (model, Cmd.batch commands)

[3:07]  
you can use it with [] to avoid having to put parens around a big model 🙂

[3:07]  
like `{ ...multiple lines... } ! []` instead of `({ ... multiple lines ... }, Cmd.none)`

B [3:09 PM]  
The better part is that you do not need to chain those ({...}, some cmd) things. I've done that until now >_<

[3:12]  
I've chained effects until I realized that I can just list them after an `!` :umbrella_with_rain_drops: and they all get evaluated.

A [3:13 PM]  
@b: Doesn't Cmd.batch give you that too?

B [3:14 PM]  
@A: Looks like its similar yes.

A [3:14 PM]  
(!) just makes Cmd.batch a little tad nicer 🙂

B [3:15 PM]  
😄

willwhite [3:16 PM]  
Maybe `!` has a history, but I think it could do with a more descriptive name.

[3:18]  
I've avoided using it so far because it's harder to understand than the alternative.

A [3:19 PM]  
I guess since its use is shortening down code that you have to write often, it's intentionally succinct

willwhite [3:20 PM]  
I guess shorthand is useful, but I always feel like I never know who's going to need to understand my code quickly.


A [3:22 PM]  
maybe `withCmds` as an alias for `(!)`. you could do
```{ ...model... } `withCmds` [cmdA, cmdB]```
. but then again that's something people might have to look up once and remember then too

willwhite [3:24 PM]  
Though that might be an even better "basic" way because it gets rid of the tuple syntax too.

[3:25]  
I was wondering if `!` was used for anything else because I think `withCmds` like this is the most readable.

A [3:28 PM]  
and since this is a thing... http://package.elm-lang.org/help/design-guidelines#avoid-infix-operators

[3:28]  
heh 🙂
@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Jul 14, 2016

Thanks for the pull request! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Jul 14, 2016

Thanks for the pull request! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@rtfeldman

This comment has been minimized.

Show comment
Hide comment
@rtfeldman

rtfeldman Jul 14, 2016

Member

I think the point of ! is to reduce verbosity in an super common operation. You can always do this:

( model, Cmd.none )

...but you end up writing that extremely often as your code base grows, so ! gives you a more concise way to express it:

model ! []

I wouldn't use a withCmds, since it'd be more verbose than either of these! 😄

If I didn't want to use !, I'd just fall back on the tuple style. Either works fine!

Member

rtfeldman commented Jul 14, 2016

I think the point of ! is to reduce verbosity in an super common operation. You can always do this:

( model, Cmd.none )

...but you end up writing that extremely often as your code base grows, so ! gives you a more concise way to express it:

model ! []

I wouldn't use a withCmds, since it'd be more verbose than either of these! 😄

If I didn't want to use !, I'd just fall back on the tuple style. Either works fine!

@willnwhite

This comment has been minimized.

Show comment
Hide comment
@willnwhite

willnwhite Jul 14, 2016

( model, Cmd.none ) is clearer than model ! [], so I use that.

model `withCmds` [cmdA, cmdB]

is less verbose (and arguably clearer) than

( model, Cmd.batch [cmdA, cmdB] )

and clearer than

model ! [cmdA, cmdB]

willnwhite commented Jul 14, 2016

( model, Cmd.none ) is clearer than model ! [], so I use that.

model `withCmds` [cmdA, cmdB]

is less verbose (and arguably clearer) than

( model, Cmd.batch [cmdA, cmdB] )

and clearer than

model ! [cmdA, cmdB]
@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jul 15, 2016

Member

Don't want to have PRs open for API change suggestions. I think this is viable, but I also would like to let (!) live for longer and see what happens.

Member

evancz commented Jul 15, 2016

Don't want to have PRs open for API change suggestions. I think this is viable, but I also would like to let (!) live for longer and see what happens.

@evancz evancz closed this Jul 15, 2016

@willnwhite

This comment has been minimized.

Show comment
Hide comment
@willnwhite

willnwhite Jul 16, 2016

I was suggesting it as an alias for (!), rather than as a replacement, but sure. I guess I should start using it in my own code first!

willnwhite commented Jul 16, 2016

I was suggesting it as an alias for (!), rather than as a replacement, but sure. I guess I should start using it in my own code first!

@willnwhite

This comment has been minimized.

Show comment
Hide comment
@willnwhite

willnwhite Aug 19, 2016

model ! [] == (model, Cmd.none) is now a loading screen message on Slack.

willnwhite commented Aug 19, 2016

model ! [] == (model, Cmd.none) is now a loading screen message on Slack.

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