Replying to Avatar jgomo3

nostr:npub19mun7qwdyjf7qs3456u8kyxncjn5u2n7klpu4utgy68k4aenzj6synjnft, reading your Functional Design book.

I have a question regarding style.

Why in the following snippet (page 208) you prefered not to destruct the turtle key from the state, as you did with the channel?

I don't understand the question. Could you elaborate?

From: jgomo3<-randymcmi... at 10/09 13:33

> nostr:npub19mun7qwdyjf7qs3456u8kyxncjn5u2n7klpu4utgy68k4aenzj6synjnft, reading your Functional Design book.

>

> I have a question regarding style.

>

> Why in the following snippet (page 208) you prefered not to destruct the turtle key from the state, as you did with the channel?

>

>

>

>

>

CC: #[3]

Reply to this note

Please Login to reply.

Discussion

As the picture shows, the `update-state` function receives an `state`. In the function's signature, you destructure `state` extracting `channel` from it. I wonder why you didn't extract also `turtle` in that moment?. You prefered to get the `turtle` explicitly in the `let` expression instead.

I think it was a matter of taste, or style. Maybe related to the fact that `turtle` inside the `let` body is a derivates value from the original `turtle` you get from `state`.

Ah, I see. I don't have a real good explanation. I probably started with the destructuring of the channel, and then added the :as clause later. I am in the habit of beginning each function with a 'let' clause so it's not unlikely that I reflexively pulled the turtle out there.

It's also possible that I wrote the 'assoc' statement as a single long expression that inlcuded the 'turtle/update-turtle' call, and then later extracted that function into a 'let' clause. My IDE implements that kind of refactoring very nicely.

anyway I don't remember the order in which these lines were written, nor the way in which my tests drove me to implement the function. In the end, however, you are right to point out the inconsistency. I missed an obvious refactoring.

From: jgomo3<-randymcmi... at 10/09 21:57

> As the picture shows, the `update-state` function receives an `state`. In the function's signature, you destructure `state` extracting `channel` from it. I wonder why you didn't extract also `turtle` in that moment?. You prefered to get the `turtle` explicitly in the `let` expression instead.

>

> I think it was a matter of taste, or style. Maybe related to the fact that `turtle` inside the `let` body is a derivates value from the original `turtle` you get from `state`.

CC: #[4]

CC: #[5]