AJ_O’NEAL: Yo, yo, yo, coming at you live from the, is my audio in sync?
CHARLES MAX_WOOD: It looks like it.
DAN_SHAPPIR: Yes, it is.
STEVE_EDWARDS: That's a new place. I haven't heard of that place before.
AJ_O’NEAL: Yeah. Well, I was on the boot.dev podcast and when it got released on YouTube, I'm like half a second off.
CHARLES MAX_WOOD: Ooh, yes.
AJ_O’NEAL: It looks terrible. And I was trying to figure it out. And as far as I could tell my audio is in sync on this end.
STEVE_EDWARDS: And I can see lag too now that you say it.
DAN_SHAPPIR: Yeah, there's, there is a slight lag.
AJ_O’NEAL: It really, if you're looking for it, you can see it. Well, that's what we need to know because I can fix that extremely easily. I can fix that with. Okay. Is the lag better or worse?
DAN_SHAPPIR: Not the same.
AJ_O’NEAL: Okay. How about now? Is it?
CHARLES MAX_WOOD: Double shooting live on the show.
STEVE_EDWARDS: I know that. That's what I was about to say too.
DAN_SHAPPIR: It looks better now. I think.
AJ_O’NEAL: Yeah. Okay. Deal. All right. A hundred millisecond delay.
STEVE_EDWARDS: This is how the sausage is made.
AJ_O’NEAL: Yes. This is how the sausage is made. Come in at your live from how the sausage is made.
DAN_SHAPPIR: I think there is still an, I would add another a hundred milliseconds.
AJ_O’NEAL: All right. Thanks.
CHARLES MAX_WOOD: All right. We also have Dan Shapiro.
DAN_SHAPPIR: Hey from an Israel still at war.
CHARLES MAX_WOOD: Steve Edwards.
STEVE_EDWARDS: Yo from I'm only one. Yo, yo, yo, yo, from a very foggy Portland area where we need more snow.
CHARLES MAX_WOOD: Yeah. I'm Charles Maxwood from top end devs and, uh, I'm going to tell y'all to go over to top end devs.com slash calendar. We have a whole bunch of stuff coming up. And I'm super excited to be working with folks to help them get ahead and figure things out. So,
Hey folks, this is Charles Maxwell. I've been talking to a bunch of people that want to update their resume and find a better job. And I figure, well, why not just share my resume? So if you go to topendevs.com slash resume, enter your name and email address, then you'll get a copy of the resume that I use, that I've used through freelancing, through most of my career as I've kind of refined it and tweaked it to get me the jobs that I want. Like I said, topendevs.com slash resume will get you that. And you can just kind of use the formatting. It comes in Word and pages, formats, and you can just fill it in from there.
STEVE_EDWARDS: And the makers of Svelte would agree with that.
CHARLES MAX_WOOD: Just keep in mind that most of our Uh, yeah, this audio only, so we need to make it friendly to that.
DAN_SHAPPIR: Yeah, obviously. Uh, here we go. Can you see it now?
CHARLES MAX_WOOD: Nope, I gotta add it to the... Oh, there we go. Good deal.
DAN_SHAPPIR: Okay, the only problem is that the now I don't see you guys, but you know, be that as it may. It could be a good thing. Yeah. So again, the numbers are 55% almost use TypeScript without any, 20% use TypeScript with any, another 14% use JS doc and then.
CHARLES MAX_WOOD: Um, I think I voted in this one and I think I was the last. Cause I've just, I've been too lazy to really deeply go for any of it.
CHARLES MAX_WOOD: I always do the dummy thing.
AJ_O’NEAL: As a float, but you, you realize, oh, that should be a string instead. Cause it's money and money and floats don't mix. Right. And you know, so you change it to a string. It gives you that capability. To get errors where you forgot something. And I think that's really where the core value of it is.
AJ_O’NEAL: Oh, sure, sure. Pardon my French. Yeah.
DAN_SHAPPIR: Again, I'll slightly rephrase. If you are consistent in terms of the type information, you are making it much easier for the JIT to optimize it. It still may not optimize it. For example, if it's only run once, then it might decide that it's just not worth the effort. But yeah, by doing things poorly in terms of type consistency, you're effectively preventing from optimizing it even if it wants to. The other point that I wanted to make is that I don't know what surprised me more. Was it the fact that 88% effectively used TypeScript or that 12% don't?
AJ_O’NEAL: Well, we had a comment, somebody said that 50% is lying and I'm going to agree with them.
CHARLES MAX_WOOD: Well, just to back up, you know, you said that typescript with any is, or without any is, you're making an effort to minimize any, but I don't know if I get that from this question.
AJ_O’NEAL: Well, I think, I think this is where languages need to go. And this is one of the things that Zig has maybe not pioneered, but advertises. There's no reason that your tooling shouldn't be able to look at your code and effectively run whatever is runnable at dev time. Like it shouldn't have to wait until it's machine code to be able to understand, oh, this string, it's obviously the word div, you know? So I'm not as impressed by that as I am disappointed that it's taken this long and has so few implementations.
DAN_SHAPPIR: There's a whole other topic which I think is beyond the scope today, which is about the fact that TypeScript really has effectively like two levels. There's the level of usage by most application developers. And then there's the level used by library creators, which is much more difficult and is much, makes much more use of things like generics and stuff like that in order to make the interfaces as type-safe as possible. And sometimes that does require a lot of know-how and effort, but again, I think that kind of goes beyond the scope of, of, you know, how much we want to talk about that particular question. Otherwise, you'll never get to any of the others. Yeah.
AJ_O’NEAL: But to that, to that end, did you hear about a floppy bird being implemented in TypeScript?
DAN_SHAPPIR: Well, yes, I did and it's not surprising because in order to do you know once you introduce generics into the type system. You've effectively made your type system a programming language
AJ_O’NEAL: Yeah, and by typescript I meant not typescript but type the types of type.
STEVE_EDWARDS: So, coming from the PHP world where they're required is just sort of habit anymore. For me, it just makes neater and easier to read code. You know, that's, and there's times where code won't have a semicolon, but that's pretty rare for me.
CHARLES MAX_WOOD: I like magic in my code, but not this kind of magic.
AJ_O’NEAL: That's one of the things that's nice about Prettier is when you accidentally forget a semi-colon or whatever Prettier reformats your code in such a way that it is clearly obvious that the structure of the code and the way it's executing has changed. Um, but I will also say one of the reasons that I'm against not using semi-colons is that they are required because there's a list of edge cases that you have to be aware of. And you can either choose to just always put a semi-colon or you can carry around in your head that list of like five or seven checks and then always be thinking about like every single time you don't insert a semi-colon. Is it breaking any of these five or seven rules? And if you are willing to do that mental gymnastics, then you don't need semi colons. Um, however, I've found a very, very simple list of rules that I believe also would eliminate the need for semi colons, which is if you either always capture the results of a function or use the keyword void to explicitly disregard what the return of the
AJ_O’NEAL: And if you never do something that requires parentheses, uh, in the order of operations fashion, you know, like if you never, if you always split multiplication and addition onto two lines or, or, you know, something like that, anything that would require parentheses to be able to
DAN_SHAPPIR: Yeah, and be careful of the return keyword and other various rules, just easier to use semicolons. Oh, yeah.
DAN_SHAPPIR: Yeah, it would be called Python.
AJ_O’NEAL: I was I was actually gonna call it AI script but
CHARLES MAX_WOOD: There we go.
CHARLES MAX_WOOD: Wow. That's very mature of you.
DAN_SHAPPIR: I know
CHARLES MAX_WOOD: Dan.
DAN_SHAPPIR: I know.
CHARLES MAX_WOOD: I have to say that readability-wise, I prefer the bottom one, but I am freaking lazy and so I very often do the top one.
AJ_O’NEAL: Why is it just make F in a macro? Like if you want to be lazy, be really lazy. Like use the tools. That's why you're typing out the whole word const when you could just type F in and tab. Hmm.
CHARLES MAX_WOOD: Um, I feel bad.
DAN_SHAPPIR: To be honest, I really don't know why people preferred the assignment of the arrow. Um, you know, maybe it's look, it is the one benefit which or there are a few benefits. First of all, it does explicitly make the, the identifier immutable, which is probably what you want in a function in like 99.9% of the time. Another advantage is that you don't, that this is not bound, which is again, is what you generally want these days. And another advantage is that it you don't there's the arguments object doesn't exist and the argument object is something that you probably don't want to use anyway these days. Other than that. It's I don't see it like it's it seems less readable to me like being saying something is a function is a much more explicit way of saying something is a function and I like my goal to be explicit. Uh, the other thing is hoisting. I like hoisting, uh, with, with the assignment it's. You know, it's not hoisted and you can get into trouble in unexpected scenarios. Um,
AJ_O’NEAL: what do you think about exports dot foo equals or exports being a stand in for the larger object people dot get name equals, et cetera.
DAN_SHAPPIR: I'm not sure I follow.
AJ_O’NEAL: Well, most of the time you have a function, it's on an object, right? So you just.
DAN_SHAPPIR: No, not necessarily. A lot of my code just has a lot of exported functions. Not necessarily a lot, but, uh, you know, one or more exported functions from a file, from a module.
AJ_O’NEAL: Right. So what I'm saying is you just assign the function to the object that gets exported.
DAN_SHAPPIR: No, I use the export keyword.
AJ_O’NEAL: You can't be saved.
STEVE_EDWARDS: So you can be structured then? So you can be structured or?
DAN_SHAPPIR: No, he's just using a common JS. That's, that's the thing. It took me a moment to realize what he meant.
AJ_O’NEAL: But even if it's not common JS, I mean, just having, you know, whatever object you're exporting be the thing that you attach the functions to.
AJ_O’NEAL: Well, because then you have a lot. It's just a lot more to parse. It's a lot like if you try to grip through the code, it's a lot easier to see the get name function attached to person than it is to see a bunch of get name functions across the code base. Read through the different, you know, like there's a get name in person. There's a get name and dog. There's a get name. I
DAN_SHAPPIR: get what you're saying. Yeah, I get what you're saying. The way that I deal with it is, first of all. That's the kind of the, first of all, the reason that I like hoisting is that I put the exported stuff at the top. Uh, so it's not as if you're likely to, you'll see something exported and then a lot of unexported stuff and then another exported something, you know, as soon. So that's one thing.
DAN_SHAPPIR: and um so so that's that's one. Another thing is that I tend to keep my modules small. So it's not as if I'm going to be exporting a hundred things out of the same file. Again, unless it's like this special, like, uh, you know, some people like coalesce a lot of the exports like into the, like, uh, sort of an index file at the root of a library or something, so to make it easier to import things, but for most actual implementations, I don't export a ton of stuff. So again, you don't need to scan a large amount of code just to find all the exports. But I do get what you're saying, AJ. There is merit in that. You know, if you're exporting something that feels like an interface, it makes sense to like put it all within an object or something.
AJ_O’NEAL: So I mean, just so you can see what's public at a glance and when you grep through the code, you can easily find like, show me everything, show me all the methods that are exported from person at a glance. I can just grep person dot, right?
DAN_SHAPPIR: And you also can get potentially easier completion.
AJ_O’NEAL: I don't use completion, but maybe. So it takes too long to pop up on the screen. I can finish typing it by the time that
CHARLES MAX_WOOD: we did have a comment here. And I think it's an interesting, uh, kind of, I know you're talking about named functions here, but, uh, and I'm sorry if I butcher your name. But Bellagio, Bellagio, anyway, he says good old function every day, all day. The only time I use the arrow function are in callback. So I guess the question that I'm aiming at here is, do you ever use arrow functions for anonymous functions?
DAN_SHAPPIR: Oh yeah, for sure. For sure. The name describes their use. Their function expressions. So whenever I need a function, a lambda effectively, within an expression, I use arrows. Okay. So you know, I'm a big fan, for example, of chaining. You know, using stuff like map or filter, stuff like that. And in those, unless it's some sort of a reusable code, a really complex, let's say filter that I, you probably don't want overly complicated filters and functions anyway, but otherwise, I definitely use function expressions there or lambdas and then I definitely use arrows. I never, you can use the function keyword for lambdas. That's the old school way of implementing them.
CHARLES MAX_WOOD: Yeah, you just don't give it a name.
DAN_SHAPPIR: Exactly, I don't do that.
Time is of the essence when it comes to identifying and resolving issues in your software, and our friends at RayGun are here to help. With RayGun alerting, get customized error, crash, and performance alert notifications sent directly to your preferred channel with integrations, including Microsoft Teams and Slack. Set thresholds on your alert based on an increase in error count, a spike in load time, or new issues introduced in the latest deployment, along with custom filters that give you even greater control. Assign multiple users to notify the right team members with alerts linked directly to the issue in Raygun, taking you to the root cause faster. Never miss a runaway error. Make sure you're quickly notified of the errors, crashes, and front-end performance issues that matter the most to you and your team. Try Raygun alerting today and create a world-class issue resolution workflow that gives you and your customers peace of mind. Visit raygun.com to learn more and start your 14-day free trial today. That's raygun.com.
AJ_O’NEAL: Okay. The problem with that, with the Lambda expression style, is that the opening and closing curly braces become ambiguous. And so it's very difficult to tell whether you're returning an object or whether you're defining a block. That's my beef there. I've had bugs pop up with that multiple times.
DAN_SHAPPIR: Yeah, it's always a block. And if you really want it to be an object, you need to
AJ_O’NEAL: Yeah, anyway. Yeah. Yeah. So I'm hard against the implicit parentheses.
DAN_SHAPPIR: Yeah. But again, this has to do with the whole expression thing that it's, you know, but yeah, I can see your point. You know, nothing's perfect. Moving on to the next one. I was just I was just curious how people use, you know, how people write strings these days. Do they use single quotes, double quotes, backticks? What do they use for simple strings? And not surprisingly, the majority prefer single quotes. It's not surprising to me because why press the shift key when you don't have to?
CHARLES MAX_WOOD: I looked at that one and I was trying to decide why anybody cared.
DAN_SHAPPIR: Oh, I was just curious.
CHARLES MAX_WOOD: Yeah.
AJ_O’NEAL: So I write the single quotes But I commit the double quotes because every time I write single quotes it just gets Transpiled to double quotes with prettier the reason for that is that in every other programming language, single quotes are constants, and double quotes are expressions. So I tend to only use single quotes intentionally when it's something that is a constant value. And I use double quotes in general because usually you're doing expressions. You're not doing constants.
DAN_SHAPPIR: Yeah. Well. I'm not sure what you mean by expression versus constant really.
AJ_O’NEAL: Yeah. Nevermind. Yeah.
CHARLES MAX_WOOD: I can't say the differences is that you can interpolate within double quotes and you can't within single quotes. Right. Yeah.
DAN_SHAPPIR: So in Ruby double quotes are the bit like the back ticks, aren't they kind of like
CHARLES MAX_WOOD: kind of, but yeah, but, but. But the thing is, is that people try to make all kinds of arguments about like performance and stuff like that. And I just haven't seen anything there that holds water. So that's why I'm saying, you know, if people look at it and they know it's a string, then why, why do you kill?
CHARLES MAX_WOOD: Uh-huh.
DAN_SHAPPIR: And in those languages, double quotes are zero terminated or null terminated and single quotes are not. And usually you want the string to be null terminated. Usually in C. Yeah. So yeah. Now the only-
AJ_O’NEAL: If you want security vulnerabilities, you definitely want the null terminated.
DAN_SHAPPIR: Exactly. Now the only comment, I'm not really surprised that hardly anybody chose the backticks. The only thing that's kind of surprising- surprising about that is that we will see later on people do like backticks for template expressions.
DAN_SHAPPIR: And it's kind of funny that you if a string becomes template in a template expression, which it might, you need to change the quotes syntax. And then if it stops being a template expression for some reason, you need to change the quotes again rather than just leave them as they are which works. So you could just use backticks everywhere, but apparently people don't like that.
AJ_O’NEAL: You can't actually.
DAN_SHAPPIR: So why not?
AJ_O’NEAL: I was actually on full backtick everywhere train for a while. You cannot use backticks for a key name. So if you were to do an object and you put double quotes around, you know, name and then colon double quotes AJ. You cannot do backtick name, colon backtick AJ. You can't, you can't do that. And I think this just goes to, I, this is very confusing to me because we have a template syntax for keys and an object, which is to put square brackets around it. And to me, it seems, I guess they were standardized at different times. I like why this is seems redundant and silly, we should just be able to use the backticks as the template expression. But instead, if it's an object key, the template expression is you put brackets around the variable name.
DAN_SHAPPIR: Another interesting thing is that JSON uses double quotes.
STEVE_EDWARDS: Yes, that's thrown me off before more times and I can't remember.
CHARLES MAX_WOOD: Yeah, I think everybody's put gun that.
AJ_O’NEAL: NPM install fix JSON and it'll usually get picked up by your editor automatically. And then when you're editing JSON and you put a single quote by mistake, it'll just swap it to double quotes. It'll also deal with the trailing commas and stuff like that.
AJ_O’NEAL: Yeah, that's the other annoying thing.
STEVE_EDWARDS: So my rule, Dan is I'll generally default to single quotes everywhere. Double quotes. If I have to quote something inside a single quote, like say, uh, an attribute inside of a template, uh, like an abuse single file component in the template portion. And then the only time I ever find myself using backticks is when I need to do a template string. And the example that I've been using a lot lately is if I'm defining a poster, a get URL within my view component, and it requires a dynamic value like an ID value, as part of the string or something dynamic, and I'll use the backticks with the dollar sign curly brackets around it. But general rule is single unless I have to otherwise.
DAN_SHAPPIR: So the vast majority agree with you. Steve and that also exactly goes to the next question on my list, which was about building a string from a static value and the dynamic value. So would you write greet equals hello plus name or greet equals backtick hello dollar curly bracket name curly bracket. And it's amazing to see how popular template strings have become. You know, people have told me that it's not really surprising because most default ESLint rules or linting rules now we kind of enforce this approach. So people really got used to it. But still, it's interesting that so many people just prefer to use template, the template literals.
STEVE_EDWARDS: Well, it makes sense. It makes sense because basically you're not switching in and out of your context. You don't have to do like hello plus space plus string variable plus comment and quotes, but you know, in this you can just do it all in one fell swoop without having to switch context like that.
CHARLES MAX_WOOD: Well, and in my opinion, it's easier to parse because the plus with the quotes, it blends into one line more easily, the dollar bracket stands out more. And so you know where you're sticking dynamic values into that sucker.
STEVE_EDWARDS: Yeah, and in my at least in my DEF. ID and I'm assuming I use PHP storm. I'm assuming it does the most it will highlight those colors Yeah, it's all highlights your template strings and they stand out more easily
CHARLES MAX_WOOD: Yeah, so I know exactly what I did and and that's always my issue is how can I make it easier for future me or some? Other idiot, but it's usually future me. That's the idiot Right to look at this and go. Oh, I can easily see what's going on here
DAN_SHAPPIR: Um, yeah, and the vast majority agree with you. Like 88.4%. Yes, AJ.
AJ_O’NEAL: Yeah, this gives you that this so that's
DAN_SHAPPIR: Yeah, effectively it does. Yeah Okay, moving on to the next one where now we're entering a new topic which is array processing. So I asked a bunch of questions about the ways in which people work with arrays. And the first question is kind of like the most basic one, and which is, how would you iterate over an array in the scenario where you're kind of in the side effect scenario? So forget, for example, about something like a map or a filter. Let's say I want to log all the values of an array, or I want to send over the network all the values of an array or I want to add to the DOM all the values of an array or something like that. How would you iterate over the array? The first option is the old school one which is you know i equals zero, i less than a dot length, i plus plus. The next one is the more modern use of for of. You know it might be for const v of a. And the last one is the dot for each.
STEVE_EDWARDS: And it depends what you want to do. Oh, by the way is an area like an array this kid You and So yeah, it's interesting I I generally like to use for each I guess the caveat here Dan is what you're trying to do as compared to something like a Map or filter right you just want to do something to whatever item is you don't necessarily want to filter out certain items or only extract certain items
DAN_SHAPPIR: Yeah, as I said before, I like chaining. So when I can't chain stuff, I usually go for chaining. But I explicitly wanted to look at the scenario where you're just looping over an array and just doing something with the values. Like I said, maybe sending them over the network or adding them to the DOM or something like that.
STEVE_EDWARDS: I've seen arguments that for each is performance inhibitive. That's the best way to say it. But it's funny, some of those arguments I see, they say, well, that's better on performance here and here, but the difference is like microscopic.
DAN_SHAPPIR: First of all, first of all, the first of all, let's say this, I'll be surprised or shocked if that's the actual performance issue in your code.
STEVE_EDWARDS: Right. Exactly.
CHARLES MAX_WOOD: Yeah, I just want to chime in here because this was the debate in the Ruby community between the single quotes and the double quotes is somebody did the profiling and it was like a 20 pico second difference, right? So they were saying, see, it's more performant. And I was just like, so what you're telling me is I could just keep being lazy and I'm going to add 20 pico seconds here or there to my code. Okay, great. I'm just going to keep using double quotes.
DAN_SHAPPIR: Um, so what, what you guys prefer, which, which approach do you, would you take?
CHARLES MAX_WOOD: I use for each whenever I can.
AJ_O’NEAL: I, I got on the for each bus early. Uh, but then when promises were introduced, I'm not when async away, it was introduced eventually. I had to get off the four each async or the for each bus because then you, you, you end up with this. What color is your for loop? And I just don't want to deal with it. So I I've stopped using for each map filter, all of it, just like I've thrown it all away because it's just not worth the overhead of having to go back and refactor code for something that is,
CHARLES MAX_WOOD: I mean, it's one line anyway.
DAN_SHAPPIR: Just saying that once a sync iterator helpers hit the language whenever they finally do, you... Sorry, you let the leg get in there. And now you need to stop.
STEVE_EDWARDS: Well, it had it on looping.
DAN_SHAPPIR: Yeah, and looping is the topic. All I was saying is that if and when...
AJ_O’NEAL: Perfectly timed. That was the best one of the whole...10 year run.
CHARLES MAX_WOOD: yeah, you can start doing it right again.
DAN_SHAPPIR: Oh no, WinterCG is trying to actually...Oh, that's not exactly the case. You know, it's an aside. Winter CG is about the library code. So it's about the fetch and stuff like that. Not things that are actually part of the language. So part of the language itself is still owned by TC39 and will continue to be there. Uh, but, but we kind of deviated. I have to say that I was kind of surprised that more people preferred, uh, four of over four each. Uh, it was pretty close. It's 42% versus 40.5%. So it's kind of neck and neck. Uh, and, but you know, it still surprised me. Uh, I was expecting far fewer people to actually use for all of, I'm guessing AJ that it's probably because of the reason that you mentioned, you know, people really like a sink away. And it's much easier to use them with, uh, uh, for all of rather than for each. And I am happy that people are ditching 4i, although 18% using it is still a lot, simply because it's too much, it's TMI. Why are you in the nitty gritty of the index and whatnot?
CHARLES MAX_WOOD: Because that's what they teach you in your computer science class.
AJ_O’NEAL: But this is again, this goes back to a lack of foresight in these committees, right? Most languages that have an iterator construct, it would be 4k, comma, v of a.
DAN_SHAPPIR: You can actually do that here. You can actually kind of do that. You can do const v, let's say v i of entries. So you can have both the key and the value.
AJ_O’NEAL: Wait. Okay. So you, this can be-
DAN_SHAPPIR: You do four. You do a const open square brackets, key, comma, value of a dot entries.
AJ_O’NEAL: I'm going to have to try that because yeah, the reason that I do revert back to the i plus equals one loop is because there are occasions where I need access to the index for some reason. Sometimes it's modifying the original array. Sometimes it's so.
DAN_SHAPPIR: So instead of keys, you use the you use entries that returns. a sequence of arrays of like, well, tuples where you've got like, uh, first is the key and then the value. Uh, and then you destructure them into a key and into a key and a value. Okay.
AJ_O’NEAL: Uh, I, I might play with it, but I, I just have a sense that something will go wrong there.
DAN_SHAPPIR: is not that well let's put it this way all three actually do a different thing so they they're used for the sims for the same purpose or the very similar purpose but each one really does a different thing uh 4i literally you know goes over all the values from zero to. So it's syntactic sugar for iterator, which is why A doesn't need to be an array. It can be anything which exposes an iterator. It could be a map or a set or whatnot.
AJ_O’NEAL: Oh, OK. Yeah, because it's not intuitive when it works and when it doesn't. I always convert things to arrays before using it, because I thought it worked in a case where the thing was an object, but then it never worked again.
DAN_SHAPPIR: It works in a case where A is an object, assuming A is an object that has an iterator.
DAN_SHAPPIR: And for each depends on what the implementation of for each is on that object. You can, you know,
DAN_SHAPPIR: Yeah. I, again, as I'm saying, you know, I was saying they effectively do the same thing in most cases, it's just important to understand that the implementation is different.
AJ_O’NEAL: Well, to the point of it, iterators, they feel like I guess meta programming. It's, it's like a layer.
AJ_O’NEAL: Sure. But you don't. Okay. So let's promises you, if you're using async and await without knowing the, how promises work, you, you're probably creating bugs in your code or, or otherwise doing it wrong, the iterator stuff, thankfully. You don't have to have ever used an iterator explicitly to use the spread operator.
DAN_SHAPPIR: I totally agree. And that's a good thing because iterators, iterators were meant to be used explicitly by library creators. Library. It's like, you know, it's like as a library user, you just get a nicer interface to the code and you don't need to think about how it actually works on the inside. Yeah anyway, moving on to the next one, which is kind of related, it's about how do you concatenate two arrays? The two options are, again, either go old school and use the concat method.
DAN_SHAPPIR: Yeah. Scroll so we can see it? Here. Here it is. Muchas gracias. So you can either do like A equals B concat C, or you can do the new spread thing, which is A equals open square brackets three dots B, three dots C, close square brackets. So again, the code is not the same and there are various edge cases in which the code can behave really differently. For example, what happens if C is not an array, but You know, in most cases when a, B and C are all of them, when B and C are arrays, the results are the same. Um, so, um, it's, it's interesting to see, you know, what people use. And it's interesting to see that most people, 80% almost 80% of the people these days now prefer the spread operators inside square brackets.
CHARLES MAX_WOOD: The deep sigh. I love it I heard somebody give a deep sigh.
DAN_SHAPPIR: Yeah. Why am I not surprised? Why are you, why, why are you sighing AJ?
AJ_O’NEAL: a couple things again committees in every other language if you're doing a spread the spread is on the right side not the left side that is a collect the dots on the left side are a collector the dots on the right side are a spreader okay syntax aside it just is so much more complicated like i don't get the preference
for people to use symbols over words when the words are more clear to the most casual of observer, right? You do open bracket, close bracket, dot concat, b, comma, c, which is an option you didn't list there, but that's the way I actually do it. Just because-
DAN_SHAPPIR: What was your option again, sorry?
AJ_O’NEAL: Just a new array, dot concat, and then b, and then c. Okay. But it's just so much more explicit, it's easier to read. And, and just, I just see so much code that's like arrow symbol brackets dots. And it just, it's really difficult because people, people line noise.
DAN_SHAPPIR: It's line noise. That's what you're saying.
DAN_SHAPPIR: It's it's worth, by the way, I had an interesting conversation about this with Evita we've had from Meta we've had on the show, he spoke about the vest testing library, uh, and he actually prefers concat. And there are two reasons that he gave. One is that concat works well with chaining, which he likes. Now, of course you can add stuff after the closing square brackets. You can change stuff there, but then the chaining looks less natural because you got some of the chain inside the brackets and then some of the chain after the brackets. And the other reason that he liked it, which I'm more ambivalent about, and I told him so is that concat works when c is a value rather than a collection
AJ_O’NEAL: that's bad that's not good
DAN_SHAPPIR: that's what i think but he likes it
AJ_O’NEAL: Yeah. I have gotten a little bit scared sometimes because of concat. Um, yeah, not, not knowing how it will interpret something. Cause I want an air in that case, right? Like I want to be like, Oh, you, you F'd up. You, you put the wrong variable in here.
CHARLES MAX_WOOD: By the way, once we get through a raise, we should probably call it an episode.
DAN_SHAPPIR: Yeah, for sure. Uh, So let's speed things up. We've got two more things about arrays, which is great. We've got things for next time, and I'll probably have... By the way, if either you or the listeners have ideas about additional such polls that I should run, I'd be more than happy to if you just send me a link, either DM me or send me. By the way, to all our listeners, if you're not following us on Twitter, why? You know, I'm Dan Shapiro Twitter is thinking exactly I'm just Dan Shapiro on Twitter You know follow me. I'll probably follow you back and you know, we can all be friends. You like me here on the podcast you you you'd probably like me just as much on X. Anyway, moving to the next to the next one. It's how to get the last item of an array so again, we've got the old-school approach which is you know, just use the dot length minus one inside the square brackets. Uh, then we've got, I'll go to the other extreme. We've got the latest and greatest, which is the at method. Oh, and the at works exactly like an index only it also supports negative values. Uh, so I might see exactly, exactly like slice. So, you know, doing an at at minus one gives you the last value. By the way, I am slightly miffed that it's minus one rather than minus zero.
CHARLES MAX_WOOD: So zero base going one way and one base going the other, is that what you're saying?
AJ_O’NEAL: Yeah, this was one of the underscore versus low dash things. This low dash handles negative zero per spec.
DAN_SHAPPIR: So yeah, but anyway, it isn't. So the last item is minus one rather than minus zero. And the middle of the road is to use the dot slice, which supported minus one from way back when. Uh, and then you can destructure the result because the slice returns an array.
AJ_O’NEAL: So it was like zero. If, if you don't want your code to look weird.
DAN_SHAPPIR: Yeah. Um, and, um,
CHARLES MAX_WOOD: I always did. I liked slice.
DAN_SHAPPIR: Yeah. It's the only downside of course, is we were talking overhead and the Pico seconds, it actually allocates an array and copies into that area.
CHARLES MAX_WOOD: So there's a slight addition of my memory allocation.
DAN_SHAPPIR: Yeah, exactly.
STEVE_EDWARDS: It's gonna be a tiny bit bigger. You know, I've always used slice. I haven't used at, but just looking at the code, to me, it makes more sense.
CHARLES MAX_WOOD: I like that. Yeah, I didn't know that.
STEVE_EDWARDS: Constantly looking at the difference between slice and splice and...
DAN_SHAPPIR: Yeah, and at is pretty much universally supported these days. It's obviously in Node, the latest version of Node, and I think all the browsers now support it. So it just works. Even if you don't use some transpilations, the step or not, or whatnot. Um, but it's interesting to see that the majority of people, 55% still go old school.
AJ_O’NEAL: Well, they don't know about it. They're finding out about it today on this podcast.
CHARLES MAX_WOOD: Or when they say,
DAN_SHAPPIR: yeah, but I gave the option on the poll. They could have said, Hey, that's cool. I don't use it, but I'll start using it today.
AJ_O’NEAL: And they, yeah, but then they would have still answered the poll honestly.
DAN_SHAPPIR: Oh yeah. Okay. Maybe. Um, yeah, I'm, I'm, I'm with, with the at, um, but, uh, but yeah, uh, it's not complicated, it's easy to understand. The only potential downside that I see if it's not an actual area, but rather an area like objects, you know, those abominations, but other than that, you know, just use that.
AJ_O’NEAL: So weird thing at is not on. Can I use, are you sure you can't search for it? Probably because it's a two letter search term. I'm trying to see if I can get it. Not it is not there at is not on. Can I use so, but I have started using at for my node code. Cause now it's gotten mature enough in node that I feel comfortable using it. Uh, last time we had mentioned it on the show. It I don't think that it had been in an LTS release yet or something like that. But I believe that now it actually has been in an LTS release. So it's mature enough, but I'm not sure on the browser side of browsers actually support it yet or not.
DAN_SHAPPIR: Oh, browsers do. You know what?
AJ_O’NEAL: Oh, I found it. I found it on can I use it's just, it's, it's weird. Okay. Yeah. So basically. It doesn't work on any of the Asian browsers. So QQ, Baidu, KaiOS doesn't work on the Wii U or on feature phones on Android.
DAN_SHAPPIR: Yeah. But you'll probably use it when you build for those, you probably use a transpilation, then you're fine.
AJ_O’NEAL: Well, but if you don't want to use transpilation, if your target is people on feature phones, meaning non-paying customers or Asians then you don't want to use it unless you transpile.
DAN_SHAPPIR: OK, now moving on to the last question of the day, the last question in the array category. This one is slightly contrived, or more than slightly, but still it's interesting. Let's say you want an array where the values match the index values. So it would be an array with a value 0, 1, 2, 3, 4, all the way up to n or whatever. So there, how would you create this in your code? And it does come up, you know, I've run into the scenarios where you want it and it's kind of annoying that there's no easy way to get it. Although in the spec, they are working towards something and we can mention it at the end. But the options that I gave are using it's you know, I'll basically be reading out code. It's easy using using array dot from where you can provide it with two arguments. One is just an object with the length property that you, you know, whatever your end that you want to go up to. And the other is kind of a map function that you can provide as this as an optional second argument to the from, and you can use it to actually fill in the values into the array that you're generating. So that's option number one. Option number two is to create, you might call it, an empty array of length n by just using the array constructor with the value n. Then use the dot fill to actually fill it with something because it's so that it won't be empty. So you can fill it with zeros. And then you can use the map to actually put the indexes into the array. And then finally, there's the old-school approach of just using whatever loop construct you prefer with a push to push the values into what was initially an empty array. Um, so yeah. And interestingly, it kind of split almost, well, almost equally between all those, between these three options. Interestingly, array from is in the lead, which kind of surprised me. On the other hand, only this one was the one that got the least amount of votes. Only 71 people voted on this particular poll and it might be skewed by, you know, the people who tend to follow me. So that's definitely a possibility there. Um, I'm curious what you guys would have used in this scenario.
AJ_O’NEAL: Preferring readability. And being that looking at that screenshot is absolutely no clearer than listening on the podcast. I prefer the obvious. I create a function called range and then I do whatever I do in there and I can't remember what I do, but it is a pain in the butt. Yes, it's, it's weird, but I create a function called range so that it's clear what I'm doing.
DAN_SHAPPIR: How about you, Chuck? What would you use?
CHARLES MAX_WOOD: I do the loop and push. I didn't even know you could do the other stuff.
DAN_SHAPPIR: And Steve, how about you?
STEVE_EDWARDS: What Chuck said.
AJ_O’NEAL: Yeah, I'm definitely in support of that making it to the standard library. Hopefully it's done in a way that isn't incompatible with all the other types of loops we do already.
DAN_SHAPPIR: Let me let me slightly slightly annoy you it's iterator dot range. So it will be a method on the iterator object
AJ_O’NEAL: Well, they're gonna force people to Accept the one true iterator object, huh?
DAN_SHAPPIR: Yeah, but it does mean that it will work with for all So if you want to do a 4i over a range of values. You'd actually do a for all over a range. And the advantage of doing it over as an iterator is that it would never actually allocate the array. So you could do theoretically an infinite range and then break out of it when you don't need it anymore. You know, when you reach the point that you are done with it.
AJ_O’NEAL: I just I've got to ask the question though, because this is this is, you know, the thing that people say about iterators. Oh, it doesn't allocate the memory. In what real UK use case are you generating such a big number of things that...
DAN_SHAPPIR: No, actually that's not the right way to think about it. You either generate something that has a limited size, in which case you're absolutely correct, or you generate something that looks as if it's infinite size. And then you break out of it when you reach the point where you don't need to go any further.
AJ_O’NEAL: Okay, I'm not, I get the sense of what you're saying. I'm not sure where it's of, of practical.
DAN_SHAPPIR: Think about, think about, think about, for example, I've got the sequence of all the, all the odd numbers, and then I go as far as I need to go.
AJ_O’NEAL: I, again, it's, it's like one of those things that people say for mathematical purity, but okay, show me the use case, baby.
DAN_SHAPPIR: Anyway, this is it for today. We've got something like five more questions remaining that we can do in some follow-up episodes or not. Hopefully, I'll have more questions, more polls by then, but we're essentially out of time.
STEVE_EDWARDS: So Dan, did you calculate your margin of error for this polling?
DAN_SHAPPIR: No. You just know what your error bars are? No, I did not, but. I'll put it this way and that's another reason to follow me. I am betting that there's a certain skew in my answers given that, you know, thinking about the people who follow me, people like Dan Abramov and Rich Harris and Ryan Carniato and Adios Manny and Mishko Hevery just throwing out the names. You know, so if you want to be about amongst that refined crowd, you should follow me. And then you can, and then you'll see my polls when they come out and you can participate.
CHARLES MAX_WOOD: All right. Well, let's, let's get to some picks and yeah, by all means, if you have a question you think Dan should ask, throw that at him too.
Hey, this is Charles Maxwood. I just wanted to talk really briefly about the top in Dev's membership and let you know what we've got coming up this month. So in February, we have a whole bunch of workshops that we're providing to members. You can go sign up at topendevs.com slash sign up. If you do, you're going to get access to our book club. We're reading Docker Deep Dive, and we're going to be going into Docker and how to use it and things like that. We also have workshops on the following topics, and I'm just going to dive in and talk about what they are real quick. First, it's how to negotiate a raise. I've talked to a lot of people that they're not necessarily keen on leaving their job, but at the same time, they also want to make more money. And so we're going to talk about the different ways that you can approach talking to your boss or HR or whoever about getting that raise that you want and having it support the lifestyle you want. That one's going to be on February 7th, February 9th. We're going to have a career freedom mastermind. Basically you show up, you talk about what's holding you back, what you dream about doing in your career, all of that kind of stuff. And then we're going to actually brainstorm together, you and whoever else is there and I, all of us are going to brainstorm on how you can get ahead. The next week on the 14th, we're going to talk about how to grow from junior developer to senior developer, the kinds of things you need to be doing, how to do them, that kind of a thing. On the 16th, we're going to do a Visual Studio VS Code tips and tricks. On the 21st, we're going to talk about how to build a software course. And on the 23rd, we're going to talk about how to go freelance. And then finally, on February 28th, we're going to talk about how to set up a YouTube channel. So those are the meetups that we're going to have, along with the book club. And I hope to see you there. That's going to be at topendevs.com slash sign-up.
CHARLES MAX_WOOD: All right, AJ, why don't you start us off with our picks?
AJ_O’NEAL: Okay, picks. Dang. Uh, one thing that I, I was thinking about recently is I got, I'm, I'm now in the third book of the Chaos Walking trilogy and that is pretty good. I, I'm going to be interested to watch the movie after I finished the books and kind of
DAN_SHAPPIR: see which trilogy is that?
AJ_O’NEAL: Chaos walking. It starts with the knife of never letting go. It's about, it's about a colony. It's kind of like a space Western, but the people have crash-landed their ship on a planet and they're not going to be able to get off of it. And then they, you know, it's been almost a generation of people living there. And then the next settler ship is, is, uh, on its way. And so,
DAN_SHAPPIR: so there was a movie in 2021.
AJ_O’NEAL: I that sounds about right. Okay. Yeah. So yeah, but the movie got really bad reviews. And I think the problem was that they tried to turn it into I think this is what I what I heard is that they they tried to turn it into a story about sexism and it just didn't land with people because people didn't want to get preached at that wanted to watch that movie. They wanted the story and and so a lot a lot of people said that they're really upset that they abused the movie. And that the book, you know, if they followed the book instead of creating their own story arc that, you know, the movie could have done well. And so that got me interested in the book because I liked the trailer for the movie and I didn't know it was based on a book. But the reviews were so bad that I just didn't go see it. But I saw a review that said, look, you got to read the books because the books actually are an interesting story. And the reason that it would be an easy movie to turn into, you know, a political message about sexism is because. There is a divide the mint. So everybody is infected with a bacteria or some pathogen or, or, or parasite or whatever that, um, but it only affects males. It doesn't affect females.
DAN_SHAPPIR: Oh, I remember the, I now remember the trailer. Okay. So they project their thoughts, something like that.
AJ_O’NEAL: Yeah. So all males, um, project their thoughts as as something that and the females can sense it and this goes for animals as well as humans. So the females can sense the males but the females don't project their own thoughts. So you know every impulsive thought that a man has including about women you know like is immediately available on display to anyone within earshot let's say of of the man. And so this creates this rift in society. Um, and there is a psychopath who wants, does not like that women can hear his thoughts and the women mysteriously disappear. And that I'm in the third book and that's still not entirely resolved. I'm still kind of waiting for the reveal of what happened, but yeah, so there is, there there's, there's like the psychopath who needs complete control and the ability for others to hear thoughts or like it's, it's, it's kind of difficult to explain because of the nature of the sci-finess of it. But essentially settlers land on a planet, the women disappear, the men can see and hear each other's thoughts. And a woman is discovered in the woods by the protagonist about like two or three chapters in. And it's his first encounter with a woman and she is from the other settler ship that had been on its way for a generation. So that's kind of, that doesn't spoil too much, you know, other than the first, you know, it doesn't spoil any more than what's in the trailer for the movie. So I'll just stick with that because we talked about it a whole bunch and I don't want to take up the remainder of the hour with that.
CHARLES MAX_WOOD: Interesting.
AJ_O’NEAL: Yeah, so Chaos, the Chaos Walk in the book trilogy, really interesting to me. We'll see what I think about it when I finish the third book here, but I'm about two-thirds through the third book and I'm excited to see how things wrap together. And I think there's going to be a twist ending. I'm not sure if I'm going to like it or not.
CHARLES MAX_WOOD: Alright, Steve what are your picks?
STEVE_EDWARDS: Well, before we get to the high point of the episode, I do have another semi-legit pick. It's a blog post I came across on Hacker News from Ars Technica, and it's one of my favorite topics to read about. And it's titled, How Archaeologists Reconstructed the Burning of Jerusalem in 586 BC, or BCE, if you're politically correct. Basically, in the Old Testament, the Kings and Chronicles, Talks about how Nebuchadnezzar came and completely destroyed Jerusalem in 586. He had Captured it and taken off a lot of the Jews To Babylon but a couple of kings that stayed there decided to try to rebel and he said screw this I'm taking you all down. And so it basically completely destroyed the city and so, The article talks about a study that was done uh, there that used, uh, analytics of fire and how fire behaves. And a lot of the things we can tell now, you know, with forensic and how, what fire did to a building to, uh, pretty much nailed down the app. About that time is when Jerusalem was completely burned, uh, and destroyed. It's really pretty fascinating, especially if you're into fire science as I am. So anyway, we can put the link in the show notes for sure. And now it's time for the dad jokes of the week. I haven't been posting for a couple of weeks because I've been on vacation, but I think I can dig up a few that are worthy of being quoted here. So in the spirit of Christmas, did anybody hear about Rudolph's ride on the roller coaster when he went to the amusement park? You can say he held on for dear life. Now I am a, I think true pizza aficionados would call me a heretic and shoot me on site for saying this, that I do like pineapple on pizza. The pine and swine, pine and swine, aka Canadian bacon and pineapple is for me the best pizza. So the other day I was cooking some, but I actually burned it. I found out it was, you know, it's called a Hawaiian pizza. You know, as one of the names. I prefer pine and swine, but in the spirit of wine pizza, I should have cooked it at Aloha temperature. Pfft. Right. I love the groans. And then finally, apologies to pets fans, but I loved this one when I saw it. Does anybody know why there are no cats on Mars? No. Because curiosity killed them. All right. Curiosity is the NASA Rover that was on Mars. You know, there's curiosity with the other one.
CHARLES MAX_WOOD: Oh, discovery. I think. Yeah. Something like that. The space shuttle.
STEVE_EDWARDS: Yeah. That was the space shuttle. Anyway, anyway, those are the dad jokes of the week.
CHARLES MAX_WOOD: All right, Dan, what are your picks?
DAN_SHAPPIR: Um, okay. So I've got two. Uh, my first pick is, um, And despite your frequent recommendations, Chuck, I've not really been into board games that much. But now as a birthday present, our kids bought us Settlers of Catan. Is that how you guys pronounce it? And we've been playing it like, you know, in the family. And it's been lots of fun. I've yet to win. But I'm trying. And it's very enjoyable and it's a good game. I really like it. So so yeah, we will see how long we're able to persist. We play it like once a week something like that. We have a game night and So that's that would be my first pick my second is you know as as everybody in the world knows there's a war going on here and everybody seems to be picking sides and what I've What I've noticed is that a lot of people don't really have the context. They don't know the history. Now, you don't have to know the history to have an opinion. You can certainly have opinions about things that are happening at present without thinking about what happened 50 or 100 years ago. But I do think that having more context usually is helpful. And what I would like to pick is this documentary, Israeli documentary. So I can't say about it that it's objective. It's from the Israeli perspective. But it does try to be even-handed, I have to say. It's a documentary that came out in the 80s called Pillar of Fire. It starts when Zionism started in the like 1870s and goes all the way to the founding of Israel and a bit after that. And there's an English version that you can find on YouTube. By the way, one big advantage of the fact that it was done in the 80s is that they could still interview people who were there or even as kids, people who are deceased since then. And what's really great about this series is that they were able to uncover a lot of original films from the various periods. So it's really great in that regard. It's really good, I highly recommend it. So again, I can't say that it's like objective or, you know, you won't get as much of the Arab perspective as you would get of the Jewish perspective. But still, again, I think, you know, they do try to present all the facts and it's highly recommended for anybody who's really interested. So I link a link to the first link to the search in YouTube that will find it. You will see like episodes two and three there. Uh, I don't know if all the episodes are on YouTube, but I think at least the first four or five are there. So, uh, it's, as I said, I highly recommend that. Um, and those would be my picks for today.