BookBytes

A book club for developers.

BookBytes

BookBytes is a fortnightly (or biweekly) book club for developers. Each episode the hosts discuss part of a book they've been reading. And they also chat with authors about their books. The books are about development, design, ethics, history, and soft skills. Sometimes there are tangents (also known as footnotes).

Hosts

Adam Garrett-Harris

Safia Abdalla

Jen Luker

Jason Staten

Subscribe

17: The Imposter's Handbook: Functional Programming and Databases

11/21/2018

Safia talks about the four themes of functional programming, Jason tells us the difference between currying and partial application, Jason finds out that third normal form is not the most normal form. And Adam found out that BASE is the opposite of ACID.

Hosts

Transcript

Help improve this transcript on GitHub

(Intro music: Electric swing)

0:00:13.5
Adam Garrett-Harris

Hello and welcome to BookBytes, a book club podcast for developers. We’re continuing “The Imposter’s Handbook: A CS Primer for Self-taught Programmers” by Rob Conery, and this week we’re going over chapters 12 and 13 which is Functional Programming and Databases. I’m Adam Garrett-Harris.

0:00:31.4
Safia Abdalla

I’m Safia Abdalla.

0:00:33.1
Jason Staten

I’m Jason Staten.

0:00:35.0
Adam Garrett-Harris

And Jen, this week, is very sick. So, as she says, “Too sick to knit.” So she can’t be on the show today but we’ll carry on without her.

0:00:45.3

(Typewriter Dings)

0:00:47.1
Adam Garrett-Harris

All right, so I was pretty excited about the Functional Programming chapter, what about y’all?

0:00:50.7
Jason Staten

That’s definitely where I spent the majority of my time between these two chapters.

0:00:55.9
Safia Abdalla

I found the Databases chapter a little bit more intriguing, but I definitely did like the way that the Functional Programming chapter was set up, like the four themes that Rob separated it out into.

0:01:07.7
Adam Garrett-Harris

The four themes? What was that?

0:01:11.1
Safia Abdalla

Yeah, so if you’re reading along with us the four themes are described on page 291. They are the theme of immutability, purity, ideas around side effects, and then ideas around currying. And the book kind of went into each of these topics a little bit further in that chapter.

0:01:29.9
Adam Garrett-Harris

Nice, and yeah, this is based on Lambda calculus which we talked about before, but honestly, the only idea I think that, for me, carried over from Lambda calculus is kind of everything can be a function and you can pass around functions and you use functions a lot.

0:01:45.2
Safia Abdalla

Yes. The…

0:01:46.4
Adam Garrett-Harris

(laughs).

0:01:47.0
Safia Abdalla

Functions as values rule of thumb.

0:01:49.2
Adam Garrett-Harris

Yeah.

0:01:49.9
Jason Staten

So in asking about the background that both of you have, have you done much in the line of functional programming? Or tell me about that experience you’ve both had.

0:02:01.1
Safia Abdalla

Yeah, So I can talk a little bit about it. In University, we were working with a language called Racket/Scheme which was designed to be a function programming language with a Lisp-like syntax.

0:02:17.6
Jason Staten

Mm-hmm (affirmative).

0:02:18.6
Safia Abdalla

So I did that in a couple of classes in college. And then in my day-to-day work, right now I am using a programming language called Elm in parts of our codebase. It’s a functional programming language that compiles down to JavaScript and that’s pretty much the extent of my experience with functional programming languages.

0:02:41.4
Adam Garrett-Harris

Oh, that’s super cool that you’re using Elm.

0:02:43.1
Safia Abdalla

Yeah, I was gonna say, “Yeah, it’s been interesting.” It was my first time using that language and especially in like an application or like a software that people use on a day-to-day basis. Like, you know, like, not just like, a pet project or something like that. So, yeah. It’s been interesting learning it and figure it all out and stuff. It’s definitely like a mind shift.

0:03:03.3
Adam Garrett-Harris

Yeah! Yeah. It’s so weird. It doesn’t let you do any side effects at all, but side effects still have to happen, but they’re all taken care of by the Elm runtime.

0:03:12.8
Safia Abdalla

