5 Things I Hate About JavaScript

Поделиться
HTML-код
  • Опубликовано: 28 май 2024
  • 12 Years professional with javascript so here is my list of things I hate about js (this goes for TS too)
    Twitch
    Everything is built live on twitch
    Twitch : bit.ly/3xhFO3E
    Discord: discord.gg/ThePrimeagen
    Editor
    All my videos are edited by Flip. Give him a follow! / flipmediaprod He is also open to do more editing, so slide deeeeeeeeep into his dms.
    Links
    Linode: linode.com/prime
    / discord
    Twitch: / theprimeagen
    Insta: / theprimeagen
    Twitter: / theprimeagen
    VimRC & i3: github.com/ThePrimeagen/.dotf...
    Keyboard (15% off, I don't earn commission): bit.ly/primeagen-adv2
    #vim #programming #softwareengineering
  • НаукаНаука

Комментарии • 817

  • @ThePrimeagen
    @ThePrimeagen  Год назад +247

    I didn't include this, bind, type coercion, let dead zones, or any typical "i hate js." I also didn't include Dates because I am convinced that when it was conceived it was considered the best way to handle dates (have you seen other languages in the mid 90s? It was a literal copy of another library at tha time)
    But the items I included are truly awful items that are not found in other languages (that i know of)

    • @oskrm
      @oskrm Год назад +19

      This list is a unique one. Not just using the same broken CD.

    • @itspravas
      @itspravas Год назад

      Hello Mr @ThePrimeagent, Big Fan of your twitch stream.
      What is the green that you're using ? Or it is your wall painted in that color.

    • @DBZM1k3
      @DBZM1k3 Год назад +15

      I think the forEach case is acceptable because sometimes you just want to iterate over the value in some iterable type. So having it value, key allows for key to be ignored entirely giving (val) => {};
      Doing it the other way is more complicated to solve for.

    • @beriu3512
      @beriu3512 Год назад +2

      I just read up on `let dead zones` what a peculiar thing, I've never stumbled upon it, and I'm still confused on how someone might reach that edgecase

    • @moodynoob
      @moodynoob Год назад +2

      Thank you for not using the same lame examples people often use!

  • @alangamer50
    @alangamer50 Год назад +272

    as Fireship once said: 'JS is a language used exclusively to build things it's not supposed to'

    • @AEStolfo
      @AEStolfo 8 месяцев назад +12

      48 likes and 0 comments? lemme fix it.
      ...btw fireship rules

    • @dannyarcher6370
      @dannyarcher6370 Месяц назад +2

      Right from the very beginning.

  • @JuanPablodelaTorre
    @JuanPablodelaTorre Год назад +183

    “Any application that can be written in JavaScript will, eventually, be written in JavaScript.”
    - Jeff Atwood, founder of Stack Overflow, in 2007

  • @reo101
    @reo101 Год назад +273

    Only 5? You must've limited yourself pretty harshly :D

  • @GeekMasher
    @GeekMasher Год назад +246

    "The lords language Rust" made me laugh and started wondering... Are we all created in Rust? Are we all at heart Rustaceans? Are we all... Blazingly fast?

    • @theondono
      @theondono Год назад +56

      Light is a wave and a particle, Rust doesn’t allow this nonsense. If God had used Rust, quantum physics would make sense

    • @caerphoto
      @caerphoto Год назад +13

      If we are then I must be running in debug mode or something then :(

    • @tokiomutex4148
      @tokiomutex4148 Год назад +4

      I for sure am

    • @raffimolero64
      @raffimolero64 Год назад +13

      we’re all unsafe code and use garbage collection.
      somehow at the same time.

    • @tokiomutex4148
      @tokiomutex4148 Год назад +5

      @@raffimolero64 speak for yourself

  • @j-wenning
    @j-wenning Год назад +127

    My "favorite" bit about JS is the fact that you can still manage to create memory leaks in a GCed language, and because of the nature of the language, you're not meant to be actively thinking about that sort of thing, so you don't notice it til your program is whoring an abnormal amount of memory.

    • @j-wenning
      @j-wenning Год назад +27

      Oh yeah and good luck finding it. Especially if it's an installed dependency and not your own code.

    • @theodorealenas3171
      @theodorealenas3171 Год назад +8

      Ouch. Is that common? I'm not familiar with web dev but it sounds strangely stupid

    • @j-wenning
      @j-wenning Год назад +20

      For simple applications, no. If you ever start trying to do something clever "just because the compiler/interpreter allows it", that likelihood definitely shoots up, though. Likewise when dealing with lower level data structures and such.

    • @pxh6129
      @pxh6129 Год назад +19

      "whoring an abnormal amount of memory" lmao. I like your phrasing

    • @DFPercush
      @DFPercush Год назад +5

      I imagine it tends to happen when you have a huge stack of async functions all holding "temporary" named variables full of references to other large structures.

  • @leetaeryeo5269
    @leetaeryeo5269 Год назад +190

    5:36 This leads to one of my hot takes. Javascript is just the BASIC of the 2010-2020s. It's an approachable entry point for new programmers and people want to use it for everything, but that leads to it being used for things it has no business being used for. And everyone and their grandmother has their own library/way of doing things/dialect for any given task, which stretches the language beyond its comfortable limits

    • @hamm8934
      @hamm8934 Год назад +1

      Exactly

    • @aryandeora6631
      @aryandeora6631 Год назад +16

      But isn't that the BEAUTY of it? It can be bent forwards, backwards and upside down and it still works amazingly! Sure there are caveats but which language doesn't?

    • @leetaeryeo5269
      @leetaeryeo5269 Год назад +26

      @@aryandeora6631 I mean, it’s convenient, but I don’t think it’s ideal. Different tools/languages are appropriate for different tasks and trying to fit every task to JavaScript just feels like trying to turn a wrench into a hammer-sure, you can probably get to the same place eventually, but you’d have a way easier and better time if you just stopped and grabbed a hammer. Like, I wouldn’t use JS for systems programming, just as I wouldn’t use C for web ui programming and I wouldn’t develop an operating system APL.

    • @aryandeora6631
      @aryandeora6631 Год назад +10

      @@leetaeryeo5269 fair critique I take your point

    • @leetaeryeo5269
      @leetaeryeo5269 Год назад +10

      @@aryandeora6631 and I 100% see your standpoint as well. I’m a bit of a hypocrite because I work in C# which has libraries and frameworks for pretty much everything under the sun.

  • @peteryates308
    @peteryates308 Год назад +58

    I enjoy working in JS from time to time, 0 indexed months get me every time. Every single time.

    • @user-lb1ib8rz4h
      @user-lb1ib8rz4h Год назад +12

      sure, but that's not js-specific. it seems to have been copied from another language with java in the name...

    • @error.418
      @error.418 Год назад +1

      @@user-lb1ib8rz4h Correct. Also we have a new system coming soon, the TC-39 Temporal proposal which is now in Stage 3.

    • @Yous0147
      @Yous0147 Год назад +1

      @@user-lb1ib8rz4h That's true, but it's been a literal decade since dates have been a problem in Java, if not more. In JS, it's still the same.

  • @RedStone576
    @RedStone576 Год назад +97

    this is actually a really great video, talking about stuff that most people will overlook instead of complaining about it's quirks that basically everyone already know

  • @wlockuz4467
    @wlockuz4467 Год назад +43

    The regex one has actually screwed me over during my live exams, Luckily I was able to write a shitty function to replace what it was doing, but after the exam when I looked at why it was doing it what it was doing I had the same question, WHY?

    • @ThePrimeagen
      @ThePrimeagen  Год назад +15

      too clever by half of course

    • @error.418
      @error.418 Год назад +3

      Why were you using a global flag in a test function, though? If you're just doing a boolean test, I can't think of a good example where you actually want the global flag. Without the global flag, this isn't an issue. If you are reaching for the global flag, you're probably intending to use a different regex function, not test.

  • @keatonhatch6213
    @keatonhatch6213 Год назад +26

    With css at the stage it’s at and faster backend languages, JavaScript should be limited to web carousels and scroll loading.

    • @ThePrimeagen
      @ThePrimeagen  Год назад +13

      love this idea

    • @Prod-23
      @Prod-23 Год назад +3

      @@ThePrimeagen To be fair, that was the intended use case ... THE ONLY INTENDED USE CASE I might add ... ;)

    • @inakiarias7465
      @inakiarias7465 11 месяцев назад +1

      So how would you manage components and application state inside a browser app without JS? Go back to template engines? PHP? Lol

    • @keatonhatch6213
      @keatonhatch6213 11 месяцев назад +2

      @@inakiarias7465 you laugh but there’s a reason the largest of web apps still use them.

    • @inakiarias7465
      @inakiarias7465 10 месяцев назад +2

      @@keatonhatch6213 Yea, the reason being their code foundation is already built on that...

  • @brunocmesquita
    @brunocmesquita Год назад +1

    I knew about your channel a few days ago. What a good content man. Really cool to watch. Contratz!

  • @KnThSelf2ThSelfBTrue
    @KnThSelf2ThSelfBTrue Год назад +18

    This isn't a JavaScript but a node issue. If you spawn a child process in node, and that node process logs so much that it crashes due to running out of memory, the callback in the parent process gets passed an exit code of - not a number - but the JS value `null`... which JSers will know is dangerously close to 0.
    So anyway Jest hurts sometimes.... Don't log a bunch of stuff in your unit tests.

  • @Kriszzzful
    @Kriszzzful Год назад +27

    I was sure when I clicked that this is gonna be just another rant about implicit type conversion. Pleasantly surprised! I wasn’t aware of any of these issues lol

  • @blt_r
    @blt_r Год назад +40

    callback to Map.prototype.forEach takes (value, key, map) to be in line with Array.prototype.forEach which passes (value, index, array) to its callback. Because indexes for arrays are same thing as keys for maps

    • @claytonmarshall8564
      @claytonmarshall8564 Год назад +4

      Was about to comment the same thing. It would have been much worse had they changed the definition of the forEach callback for a single type.

    • @raffimolero64
      @raffimolero64 Год назад +1

      for consistency the whole thing should just be for v,k if they want to go the route of “you iterate over values but can optionally get the index/key”
      unless there’s some design philosophy i’m missing, which is likely

    • @falias4
      @falias4 Год назад +5

      thats actually programming 101... In simple for-loops you work with index and in foreach you work with values. (same thing in other languages too)
      ... and the second parameter is simply optional

  • @KoltPenny
    @KoltPenny Год назад +22

    6. Starts with JAVA

  • @arsereg
    @arsereg Год назад +96

    Principal Fullstack Lead developer here, 18 years of experience. I found your top things to hate about javascript really interesting and curious! Thanks for sharing!
    I think, in my personal opinion, that yes, this things can be really cumbersome, and it can lead to really messy situations where you face an additional layer of complexity. And of course, this things can leave you spending hours debugging your code for a piece of code that can be really difficult to find (Like the 'g' operator in the regex). However, the most I hate from Javascript it's a big portion of the community.
    Don't get me wrong. I've found many many many developers that create a really diverse and collaboratively community that ends up being helpful, thoughtful, and really really good educators about the perks and quirks of Javascript. However, particularly in Javascript and Python, I've also found the most toxic, irreverent and excruciating members I've faced.
    A few days ago, I found a video in a spanish-speaking channel focused on Javascript developers. The Video title was: "STOP using for cicles". That catched my attention and I went to watch the video.
    During the video, the presenter mentioned that instead of using "For" to iterate over a cycle, we should do it using a Array.map function, the reason: Legibility.
    However, during the video, the presenter also mentioned that the use of Array.map function allows you to "execute your code in a immutable way", which seemed kinda odd, because the very fact that you don't modify something during your code execution doesn't make it immutable.
    In the comments section, I saw one person mentioning how he disagreed with the video, because of multiple things. I added my support to this comment by also mentioning that the video was referring to Immutability when he wasn't actually doing immutability, as well as an improper use of the Array.map function.
    Not 5 minutes later, I got attacked by one of the people involved on the conversation saying that "Clearly I was just a junior developer that was scared of the Array.map function", and I just mentioned that even that you could achieve the same result using a for or an Array.map function, the Array.map function has much worse performance in terms of memory usage and time complexity. Long story short, I wrote a piece of code to demonstrate how using Array.map performed 28 times slower and could only manage arrays the 1/11 the size in comparison to use a for cicle, not to mention that the Array.map function semantical purpose is to map an object from one type to another, so using a map instead of a for would make the code "harder to read" because the semantics of the code itself.
    The next day, the youtube channel published a video that was titled: "Do not optimize your code" and pretty much what the video talked about is how nowadays, computers are so powerful that "small" optimizations are unnecessary, using the code I provided in the previous video.
    To finish up, I just decided to stop wasting my time with someone who's motto is: "Dont optimize your code". The person kept attacking me for around 3 days, trying to pull me into arguments.
    And although I've found amazing people that makes a great great great community around Javascript, these kinds of interactions are not rare.

    • @talhaakram
      @talhaakram Год назад +3

      There is this strange culture of putting people on pedestals and treating their opinions as facts or the only right way of doing things. If someone disagrees with it, they are treated as lesser skilled developers who simply 'don't get it'.

    • @arsereg
      @arsereg Год назад +13

      @@talhaakram Absolutely agree! Also, quite interesting is that as a response for being confronted, he decided to attack me as a person rather than discuss on the technology. This is something we shouldn't do at all when discussing about best methods

    • @upcomingweeb136
      @upcomingweeb136 Год назад +2

      I actually faced similar experience when I tried explaining to some of my colleagues why typescript is better than JavaScript.

    • @arsereg
      @arsereg Год назад +10

      ​ @Upcoming Weeb! So sorry to hear that. People are afraid of facing new things or not knowing about something. Honestly and personally, I'm glad when I found something I don't know so that I can study it, and I believe that being so aggressive against such scenarios is definitely a lost opportunity to grow.
      Sometimes, I think that languages get followers that treat said languages with religious fervour. And are willing to negate reality itself just to attach themselves to their point.
      This person I was talking about before insisted that the use of Map was better, despite the fact that it performed much, much worse, could handle much fewer data and at the cost of code semantics. His words: "This is the javascript way", reveals this religious fervour I'm talking about.
      For some reason, he thinks that Javascript existed in a separate realm, where code-optimizations, design patterns, algorithms and data structures don't apply to Javascript because "that's just how javascript works". And he's not willing to accept that he's wrong.
      That also shows a bit of immaturity in the developer as well. In my personal case, I really love and enjoy working with Java/Kotlin. However, I know that Java/Kotlin have their perks and that sometimes it is not the best fit for all. I'm willing to accept that it is "not the best language", but I do not think such a thing exists.
      Once again, I'm sorry that you had to pass through that trying to educate your colleagues about typescript. However, you are one clear example of how a community around Javascript can also be a really nice place. Let's keep it that way :D

    • @talhaakram
      @talhaakram Год назад

      @@arsereg 💯 agreed.

  • @BuyMyBeard
    @BuyMyBeard 8 месяцев назад +5

    I remember once making a procedural generation algorithm with a string sequence composed of a combinations of the characters ‘0123’. I wasn’t understanding why it was returning ‘ddeefinnu0123’. Turns out *undefined* was getting cast into a string and then sorted by characters in my algorithm. That had me stumped for a bit.

  • @fearmear
    @fearmear Год назад +87

    Here's my suggestion for JavaScript future. Implement TypeScript as a new JavaScript spec and let browsers implement it. I'm tired of having to do "builds" in a scripting language.

    • @ThePrimeagen
      @ThePrimeagen  Год назад +55

      i effing hate the eco system.

    • @theodorealenas3171
      @theodorealenas3171 Год назад +4

      But you also want browsers to pack files for you? And minify? I don't see why or how the browser could build for you.

    • @hacktor_92
      @hacktor_92 Год назад +8

      @@theodorealenas3171 main problem is, doing a simple web ui is waaay more complex nowadays. you don't need angular for a(ny thing) simple blog website. you don't need to build anything complex for a simple task. and nodejs makes you feel like you're in hell.

    • @hacktor_92
      @hacktor_92 Год назад +2

      i'd suggest some sort of apk-like, but for web apps, where you bundle your typescript files, along with assets and whatnot, and the rest is right there, in a single package file.

    • @theodorealenas3171
      @theodorealenas3171 Год назад +1

      @@hacktor_92 sorry I don't have the experience to understand, but APK is a package format apparently. So, you wish to send like a tarball with the dir tree to the browser? You don't like doing the same, but fragmented?

  • @AnalyticMinded
    @AnalyticMinded Год назад +10

    I just started learning a bit of JavaScript a couple of days ago, so most of this video just flew over my head. But the important thing is that I watched it. :P

    • @ThePrimeagen
      @ThePrimeagen  Год назад +24

      agreed. its like a boomerang, it flew over, but its coming back.

    • @eventslooped7376
      @eventslooped7376 Год назад +1

      @@ThePrimeagen Deep. And when it comes back it hits you in the back of the head

  • @brianbutton6346
    @brianbutton6346 Год назад +5

    Imagine coming to a JavaScript-labeled video and seeing TypeScript.

  • @wilfridtaylor
    @wilfridtaylor Год назад +13

    Yeah my rule for javascript is contain it on the front end. Don't let it get into cicd to much or you end up with a really flaky build system.

  • @__idan__
    @__idan__ Год назад +12

    Modern life as we know it is standing on the thin legs of JS, I'm scared.

  • @nicholaswood3250
    @nicholaswood3250 Год назад +5

    I feel like most regex issues are really, “people not admitting that their input is not actually regular” problems. Email addresses are the classic example of something that seems regular but is actually not. The only reliable way to test that an email address is valid is to send an email to it and see if it works.

  • @dealloc
    @dealloc Год назад +17

    One could argue that forEach taking value first would make other functions easier to reuse for both Map/forEach and Array/forEach. Although, I personally never use forEach for either, since for loops allows for control flow and doesn't make it more unreadable.

    • @ry4nolson
      @ry4nolson Год назад +8

      it also matches the usage of Array.forEach( (value, index) => { })

  • @aymenmt1
    @aymenmt1 Год назад +12

    Math.max();
    // -Infinity
    Math.min();
    // Infinity

  • @konga8165
    @konga8165 Год назад

    Love you man! Keep it up!

  • @kelvindecosta5350
    @kelvindecosta5350 Год назад +6

    I don't necessarily hate this about JS / Web ecosystem, but I don't like it either; there are so many different tools that can combine to do the same / almost the same task.
    When I started, I was introduced to tools like ES Lint, TypeScript, Webpack, etc.
    A while back I had to deploy a no longer maintained project ("fbctf" for those that are curious) and I was introduced to a relic called Grunt.
    Now everyone is hyped about Deno, Bun, Vite, Snowpack.
    It's nice that the community is building on each other's work but I can't help but feel like everyone is reinventing the wheel.
    I can't imagine how new developers feel about this.
    The same can be said for Python's dependency management solution.
    I don't remember the XKCD strip that discusses this obsession with creating new tools that do pretty much the same thing.

    • @charlesselrachski34
      @charlesselrachski34 Год назад

      nim/go/zig/phix-lang/vlang bro , problems solved... use the better languages

    • @FADHsquared
      @FADHsquared Год назад +3

      The xkcd is something like this:
      There are 14 competing solutions, ha, we have to make a solution that works for everyone! Now there are 15 competing solutions.

    • @dealloc
      @dealloc Год назад

      Not unique to JS. C/C++ has how many compilers and tools for building C/C++ source code?
      The thing is that as languages evolved, so does the tools; As things become more standardized, tools tend to follow the good standards that makes it easier for developers to provide good UX.
      First DX was at the front, now it's the UX and the tools we have allows for better UX while also providing good DX (in terms of not having to configure everything from bottom up to provide good UX) by being more opinionated.

    • @SimonBuchanNz
      @SimonBuchanNz Год назад

      As someone who is currently sitting on an internal custom task runner script that's grown into an entire library with a plugin system, variable expansion, config file validation, dry run, caching, etc....?
      It's because it's so easy to get the 80% you care about done when you hit some case that doesn't work well with the existing tools, and it's so easy to add features after that.
      Bundling is a great example of this, where your internal crappy tool can get thrown together in an afternoon and be useful, and the existing tools are good at one thing but bad at others.
      Even then, there are only really two "real" bundlers out there right now: webpack and rollup, and the rest are all written on top of that (though the awesome swc project is working on one too, which should be amazing for my build times!)

  • @niles_5003
    @niles_5003 Год назад +11

    One time I used an object as a lookup table rather than using a Map. Turns out you can index it with the names of the members of the built-in `Object` and TypeScript won't save you. It was kind of a funny bug because it's one of those things where you can know the codebase inside and out and then you see the output being a stringified method of `Object` and if you never realized this fact before you'll think to yourself, "Where on earth could we possibly have any code that could produce such a result?" Luckily I realized pretty quickly what was going on, but I could imagine that someone could have taken many hours to figure that one out.

    • @ThePrimeagen
      @ThePrimeagen  Год назад +3

      yikes

    • @error.418
      @error.418 Год назад

      For example you used "entries" as a key?

    • @niles_5003
      @niles_5003 Год назад

      ​@@error.418 The issue was not the data that was stored inside the object. The issue was doing a lookup in the object with an arbitrary string, and expecting it to return one of the values in the object or undefined.

    • @error.418
      @error.418 Год назад

      @@niles_5003 Yeah, unless you set the object `as const` or use the `` prefix then it doesn't try to protect you, gotcha.

  • @travispulley5288
    @travispulley5288 Год назад +4

    to answer "why?" @3:43 - because the key value isn't used sometimes in forEach blocks and it makes the code tidier to ignore a var/arg in this way, but also it's available when/if you need it. Madness? Perhaps, but there is a method to it

    • @GiveMeSomeMeshuggah
      @GiveMeSomeMeshuggah Год назад

      That’s what we get for not enforcing function arity

    • @mister-zen8491
      @mister-zen8491 2 месяца назад

      So, we are all trusting the JavaScript based on 'Maybe we need it, but maybe we don't'?

  • @EvanBurnetteMusic
    @EvanBurnetteMusic Год назад +22

    Having the user name multiple implicit return variables is the root of the k v mixup. I'm surprised more people don't talk about this! Fundamentally, if programmers cannot easily see how data is being transformed, they will not be able to find and fix problems.

    • @error.418
      @error.418 Год назад

      It's not even really a mixup. Array functions like forEach, map, and filter all have consistent parameter order and in a sensible order since often for those functions the user just wants to use the value and not the index. That you can destructure the array returned by an Object.entries into [key,value] is a language feature that came much later and has a very different context. I didn't see this one as an issue at all.

    • @Yous0147
      @Yous0147 Год назад +1

      @@error.418 The implementation detail of it is logical enough, the problem comes when you use it. Logically you'd always expect key, then value, as in key-value pair. Suddenly having to deal with turning that idea around because of an implementation detail is not only problematic, it's incredibly limiting. It's not the worst here , but this aspect has bitten me numerous times when using JS libraries.

  • @sct848
    @sct848 Год назад +1

    Man your videos are very entertaining

  • @weeb3277
    @weeb3277 Год назад +13

    Atwood’s Law: “Any application that can be written in JavaScript, will eventually be written in JavaScript.”

  • @floppa9415
    @floppa9415 10 месяцев назад +2

    One that also got me good a few times are the standard lib's array functions. Some of them like filter or map return you a shallow copy but some like splice, sort, reverse don't.

    • @studiousllama4776
      @studiousllama4776 8 месяцев назад

      omg seriously. Thankfully all the major browsers now support toSorted, toReversed, etc., so hopefully soon we'll be able to start using those instead

  • @gpcureton
    @gpcureton Год назад

    I've watched the Twitch stream you made a few days ago where you wrote a plugin. I bounced around the VOD looking, but I couldn't figure out what the hell it was for. Was it so you could do the "unfolding code" animation starting at 2:56?

  • @quentincaldway
    @quentincaldway Год назад

    The"Bruh" gets me every time! 🤣. Now I need a video on 10 things you Love about rust....Yes....I'm asking for 10 lol. You're hilarious....Your brain oozes with knowledge! Appreciate the value you always give brother!
    Hope you catch a break with that project you're working on with Netflix lol can't imagine.
    ~Blessings!

  • @oskrm
    @oskrm Год назад +14

    Clearly, [] is the same as 0. IDK how you'ren't seeing it.

    • @user-he4ef9br7z
      @user-he4ef9br7z Год назад +11

      If you're drunk they even look the same.

    • @kristun216
      @kristun216 Год назад +1

      Loose comparison do be like that in dynamic languages

    • @ThePrimeagen
      @ThePrimeagen  Год назад +1

      you are perfectly correct, drunkeness is the real reason [] = 0

  • @vladimirreyes1938
    @vladimirreyes1938 11 месяцев назад +3

    The strong point of JavaScript is it's Aquiles Heel, If you try to run JavaScript from 20 years ago, in a latest version of V8 it will still run, an run better then it did 20 years before. trying to keep the compatibility of everything that you've written makes it harder to create new features y fix everything that was mistake.

  • @earthling_parth
    @earthling_parth Год назад +2

    Yayy! We will finally get to learn the history behind the name - Primeagen when this channel hits 100K subs. My theory is that it's something related to the 'next-gen(eration)' of the Optimus prime and/or maybe gaming.

  • @scottiedoesno
    @scottiedoesno Год назад +13

    Silly footgun (and one that does somewhat fall into your type coercion moratorium), but checking whether a variable is undefined vs truthy or falsy as a practice (e.g. foo && ... ) has just caused no end of headaches for my applications in the past. Probably more of a best practices thing and goes back to the community being the problem, but it's still unbelievably aggravating.

    • @ThePrimeagen
      @ThePrimeagen  Год назад +6

      yeah, i really hate that one.

    • @bigmistqke
      @bigmistqke Год назад

      I ve written a lil package for it. Rn it's pretty dumb, it just checks if the falsey is not 0 or "", cause those are the situations that i came across that really tripped me up.

    • @kevinbatdorf
      @kevinbatdorf Год назад +1

      This is a React concern. As a policy, always check item?.length > 0 and use a ternary

    • @hakooplayplay3212
      @hakooplayplay3212 Год назад

      @@kevinbatdorf yea, ?. I a nice one, but im workin on aws lambda and we have node12 here ... So damn tired of this && checks

    • @niles_5003
      @niles_5003 Год назад

      Could you give an example of a situation that trips people up? And were you using TypeScript at all?

  • @DragonRaider5
    @DragonRaider5 11 месяцев назад +3

    From my perspective the forEach is reasonable, because for arrays etc. it also gives you value first, key second. Mabye the issue was introducing these functions in the first place, no idea why for shouldn't cut it.

  • @Chris-ln3xe
    @Chris-ln3xe Год назад +2

    1:34 What is the alternative to regex? how do you validate input to an API?

  • @Rudxain
    @Rudxain Год назад +3

    2:55 actually, any kind of array of primitives will be shallow-copied, it's just that doing a deep-copy behaves exactly the same, because primitives aren't objects.
    Buffers are part of NodeJS. It seems the slice method does a pointer-copy (pass by reference) on Buffers. You should blame NodeJS, not ECMAScript

  • @nwachukwuujubuonu6345
    @nwachukwuujubuonu6345 Год назад +2

    What alternative to regex would you recommend?

  • @amirosman8797
    @amirosman8797 Год назад +3

    Totally agree with everything you say, but enough with JavaScript we are waiting for the Elixir video, we need to know your thoughts on Elixir against Go, Rust and JavaScript.

  • @effoffutube
    @effoffutube Год назад

    I like how you've twisted your rage into joviality.

  • @katjapotensky4054
    @katjapotensky4054 Год назад

    Just wondering, how would typescript catch the uint8array problem? Buffer probably extends uint8array which makes this correct behaviour as far as typescript is concerned? Special treatment for OO hierarchies just for buffers?

  • @Rodriyabala
    @Rodriyabala Год назад +1

    Prime you've uploaded a video working with the rust framework for web dev "Yew", with assembly around is there something like that but for go?

  • @b1chler
    @b1chler Год назад +2

    The single most annoying part imho is the lack of standards. There r 100x different ways of doing things one more ugly then the other. Crap gets added with every JS version but nothing gets deleted. It’s just like a teenagers room. Dirty, stinky and full of smartasses.

  • @codeman99-dev
    @codeman99-dev Год назад +2

    I've spent an extreme amount of time on build tooling. What do I hate about JavaScript?
    Modules!
    So many freaking options to package your code. No module, just use global scope! No module, just use an IIFE! AMD! CommonJS! RequireJS! Then combine shit, cause why not? UMD! Webpack! Babel! EcmaScript modules!
    That's right kids. EcmaScript modules has more than one standard. The standard module to replace all the other standards... has more than one standard implementation!

    • @Martinit0
      @Martinit0 Год назад

      Agree. So confusing. I am now using Webpack 5 to package my code, but it took me a week to set it up and make it work.

  • @muhamadluthfia2580
    @muhamadluthfia2580 Год назад

    Nice video, it works!

  • @alexIVMKD
    @alexIVMKD Год назад

    Reminded me of a clip from Fridman's podcast about how "less than ideal" languages are so widely used, quite the mystery honestly...
    It was my first language but I am seeking to accept the lord in my heart by learning some rust-lang, hopefully

  • @kinositajona
    @kinositajona Год назад +27

    As a library maintainer... my least favorite part of JS is the lack of ECMAScript feature support among the various bundlers and frameworks.
    The number of issues where "it doesn't work in my React Native app bundled with this new bundling framework that doesn't even say it guarantees support for RN... but for some reason I thought it was your fault so fix it now, slave!" is literally the body of the issue are too damn high...
    I swear, I tried moving from ES5 to ES6, and people complain about everything. BigInt has been stable and in every browser and NodeJS install under the sun for almost a decade and literally people freaked when I tried to use it and it broke their shit.
    WHY ARE WE ETERNALLY STUCK AS LIBRARY DEVS ONLY USING ES5!?!?!?!? *pulls out hair*
    I need a coffee, but it reminds me of JavaScript so I've sworn off the stuff.

    • @dealloc
      @dealloc Год назад +3

      Not sure this is bundler issue more than it is configuration/user issue. Most bundlers supports downlevelling ES (i.e. with Babel). Although not unique to JS world, I agree that tools can make end-user think OSS library maintainers are at fault for their broken software is a problem.

    • @SimonBuchanNz
      @SimonBuchanNz Год назад +1

      This is actually a case where JS is ahead of other languages, if not perfect: Rust literally just updated their minimum Linux kernel version from 2.6.32 to 3.2 - which came out nearly a decade ago. At least with JavaScript's bundling and polyfilling environment you have a fighting chance of taking a library published using all the latest and greatest features and running it in IE5.5 for Mac.
      I mean it sucks to do so, but you can...

  • @SchneiderRob
    @SchneiderRob Год назад +1

    I wasn't subscribed. I thought I was a subscriber. But I was not. Now I am. I hope you hit 100k soon dude. Love the videos. Awesome show! Great Job!

  • @craigasketch
    @craigasketch Год назад +2

    toFixed(2) returns a string got me today. Basically the entirety of Js's number system.

  • @javascripttalks
    @javascripttalks Год назад +23

    I completely agree that JavaScript was designed for web UI dev and It should be used that way. Most UI developers don't need bit manipulations anyway. Just because you can develop low level networking stuffs with js, doesn't mean you should do. I think developers nowadays are too lazy to learn another language and keep pushing javascript everywhere. Some people think C/C++ is for old people and JS is cool :D

    • @error.418
      @error.418 Год назад

      I really hope you're not writing backend with C/C++ when we have much better languages for that domain...

    • @peteschaefer
      @peteschaefer 17 часов назад

      It's also an economic thing: JS developers are cheaper and easier to get. That's why JS intrudes into areas where it shouldn't.

  • @ethernet764
    @ethernet764 4 месяца назад

    1. Regex
    2. Buffer/Uint8Array slice
    3. Map forEach
    4. Bitwise casting to 32 bit signed
    5. Community

  • @ivoevansstorrie3916
    @ivoevansstorrie3916 Год назад +8

    This got me once:
    function average(averages: number[]) {
    return averages.reduce((sum, n) => sum + n) / average.length
    }
    we divide by average.length, not averages.length, and average.length is for some reason the number of arguments the function takes.

  • @justafreak15able
    @justafreak15able Год назад +1

    @ThePrimeagen Can you make a video on how to replace Regex with a better solution for field validations and all.

  • @SirusStarTV
    @SirusStarTV Год назад

    Array.prototype methods use (value, index, array) order of arguments (reverse of array[index] -> value), you don't always need index of value when iterating over arrays. Objects aren't iterable so "for of" doesn't work for them, only "for in" for iterating over keys only, Object.entries() does give them iterable functionality and neat syntax of destructuring like [key, value].

  • @codemastercpp
    @codemastercpp Год назад

    Heyyyy, that javascript tea pouring meme was provided by me :D

  • @KirkWaiblinger
    @KirkWaiblinger Год назад +2

    setTimeout(f, 0) // f is instantly executed
    setTimeout(f, Infinity) // f is instantly executed

    • @ThePrimeagen
      @ThePrimeagen  Год назад +1

      ... no way

    • @KirkWaiblinger
      @KirkWaiblinger Год назад

      @@ThePrimeagen i see that you just dropped a whole video on this. Nice!

  • @jandresfg
    @jandresfg Год назад +3

    Storing functions as consts will always rub me the wrong way, but I've become used to it. Also, the fact that a function may or may not receive an argument is just weird -it always frustrates me when I realize something I needed in my code was given to me all along via an angument I neglected until now 😑

    • @SimonBuchanNz
      @SimonBuchanNz Год назад +2

      As in, when you're implementing a callback? That's one of the less talked about benefits of Typescript, the editor will tell you what arguments you can add. This one doesn't even need you to be writing Typescript, just have typings installed!

    • @xdman2956
      @xdman2956 Год назад +1

      all the key, value vs value,key vs wtf are the arguments make js hard to write without help of an ide, however ide suggestions mitigate this
      this is a bit worse emotioinally, cuz you realize you wasted time for worse reinvention of a wheel, tedious and rather dumb

  • @srirajnair2594
    @srirajnair2594 Год назад +5

    You said not to use regex , but what is the other alternative to that?

    • @GiveMeSomeMeshuggah
      @GiveMeSomeMeshuggah Год назад

      For HTML, use a dedicated parsing library, since HTML is not a regular language. If you’re trying to parse a regular language, there are libraries that allow you to write out a grammar and visit each node of the parse tree. This is a lot less brittle than trying to debug a manual regex parser when the spec changes. And then if you have a use case that’s not a regular grammar and/or you can’t use a library for, (I’m so sorry) reading char-by-char and parsing that way will often be faster and less error prone than a regex.

  • @noahsark9398
    @noahsark9398 Год назад

    Can someone explain the third reason to me? Is it because when you do a forEach on a Map the second argument becomes key instead of index?

  • @bcpeinhardt
    @bcpeinhardt Год назад +12

    The fact that every function is a closure (I realize this is a fundamental feature of JavaScript and one of the reasons people love it). This is less of a footgun and more of a death by one thousand cuts situation. The fact that you can't trust any single javascript function signature to let you know what data a function interacts with makes it that much harder to reason about your code, and I think this slows down refactoring especially (or at least I notice it slowing me down). If you've ever read the body of a javascript function and thought "Where the fuck is that variable coming from" you've experienced this.

    • @shimadabr
      @shimadabr Год назад

      Having studied that topic recently after seeing this feature a lot in conjuction with callbacks, i agree. It's so strange to me to have data "leaking" downstream to functions on the same scope. The fact that it's so useful and heavily used makes me wonder if it's bad or not (i'm a beginner, so idk)

    • @user-lb1ib8rz4h
      @user-lb1ib8rz4h Год назад

      @@shimadabr lack of predictable behaviour makes it harder to write code with less bugs. if someone's aware of the behaviour and using it, i feel like there's easier ways to write clearer code?

  • @jsonkody
    @jsonkody Год назад +12

    Hmm .. if you show that FOR and FOR_EACH next each other it looks strange but it's kinda consistent from other standpoint ->
    FOR just iterate on key:value pairs while those functional methods like .map .filter .forEach .. they use index just as optional second argument(or key in this case) but they always use value as first 'thing'/argument/whatever -> and they work somewhat like this in many languages I think .. so it does make sense :D
    Thx for the video

  • @jaredsmith5826
    @jaredsmith5826 Год назад +15

    In addition to the things on your list and the things you deliberately left out in the pinned comment, I would say the thing I hate the most about writing Javascript is the lack of a standard library (insert leftpad joke). How many devs start every project by pulling in lodash and moment and... but the worst part about it to me is how it leads to tragicomically fragile transitive dependency graphs: you pull in some huge popular library and you look at their dependencies and half of them are throwaway utility functions and those haven't had an update in the last 5 years. Or the author of one of them gets butthurt over something and yanks it, breaking the internet in the process. You know, the little things. Oh, and PHP has the same inconsistent API issue: some of the "find this thing in a data structure" functions are needle, haystack and some of them are haystack, needle and no one can ever remember which is which. Of course, PHP pretty much sucks in general, so maybe not worth making fun of.

    • @ThePrimeagen
      @ThePrimeagen  Год назад +8

      ok, this is a good call. the lack of std is mind boggling

    • @Winnetou17
      @Winnetou17 Год назад

      PHP pretty much sucks in general ? *massively triggered* Have you even checked it in the last 10 years ? I'll fight you to death on this bro!

    • @jaredsmith5826
      @jaredsmith5826 Год назад

      @@Winnetou17 not quite ten but it's definitely been at least 7 or 8 years since the last time I coded in it. So maybe it's better now? I've never actually met somebody actually willing to defend it as a language (plenty of people defend it as a technology choice while conceding its flaws).

    • @Winnetou17
      @Winnetou17 Год назад +3

      @@jaredsmith5826 Well, getting more serious now, it actually improved a lot. Since PHP 7.0 (now we're at version 8.1), I'd say it's a decent language. Much more static typing, less bugs, less exotic behaviours and hidden errors because 0.1% might want that feature, and general modern features.
      It has pretty regular releases, though it also followed the extremely annoying and stupid trend of only supporting a version for a couple of years, but other than that, it's going well.
      There's still some of that haystack, needle and needle, haystack nonsense, because backwards compatibility (ugly or not, there's millions of websites written in PHP, so backwards compatibility is very important).
      I like it as a language because you can easily grow with it. You can start by simply having a really simple program with several functions and ifs and fors, fully procedural. And you can expand easily and at your own pace towards fully featured OOP style, with namespaces, interfaces and traits, with autoloading. You get the idea.

  • @maxwellhunt3732
    @maxwellhunt3732 10 месяцев назад +1

    The fact that the condition undefined > 0 simply evaluates to false and doesn't cause any sort of error has caused me endless pain debugging at work. When there's a function which isn't working probably, returning undefined instead of a number, which then gets compared to 0 and there's no way of knowing.

  • @arsnakehert
    @arsnakehert Год назад +7

    The (value, key) in forEach actually makes sense and is kind of expected, typically optional arguments in programming languages come in a “most optional comes last” kind of fashion, and typically with forEach you only want to iterate over values, with the index or key being the optional argument in the lambda, so it makes sense that it comes after the “less optional” argument

    • @ThePrimeagen
      @ThePrimeagen  Год назад +7

      This is only an argument in js that makes sense. Go, rust, cpp, lua, who knows else don't do this

    • @theodorealenas3171
      @theodorealenas3171 Год назад +1

      It clicked instantly to me, when I first used it a few months ago. And that's the reason it clicked too. But yes Python doesn't do that.
      Also I thought I'm the only one who comes back to this video periodically

    • @arsnakehert
      @arsnakehert Год назад +1

      @@ThePrimeagen Sorry, when I said "typically in forEach" I meant typically in forEach as used in JS specifically

    • @CheefCoach
      @CheefCoach Год назад

      @@ThePrimeagen Lucee does. I am pretty sure that php is doing that as well.

    • @GreyDeathVaccine
      @GreyDeathVaccine 11 месяцев назад +1

      @@CheefCoach It's wierd in PHP. We have optional indexing but it is in correct order.
      With index
      foreach($array as $key => $value)
      Without index
      foreach($array as $value)
      So it is obvious. Just look for => 🙂

  • @Kaiju3301
    @Kaiju3301 Год назад +6

    JavaScript isn’t my favorite but I keep a toaster in my bathroom with a php sticker on it just in case.

    • @ThePrimeagen
      @ThePrimeagen  Год назад

      this seems to be the most reasonable

  • @owlsmath
    @owlsmath Год назад +2

    What do you use instead of regex? I understand you try not to use it if you don’t have to but what’s the better method?

    • @dealloc
      @dealloc Год назад +2

      Either minimum effort (i.e. for email only check if @ is present, send an email to the user to confirm that the email is valid), or if you must parse things like HTML or other markup, use a proper parser that can tokenize and correctly follow a spec and will likely be faster than Regex, and can sanitize user input (i.e. for HTML parsing).
      Another issue that Regex has is that it can be very slow for large inputs, which means that passing user input directly into regex validators can result in denial of service attacks (ReDoS) and halt your program indefinitely until timeout or restart.

    • @owlsmath
      @owlsmath Год назад

      @@dealloc Thanks

    • @owlsmath
      @owlsmath Год назад

      @Maksim Verkhoturov Yes makes sense. Thanks

  • @Zooiest
    @Zooiest Год назад

    More on reference types and shallow copying, if you `.fill()` a (regular) array with one, all indices point to the same object
    const arr = new Array(5).fill({});
    arr[0].a = "Hi Primeagen";
    console.log(arr[2].a);

  • @TheStruders
    @TheStruders Год назад

    TypeScript is ok when deploying to AWS Lambda or another serverless cloud function. We can get features/services out so fast, and when our company needs money, it's keeps us going

  • @BlitzkriegHD
    @BlitzkriegHD Год назад

    Gotta say, right off the bat you mentioned the global regex flag and I audibly YELLED after realizing THAT was the reason of some annoying bug in a project I have been working on. Strong start hahaha

  • @sadikkadom9566
    @sadikkadom9566 Год назад +1

    Is it possible to create the C language from Javascript to make Javascript faster?

  • @matiasbpg
    @matiasbpg Год назад +1

    First, love your videos as always. Didn't you leave Netflix? I remember a vlog you weren't happy at how that went. Now I'm not sure lol, but if you returned to Netflix I just wanna say I'm happy you.

    • @ThePrimeagen
      @ThePrimeagen  Год назад +2

      if you watched the full vid i explain at the end someone brought me back in :)

    • @matiasbpg
      @matiasbpg Год назад

      @@ThePrimeagen I missed that completely hahaha. Anyways happy for you it worked out!

  • @davidattlee2734
    @davidattlee2734 Год назад

    I want that backstory to the Primeagen. 100k special plz.

  • @bbanggdeveloper6839
    @bbanggdeveloper6839 Год назад

    why you are using node v14? is latest lts 16 is not fine?

  • @anch072
    @anch072 Год назад

    Can this be fixed with the new ES updates, has there been a proposal? Will, it even get addressed in the future?

  • @xBZZZZyt
    @xBZZZZyt Год назад +1

    02:58 you can use
    Uint8Array.prototype.slice.call(buffer,start,end)
    to always deep copy

  • @oussamabouchebak6877
    @oussamabouchebak6877 Год назад

    So you suggested we avoid using regex, so what's an alternative to testing a pattern on a string?

    • @fearmear
      @fearmear Год назад +1

      Use String.prototype.match instead

  • @bernhardposselt6467
    @bernhardposselt6467 10 месяцев назад +1

    [1, 2, 10].sort() => [ 1, 10, 2 ]
    Because sort coerces everything in the array into strings in the sort method. HF debugging

  • @tah3460
    @tah3460 Год назад +3

    Sort() defaulting to sorting lexiographically, despite dealing with numbers.

  • @iqtutorials2891
    @iqtutorials2891 Год назад

    Ok We are now at ES 8 or 9
    Let and const intreduced in es 6 (2005) . Whay are you using Var ?

  • @t3dotgg
    @t3dotgg Год назад

    Banger video tbh

  • @marcomongalo3328
    @marcomongalo3328 Год назад +3

    Not using regex patterns? What's the alternative you guys use?

    • @ThePrimeagen
      @ThePrimeagen  Год назад

      parser

    • @marcomongalo3328
      @marcomongalo3328 Год назад +1

      @@ThePrimeagen which type? Although parsers require more code and are slower for short convoluted patterns. Don't you think?
      On the other hand, parsers are more easily read by humans.
      Wouldn't regex be "blazingly fast" compared to parsers ?
      Don't get me wrong, I love me some PEGs

  • @brentlio5578
    @brentlio5578 5 месяцев назад

    The best place to use regex is for things that you know for a fact that has a very rigid and predictable pattern. Like repetitive codes and languages.
    Or just a quick tool for extracting data from large amount of text that you need very often.
    What regex is really not good at is filtering things that are potentially bad for your purposes.

  • @Hunsenbargen
    @Hunsenbargen Год назад

    I don't know why, but I just laugh at the Map/forEach thing. It's so dumb hahahaha.
    Btw, what do you think about .NET? is there any chance for a video about .NET vs Rust vs Go?

  • @taragnor
    @taragnor Год назад +2

    My personal favorite is that NaN (not a number) has the type "number."

  • @anisoseryx
    @anisoseryx Год назад +17

    Lemme add number 6, this keyword with functions
    When I started to learn I used a normal anonymous function instead of arrow function within a class, i never suffered like that hour all I needed was the arrow function
    Number 7 threading: the reason why I switched to another lang whenever I needed threading it's pain =(

    • @ThePrimeagen
      @ThePrimeagen  Год назад +14

      hah. I didn't want to talk about this. everyone knows about this being a bit confusing. And threading! Its the reason why people _like_ javascript unironically.

    • @sagarrajak6996
      @sagarrajak6996 Год назад +5

      Use promise brooo

    • @anisoseryx
      @anisoseryx Год назад

      @@ThePrimeagen I liked at first too I was like woaaa it's cool but it's absolutely painful xd

    • @parlor3115
      @parlor3115 Год назад +5

      @@anisoseryx No it's not. Promises is a really great API and I see a lot of languages having a similar approach to async programming.

    • @anisoseryx
      @anisoseryx Год назад

      @@parlor3115 the prove isn't with promises I use them all the time dw, it's for certain cases where threading becomes painful like when I made a discord api wrapper I needed some variables to be shared and it was a real pain to get it done since my variables were constantly changing and needed to be updated across all threads, you can see how complex this problem can be by checking djs code they do that too. Long story short threads are nice but Javascript isn't made for this and I prefer to use another language like csharp to tackle it

  • @lpanebr
    @lpanebr Год назад +2

    In love regular expressions!

  • @petarkolev6928
    @petarkolev6928 Год назад

    If not using Regrets (RegEx) fpr email than how one should validate email?

  • @stephenJpollei
    @stephenJpollei Год назад +4

    I actually really like regexps, but never use the g flag. I also tend to write regexps that are anchored and don't have multiple ways that they can match. I kind of wish that raku style regexps and friends were available in more languages.
    The using signed 32bit for bit-ops is super gross.

  • @adrianburgoscolas520
    @adrianburgoscolas520 Год назад +1

    i've just been bitten by the bitwise operation thing 🤣

  • @EvanBoldt
    @EvanBoldt Год назад +2

    The worst one to me is the behavior of "this" on UI callbacks like click.

    • @ThePrimeagen
      @ThePrimeagen  Год назад

      Shockingly that's never bothered me. The rule is stupid, but I get it

  • @HuntingKingYT
    @HuntingKingYT Год назад +2

    JavaScript: "is slow"
    Python:

  • @mjrduff-gaming2365
    @mjrduff-gaming2365 Год назад +1

    Last time in typescript, I figured out that, any regexp for an HTML file does not show you all groups that match you regexp. If you write it like that /href="(\/[\w]+)"/g or as new RegExp(/href="(\/[\w]+)"/, "g")
    It matches only the first match while using exec, but string.match shows you all matches. But no groups, only full matches

    • @dealloc
      @dealloc Год назад

      Don’t use regex to parse HTML. Ever.

  • @Kotfluegel
    @Kotfluegel 10 месяцев назад

    2:54 I don't get this part. A buffer is just an array of primitives. Shallow copy or deep copy, doesn't matter. It's the same. Or do you mean, the slice method creates a view on buffer with changed begin and end indices?

  • @MrPoselsky
    @MrPoselsky Год назад

    How would you compare it to Elm?