3 Minutes with Kent

3 Minutes with Kent

By Kent C. DoddsTechnology
Download on the App Store

All 3 Minutes with Kent episodes

  • Lines of code !== Complexity

    https://twitter.com/DavidKPiano/status/1361353521648590853?s=19

    What up folks Happy President's Day for those in the US I wanted to talk

    about this tweet that I saw from David K. Piano that's his Twitter handle
    his last name is Korshid and the tweet is can we stop with the myth that
    more code means more complexity? Sometimes less code means more edge
    casings ignored which means willfully and dangerously ignoring complexity
    not reducing it.

    And he gives some a sample of some simple code that just awaits fetch from

    API and then returns the data and it's saying here are some of the
    ignored.Complexity error handling data validation timeout handling
    cancellation interruption, etc. I super duper agree with David here and I
    very often will have people ask me about the complexity of some code
    because there's a lot of it.

    And the code that they're talking about is maybe some class name for

    tailwind, you know, a tailwind has tons of class names or maybe they're
    talking about inline styles with the CSS prop or sorry CSS and JS or like
    maybe they're talking about.JSX and this component just has like 200 lines
    of JSX or something.

    Whatever the case may be the number of lines of code is maybe correlated

    but not necessarily correlated even with the amount of complexity. You
    could have a list of all the countries in the United States. And now that
    would be that would be represented by a lot of lines of code.

    Sorry, did I say all the countries? I meant, like all the cities in the

    United States. That would be a lot of code but it would not be complex.At
    all. So the there's a very subtle if any relationship between the amount of
    code and the complexity thereof and I think that it's an important thing to
    to keep in mind.

    So just because there's a lot of code doesn't mean that this is going to be

    a maintainability nightmare or it's going to be complex. I actually find
    that prematurely abstracting some of that stuff because you think it's
    complex can make things even more complex, for example, if you have a I
    don't know some like tons of.

    TSS or something like that CSS like class names or something you try to

    abstract that away with some fancy higher order component or something then
    that would be even worse. Or if you like have a bunch of JSX and then you
    wind up trying to like extract these into little components then now you
    have to worry about passing props and everything and that just increases
    the complexity.

    Now, I'm not saying that's always the case but just keep that in mind.

    There's not necessarily relationship between the amount of code and how
    complex that code is. I hope that's helpful. I have an awesome day. Goodbye.

    3 min
  • Code comments: tell me "why," not "what"

    Code comments, they're important you need to have them but what you say in

    the code comment is important so I worked at a place where we were starting
    to transition to ES6 and you know from using var to constant lead and you
    know all the new cool features, you know, JavaScript and gotten a lot of
    new and interesting things in a long time and so we're all starting to use
    these new things and I saw a lot of comments from some of my coworkers
    about like basically describing what the syntax.

    Was doing because it was unfamiliar done oh so that was I was installing

    with NPM and so in the in the code you would just find all sorts of places
    where just described what the syntax was doing because we were we weren't
    used to it. I never wrote those comments because those comments were not
    really helpful and I would not recommend to anybody write those kinds of
    comments and like you could do the same thing for APIs to libraries that
    that you're using that you're not used to like or you know, you could
    say,Maybe you have a function component that returns null you could add a
    comment that says you when you return no it doesn't render anything, you
    know, like you just go forever on code comments so it comes down to what is
    the code comment actually telling and what's useful about it and yeah like
    there there's a difference between a code comment that says what you and
    you're doing and it could comment that says why you're doing it and that's
    what you really should be focusing on is what you're doing if it needs to
    be explained then you should be doing what you're doing a little
    differently.

    Because code comment won't necessarily make it any easier to understand so

    yeah, if if your code comment is just saying this assigns the variable root
    to the string hello world like that is not gonna be at all useful but you
    could explain why you're doing that now you say well our back end expects
    us to send a hello world string because of this weird historical fact
    something that somebody couldn't just Google and figure out you know, what
    it's going on, you know, what with?

    With syntax that's something people can figure out but when it comes to

    like business domain specific things that's the sort of thing that you want
    to write a code comment about it's especially useful when you're default
    like what you would expect somebody to do would be X but you can't do that
    for reason why and so then you explain why you're doing something that may
    not be what people would expect you to be due doing that's what could
    comments are for it's to explain why you're doing something that may be
    unexpected.

    I hope that's useful have.A wonderful day.

    3 min
  • Keep an eye on Remix

    Hey friends I've just been thinking a lot about remix recently, so if you

    haven't heard of remix this that's what I want to tell you about just to
    try and convince you to go give it a serious look so remakes is a react
    framework that is both server side and client side it's a lot of people
    compare it to next but it's pretty fundamentally different from the way
    that next operates it is file system based routing though, there is a
    imperative API that you can use to declare routes programming
    programmatically, but what?

    Makes remix really special is it's embracing of the web platform and not

    just brand new features though, it does leverage newer features and things
    and take advantage of those when they're available but also like age-old
    features like http caching very heavily and gives you just really nice APIs
    for that sort of thing and I'm like resource preloading and prefetching a
    lot of really really cool things.

    Frankly that we reached for or we were excited about suspense for so like

    react suspense we're trying to optimize for loading resources and
    preloading them and whatever remix has like solves pretty much all the same
    problems and it's built in and it works for the first initial load where
    suspense can't help you with any of that stuff you have to get suspense
    into the browser before it can do anything to help you so yeah anyway, I'm
    just super impressed by what remix has to offer and what's cool is I've
    talked with Ryan Florence about this.

    Right so remix has created by Ryan Florence and Michael Jackson's Jackson

    the creator creators of Reactor and Ryan has told me that their plan is to
    put a lot of what is in remakes into react router and there will be plenty
    of stuff that's in remix to like all the build and the file system stuff
    and whatever but a lot of the really cool features that I I'm personally
    really enjoying will be a part of React router and so I think that that's
    gonna be pretty legit we'll look forward to.

    An official release of reactive router V6, you know nested routing oh it's

    awesome yeah lots of really cool things coming to react around her but in
    general remix will wire things together for us really nicely to make some
    really fantastic user experiences and just with a really great developer
    experience so I would encourage you to take a look at remix maybe you don't
    have to buy a license right away but like go to check out the YouTube
    channel and watch a couple videos, it's awesome take care.

    Yeah.

    3 min
  • Different Problems, Different Solutions

    Hey folks I know it's a little bit noisy I'm in my car with the fans on

    because it's cold I just wanted to mention something that I thought was
    going to interesting. I was just thinking about how sometimes we argue
    about taking it technological choices, like what framework we use whatever
    and I thought of a kind of a real world situation that is kind of like this
    and let's say that you're talking to somebody and they're talking about how
    much they love their truck and and it's just the best and they can do
    anything they want to with it, you know, like what the like whatever I my
    sudan is amazing theKnowledge all this stuff is amazing like it's does
    everything that I need to and you can like argue and argue all day long
    about why you're sedan is better your hatchback or you're or the track or
    whatever but at the end of the day these things serve different and use
    cases for different people and so just like there's no one vehicle that can
    solve everybody's problems and there's no one JavaScript framework or it's
    tool or technology that can solve everyone's problems either it is a vast
    world of use cases and user experience that we're trying.

    To create and whatever it's just there's so much out there that we're

    trying to accomplish with the web and with software in general that there
    can't be a silver bullet for for everything that you could possibly imagine
    so and keep that in mind next time you are talking with people about
    different things.

    I know sometimes I can be a little dogmatic on certain of my opinions. I

    kept like especially shallow rendering you should never shallower but um,
    most of the time there are nuances and trade-offs that were all making and
    we're all just trying to get.Hit by and do our best to avoid you know doing
    the wrong thing making the wrong choice but also make sure that we're you
    know, and doing the best that we can and keep keep those trade offs in mind
    and the fact that your problems may not be in line with someone else's
    problems, you may have different problems from another person maybe you
    don't need to haul number and maybe they do and that's why they like their
    truck, you know, whatever the occasion maybe so anyway, especially when
    you're having these kinds of conversations that people be sure.

    To be nice to each other and yeah and just keep in mind that your problems

    may not be their problems. Cheers.

    3 min
  • Don't build the solution before you understand the problem

    What is up my friends all right, so today I wanted to talk about investing

    the time at the right and appropriate time so I actually talked with my
    friend Jacob about this and yo-yo Jacob if you're listening and just in
    general we're talking about you have this really big plan for a big and
    exciting thing and you want to like create a business out of it or you want
    to build a whole new application or something like that and so you have
    these really giant plans what I want to tell you is try to.

    Avoid doing as much work as possible and like sorry let me say that again

    try to avoid solving problems that you don't yet have but thank you will so
    you have really have to have a compelling reason to solve a problem that
    you think you're going to have rather than solving problems that you know
    that you have right now so let me give you example of this my sister about
    a year ago when covet started she is a violinist she's very good and she
    all of her violinist friends were just not doing great becauseCovid and
    everything just messed up their lives and so she had this idea that she
    could make an app that would enable violin professionals to teach online
    and she done a lot of research and everything said there wasn't anything
    quite like what she was thinking and so she wanted to hire a developer to
    build something for her she basically wanted an app that was like zoom and
    Tito for the ticketing and like had all of these things built in as.

    You know an app and it would be a really cool thing potentially and so she

    was ready to like go go hire an engineer paid hundreds of thousands of
    dollars to make this dream of hers a reality probably more is what it would
    end up costing and I and she asked me because I'm a developer and so I
    could tell her about some of that aspect of stuff and I told her hey, it's
    great that you think this is gonna be so awesome and it probably like a
    very much could be awesome but really really try to avoid.

    Doing all of this stuff until you're like solving all these problems until

    you're certain that you know what the problems are because often you'll get
    into things and you'll just you think that you know what promise you need
    solve okay, we need this feature in that feature in that feature and then
    by the time you're done you find out that you're no longer into it at all
    and so you don't even need the solutions in the first place or you
    misunderstood the problem and so the solution doesn't fit the problem yeah
    that I maybe need a little bit more time to talk about this but yeah just
    avoid like I don't own any domains for apps that I haven't built I built
    the app first then I buy the domain.

    Yeah take that and run with it good luck see you later.

    3 min
  • Testing with Text and Internationalization

    Hey folks a common question that I get about testing and especially since

    react testing library or testing library in general you query the DOM by
    giving it the text that you're looking for so you say hey I want to get a
    button and it's accessible name is submit. And so the comment question that
    I get is well that must not work for internationalized websites that's
    probably just for like little toy apps or internal apps or whatever where
    you don't have any internationalization going on, no different languages
    because the word submit in English is not the same as it is in French
    orWhatever.

    So yeah, this is a really common question and what my answer is. Well, just

    use the default language. So if you're agency in Spain and so most of your
    websites your default language is Spanish then write the tests using the
    Spanish text and you when you run the test make sure that the all the
    languages and stuff are accessible to the tests so that when the components
    are rendered and the actual default language text is there and you can
    query off of it.

    And,So then the next question is well, okay, but I'm not managing the those

    strings myself. We've got a an internationalization team or we've got
    somebody responsible for managing that content and I just put in the IDs
    and that's not my responsibility and so the problem there is okay, so now
    my the localization team is it's possible for them to break my tests.

    And so my response to that is well, okay, so let's say that you're testing

    the login form and you're accepting the username and password and then,It
    comes around and changes that content on you as you propose they can and
    they change it to email and password instead. Well in that situation, I'd
    actually be glad for my test to fail and catch that and and notify me that
    this change was made because I don't want the content editors to make a
    change like that without me giving that go ahead because I'm going to need
    to change my implementation.

    If we change from username to email well now I'm going to need to change

    maybe even the back end on how we store this invalidate this and also on
    the front.End as well So I I don't really worry too much about that Now
    let's say that it's something innocuous like who we don't know it's it's
    just two ways of saying the same thing they change it to the other way.

    If that does happen, then it is going to break and and it's not going to

    actually be a problem for the user. So that'll be annoying but those sorts
    of things are super easy to go and fix. You know exactly what went wrong
    with the error messages that you get and you can go back and fix it and and
    then move forward.

    So, I suggest just use the regular text and it's it use the default

    text.And it's pretty straightforward to do that. Good luck.

    3 min
  • Is it okay to make a function async if it doesn't need to be async?

    Hey friends so I got a question on discord from somebody who asked

    effectively is it okay to put async away on a function that doesn't need it
    and you can get useless rules that will prevent this. I think I have the
    enabled because I don't typically want to do this but there are situations
    sometimes where you want to start with an API that isn't asynchronous now
    but you're pretty confident that it's going to be asynchronous in the
    future and it's just easier.

    To plan with that asynchrony from the get-go rather than try to retrofit

    everything to work with asynchrony in the future and so yes, it's I think
    it's acceptable and it's okay to make something async when it doesn't need
    to be and you just have to be aware that any consumer is going to have to
    consume an async API rather than a synchronous one and you'll have to
    consider the fact that because it's async it it is like as soon as you
    attach that async keyword onto the function onto the function keyword like
    right in front of that function keyword or in front of theParentheses if
    you're doing an arrow function whatever as soon as you put that async
    keyword on there it immediately means that no matter what the function does
    it's returning a promise and the any consuming code cannot proceed until
    the next tick of the event loop, you know, I'm talking about like if the
    consuming code is using async away if it's using promises with dot then
    then the the success handler of that promise is going to run on the next
    tick of the event loop and so that means that just has some interesting
    implications around you know closures andStillness and but in in practice
    that's not normally going to be too much of an issue so I would say that
    yeah it's okay to put async on a function that doesn't need it but I
    wouldn't do it for no reason so like there would need to be an explanation
    and in a code base where you have coworkers who are going to look at this
    code and and even yourself who's going to look at this code in the future,
    it would be useful for you to write a code comment to explain why you're
    doing this so that people don't remove it and then accidentally break some
    consuming code because you're not using type script, for example.

    If you're using textcript then you know, maybe it's okay, but anyway, I

    hope that is useful to you and I hope that you had a marvelous day in that
    or that you're going to whenever this is, you know, good afternoon good
    evening tonight. Truman shows now and I'll talk to you later bye.

    3 min
  • Where my money comes from: my transparency page

    Hey there friend so today I want to talk to you about my transparency page.

    So I just added a new page to my website can't see Dodds.com slash
    transparency and I created this website or this page after I was thinking
    about something over the last few days about actually started with
    clubhouse.

    So actually, you know, what even before Covas I've always really been

    concerned about the incentives of companies. And how messed up incentives
    can give us companies that will pollute the planet and sell users.Data And
    so if you have the right incentives and you know like for example a company
    that includes the planet needs to pay for the cost of cleaning that
    pollution up if that were to be the case then we would not have nearly the
    problem that we have now.

    And so just getting an incentives aligned in in the right way can solve a

    lot of problems. However regulation isn't there yet and and I don't know if
    it ever will be and I'm not here to talk about politics or anything. But
    incentives are important and so as consumers we should be thinking about
    theIncentives of the companies that we consume or the companies that we
    support.

    And so with clubhouse recently I was thinking about well, we don't know how

    they make money and so I'm unsure whether I want to really support them
    because we don't know how they make money. I realize that I do interact on
    Twitter and they make the way they make their money is something.

    I don't necessarily agree with either but that's a decide the point.

    Anyway, I'm interested in.In understanding at least where companies make
    money and I feel like and this is what I tweeted the other day I feel like
    every company should have a page that describes how they make money and if
    they don't make money yet and they're just like burning through VC funds or
    something then they should explain what they what their plan is for making
    money eventually and if they don't know then they should at least tell us
    whether they're going to turn their users into the product or if they're
    going to sell a product to their users.

    And so as I was thinking about this and I said, every company should have a

    page like this, I realize oh I have a company. I guess I could make aA page
    like this and so I did and this that's what the transparency pages. It's
    all about helping you get an idea of what my incentives are.

    So that when you're supporting me you understand where what you are

    actually supporting. And so go ahead and go take a look at it. I also break
    down like where my money comes from who pays for the things that I'm
    selling and and then what I do with that money as well.

    So go ahead and take a look at that page and I hope you have a spectacular

    awesome day. Bye.

    3 min
  • Rarely forEach, normally for..of

    Hey friends. So today I wanted to talk about looping over a raise and stuff

    like that. And pretty much I'm mostly want to talk about for loops. Early
    on in my software developer career that's pretty much exclusively how I
    looked over things and I learned about filter and map and reduced and all
    of those things and for each and all that and I went full in on that stuff.

    More recently, I've been getting into using four of loops for stuff. And I

    find that to work out really nicely.To the point where I don't think you'll
    ever ever catch me use a for each on an array anymore I and like I can't
    think of a scenario where that would be more simple than just doing a four
    of loop.

    With potentially the exception of you've got a function over here already

    to find and you're just gonna pass it as the argument to for each. Maybe
    that I guess could make sense but most of the time I'm just gonna be using
    a forever. So anyway, I Yeah, I don't really have much more to say about
    that.

    It's just kind of.Something interesting to think about and I do have a blog

    post actually about using map and filter versus reduce and a regular old
    sea style loop where you have the index and everything like that. And so
    you could go take a look at that if you're interested in diving little
    deeper, it even has an egg-head video on there.

    But yeah, just look at my blog look for reduce or filter. You'll find it on

    there. But yeah, I find myself like early on. I used those sea style loops
    and,Then and full on a raise and now I'm kind of yeah between array
    methods, sometimes I'll use reduced but not often I'm mostly on filter and
    map.

    If I really need performance gains of using reduced then I'll go with that

    just fine but anyway hope that is interesting and useful and insightful. If
    you haven't been using four ofs and you've been finding you're using for
    each then yeah, go ahead and give a four of trying they're pretty great.

    Thanks bye.

    3 min
  • When client-side routing is worse than server-side routing

    Hey there friend so today I wanted to talk about something that I've been

    thinking about a little bit and it is client side routing. So Ryan Florence
    actually tweeted about this. I think like a year ago or something and and I
    talked about it recently on a podcast that I was on I think Dev mode FM or
    something.

    But yeah his tweet was basically like I kind of feel like client side

    routing is a mistake and we're better off with like actually going to get
    the document on it, you know, full-page refresh basically on every page.
    AndI I've talked with Ryan Florence about this quite a bit.

    And here are just some thoughts that I have about it. And I kind of agree

    with him sort of. So basically what what I'm thinking is that with client
    side routing by default or let's take a step back. So like before client
    side routing goes the thing you'd find a link on the page you'd click on
    that link and then you would see like the browser would give you some
    indication that something's happening.

    So you'd get the spinner at the top where the favicon is and you'd get.Like

    some information on the bottom typically telling you that you're waiting on
    a particular resource and then while that's happening you actually still
    get to see the page that you were on before. So you still may be able to
    make use of that information or something or notice something or whatever.

    And then when we move to client side routing then pretty often what happens

    is you click on the link and you immediately navigate to the page that
    you're going to and then you see a bunch of spinners all over the place. Or
    even worse you don't see spinners andYou just you land on the page and then
    things pop into place as they become available and that typically will
    happen when the developer who worked on the page was on a really fast
    internet connection just didn't really consider what a loading experience
    would be like.

    And in fact, very very often our designers don't design loading

    experiences. And so we have to be explicit about it. And so what's
    interesting is that the the default behavior gives you all the right
    affordances for the loading state. And when you go to client side
    routing,You have to opt into giving those affordances so there's some
    indication that a loading state is showing it's something is loading and
    you have to worry about when things load and when things pop into place and
    stuff and so yeah, it's it's a little bit of a step back maybe you just
    have to be a lot more intentional and so maybe the default of having it do
    a full page refresh essentially is an entirely a bad one from that
    perspective and then when you go to client side routing, you just really
    have to think about those things.

    So anyway, just some thoughts hopefully,

    3 min