Yeah, and for me personally, the syntax was one of the hardest things to grasp, and also just its strictness around typing. Elm has a lot of type inference built in that’s designed to kind of avoid errors that might come up in runtime. So, you know, you have strict types to find for something that are going to capture all of like, the annoying corner cases and like flukes that you get when you might be running a program and give you a chance to deal with those. So navigating its strict typeness and, like, building a good type model for the application was something I had to figure out, too. ‘Cause it was like you have to be like, very strict and precise about types and make sure that it all worked well in the Elm model. I don’t know if I’m explaining this well.

0:04:06.4
Adam Garrett-Harris

Yeah.

0:04:07.2
Jason Staten

Yeah. That’s actually one thing that I don’t feel like was brought up a lot within the book, at least as far as I’ve seen, and I don’t know if there’s a chapter on it, maybe season two, it is talking about static typing versus dynamic typing, right?

0:04:21.7
Safia Abdalla

Yeah.

0:04:22.4
Jason Staten

And then there’s also like, strong versus weak typing, which is a different thing as well. But yeah, coming from being in a JavaScript space where like, everything’s dynamic and a little bit more free-for-all, versus like, in Elm where you have to type things up front.

0:04:38.5
Safia Abdalla

Mm-hmm (affirmative).

0:04:39.2
Jason Staten

Your mental concepts and approach to handling problems is definitely different, but that’s awesome that you’re using Elm. It’s something that I’ve only tinkered with on the side. So like, to hear the experience of somebody using it in a production, like I'm curious how you’re perceiving that within Elm as we kind of, hit through some of the topics.

0:04:59.1
Safia Abdalla

Yeah. I would say it’s generally… Has been pretty easy for me to grasp and start to work with. The one way that Elm is lacking, with a respect to JavaScript, is just around developer tools. So it’s kind of hard to get a good debugger set up in Elm, and when you’re like, trying to work through things and like, step through everything, there have been a few contacts in my day-to-day job where I was trying to debug an issue and I was like, “Oh, if I could just put a breakpoint here in this Elm code, that would be so great.” But you know it’s not set up for that, at all. So that makes it difficult. I think the general recommendation for debugging is you use their like, debug.log statement, which is just like console.log.

0:05:46.7
Adam Garrett-Harris

Hmm.

0:05:47.4
Jason Staten

I’d thought the promise was that if it compiles in Elm, it just works.

0:05:51.2
Safia Abdalla

Oh! I have fun stories about that! (laughing)

0:05:54.5
Adam Garrett-Harris

(laughs)

0:05:57.4
Safia Abdalla

There have been a few occasions where… So the part of the codebase that’s written in Elm is not the entire codebase, it’s sort of like a small chunk of it and it sits at the intersection between two other codebases that are not written in Elm, and that are not as strictly typed. So there are situations where Elm is communicating with an external system and that external system unexpectedly gives it data that causes Elm to bork.

0:06:26.8
Jason Staten

Hmm.

0:06:26.4
Safia Abdalla

So it’s not in within Elm itself, it’s within its interfaces to the outer... To other parts of the codebase. I don’t know if that made sense.

0:06:34.3
Adam Garrett-Harris

Yeah. My understanding was that when you’re getting data from the outside you have to take care of every possibility and handle every case.

0:06:44.3
Safia Abdalla

Yeah you have to write decoders-

0:06:46.2
Adam Garrett-Harris

Yeah.

0:06:46.7
Safia Abdalla

To decode the data that comes in, and then encoders to send it back out. And those are where a ton of the bugs happen.

0:06:53.5
Adam Garrett-Harris

Gotcha. Okay so, as far as my experience goes with functional programming, about 6 years ago I tried to take a course on Scala on Coursera-

0:07:04.1
Jason Staten

I think they’re starting that up again.

0:07:05.9
Adam Garrett-Harris

Oh yeah. And it was taught by the creator of Scala and it was just way over my head at the time but I thought that it was really cool. And then a few years ago I read some of this book called “Professor Frisby's Mostly Adequate Guide to Functional Programming” and it uses JavaScript. I don’t know if you’ve seen it or not but it’s free on GitHub, and it’s really cool. And then at my last client I did use a little bit of Elm.

0:07:34.2
Safia Abdalla

Oh, wow.

0:07:34.6
Adam Garrett-Harris

Yeah! So I’ve written some functional programming in production. It was just, the same kind of thing as you, Safia. It was just a tiny little part of… I mean this was a really tiny part of a website. But-

0:07:46.9
Safia Abdalla

Yeah.

0:07:47.4
Adam Garrett-Harris

It was fun.

0:07:48.9
Safia Abdalla

I know Elm recently released their 0.19 version, which is like a long awaited update, and I was exploring some of the things they’d laid out, and they do have an example codebase up that is a full-on web app written entirely in Elm, and I will try and find the link for it and put it in the show notes for people who are curious as to what a web application that is written entirely in Elm would look like, and not just…

0:08:14.3
Adam Garrett-Harris

Yeah.

0:08:15.0
Safia Abdalla

As like, a tiny, auxiliary thing.

0:08:16.9
Adam Garrett-Harris

Yeah, I think it looks really beautiful and they’ve got the built-in formatter, and the way everything lines up is really cool.

0:08:23.9
Safia Abdalla

Yeah, when it works with you and when it’s not super stressful, it is really great. And I guess that’s just software in general, and programming. When it, like, you get it and your mind is flowing and you’re like, in tune with everything, it works well. But yeah, when you’re trying to figure out how to write a decoder to cover all the cases, or something …

0:08:41.6
Adam Garrett-Harris

Yeah.

0:08:41.6
Safia Abdalla

That’s not super fun (laughs).

0:08:43.6
Adam Garrett-Harris

(laughs) Yeah. What about you, Jason? What’s your background?

0:08:47.0
Jason Staten

So, I have less production functional experience than both of you, and so I have, I have a little bit of Elm envy, I guess. But I have spent a good chunk of time doing some Clojure work in the past. I studied the “Programming Clojure” book and then followed it up later with “The Joy of Clojure”, which was probably one of my favorite programming books that I’ve read, just because it really showcased how thought-out the language was, and how much it built on pre-existing concepts. Everything that they were going through in the book where they talked, say, about software transactional memory, they went and said, “Well, here’s the whitepaper for the thing.” And it was written back in the 70s, or something like that, and so like, it’s not necessarily all these new ideas, but they show how like, Clojure took these old concepts and applied them to a modern Lisp. And so I’ve spent time with that.

0:09:48.8

I’ve also run a book club within a company doing Haskell work, and so worked through the “Haskell Book” by Chris Allen, and that was really enlightening. Haskell, being on the other end where is like, Clojure is dynamically typed, Haskell has an uber powerful type system that is a change to wrap your mind around, and so I definitely haven’t used it within production, but a lot of the concepts do get applied within my daily work, because as you said, I mean, even JavaScript can have functional concepts brought to it with the way that, I mean, functions are pretty first class within it.

0:10:34.6

I mean we don’t necessarily get all of these things and they’re not as baked into the language in the same way. Like, you’re talking, I guess “bringing it back” to immutability, is something JavaScript doesn’t have built in it by default, is persistent data structures where, if you were to go and, say, create a map, or I guess an object in JavaScript, you can go and you can mutate that. Like you could go and add a new property or reassign a property within JavaScript, and it lets you do that. But if you-

0:11:05.0
Adam Garrett-Harris

Yeah.

0:11:05.8
Jason Staten

Were to use an immutable data structure, the way that you would have actually approached it is to create a new object with that updated key, whether it be new or replacing an existing one, and in JavaScript you can do that. It’s definitely common now with the object spread operator where you can do dot, dot, dot, and take the original source and copy it, but in functional languages, one thing that they have within them, is persistent structures that when you, say, go and update a map or something, it doesn’t actually copy everything, but instead it creates a new map with your single, say, updated key, and then everything points back at the original piece of memory as well because you know that because that original piece of memory is also immutable, that it’s never going to change, and so you don’t have to copy everything, you just go and have a change set that points back to the original version of it, so it’s still efficient on that front.

0:12:04.2
Adam Garrett-Harris

Yeah, yeah. So in JavaScript it just take a lot more self-discipline to keep things immutabile.

0:12:10.2
Jason Staten

Yeah.

0:12:11.0
Adam Garrett-Harris

And yeah, it’s definitely a common pattern to see now. Today, I actually found out that Internet Explorer does not support object.assign which is-

0:12:18.7
Jason Staten

(laughs)

0:12:19.5
Adam Garrett-Harris

Kind of the old-school way of doing an object spread.

0:12:22.6
Safia Abdalla

What version of IE? Is it just prior to Edge?

0:12:25.9
Adam Garrett-Harris

Looks like all of them. Yeah, prior ot Edge. So all the way up to IE 11.

0:12:29.9
Jason Staten

Good thing for polyfills I guess.

0:12:31.7
Adam Garrett-Harris

Yeah. (laughs)

0:12:33.2
Jason Staten

You talking about the discipline and immutability requiring developer discipline within a language that’s not necessarily functional, and that’s definitely one of the things that I like about when you have a codebase that’s written in a functional style, or working within a functional language, is that the language, it provides you guarantees and lets you work safely without having to always concern yourself, “Is this thing going to get mutated from underneath of me?” And instead just write it and like, if you’re writing it within the bounds of what the language gives you, then you’re going to be safe versus like, within JavaScript, I guess kind of going back to the Redux example, or React for that matter, if your state is mutated, there’s no safeguards in place that actually stop you from doing that. You can do that and then your application can kind of continue to work, or silently start acting weird, and it’s all based on developer discipline versus like, having those things baked in, can make your life a little bit easier.

0:13:36.9
Adam Garrett-Harris

Yeah. Yeah, for sure. And it can seem annoying, too, that you have to try to make the compiler happy and a lot of times we tend to think like, “Oh, the compiler’s complaining or yelling at me.” But it’s… It’s forcing you to do something you should be doing anyway.

0:13:53.0
Jason Staten

Yeah, I’ve had a lot of that experience with the Rust programming language. I just got back from RustConf a couple weeks ago, going to Portland for it, and that was one of the major points that was brought up is, “The compiler yells a lot, but it’s often because you’re used to doing something in a language that wasn’t truly safe to do, and just think about like, passing an object to another function within JavaScript. That object can go and get modified by that function before it’s returned back to you. And you hope that it doesn’t sometimes, but maybe it will, maybe it won’t. There’s no certainty on that front. And whether you have immutabile structures, like you know that that can’t happen to you anyways, or in Rust case, calling function actually says, “I am going to mutate this thing” or “I’m not going to mutate this thing.” So like, it’s within the type system that it tells you that information. But things that you can be really loose on in some other languages, a powerful compiler can actually call those out and make it so you are not having to keep that in the back of your mind as a developer, but instead the computer is doing that work for you.

0:15:02.0
Adam Garrett-Harris

Yeah, that’s a good way to think about it, it’s doing that work for you. Yeah. All right. So that pretty much covers immutability, I guess. What about purity?

0:15:10.4
Safia Abdalla

So I think it’s coupled this way in the book, and I think it also makes sense for me, personally at least, to think about them together. Purity and side effects is things that go hand in hand. So purity is the notion that your function only relies on data that it’s given. So it’s not accessing any like, global data or things like that. The parameters that you pass to your function are all the parameters it needs to do its work. And then side effects are functions. The fact that the function will only operate on the parameters that you give it, so it’s not going to mutate some global object or some other data element that you didn’t give it.

0:15:53.2

I try and do this in general, because I think it makes code a little bit easier to test, and this kind of relates to the discussion that we’ve had in the last episode, is that when you write code with the intention… When you write tests first or when you write code with the intention of testing it very well you end up writing functions that are purer and don’t have side effects because those are the functions that are easier to test. So that’s one of the reasons that I employ that technique. Not really relationed to functional programming at all, just related to how easy it is and how safe I feel using that function and testing it.

0:16:35.6
Adam Garrett-Harris

Yeah, definitely. I think if you followed test driven development you’re more likely to do this ‘cause it’s easier to test pure functions.

0:16:42.0
Jason Staten

Purity is one of the concepts that I wish that he would have put, actually even before immutability.

0:16:48.1
Safia Abdalla

Hmm.

0:16:49.0
Jason Staten

Because, I mean, like, immutability is important, but I think having a function that works more like the mathematical concept of a function where given an input, you always get the same output out of it, like that being a pure function, that’s what you get in math. Like, you don’t ever have to worry about some other thing changing your f(f) that you’ve written in math. And that was probably the most eye-opening concept for me when learning about functional languages long ago; that all of your state is just things that are passed in to your function. It’s very explicit and obvious where that’s coming from, versus even in an object-oriented language…

0:17:31.2

Like, I had the example once of a person object and maybe you had a method on that person of “Is old enough to drink” or something, and that function itself, or method on that person, would be entirely dependent on the person’s age which is probably not something you would pass into the method itself but instead you would read off of that object. And so the scope of code that you have to concern yourself with becomes a greater amount versus if everything is just within that single block, it can make it easier to test as well as read. And I know like, saying “code is easier to reason about”, that is a dangerous term to say, but in short, like, sometimes it can be because your context you have to be aware of is smaller.

0:18:19.4
Adam Garrett-Harris

So why do you say it’s a dangerous thing to say? I agree that it’s become kind of cliche.

0:18:24.2
Jason Staten

I guess maybe not “dangerous”, but cliche is also very opinionated, too. In terms of what’s easier to read…

0:18:31.5
Safia Abdalla

It’s subjective.

0:18:32.4
Jason Staten

Yeah, like functional programming can be written in super terse ways as well. Like, if you go and look up point-free programming, that is a realm of like, making super terse code that is all just data transforms. And in one person’s mind that can be super readable and they know that data’s just flowing through all the transforms, but somebody else would see it as totally unapproachable because they don’t even have a way to inspect in between what’s going on in the functions. So that’s more of what I mean about being dangerous. So maybe it’s just a subjective type of view.

0:19:09.3
Adam Garrett-Harris

Yeah, I guess it could really make people feel excluded if they look at it and it doesn’t seem easier to reason about to them, because they don’t have the same context and experience.

0:19:20.6
Jason Staten

Yeah, and that is something that I do try and keep in mind when working on a codebase, is some functional concepts are fun to bring in, but if it’s not really the norm for your language you may be excluding others in terms of like, making them want to work on that codebase. In JavaScript in particular there is a utility that’s similar to Lodash called Ramda, if you’ve heard of it.

0:19:46.5
Adam Garrett-Harris

Yeah.

0:19:47.1
Jason Staten

And Ramda is awesome because you can do all of these really cool functional things with it, like it’s got currying built in, which we’ll cover in a just a moment, and other niceties, but it also is a way to make a codebase that somebody who’s unfamiliar with it can take a while to actually go and grok. So you also have to consider, like, if you’re working in a nonfunctional language and you’re writing things in an attempt to be super functional then you may make your codebase unreadable by anyone but you.

0:20:19.8
Adam Garrett-Harris

Yeah, good point. Okay. Yeah, so what is currying?

0:20:23.5
Jason Staten

I went and did some googling, too because he talks about currying and then a little bit later into the chapter Rob actually mentions Partial application and I was not totally clear on the differences between the two of them and now I think I have an understanding.

0:20:39.3
Adam Garrett-Harris

Oh yeah, I see on the Wikipedia page that “currying is related to, but not the same as partial application.*

0:20:45.4
Jason Staten

Yes. They may bring up the same concept and it’s similar. So the shortest description I could think of is like, currying is a way of taking a function that may take three arguments and converting it to a function that takes one argument, and then returns a function that takes one argument, and returns a function that takes one argument until ultimately there are no more left; Whereas partial application is a way to take a function of n arity and make it a function with less than n arity. So like,it’s applying one function but it’s not necessarily returning back a function that only takes a single argument after that.

0:21:26.5
Adam Garrett-Harris

So arity is the number of…

0:21:30.2
Jason Staten

Arguments.

0:21:30.7
Adam Garrett-Harris

Arguments to a function.

0:21:31.9
Jason Staten

Yes.

0:21:32.5
Adam Garrett-Harris

Okay. So currying, it only does one at a time?

0:21:36.6
Jason Staten

So currying, it will take an n arity function and turn it into a function that takes 1 arity. It will take n levels deeps. So an n arity function into an a 1 arity function n levels deep.

0:21:52.1
Adam Garrett-Harris

Oh good. Good way to make it…

0:21:54.5
Jason Staten

And a partial application takes an n arity function and turns it into a less than n arity function. So it doesn’t necessarily return back a function that has just one.

0:22:06.5
Safia Abdalla

Oh wow.

0:22:07.4
Adam Garrett-Harris

I wish when I was applying for jobs I could turn in a partial application.

0:22:11.2
ALL

(laughing)

0:22:12.9
Safia Abdalla

