Ok, I was skeptical at first, but this is pretty nice.

Ok, I was skeptical at first, but this is pretty nice.

Thalidomide Vintage Ad Shirt $22.14

UFOs Are A Psyop Shirt $21.68

Thalidomide Vintage Ad Shirt $22.14

  1. 2 months ago
    Anonymous

    >unwrap
    >unwrap
    >unwrap
    now show the code without making it crash on error. Even c looks clean if you don't have error handling

    • 2 months ago
      Anonymous

      >unwrap()
      >unwrap()
      >unwrap()
      >unwrap()
      >unwrap()

      i know the language syntactically forcing you to handle all errors is a good idea but damn

    • 2 months ago
      Anonymous

      C doesn't do error handling at all. In my case if something fails I know exactly where it failed and why. These aren't remotely the same things.

      I also didn't mention C at all, and you couldn't do this kind of functional style with C, which is what I'm trying to focus on, but I'm looking forward to you sharing your convoluted macro stack that "kinda" allows you to do the "same thing," inadvertently proving my point without realizing it.

      In other words, frick off from my thread, cnile baby duck.

      • 2 months ago
        Anonymous

        I dont use c, I use zig which handles errors much cleaner than rust codebases. All error types are automatically joined when you propagate it up. Zig doesn't abort on memory allocation failure either unlike rust. Rust is a meme, they can't use the standard library in the linux kernel since it's unsafe (abort on failure), and that also includes all third party libraries. Linus complained about this. Zig doesn't have this problem. Nobody does a "unwrap" for errors that can happen in zig because the language makes it very clean to handle properly.

        • 2 months ago
          Anonymous

          I have used zig before I used rust. Zig's errors are essentially global error codes, which is fine, but you absolutely have to check for errors if you want to catch them, and worst, it won't give you a neat stack trace with the exact error info for absolutely no work at all.

          Like I said, those unwraps are essentially assert macros I use to check the correctness of the code, they aren't serious attempts at error handling. To do the same in zig you would still have these asserts. Exact same with C. The difference is that Rust
          1. doesn't let me forget the asserts,
          2. gives me automatic error information when these asserts fail that go beyond "this assert failed."

          Zig has had this really annoying issue for a while where its absolute cancer to tie any sort of error info to errors sent by Zig without returning actual structs. Rust simply doesn't have this problem, and propagated errors can be converted through traits without any extra syntax.

          >they can't use the standard library
          Have they fixed Zig's vector implementation yet?

          • 2 months ago
            Anonymous

            >Have they fixed Zig's vector implementation yet?
            What is (was?) wrong with Zig's vectors?

          • 2 months ago
            Anonymous

            I do not remember the timestamp, but it's a nice talk anyway.

          • 2 months ago
            Anonymous

            they dont conform to rust ideology

          • 2 months ago
            Anonymous

            https://www.youtube.com/watch?v=dEIsJPpCZYg
            I do not remember the timestamp, but it's a nice talk anyway.

            8:30, thereabouts. Not sure if they changed anything with aliasing since then, since I stopped using zig in 0.11. I used to be super hyped for zig and used to think rust was the shittiest thing. But then I learned rust and I don't much care for zig anymore.

          • 2 months ago
            Anonymous

            he's a c++nile who still thinks "vector" is a synonym for "array list"
            Zig's actual vector types are fine
            Zig's array lists are also fine but affected by the parameter optimization footgun

        • 2 months ago
          Anonymous

          They use the standard library in a configuration with fallible allocation. This doesn't neatly apply to all APIs but it's available and it's enough to get them going.

          • 2 months ago
            Anonymous

            Couldn't you just use the parts of the std which do not allocate memory along with implementing standard traits for custom heap management structures? I imagine you can still get a lot of good stuff from the std.

        • 2 months ago
          Anonymous

          >pretty nice
          >let t_db = Arc::clone(&self.0);
          >.unwrap() x100
          >multiple ways to pass parameters to prepared queries, using completely different methods
          Is this bait?

          >zig
          >the language that accidentally compiles your valid and standard-compliant code into UB
          This is 100% bait.

          • 2 months ago
            Anonymous

            >let t_db = Arc::clone(&self.0);
            What's the problem with this, other than you not understanding it?
            >multiple ways to pass parameters to prepared queries, using completely different methods
            It's all done through a single trait. You can use tuples if you need differently typed arguments and arrays otherwise. What exactly is the problem, other than you not understanding it?
            >.unwrap() x100
            Post your alternative.

          • 2 months ago
            Anonymous

            >y-y-you don't understand it!!!
            It's code golf homosexualry, same as Vector being shortened to Vec.
            If I was into the "cryptic single character variable names" niche then C does it already.

          • 2 months ago
            Anonymous

            >It's code golf homosexualry
            Thank you for confirming that you indeed do not understand it. I like you didn't change your shit opinion at all even after I explained it to you.
            >I am before I think
            Yup, you sure are. A homosexual, that is.

          • 2 months ago
            Anonymous

            wtf are you talking about? Nothing about this is code golfed. It's almost like (You) don't even know the sqlite c API or why the code has so many potential failure conditions.

      • 2 months ago
        Anonymous

        >C doesn't do error handling at all. In my case if something fails I know exactly where it failed and why.
        holy shit, this is the most enlightened post i've ever seen on this website

      • 2 months ago
        sage

        You're just moronic. Get back to me when you finally finish a rust project

      • 2 months ago
        Anonymous

        >C doesn't do error handling at all
        Yes it does it just handles it with error values that you have to operate on. This is pretty similar to what go does except there isn't explicit error types.
        >C can't do functional style programming
        If you mean chaining functions using the dot operator, sure, but you could pretty much do the same thing if you just moved the arguments into the parenthesis.

        • 2 months ago
          Anonymous

          >Yes it does it just handles it with error values that you have to operate on.
          Yes, which would make it about 3 times as verbose as just calling
          >.unwrap()
          and getting a proper error report if things go wrong. This is NOT a simple
          >assert(a, b)
          which is what you would otherwise do (in C for instance.)
          Not only that, but if you want to add defaults in C then congratulations, you've just added about 200% more code, while in rust this is just
          >unwrap_or(...)

          But you will never actually see cnile baby ducks posting any alternatives to what they're complaining about because they know it would look like absolute dogshit, would be about 10 times as annoying to actually write, and 3 times as verbose. Not even gotos can save you in some cases.

          >and you couldn't do this kind of functional style with C, which is what I'm trying to focus on, but I'm looking forward to you sharing your convoluted macro stack that "kinda" allows you to do the "same thing,"
          I do enjoy the implementation in the STC. Best thing is it actually works better out of the box in terms of optimization than sophisticated implementations in C++.
          #include <stdio.h>
          #define i_TYPE Vec, int
          #include "stc/stack.h"
          #include "stc/algorithm.h"

          int main(void)
          {
          Vec vec = c_init(Vec, {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10, 11, 12, 5});

          c_filter(Vec, vec
          , c_flt_skipwhile(*value < 3) // skip leading values < 3
          && (*value & 1) == 1 // then use odd values only
          && c_flt_map(*value * 2) // multiply by 2
          && c_flt_takewhile(*value < 20) // stop if mapped *value >= 20
          && printf(" %d", *value) // print value
          );
          // 6 10 14 2 6 18
          puts("");
          Vec_drop(&vec);
          }

          Lmao.

          > rust troony screencaps random code it doesn't understand
          have a nice day, troony.

          >C doesn't do error handling at all.
          stick to what you're good at, rust troony: child rape. computers are just not your thing.

          >random code it doesn't understand
          I wrote that code motherfricker
          >C doesn't do error handling at all.
          No, there is no equivalent to that type of error handling in C, you have to manually check thread global error codes and write out error messages manually as well. I look forward to reading your mental gymnastics on how
          if (errno == ...) {
          printf("...", ...)
          exit(1);
          }

          is actually totally better than .unwrap()

      • 2 months ago
        Anonymous

        > rust troony screencaps random code it doesn't understand
        have a nice day, troony.

        >C doesn't do error handling at all.
        stick to what you're good at, rust troony: child rape. computers are just not your thing.

        • 2 months ago
          Anonymous

          You drive to school in a special van, don't you?

      • 2 months ago
        Anonymous

        >and you couldn't do this kind of functional style with C, which is what I'm trying to focus on, but I'm looking forward to you sharing your convoluted macro stack that "kinda" allows you to do the "same thing,"
        I do enjoy the implementation in the STC. Best thing is it actually works better out of the box in terms of optimization than sophisticated implementations in C++.
        #include <stdio.h>
        #define i_TYPE Vec, int
        #include "stc/stack.h"
        #include "stc/algorithm.h"

        int main(void)
        {
        Vec vec = c_init(Vec, {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10, 11, 12, 5});

        c_filter(Vec, vec
        , c_flt_skipwhile(*value < 3) // skip leading values < 3
        && (*value & 1) == 1 // then use odd values only
        && c_flt_map(*value * 2) // multiply by 2
        && c_flt_takewhile(*value < 20) // stop if mapped *value >= 20
        && printf(" %d", *value) // print value
        );
        // 6 10 14 2 6 18
        puts("");
        Vec_drop(&vec);
        }

    • 2 months ago
      Anonymous

      Unwrapping a mutex lock is idiomatic, that propagates any panic that happened while the lock was held by another thread.
      Unwrapping on db.prepare is probably idiomatic because it's a string literal, it can be statically guaranteed to be correct and if it's not then you want a loud crash. (I don't know the library though.)
      Unwrapping spawn_blocking probably propagates any panic that happened in the closure?
      Probably some of the other unwraps are not justified and are better bubbled upwards as Results.

      • 2 months ago
        Anonymous

        >Probably some of the other unwraps are not justified and are better bubbled upwards as Results.
        Depends. In my case I have no reason to handle these kinds of errors in my personal program nobody is going to use besides me. I am treating these unwraps as asserts, if something fails here I have 98% certainty I fricked up something in the code, and that's all I want.

        In other words I get nothing from handling or propagating the rusqlite Result type. Even interning it into my custom Result would be a waste of time because I'm never going to handle it.

        • 2 months ago
          Anonymous

          Also just to be clear, the thread was about functional style shit like map, filter, etc. not error handling.

    • 2 months ago
      Anonymous

      >unwrap derangement syndrome
      let me guess you think all day about unwrapping "things" huh

    • 2 months ago
      Anonymous

      .unwrap_or(null)

    • 2 months ago
      Anonymous

      >Explicitly panic instead of exceptions as shitty flow control
      >Explicitly panic instead of completely ignoring errno or error returns
      What's the problem again? Anytime you see unwrap, you know you can always expand it and if the condition is basically an impossibility unless your shit is broke, unwrap is fine.

    • 2 months ago
      Anonymous

      How do you do error handling for a database failure anyway? Either it works or it doesn't and if it doesn't then who gives a frick if it crashes?

      • 2 months ago
        Anonymous

        Honestly after years of experience, I really believe you don't want to handle errors other than maybe printing or signalling something to someone else.
        Every shit code I've had problems with tries powering through a broken situation and will just uselessly stay broken until someone notices it.
        Just have your code log some event and then immediately _exit() with some bad status code.
        You have a service manager anyway and the service manager can execute extra code when your shit fails and restart your app in a good state.

        Right now this morning I had to login, go check on an app in a k8s cluster that claims to be "healthy" only to find it is in a fail loop trying to connect to some service it can't reach. I kill the pod and it magically starts working. Made me more convinced that sometimes failing hard and fast is better than trying to be smart

  2. 2 months ago
    Anonymous

    pure cancer

  3. 2 months ago
    Anonymous

    >manually binding values and fetching results by position
    ngmi

    • 2 months ago
      Anonymous

      Dont see a problem.

  4. 2 months ago
    Anonymous

    >using | | for lambdas
    stopped reading right there

  5. 2 months ago
    Anonymous

    >unwrap();
    >unwrap();
    >unwrap();
    >unwrap();
    >unwrap();
    unlive() yourself
    technology is fricking degrading

    • 2 months ago
      Anonymous

      >assert(...);
      >assert(...);
      >assert(...);
      >assert(...);
      >would somehow be better

      is this for a booru?

      Sorta.

      Either use an async database driver or don't offer an async api. It's just making everything slower and dirtier. Cloning tag_ids just to use it in spawn_blocking is particularly egregious.
      And stop using unwrap

      I'm using rocket, it has to be async and spawn_blocking works for my particular use case. If you know of any async sqlite libraries I'm all ears though.
      >And stop using unwrap
      Why, lol

  6. 2 months ago
    Anonymous

    is this for a booru?

  7. 2 months ago
    Anonymous

    Either use an async database driver or don't offer an async api. It's just making everything slower and dirtier. Cloning tag_ids just to use it in spawn_blocking is particularly egregious.
    And stop using unwrap

  8. 2 months ago
    Anonymous

    Do not use {} when it's not needed. That let db is also pointless. Handle errors properly instead of unwrapping everything.

  9. 2 months ago
    Anonymous

    what in christ's forsaken name is this syntax?

  10. 2 months ago
    Anonymous

    All line noise

  11. 2 months ago
    Anonymous

    >everyone has the same reaction to rust syntax that I do
    Glad it's not just me.

    Tbh I think the worst offense is the brackets for arrays.

    • 2 months ago
      Anonymous

      what......................

      • 2 months ago
        Anonymous

        You're obviously supposed to use parentheses

  12. 2 months ago
    Anonymous

    ew

  13. 2 months ago
    Anonymous

    This is why CS is dead

    • 2 months ago
      Anonymous

      why

    • 2 months ago
      Anonymous

      >the hecking rust trannerinos decided to use || for lambdas, it's over, CS is dead

      • 2 months ago
        Anonymous

        Actually it's because of the let keyword

  14. 2 months ago
    Anonymous

    man low level languages look like shit

  15. 2 months ago
    Anonymous

    ugly syntax 🙂

  16. 2 months ago
    Anonymous

    synchronous async is the best kind there is

  17. 2 months ago
    Anonymous

    can you do something like create an array of lambdas and run them in sequence, unwrapping each step? if you do this please make a generic version and release a crate

  18. 2 months ago
    Anonymous

    zig is nicer

    • 2 months ago
      Anonymous

      Show us analogous zig code.

      • 2 months ago
        Anonymous

        Or you could actually spend a bit of time making projects in both languages and decide for yourself.

        • 2 months ago
          Anonymous

          Do what he asked. You won't because you know you're full of shit. Pic rel is the output I get from a single unwrap in rust. Shit like this is notoriously difficult to do cleanly in zig like I mentioned here

          I have used zig before I used rust. Zig's errors are essentially global error codes, which is fine, but you absolutely have to check for errors if you want to catch them, and worst, it won't give you a neat stack trace with the exact error info for absolutely no work at all.

          Like I said, those unwraps are essentially assert macros I use to check the correctness of the code, they aren't serious attempts at error handling. To do the same in zig you would still have these asserts. Exact same with C. The difference is that Rust
          1. doesn't let me forget the asserts,
          2. gives me automatic error information when these asserts fail that go beyond "this assert failed."

          Zig has had this really annoying issue for a while where its absolute cancer to tie any sort of error info to errors sent by Zig without returning actual structs. Rust simply doesn't have this problem, and propagated errors can be converted through traits without any extra syntax.

          >they can't use the standard library
          Have they fixed Zig's vector implementation yet?

          because of the way error handling works. You pretty much have to always retrieve data external to the error from somewhere else, which translates to extra code.

          • 2 months ago
            Anonymous

            Lazy Black folk can't into error handling. Here's an error message your fricking user. Suck on this. Want more? Set a fricking environment variable if you know what that is. Ha, ha go frick yourself. ABEND. Core Dumped. Frick off.

          • 2 months ago
            Anonymous

            >Incoherent melty when asked for code
            Classic rust derangement syndrome.

          • 2 months ago
            Anonymous

            Lazily written Rust code gives an ugly panic with plenty of error messages. Lazy C code tends to segfault. I know which I prefer
            Good effortful code in either language doesn't do either of those of course

          • 2 months ago
            Anonymous

            Good effortful code in C is also about 5 times as verbose, but lets just ignore that.

          • 2 months ago
            Anonymous

            That's less relevant to that particular post. If you call people "lazy Black folk" then you probably think boilerplate builds character or something

          • 2 months ago
            Anonymous

            I meant to say that was a bad thing. Verbose is probably not the correct word, noisy would be more apt, if we're comparing to something like Rust.

  19. 2 months ago
    Anonymous

    The unwrap Language

  20. 2 months ago
    Anonymous

    OP, instead of single db connection when sqlite already implements its own multiple reader / single writer concurrency and since you're using async based on the spawn_blocking and await:
    https://lib.rs/crates/deadpool

  21. 2 months ago
    Anonymous

    How about creating an "unwrap block" macro?

    • 2 months ago
      Anonymous

      Why? Just use ? and handle errors properly. There are even try blocks you can use for that.

  22. 2 months ago
    Anonymous

    Exception might not be a bad idea after all.

    • 2 months ago
      Anonymous

      How?

  23. 2 months ago
    Anonymous

    instead of spamming .unwrap i prefer to spam the ? operator
    and then the function returns the Result

    kinda ziggish

    • 2 months ago
      Anonymous

      Why pollute the return type when I'm not going to do anything with the error anyway? I get no benefit from propagating rusqlite results. Doing an unwrap directly after these calls gives me a message that exactly pinpoints where the error came from.

      • 2 months ago
        Anonymous

        Even in dirty personal projects I find it can be helpful to distinguish between "this can happen" and "this shouldn't happen". anyhow makes it easy peasy and can even generate backtraces nowadays

        • 2 months ago
          Anonymous

          Well yeah, none of my unwraps should happen.

          How do you do error handling for a database failure anyway? Either it works or it doesn't and if it doesn't then who gives a frick if it crashes?

          There are plenty of errors I don't check for:
          Syntax errors I don't check for because if my syntax is wrong then it will always fail. I fix the code and move on.
          Same with invalid field accesses,
          Same with invalid inputs, since rust is statically typed.
          Poisoning happens sometimes since I'm fricking around with the database manually, but it's for testing purposes and I have no interest in handling them.
          Constraint violation should never happen as per the invariants of the underlying system. If you were writing something to be used by a lot of users you should definitely check for this! In my case, this is a dashboard for a daemon that I'm never going to share with anybody, so it doesn't really matter at the moment. I still use PRAGMA foreign_keys = ON; for extra insurance on the database side. SQLITE constraint check violation messages are also terribly unhelpful in my experience.
          I don't particularly care about any other kind of error at the moment.

          I'm sure someone who knows a lot more about SQLITE than I do would have other important fail point checks, but for me it quite simply just works.

          • 2 months ago
            Anonymous

            I know all of that but how do you actually handle the error other than dumping a message to the console and exiting anyway?

            If it can't open the database or can't write to the database, etc, then you're fricked. Crashing versus printing a message nicely and exiting anyway isn't going to make much of a difference.

          • 2 months ago
            Anonymous

            Well for syntax failures it's hard, unless you're talking about taking in external inputs, of course.
            For poisoning you could reset the database connection, for instance.
            For constraint violation you could have a message, no need to even break flow at all in this case, let alone exiting the program.
            For everything else I have no clue, that's the only SQLite errors I know, lmao.

          • 2 months ago
            Anonymous

            >If you can't open the database or can't write to the database, etc, then you're fricked
            Depends on the DB, you can have failures for plenty of reasons. There's plenty you can do, f.e.
            >log the error
            >stash the transaction somewhere to be rerun later
            >call some centralized error handling stuff
            if what you're writing is not an application but a library, for the love of god don't crash because a DB request went wrong.
            Either propagate an error code back to your caller, or ask the caller to give you a callback to handle errors however he wants.

  24. 2 months ago
    Anonymous

    >this is what FPgays consider to be "good" code
    Every day it becomes clearer that OOP is the least horrendous programming paradigm.

    • 2 months ago
      Anonymous

      Show an analogous OOP implementation.

      • 2 months ago
        Anonymous

        The equivalent oojeet code wouldn't run on EL7 anyhow since the only used sqlite3 jdbc driver writes the sqlite executable code to /tmp.
        Java jeet shit is a mess.

  25. 2 months ago
    Anonymous

    None of you will ever be a real woman

    • 2 months ago
      Anonymous

      and you'll never be a man.

  26. 2 months ago
    Anonymous

    >pub async fn
    why do I have to tag a function as "async"? why can't i just pass an arbitrary function into a threading api?

    • 2 months ago
      Anonymous

      >why can't i just pass an arbitrary function into a threading api?
      You can do this with e.g. std::thread::scope but that's not what async is. Async functions can halt midway through (when you await) to make room for another task on the same thread, there's some special stuff going on under the hood

      • 2 months ago
        Anonymous

        >Async functions can halt midway through (when you await) to make room for another task on the same thread
        Time slicing is a basic function of threads though, and external management exists in all threading APIs (though I don't know of any pthreads implementation that implements pthread_suspend, but there are alternatives that use signals, and Windows has SuspendThread)

        It seems like async is a really fuzzy abstraction over the already super fuzzy abstraction of threads? At least on most platforms. Really strange language tbh.

        • 2 months ago
          Anonymous

          You are on top of mount stupid right now my man. Async is not threads.

    • 2 months ago
      Anonymous

      async tbhgars the function to a state machine that's polled until it's completed

      • 2 months ago
        Anonymous

        That sounds insanely inefficient, like just gonna frick over the branch predictor? How does the function detach from the execution context? Any good reading on this?

        • 2 months ago
          Anonymous

          https://rust-lang.github.io/async-book/01_getting_started/02_why_async.html

          This has been the standard for high volume servers for decades. Do you think threading is fast?

        • 2 months ago
          Anonymous

          Polling based, composing async model is generally zero cost or even faster than hand written solutions. It's definitely much faster than callback based async model.

          • 2 months ago
            Anonymous

            Proofs? Moving some data and two hardware interrupts costs about the same as a single conditional.

            >That sounds insanely inefficient
            as opposed to what?

            Literally anything that doesn't loop over a branching instruction.

        • 2 months ago
          Anonymous

          >That sounds insanely inefficient
          absolute moron, why do you bother opening your mouth

        • 2 months ago
          Anonymous

          >That sounds insanely inefficient
          as opposed to what?

  27. 2 months ago
    Anonymous

    OP, for the love of god. Use deadpool-sqlite you frick.
    why the frick are you gating a single connection to a sqlite db behind a mutex? did you build sqlite to be single threaded only or something?

  28. 2 months ago
    Anonymous

    I'm not going to even bother arguing constructively anymore.
    t. C-nile

    • 2 months ago
      Anonymous

      >I'm not going to even bother arguing constructively anymore.
      You never did in the first place.
      >Rust derangement syndrome
      Now post the alternative code in C.

      • 2 months ago
        Anonymous

        none of these morons ever used sqlite in c because they're pyBlack person toddlers.

  29. 2 months ago
    Anonymous

    why does rust not have pipes?
    It's already got the functional influence, and pipes are just a superior, more flexible way to handle method-chains/ function-pipelines.
    It also seem like a comparatively simple thing to implement, since any code that uses pipes could be trivially rewritten to not use pipes.

  30. 2 months ago
    Anonymous

    if you remove all the unnecessary syntactic vomit, rust actually looks like a decent and readable language lol

    • 2 months ago
      Anonymous

      >if you remove all the unnecessary syntactic vomit
      Post the alternative in your language.

      • 2 months ago
        Anonymous

        i don't have a "my" language, i'm critiquing rust

        unwrap() is a method, not syntax

        if you need to spam it every 2nd line, it sounds like it should not exist, it's just bloat that hides what's actually going on

    • 2 months ago
      Anonymous

      unwrap() is a method, not syntax

    • 2 months ago
      Anonymous

      >unwrap()
      >syntax
      What

      >added extra =>
      >confuses values for references
      >confuses namespaces for methods
      What

      • 2 months ago
        Anonymous

        i don't claim to understand rust and i spent like 1 minute doing that shitpost in ms paint, i just wanted to illustrate how unapproachable rust looks at the first glance to someone like me who doesn't know shit about it

        • 2 months ago
          Anonymous

          You don't need to understand rust to know what is a syntax.

      • 2 months ago
        Anonymous

        there is zero reason the accessor for a data structure's members and a namespace's members should be different. It's one of the many moronic design traits of C++ that Rust adopted for literally no reason except to make the language uglier.

        • 2 months ago
          Anonymous

          foo::method(...) is something different than foo.method(...). foo.method(arg) is just a syntactic sugar for foo::method(foo, arg).

    • 2 months ago
      Anonymous

      https://matklad.github.io/2023/01/26/rusts-ugly-syntax.html

      what is .unwrap and why do you call it so many times? Is it a function, if so then why do you start it with dot? Is it kinda like pythons self.something?

      turns an Option/Result into a T and panics if it's None/Error, like Maybe/Either type in Haskell

      • 2 months ago
        Anonymous

        >https://matklad.github.io/2023/01/26/rusts-ugly-syntax.html
        great article, i really like what the final result looks like, you get a clear picture of what's going on immediately upon glancing at the code, without having to focus on ignoring all the visual noise around it.
        that is the style of code i like to read

        • 2 months ago
          Anonymous

          that's what rust looks like when you've used the language and learned it after a few weeks. it's not noise, it all conveys information

      • 2 months ago
        Anonymous

        Maybe doesn't panic. Except if you are using patternmatching. If you use the monad then
        Nothing >>= f = Nothing

        This means that in Haskell you don't have to explicitly error handle unless you want to:
        main = do
        x <- thing1
        y <- thing2 x
        z <- thing3 y
        return z

        Will return Nothing if any of things evaluates to nothing. Furthermore you can do case on any one of them for explicit error handling. Unfortunately in Rust something like that would require either the libraries be reimplemented accepting option types as input or perhabs a better idea would be some special function trait like async (if it's called a trait) that when used all option<T> types within the function are automatically unwraped when used somewhere where a T is expected and if the result is None then returning None. Basically making it so that
        returns_option_T().expects_T()

        is sugar for
        match returns_option_T() {
        None => return None
        Some(t) => expects_T(t)
        }

        I think this would be good

        • 2 months ago
          Anonymous

          Wait that's literally ? lol. I was thinking too much about emulating Haskell

    • 2 months ago
      Anonymous

      literally javascript at that point

  31. 2 months ago
    Anonymous

    what is .unwrap and why do you call it so many times? Is it a function, if so then why do you start it with dot? Is it kinda like pythons self.something?

    • 2 months ago
      Anonymous

      i don't have a "my" language, i'm critiquing rust

      [...]
      if you need to spam it every 2nd line, it sounds like it should not exist, it's just bloat that hides what's actually going on

      .unwrap() is an assert which tells me when something goes wrong with the call.

    • 2 months ago
      Anonymous

      Instead of functions raising exceptions they typically return a Result that might be either an error or the return value. To get the return value out you have to decide what happens if there's an error inside. With unwrap() you tell it to just crash if there's an error. (You can also write ? to return the error from the current function, and there are a few other ways to do more sophisticated handling.)
      unwrap is a method on Result.

      i don't have a "my" language, i'm critiquing rust

      [...]
      if you need to spam it every 2nd line, it sounds like it should not exist, it's just bloat that hides what's actually going on

      >if you need to spam it every 2nd line, it sounds like it should not exist, it's just bloat that hides what's actually going on
      A lot of these should be replaced by "?" in non-toy code.
      If you got rid of it altogether then you wouldn't be able to see which operations could fail, you'd have much less of an idea what was going on.

  32. 2 months ago
    Anonymous

    i just don't get the usecase of async

    • 2 months ago
      Anonymous

      calling out to a peripheral with high latency, but you can do some stuff while you wait.

      • 2 months ago
        Anonymous

        >but you can do some stuff while you wait.
        can you though? doesn't awaiting the function hog the thread?

        • 2 months ago
          Anonymous

          Let's say you want to perform some kind of transformation on the GPS coordinates of the computer. You query out to the GPS peripheral, which takes a while, and in the meantime you can actually calculate out most of the transform information regardless of having the coordinates or not. So while you're waiting, you spend processor time doing that. When you run out of stuff to do, you finally wait for the coordinates to come back to you, and then just add the two vectors together. You've now ultimately saved yourself a little bit of time.

          When asynchronous tasks don't run parallel, it starts to be a bit of a meme.

        • 2 months ago
          Anonymous

          Awaiting a future pauses the task so the thread can pick a different task to work on. It's basically for IO bound programs.

  33. 2 months ago
    Anonymous

    is this actually fun to code in?
    t. only know JS and Python

    • 2 months ago
      Anonymous

      yeah and it's really fast. you don't really use types so it could be easy and what you've been missing your whole life or it could be hard

    • 2 months ago
      Anonymous

      It's tedious if you aren't accustomed to type tetris. But it's a massive improvement over C++, and IIRC you can write Python modules in it.

    • 2 months ago
      Anonymous

      No, it's absolutely abortive. Learn Haskell instead.

    • 2 months ago
      Anonymous

      Very fun in ways that you won't find in JS and Python. Depends on taste of course but it taught me a lot about how things work under the hood and about what a type system can do for you

      You don't need to understand rust to know what is a syntax.

      .await is syntax that looks like a property, not entirely unreasonable

Your email address will not be published. Required fields are marked *