You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collections of values can have complex forms/structures. Getting/Putting/Engineering the data of your application/system into an optimal shape/structure is a difficult problem.
The following examples are going to deal with small structure that represents a user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A: The bottom one is better, but only SLIGHTLY. And they are both bad.
A CONTRIVED SEMI-PASSIVE-AGGRESSIVE CONVERSATION BETWEEN JOE HARROW AND JASON GOLDBERGER
Imagine a conversation where joe is Joe Harrow and me is Jason Goldberger.
--
joe: Why is the bottom one better?
me: It crashes when the caller gives a bad params map or anything else.
--
joe: Why is that good? I don't want my code to crash.
me: Crashing here is better than continuing with bad inputs.
--
joe: I don't want my code to crash. Why is this better?
me: Ask me for 2 inputs.
joe: Why? This is stupid.
me: Just do it.
--
joe: Please give me two inputs.
me: 2 and 10
joe: Ok.. 2 and 10.
me: Give me a number between the two numbers.
joe: 6.
me: Ok. Ask me for two inputs again.
joe: Please give me two inputs.
me: 2, 10, 25, and "beef"
joe: That makes no sense.
me: Are you telling me I have provided you with unacceptable input?
joe: I said 2 inputs, but you gave me 3 numbers and "beef".
me: I know what I gave you. Do you accept my 2 inputs?
joe: But it was 3 numbers and "beef".
me: Do you wish to continue with the 2 inputs I gave you?
joe: But it was 3 numbers and "beef".
me: I gave you 2 inputs: 2, 10, 25, and "beef".
joe: That makes no sense. Are you messing with me?
me: Only a little... What you are experiencing is an exceptional input. AN EXCEPTION.
--
me: Given exceptional input should a program continue?
joe: Probably not.
me: No. It should not.
--
joe: But that does not differentiate the two examples above.
joe: Why is the "whole-map-pattern-matching-bottom-example" better than the "get-each-key-or-nil" example?
me: Ah.
me: Ask me for two numbers.
joe: Please give me two numbers.
me: 10 and "beef".
joe: Dude! "beef" is not a number.
me: Joe, are you checking types in the example above?
joe: No...
me: I have given you 2 numbers as you requested. What are the inputs?
joe: 10 and "beef"... (but "beef" is not a number)
me: Write them down on this sheet of paper. Now put the paper into this envelope.
me: Later on we are going to open an envelope. It might be yours it might be another. We will read the contents and then pick a number between the two numbers.
joe: But...
me: but, what?
joe: That might not work.
me: Why would you say that?
joe: it had "beef"...
me: The function we are calling is open_the_envelope_and_pick_number_between_the_two_numbers.
me: Why would that not work?
joe: "beef" is not a number.
me: So.. you can't pick a number between "beef" and some other number?
joe: Dude. I know you are messing with me.
me: Joe, if "beef" is not a valid number why would you put it in the envelope?
me: Why not check the type of your inputs BEFORE you put them into the envelope?
me: Can you imagine what it is like for a poor little function to get envelopes all day and the values inside make no sense?
me: Do you even care about the little functions, Joe?
joe: I CARE!
--
Epilogue
After this conversation, joe became an advocate for the care and good treatment of functions. He improved his type checking and went on to become a master codeologist.
It is said that me is still out there complaining about loss of type specificity to this day...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters