You Don't Need Try/Catch Anymore With This New Operator

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ต.ค. 2024

ความคิดเห็น • 212

  • @CoderOne
    @CoderOne  2 หลายเดือนก่อน +4

    If you want to shape the future of this proposal you can join an upcoming conversation Aug 25 on a google meet meeting with the author github.com/arthurfiorette/proposal-safe-assignment-operator/issues/28

    • @etherweb6796
      @etherweb6796 2 หลายเดือนก่อน

      This can already be done without a new operator with vanilla JS.

  • @anasouardini
    @anasouardini 2 หลายเดือนก่อน +272

    I liked treating errors as values as soon as I encountered it in Golang.

    • @DaPaBe1999
      @DaPaBe1999 2 หลายเดือนก่อน +2

      Amen

    • @GJCloud
      @GJCloud 2 หลายเดือนก่อน +2

      Still better then try catch

    • @WorkerThreads
      @WorkerThreads 2 หลายเดือนก่อน +1

      In js they try to do like in golang, and golang is already thinking about a new alternative like in zig

    • @--bountyhunter--
      @--bountyhunter-- 2 หลายเดือนก่อน

      wassup akhi. hry?
      WP sucks btw

    • @voltflake
      @voltflake 2 หลายเดือนก่อน +2

      zig has op error handling

  • @steve-adams
    @steve-adams 2 หลายเดือนก่อน +33

    Although this is an improvement over try/catch and I appreciate the Go-ness of this pattern, I still prefer pattern matching on Result in Rust with the Ok and Err methods far more. If we could get pattern matching into JS (still in stage 1), I'd be so stoked to have a Result-like convention instead of Symbol.result. Regardless, this is better than what we've got.

    • @CoderOne
      @CoderOne  2 หลายเดือนก่อน +1

      Can't agree more!

    • @Tijme
      @Tijme 2 หลายเดือนก่อน +2

      True, but you can easily implement this yourself now with this new operator!

    • @ncpurge789
      @ncpurge789 2 หลายเดือนก่อน

      const result ?= funcThatCanFail();
      if (result[0]) console.error("error");
      else console.log(result[1]);

    • @etherweb6796
      @etherweb6796 2 หลายเดือนก่อน

      All of these things can be implemented with current JS. Write a factory/decorator function that returns a proxy with an Apply handler that uses try/catch and then returns an error or a result (based on the try/catch), then do a switch based on instanceof the resulting object. Then decorate any function you want to make it return an optional result. JS is super flexible without having to add new features, and we should be using the existing ones over adding new ones to make it like other languages.

    • @JiggyJones0
      @JiggyJones0 2 หลายเดือนก่อน

      ​@@etherweb6796 🤢🤢

  • @rjtdas
    @rjtdas 2 หลายเดือนก่อน +129

    It's like Go's error handling but with JavaScript's flair.

    • @eduardmart1237
      @eduardmart1237 2 หลายเดือนก่อน

      yep.

    • @forinda
      @forinda 2 หลายเดือนก่อน

      Thought the same thing.

  • @TianYuanEX
    @TianYuanEX 2 หลายเดือนก่อน +47

    Damn, this is actually amazing. One of the few useful things missing in JS will be added natively, no need to write try-catch wrappers that do this 😄

    • @deathineyes
      @deathineyes หลายเดือนก่อน

      Imagine the code after that statement. What logic it would be required to handle error case and non error case? If-else? Isn't the same?

  • @andrewk2756
    @andrewk2756 2 หลายเดือนก่อน +53

    >Don't Need Anymore
    >Proposal under active development

    • @Александр-ч4п5ъ
      @Александр-ч4п5ъ 2 หลายเดือนก่อน

      😢

    • @russellchido
      @russellchido 2 หลายเดือนก่อน

      >don't need anymore **with this**

    • @andrewk2756
      @andrewk2756 2 หลายเดือนก่อน +2

      @@russellchido but you don't have *this* since it's not released.

    • @theseangle
      @theseangle หลายเดือนก่อน

      ​@@andrewk2756learn English language

    • @michawhite7613
      @michawhite7613 หลายเดือนก่อน

      In it's current state, not being considered

  • @Voidstroyer
    @Voidstroyer 2 หลายเดือนก่อน +27

    Here are my thoughts:
    - This is obviously inspired by Go.
    - We use try/catch because we don't know if a function can throw an error or not. This proposal doesn't solve that problem. It kinda just adds an easier way to use try/catch but for individual functions. So instead of try {a(); b(); c()} catch (error) {...}, we will have let [errA, resA] ?= a(); [errB, resB] ?= b(); [errC, resC] ?= c();, which is equivalent to try {a()} catch (errA) {}; try {b()} catch (errB) {};try {c()} catch (errC) {}.
    - Without knowing if a function can throw or not, you would have to use this new operator for pretty much every function call unless you absolutely know that the function can not throw.
    It's still a step in the right direction though.

    • @Cypekeh
      @Cypekeh 2 หลายเดือนก่อน +2

      you could just do
      const [err, res] ?= (() => {a(); b(); c();})()
      But it's better to handle errors individually, because you know exactly what failed

    • @Mr.BinarySniper
      @Mr.BinarySniper 2 หลายเดือนก่อน +2

      ​@@CypekehYeah. you are right. the mentioned way is really awesome

    • @Voidstroyer
      @Voidstroyer 2 หลายเดือนก่อน +7

      @@Cypekeh That's a cleaner way to write it for sure, but it is exactly the same as doing try/catch in the first way I wrote it. It's just syntactic sugar and it doesn't solve the underlying problem.

    • @bricecarpentier5817
      @bricecarpentier5817 2 หลายเดือนก่อน

      @@Voidstroyerto be fair you just summed up JavaScript 😅

    • @Voidstroyer
      @Voidstroyer 2 หลายเดือนก่อน +1

      @@bricecarpentier5817 Lol you know I was thinking the exact same thing as I was writing my comment. The underyling problems of Javascript can't be solved anymore so they are just focusing on how to get developers to write prettier code.

  • @CoderOne
    @CoderOne  2 หลายเดือนก่อน +2

    You can try out the new operator by cloning this repo:
    github.com/ipenywis/safe-assignment-operator-demo

  • @farzadmf
    @farzadmf 2 หลายเดือนก่อน +102

    It's funny; LOTS of people complain about Go's error handling being verbose, and now this proposal is suggesting to mimic Go's behavior!

    • @chudchadanstud
      @chudchadanstud 2 หลายเดือนก่อน +31

      Go's error handling is very nice actually. You know that something returns an error and you know how it should be handled and you don't have to worry about it taking down your system.

    • @farzadmf
      @farzadmf 2 หลายเดือนก่อน +8

      For sure, forgot to mention that I'm personally not part of the "LOTS of people" I mentioned 😉

    • @lack_of_awareness
      @lack_of_awareness 2 หลายเดือนก่อน +4

      It’s very verbose, a Result generic type with syntax support in the language will always be superior

    • @Mr.BinarySniper
      @Mr.BinarySniper 2 หลายเดือนก่อน

      You know what. ?? you are funny.. I think its really a nice feature.

    • @bring-shrubbery
      @bring-shrubbery 2 หลายเดือนก่อน +3

      Also LOTS of people don't handle errors at all, then you have to deal with it either as a user, or as a developer who's thrown into that project to fix it :D

  • @henrique-work
    @henrique-work 2 หลายเดือนก่อน +5

    Looks a good alternative to try-catch

  • @quietfox157
    @quietfox157 2 หลายเดือนก่อน +2

    There's another proposal that comes into play with this. If you don't want to accept a value you will be able to use the keyword 'void' instead, like this:
    const [void, result] ?= await fetch(...)
    (why? Readability. And the current solution of just skipping bindings causes some real issues in combination with trailing commas. Like does "const [,,] = arr" try to get two or three values? Could be both.)
    (edit: I forgot the question mark 🤣)

  • @steadexe
    @steadexe 2 หลายเดือนก่อน +4

    This is what we needed for so long!

  • @quietfox157
    @quietfox157 2 หลายเดือนก่อน +1

    This is SO good. I never understood the concept of try/catch anyway. Like, errors/exceptions are thrown on a expression or statement level. Then why is handling these done on a BLOCK level instead? That's a completely different context. That never made sense to me.

  • @crowleyeusford7886
    @crowleyeusford7886 2 หลายเดือนก่อน +12

    JavaScript keeps making us surprised!

    • @CoderOne
      @CoderOne  2 หลายเดือนก่อน +1

      More weird syntax is incoming!

  • @rafageist
    @rafageist 2 หลายเดือนก่อน +4

    It's still a draft. In the meantime you can do this:
    ```javascript
    const attempt = (operation) => {
    let result = null;
    let error = null;
    try {
    result = operation();
    } catch(err) {
    error = err;
    }
    return [error, result];
    };
    const attemptAsync = async (operation) => {
    let result = null;
    let error = null;
    try {
    result = await operation();
    } catch(err) {
    error = err;
    }
    return [error, result];
    };
    ```

    • @vsDizzy
      @vsDizzy 2 หลายเดือนก่อน +1

      you can await non-promises and have only one wrapper function

    • @rafageist
      @rafageist 2 หลายเดือนก่อน

      ​@@vsDizzy Marking a function as async when it doesn't perform any asynchronous operations is considered bad practice because it can lead to unnecessary confusion for those reading the code and propagate the need to handle these functions with async/await, adding unnecessary complexity.

    • @vsDizzy
      @vsDizzy 2 หลายเดือนก่อน

      @@rafageist i see

  • @shahbaz_shueb
    @shahbaz_shueb 2 หลายเดือนก่อน +2

    Wow. This is amazing. Will make live easier for devs.

  • @ReasonX3
    @ReasonX3 2 หลายเดือนก่อน +11

    According to the proposal the error go first, because a programmer can forget about the error, if it'll be the second element of the cortege? Here is the qoute:
    "If someone is using ?= as their assignment operator, it is because they want to ensure that they handle errors and avoid forgetting them. Placing the data first would contradict this principle, as it prioritizes the result over error handling."
    If I already use the operator "?=", I already know their might be an error. Why would I forget about it?
    Another qoute:
    "In Go, the convention is to place the data variable first, and you might wonder why we don't follow the same approach in JavaScript."
    I suspect most other languages would go for similar approach - data go first. Why JS should be an different? It only adds confusion, especially for those devs who use several languages in on project and constantly switch between them.
    Let's also not forget about multiple JS libs that use data first approach as well.

    • @teamadostamine9657
      @teamadostamine9657 2 หลายเดือนก่อน

      Addind to that, even IF you forget it, i'm sure this is a very simple lint option to create and add to the project

    • @arjix8738
      @arjix8738 2 หลายเดือนก่อน

      ​@@teamadostamine9657you wouldn't even need a special lint rule for this
      The typescript linter would complain if you used the unknown error value instead of the typed data value in the wrong places

    • @mrwensveen
      @mrwensveen 2 หลายเดือนก่อน

      There's already precedent in the Either monad that places the error in the Left. But other than that, I think in JS you'd be able to write "var [result] ?= blah();" and forget about the error if the result is first, while "var [_, result] ?= blah();" makes you explicitly discard the error value.
      Pedantic: both the error and the result are data, so it actually doesn't break the paradigm 🙂

  • @etherweb6796
    @etherweb6796 2 หลายเดือนก่อน +1

    This sorta thing is cool, but it also makes me kinda sad because we can already do exactly what this does without this operator, and just a few lines of JS. I see other comments saying "we should have a Rust style Ok/Err Result syntax added too". This just makes me feel like people don't write JS anymore - Both can be achieved quite easily:
    // Implementation
    class Ok {
    constructor(data) {
    this.result = data
    }
    }
    class Err {
    constructor(data) {
    this.error = data
    }
    }
    function makeOptional(func) {
    if (typeof func !== 'function') throw Error("Can't make a non-function object optional");
    return new Proxy(func, {
    async apply(target, thisArg, args) {
    try {
    const ok = new Ok(await func.apply(thisArg, args));
    return ok;
    } catch (error) {
    return new Err(error);
    }
    }
    });
    }
    // End Implementation
    // Demonstration
    const optionalFetch = makeOptional(fetch);
    // ?= Style error handling
    const { error, result } = await optionalFetch("/index.html");
    if(error) {
    console.error('Error fetching index.html', error)
    } else {
    console.debug('Fetched index.html', result);
    }
    // Rust Result style handling
    const Result = await optionalFetch("/index.html");
    switch(result.constructor.name) {
    case 'Ok':
    console.debug('Fetched index.html', Result);
    break;
    case 'Err':
    default:
    console.error('Error fetching index.html');
    }
    // End Demonstration

  • @DiogoLScarmagnani
    @DiogoLScarmagnani หลายเดือนก่อน

    It would be a very good approach, I hope they release this.

  • @babatundeojerinde
    @babatundeojerinde หลายเดือนก่อน

    I don't think there's anything wrong with try-catch or using Promise.catch. I have mixed feelings about this operator. I'm not sure I'll be motivated to use it. How do you determine there's an error? Are you going to use if(error)? With try-catch, you have different blocks dedicated to normal flow and error handling. This blurs that line. Readability might be an issue

  • @karamuto1565
    @karamuto1565 หลายเดือนก่อน

    Before that we would need a "Symbol.doesError" added to all functions in JavaScript that can throw an error s.t. we can actually detect which ones need error handling.

  • @Jamiered18
    @Jamiered18 หลายเดือนก่อน

    In the proposal examples, they should really be setting the cause in the constructors of their new errors. People often forget to do that, it hides the original error

  • @eugeneponomarov7429
    @eugeneponomarov7429 2 หลายเดือนก่อน +1

    It's like error handling in go, but there error is the second argument. I think it's completely useless for js, since nobody is using fetch in place, usually it's a class or function wrapper for http calls, or axios.
    One more thing: almost everybody loves to catch and throw in js, so this one will be a dead feature anyway, it can make sense if js will ban try/catch which will never happen.

  • @marcusradell7544
    @marcusradell7544 2 หลายเดือนก่อน

    If this puts pressure on TypeScript to treat errors as normal values with types, I'm all in!

  • @okadz7037
    @okadz7037 2 หลายเดือนก่อน +2

    good morning js, thanx bro for this great content

  • @JoseHenrique-xg1lp
    @JoseHenrique-xg1lp 2 หลายเดือนก่อน

    I like this. Not all exceptions should make my code panic.

  • @pokefreak2112
    @pokefreak2112 2 หลายเดือนก่อน +2

    This is a very bad idea. Exceptions are one of the worst parts of js, you can throw literally any value and the language has no mechanism of only catching a specific kind of error.
    It seems like the idea behind this proposal is just syntax sugar for a Result mechanism, but basing it on exceptions means you can't know what the type of the error actually is.
    It also encourages you to write more code that throws exceptions so you can use the pretty new syntax, which is just making the problem worse.

  • @ugentu
    @ugentu หลายเดือนก่อน

    I curious why not returning objects like
    const {error, result} ?=...
    With deconstruction, you can pick the parameters you need and don't stick to the parameters order, which is always a source of dummy errors.
    And I'm kind-of sceptical on "the main point" which is force to handle errors.
    Why should I? In most cases, I'm primarily concerned with "do I have required data or not?" and branch my logic accordingly.
    Error message are good for debutting\logging purposes, and yeah, it's better to have them, but why force?
    Easily accessible error message without the mess of try-catch will bump the error handling to the moon already.
    Other outcomes about code organisation, variable scope are much valuable

  • @elontang2358
    @elontang2358 2 หลายเดือนก่อน +1

    Like golang. But why not error is the second parameter?

  • @carloshenriquefonseca8459
    @carloshenriquefonseca8459 หลายเดือนก่อน

    Why they dont put the error as second value of result array? I think wuold be more convenient.

  • @mfpuente
    @mfpuente 2 หลายเดือนก่อน +1

    I like this approach better than using try-catch blocks, but it's just another way of writing JavaScript. I mean that since we have to maintain compatibility with previous versions of JavaScript, there are different ways of programming to solve the same problem. And we have to learn to read and write in the ways we like and the ones we don't in order to be able to contribute our solution to different projects. But it's the JavaScript way.

    • @arjix8738
      @arjix8738 2 หลายเดือนก่อน

      This wouldn't replace try/catch even if we did not care about backwards compatibility.
      It is not equal to a try/catch block, since a try/catch block can contain multiple lines of code, aka multiple statements.
      To imitate such behaviour with this operator you'd have to make an immediately invoked function that has the multiple statements.
      e.g.
      const [error, data] ?= (()=>{
      // statement 1
      // statement 2
      })();

  • @oussamasethoum1665
    @oussamasethoum1665 2 หลายเดือนก่อน

    this is beautiful but I think if they can add multiple return values from a function like golang it will do the trick.

  • @macon5696
    @macon5696 หลายเดือนก่อน

    does this feature gives ability to use promise in synchronous function?

  • @ErnestOak
    @ErnestOak 2 หลายเดือนก่อน +1

    Kind of like the callback signature

  • @m2g5
    @m2g5 2 หลายเดือนก่อน

    is like Golang of await-to-js/ts (older libs async await wrapper for easy error handling)

  •  2 หลายเดือนก่อน

    Thank you for the video, 👍
    So little bit confused as low level js developer , Can Someone guide me what is proper way of using try and catch beside simple usage and how to handle the exceptions ?

  • @dimitro.cardellini
    @dimitro.cardellini 2 หลายเดือนก่อน

    Actually, it seems that using ?= leads to implicit error ignoring.
    There is an issue with catching falsy or nulish exceptions
    And finally, the Polifill doesn't polifills. Syntax couldn't be polifiled ,and Symbol.result is excessively used in this proposal.
    I think this proposal doesn't have chances to be ever approved

  • @offgridvince
    @offgridvince หลายเดือนก่อน +1

    I like it

  • @superlogic255
    @superlogic255 2 หลายเดือนก่อน

    It would make the code Golang-esque, which is nice.

  • @xenon-x54
    @xenon-x54 2 หลายเดือนก่อน

    what theme are you using?

  • @НаильШайхинуров-п7л
    @НаильШайхинуров-п7л 2 หลายเดือนก่อน

    Just use the Either monad! It’s actually more fp style

  • @IceMetalPunk
    @IceMetalPunk 2 หลายเดือนก่อน

    I always create a little helper/wrapper function -- which I put in an object so I can call it `safe.ly()` 😁 -- that does exactly this for any promises. It would certainly be nice to have it build into the language.
    (To be clear on my version: it lets you do something like `const [response, error] = await safe.ly(somePromise(...))` . And is TypeScript safe. It's *so* nice not having to chain `.then.catch` and also not having to `try...catch...` around every promise. But I also specifically like having the error be second, to be able to ignore errors/rejections if desired -- for future handler implementation later -- without them bubbling up, simply by declaring a one-element destructuring. I understand why they want to do it the other way around, though.)

  • @chrisfelicien
    @chrisfelicien 2 หลายเดือนก่อน

    This will be great

  • @jorgehabib3933
    @jorgehabib3933 2 หลายเดือนก่อน

    Does any one know what are the possibilities of this becoming a real feature of JavaScript? I simply loved it!! Even if there is a chance of it becoming a feature of the language, i assume it would take several years, right? 😢

  • @karakaz
    @karakaz 2 หลายเดือนก่อน

    Not ideal for functional programming but curious to see how it plays out

  • @MyGeorge1964
    @MyGeorge1964 2 หลายเดือนก่อน

    What is the actual code under the hood...

  • @mohanedomer9081
    @mohanedomer9081 2 หลายเดือนก่อน +1

    that would be soo cool

  • @papa_ethan
    @papa_ethan 2 หลายเดือนก่อน

    try/catch catches all errors, this proposal catches the specific error from the current async function

    • @CoderOne
      @CoderOne  2 หลายเดือนก่อน

      It caches any error thrown inside the target function. Any thrown exception.

  • @vicca4671
    @vicca4671 2 หลายเดือนก่อน

    Almost like Lua's protected calls.

  • @olhoTron
    @olhoTron 2 หลายเดือนก่อน

    Why [error, result] and not [result, error]?

  • @gamingwolf3385
    @gamingwolf3385 2 หลายเดือนก่อน

    Really cool , i like your content bro , next time course about react motion

    • @CoderOne
      @CoderOne  2 หลายเดือนก่อน

      Ty dude! Hopefully soon

    • @gamingwolf3385
      @gamingwolf3385 2 หลายเดือนก่อน

      Thank you a lot 💪

  • @zenoviyfil
    @zenoviyfil หลายเดือนก่อน

    I simply dont understand the main reason they invented it, I think new feature should simplify code, and by that I mean make it shorter, so if my try&catch function has 10 rows the new operator ?= has to do it in 5 rows or still UNDER 10. But this looks pretty much the same length.

    • @Robert-yw5ms
      @Robert-yw5ms หลายเดือนก่อน +1

      Biggest advantage I see is when coupled with typescript. In typescript you can just ignore thrown errors but with this you have to either handle the error or explicitly pass it up in the call chain.

  • @RatherBeCancelledThanHandled
    @RatherBeCancelledThanHandled 2 หลายเดือนก่อน

    This is really cool

  • @ransomecode
    @ransomecode 2 หลายเดือนก่อน

    I usually do:
    ```
    let error
    const value = await something().catch(e => void (error = e))
    ```

  • @sudeep.g
    @sudeep.g 2 หลายเดือนก่อน

    Let's gooo! errors as values ftw

  • @shyrogan2341
    @shyrogan2341 2 หลายเดือนก่อน +2

    Everyone is slowing turning into rust/go

  • @talhaibnemahmud
    @talhaibnemahmud 2 หลายเดือนก่อน

    I want this so bad

  • @wojciechosinski5927
    @wojciechosinski5927 2 หลายเดือนก่อน +1

    Alright fine, but why error is first?

    • @CoderOne
      @CoderOne  2 หลายเดือนก่อน +1

      github.com/arthurfiorette/proposal-safe-assignment-operator?tab=readme-ov-file#why-not-data-first

    • @arjix8738
      @arjix8738 2 หลายเดือนก่อน

      Because they didn't want to just copy homework.

  • @altermunmis
    @altermunmis 2 หลายเดือนก่อน

    I felt like coding JavaScript when coding go, now I feel like coding go when coding JavaScript 😅

  • @zebraforceone
    @zebraforceone 2 หลายเดือนก่อน

    Typed catching would be preferable

  • @chess4964
    @chess4964 2 หลายเดือนก่อน

    So Go is the way to Go?

    • @CoderOne
      @CoderOne  2 หลายเดือนก่อน

      This should be the new javascript slogan

  • @algonix11
    @algonix11 หลายเดือนก่อน

    and then you exchange a try catch for a workaround and an if. It's the same thing with other makeup.

  • @WorkerThreads
    @WorkerThreads 2 หลายเดือนก่อน

    In js they try to do like in golang, and golang is already thinking about a new alternative like in zig

  • @vitorhideyoshinakazonebati7531
    @vitorhideyoshinakazonebati7531 2 หลายเดือนก่อน

    YESSSS!!! ERRORS AS VALUES!!! As the lord intended

  • @zbynekriha
    @zbynekriha 2 หลายเดือนก่อน

    oh, it looks more like functional aproach without pipe.

  • @taquanminhlong
    @taquanminhlong 2 หลายเดือนก่อน +9

    If error !== null 😂

    • @senselessplays
      @senselessplays 2 หลายเดือนก่อน +2

      Is still useful because null consider as 0 so - if(error) return Error

    • @ДмитрийГоловенчик
      @ДмитрийГоловенчик 2 หลายเดือนก่อน +2

      You don't understand it's joke from GO)

    • @theairaccumulator7144
      @theairaccumulator7144 หลายเดือนก่อน

      😂 if I worked recruitment at a company and a candidate wrote that in front of me there's no chance they'd get hired

  • @Mestre_tainha
    @Mestre_tainha 2 หลายเดือนก่อน

    Great content. BTW, you sound a little like walter white's son.

  • @maximenadeau9453
    @maximenadeau9453 2 หลายเดือนก่อน

    If only TS had native support for errors as values like rust or zig.

  • @Georgggg
    @Georgggg หลายเดือนก่อน

    try/catch in javascript is ugly, because you have scope in try block, and whatever you declare here, you can't access after.
    So, this potentially can remove annoying try/catch in a codebase entirely, without needing wrappers around native fetch, for example.

  • @nanonkay5669
    @nanonkay5669 2 หลายเดือนก่อน

    Heavily inspired by Go, I see

  • @joshiboshi6140
    @joshiboshi6140 2 หลายเดือนก่อน +2

    That’s syntactic sugar, but I’d prefer to be able to see if a function throws like in Java and be forced to handle the throw 😅

    • @theairaccumulator7144
      @theairaccumulator7144 หลายเดือนก่อน

      At least we should know if it throws, oftentimes you want an error to bubble up to the top of the request handler and just log and/or return an error response.

  • @PhilipAlexanderHassialis
    @PhilipAlexanderHassialis 2 หลายเดือนก่อน

    12:40 "...imagine having 3 or 4 levels try-catches one inside of another...."
    Average Java engineer: "first time?"

    • @nivethan-me
      @nivethan-me 2 หลายเดือนก่อน

      is it same issue in Java?

    • @PhilipAlexanderHassialis
      @PhilipAlexanderHassialis 2 หลายเดือนก่อน

      @@nivethan-me Well, first of all, Java is built in such a way that if a function has a chance to throw, it must be declared as such - this happens with the built in language primitives too. So, the developer knows if something throws. This leads to funny chains of try-catches which is fun to think about and a living hell to work with. But on the other hand, things do not go haywire and the applications do not crash in an unexpected way. Most of the time.

  • @justafreak15able
    @justafreak15able 2 หลายเดือนก่อน

    ah finally let's 'GO'

  • @cotyhamilton
    @cotyhamilton 2 หลายเดือนก่อน

    I love this

  • @dxbgaming4813
    @dxbgaming4813 2 หลายเดือนก่อน

    Yeah it's the Go's way, it's easy to handle errors.

  • @729usbow
    @729usbow 2 หลายเดือนก่อน +1

    Dont be happy, stage 0 proposals can take 10 years or more to get to the actual JavaScript and some despite being good never get to JavaScript

  • @thejimmylin
    @thejimmylin 2 หลายเดือนก่อน +2

    Go always kept two cups on the bedside table. One cup had water, while the other was always empty.
    Rust was very puzzled and asked, "Why do you keep two cups here all the time?"
    Go replied, "Because I need to drink water when I wake up at night."
    Rust then asked, "But why do you need an empty cup?"
    Go responded, "What if one day I wake up and don't feel like drinking water?"

  • @MrEliteXXL
    @MrEliteXXL 2 หลายเดือนก่อน

    Great

  • @muratcemyalin
    @muratcemyalin 2 หลายเดือนก่อน

    next propose "You don't need to javascript anymore ..." :)

  • @michawhite7613
    @michawhite7613 หลายเดือนก่อน

    I hate the multi value return. Use a Result type.

  • @Zeero3846
    @Zeero3846 2 หลายเดือนก่อน

    I wish this would get into Java, and by Java, I mean Java 8 or 11, because no one uses later versions. Exceptions are the bane of what little terseness the language has.

  • @OneBrighDay
    @OneBrighDay 2 หลายเดือนก่อน

    Crazy

  • @elvispalace
    @elvispalace 2 หลายเดือนก่อน +1

    bro, it's a proposal

  • @zephilde
    @zephilde หลายเดือนก่อน

    This is waaaaay too close to ??= (already shipped) for it to be any close to be accepted...
    Plus, it's not needed by any good devs ;)

  • @shekharsikku
    @shekharsikku 2 หลายเดือนก่อน

    I think this should be in all programming languages, Like it is already in golang 😅

  •  หลายเดือนก่อน

    Instead of having bazillion try catch, we have bazilion err != nil

  • @nomadshiba
    @nomadshiba 2 หลายเดือนก่อน +1

    i dont like it returns a tuple and not a union

    • @CoderOne
      @CoderOne  2 หลายเดือนก่อน

      Union??

    • @tjtjtyjtyjt
      @tjtjtyjtyjt 2 หลายเดือนก่อน

      @@squishy-tomato yeah but yr variable name looks weird
      errOrResult

  • @KonradZielinski
    @KonradZielinski 2 หลายเดือนก่อน +1

    This is an awful proposal. The nice thing about try catch is that it makes it explicit that you are handeling errors. this proposed operator just makes the error handling less explicit.

  • @dodgeclub7162
    @dodgeclub7162 2 หลายเดือนก่อน

    JS become GO

  • @gamingwolf3385
    @gamingwolf3385 2 หลายเดือนก่อน

    I think this idea is stolen from golang, because in golang functions can return two values data and error the same idea but with a tuple , yeah kts great so you can handle errors in local not in global no need for one try catch but you will have opportunity for more try catches for more flexibility in error handling

    • @impostor8984
      @impostor8984 2 หลายเดือนก่อน +2

      This looks similar to the one in go but this kind of pattern exist since forever. In C there's error codes. In most functional programming languages like Haskell, Scala, instead of try catch they use a monadic approach which is using Either, in Rust there's something similar also called Result. Personally I think this is a superior way of handing errors instead of try catch especially using monad/functor but that's a topic for another day

    • @RaZziaN1
      @RaZziaN1 2 หลายเดือนก่อน

      same in .net, java and rust. so it's not really stolen from go

  • @jfftck
    @jfftck 2 หลายเดือนก่อน

    This is JavaScript, how is it enforcing the handling of the error? Because, unlike Go, you can assign variables and not use them. This doesn’t make any improvements to the language, it just means more syntax and another way to do the same thing as before.
    JavaScript needs to have a new mode that would force variable usage. Additionally, it would be nice for all languages to have some kind of syntax to indicate that an error could be returned from a function, this would provide information immediately when calling the function. I like the idea of function names ending with a symbol, like “?”, where a function named “fetch?” would be expected to have errors in certain cases.

  • @ralkey
    @ralkey 2 หลายเดือนก่อน +1

    I think this proposal is awful.
    It is not clear enough from a glance what ?= does, and when I first saw it, replacing try-catch was my last expectation.
    Also, changing the output, just because you changed the assignment operator, is going to cause a lot of confusion and is very human error-prone, especially when converting an existing codebase to use this.

  • @EduarteBDO
    @EduarteBDO 2 หลายเดือนก่อน

    Javascrypt looking a bit like Rust

  • @everyhandletaken
    @everyhandletaken หลายเดือนก่อน

    LGTM !

  • @rafageist
    @rafageist หลายเดือนก่อน

    The assignment operator should not have the responsibility of flow control

  • @Robert-yw5ms
    @Robert-yw5ms หลายเดือนก่อน

    throw null

  • @teknolovedigital
    @teknolovedigital 2 หลายเดือนก่อน

    If (error !=== null) 😅

  • @cxarra
    @cxarra 2 หลายเดือนก่อน

    JavaScript (Go edition)

  • @0X_0LL4R-
    @0X_0LL4R- 2 หลายเดือนก่อน +1

    like Golang do !, hey JS stop cheating

  • @aldialfarnando6813
    @aldialfarnando6813 หลายเดือนก่อน

    your opinion * 2