That is such… I’m really glad you shared that, Jason, because I actually used the second technique, partial application, a lot in my code and I’ve always called it currying, ‘cause I thought that’s what it was. Now I realize, it’s not what it is. It’s… ah, thank you.

0:22:30.4
Jason Staten

So what happens in Elm or other ML-type languages is they curry the function for you, that’s what the compiler does for you, where you can go and say, “Add (A-B) equals” and then “A+B.” That, by the compiler, get curried into a bunch of single arity functions whereas partial application is you actually invoking those until you ultimately get the result. So…

0:22:56.2
Safia Abdalla

Yeah. Words are hard.

0:22:59.1
Jason Staten

Yeah! Especially when they’re so close.

0:23:02.7
Safia Abdalla

(laughs) Yeah.

0:23:03.7
Adam Garrett-Harris

So, in JavaScript, the examples he has in the book, they look kind of weird because you have to put ((( to invoke it that many times in a row, but I’m pretty sure in other languages where you don’t have to put parentheses around your arguments and they’re not comma separated they’re just separated by spaces it looks a little bit nicer and you can’t really tell the difference between passing in three arguments in the first invocation versus invoking it three times with one argument. Does that make sense?

0:23:38.1
Jason Staten

Yeah.

0:23:38.2
Adam Garrett-Harris

I- Is ELM that way? Where you don’t have parentheses?

0:23:40.8
Safia Abdalla

You don’t have to, there are cases when I have done it, but I think that’s because the type of data that I was passing made it so that you needed to separate it, but usually there’s no parentheses or anything, it’s just like a space or you can use the pipe command, like the ones we saw earlier in the Elixir examples he had.

0:24:03.8
Adam Garrett-Harris

Okay.

0:24:04.4
Jason Staten

I think that’s another case where if the language has it built in, like currying built in, then it makes it intuitive, but in JavaScript knowing that you’re supposed to call this select query function four times is not the most intuitive.

0:24:20.2
Adam Garrett-Harris

Yeah.

0:24:21.0
Safia Abdalla

Yeah.

0:24:21.1
Adam Garrett-Harris

It almost seems like a code smell in JavaScript.

0:24:24.0
Jason Staten

Mm-hmm (affirmative).

0:24:24.0
Adam Garrett-Harris

To have to invoke a function that many times.

0:24:27.1
Safia Abdalla

Yeah.

0:24:27.7
Jason Staten

I know that he was, like, trying to prove the point though in a familiar language though.

0:24:32.4
Safia Abdalla

Mm-hmm (affirmative).

0:24:33.1
Adam Garrett-Harris

Yeah.

0:24:33.4
Jason Staten

It shows what it’s doing, but writing code like this is a way to scare people away from your codebase.

0:24:39.3
ALL

(laughing)

0:24:41.3
Adam Garrett-Harris

So if you want to scare people away, use functional programming in a language that’s not purely a functional programming language.

0:24:47.4
Jason Staten

Yeah.

0:24:47.8
Adam Garrett-Harris

Or I guess, maybe even in a functional programming language, too.

0:24:50.5
Safia Abdalla

I was gonna make a joke and say if you want to scare people away use function programming.

0:24:55.5
Jason Staten

(laughs)

0:24:56.2
Safia Abdalla

(laughs)

0:24:56.8
Adam Garrett-Harris

Yeah, yeah.

0:24:58.0
Safia Abdalla

(laughs)

0:24:59.4
Adam Garrett-Harris

So the book mentions this line from Douglas Crockford about monads where if once you understand them you lose the ability to explain it anybody, which I guess you don’t really lose the ability if you just now understood it for the first time… But anyway, I hear that all the time, do either of y’all have the ability to explain monads?

0:25:20.2
Safia Abdalla

Absolutely not.

0:25:21.4
Adam Garrett-Harris

(laughs)

0:25:21.4
Jason Staten

(laughs) So, I mean, I uh… A monad is a monoid in the category of endofunctors, right?

0:25:29.0
Safia Abdalla

(laughs)

0:25:29.6
Adam Garrett-Harris

(laughs) Yeah.

0:25:31.8
Jason Staten

Which there is a-

0:25:32.2
Safia Abdalla

Oh! I totally get it now!

0:25:34.0
Jason Staten

Yep.

0:25:34.3
Safia Abdalla

Thanks!

0:25:35.2
Adam Garrett-Harris

(laughs)

0:25:36.0
Jason Staten

You’re not up to date on your category theory?

0:25:39.1
Safia Abdalla

(laughs)

0:25:40.2
Jason Staten

So there is a guy that does a course on Haskell and category theory called “Bartese … “ Something or other. I need to go and look up the link on it, but he actually does an explanation on Quora, like, of what that actually means, because somebody on Quora was like, “Is this actually true?” And he gives the drawn out definition as to like, why that actually is. Like, what the category of an endofunctor is, and I will not try and explain what a monad is within the podcast because it’s definitely going to be wrong, and so I won’t go there. But I do have some feedback on some of the stuff Rob wrote, actually. With regards to: first, the select query he refers to it as… So select query, I think it’s initially written, in the hard copy of the book on 305, and he calls the function curried, but if you notice the second function deep within it-

0:26:41.0
Safia Abdalla

Hmm!

0:26:41.8
Jason Staten

It actually takes in two arguments.

0:26:43.6
Adam Garrett-Harris

True! Yeah.

0:26:43.8
Jason Staten

And so that is not curried, and so… I was like, “Wait a second…” And I only figured that out after reading like the currying versus partial application thing and I was like, “No, it’s gotta be one! Otherwise it’s not currying.” So…

0:26:57.2
Adam Garrett-Harris

Mm-hmm (affirmative).

0:26:58.0
Jason Staten

I’ll have to submit that in an errata and see.

0:27:01.1
Adam Garrett-Harris

Yeah, I also feel like there’s an errata on page 304 with the dancing with wife function, or the one where he’s currying the date night function and I think at one point the arguments get passed in in the wrong order.

0:27:17.5
Safia Abdalla

Hmm.

0:27:18.0
Adam Garrett-Harris

It’s supposed to be Who, What, Where but then he passes in Dancing, Wife, Club.

0:27:26.1
Safia Abdalla

Yeah.

0:27:27.2
Adam Garrett-Harris

So the output, actually would have said, “Out with dancing, having fun wife at club 9.”

0:27:32.6
Jason Staten

(laughs)

0:27:34.0
Adam Garrett-Harris

(laughs)

0:27:34.6
Safia Abdalla

(laughs)

0:27:36.1
Jason Staten

Nice.

0:27:37.7
Adam Garrett-Harris

It’s like a MadLib!

0:27:38.6
Jason Staten

Yeah! Yeah, just put noun here.

0:27:42.9
Adam Garrett-Harris

So anyway, what else about the select query example?

0:27:45.5
Jason Staten

So this is not specific to the select query, I did actually go and rewrite his Monad version of it because I didn’t like it and he asked for a new version. So I write a gist of it. And mostly I didn’t like that he went and wrapped his concatenation of strings within the maybe when it really wasn’t necessary. Even he brings that up, that it’s not necessary here. He’s like, “I could just use a template string, but I’m gonna go and this inside a whole bunch of maybes.” And I think that that is not right.

0:28:18.8
Adam Garrett-Harris

Hmm.

0:28:19.4
Jason Staten

That is a case of like, usening a construct that you don’t really need. And so like, that’s the way that you can go and make codebases unapproachable.

0:28:29.6
Safia Abdalla

Hmm.

0:28:30.4
Jason Staten

So, don’t just go and use it because it looks fun to use. I also don’t like his maybe implementation because value winds up just being like a ternary that produces an empty string out of it.

0:28:41.7
Adam Garrett-Harris

Yeah, I was wondering about that.

0:28:43.4
Jason Staten

Yeah, and so I will have to like, send you my gist so you can take a look at that. Not that it’s necessarily a whole lot better, but it doesn’t do that. It actually gets mad at you if you try and extract a value out of a nothing type maybe. So…

0:28:59.6
Adam Garrett-Harris

Okay.

0:29:00.8
Jason Staten

Yeah, I guess I went and split it up into two classes. One class is called a Just and the other one’s called a Nothing, resembling that of Haskell that has those two that represent a maybe. You can either be a Just with some value in it, or you can be a Nothing that has no value. And if you were to try to extract a value out of nothing, actually Haskell’s type system wouldn’t even let you do that, but my JavaScript form of it is like, if you’re trying to pull a value out of that then you get an exception thrown at you because you shouldn’t be trying to do that.

0:29:33.2