I'm a software developer based in Newcastle Upon Tyne, England. I've got a wide range of experience in companies of varying sizes and cultures, and in roles of varying degrees of responsibility.
That's an interesting point re mixing tense - perhaps messages should generally be imperative and commands should generally be past, since for the most part a message is something a user has intentionally requested happen where a command is something that has happened without them realising.
If you're talking about commands as in Cmd msg, I disagree. Commands are imperative by definition.
For messages caused by a Sub msg, that does make a degree of sense.
For messages pushed by the execution of some command, maybe. You could say (a) firstCmd |> Cmd.map doSecondCmd or (b) someCmd |> Cmd.map firstCmdDone. (a) communicates intent directly in the execution of the command, (b) does not communicate intent directly, but elsewhere the update function. Considering update is supposed to handle and react to messages (b) seems to be "correct" most often, but in cases where the handling of the message logic is shared by multiple commands, (a) might be a better fit.
I'm a software developer based in Newcastle Upon Tyne, England. I've got a wide range of experience in companies of varying sizes and cultures, and in roles of varying degrees of responsibility.
I'm a software developer based in Newcastle Upon Tyne, England. I've got a wide range of experience in companies of varying sizes and cultures, and in roles of varying degrees of responsibility.
Of course, the inverse of that is that the user can in fact change the URL for themselves, so I guess this hasn't actually helped anything at all. D'oh.
GameMsg ToggleInventory, will it, when passed to update, create a new Model that when passed to view will show an inventory? Then imperative makes sense.
If you'd use the name InventoryToggled to denote that the user has e.g. pressed the ToggleInventory button, I'd say you're naming things incorrectly because the inventory wasn't toggled, as the message has not been processed by update yet.
ChangedUrl on the other hand denotes something that definitely did happen. It is more similar to ToggleInventoryButtonPressed.
I'm a software developer based in Newcastle Upon Tyne, England. I've got a wide range of experience in companies of varying sizes and cultures, and in roles of varying degrees of responsibility.
That's an interesting point re mixing tense - perhaps messages should generally be imperative and commands should generally be past, since for the most part a message is something a user has intentionally requested happen where a command is something that has happened without them realising.
If you're talking about commands as in
Cmd msg
, I disagree. Commands are imperative by definition.For messages caused by a
Sub msg
, that does make a degree of sense.For messages pushed by the execution of some command, maybe. You could say (a)
firstCmd |> Cmd.map doSecondCmd
or (b)someCmd |> Cmd.map firstCmdDone
. (a) communicates intent directly in the execution of the command, (b) does not communicate intent directly, but elsewhere the update function. Consideringupdate
is supposed to handle and react to messages (b) seems to be "correct" most often, but in cases where the handling of the message logic is shared by multiple commands, (a) might be a better fit.I was thinking specifically with the example I posted initially to be honest:
Now you can see what effects the user intentionally chose, and which one was a side-effect of something that they chose to do.
Of course, the inverse of that is that the user can in fact change the URL for themselves, so I guess this hasn't actually helped anything at all. D'oh.
It depends on what those messages are.
GameMsg ToggleInventory
, will it, when passed toupdate
, create a newModel
that when passed toview
will show an inventory? Then imperative makes sense.If you'd use the name
InventoryToggled
to denote that the user has e.g. pressed theToggleInventory
button, I'd say you're naming things incorrectly because the inventory wasn't toggled, as the message has not been processed byupdate
yet.ChangedUrl
on the other hand denotes something that definitely did happen. It is more similar toToggleInventoryButtonPressed
.Yeah, the more I think about it the more I think mixed tense (but intentionally so, rather than accidentally so) feels like the way forward here.
Appreciate your input, this has been a useful conversation.
Glad it was of use to you