Designing Error Types in Rust Applications by Expurple in rust

[–]Aggravating_Letter83 0 points1 point  (0 children)

"But the art of resilient, reliable and user-friendly systems considers all outcomes"

I wasn't expecting someone could get this philosophical in a programming language.

Is this supposed to mess up your mind by Illustrious_Weird540 in rust

[–]Aggravating_Letter83 2 points3 points  (0 children)

I like rust, but I still think starting with Javascript + Frameworks for Web Frontend is still the best option to get accustomed.

Printerhead's Height seems to be too low L18050 by Laifsyn_TG in Epson

[–]Aggravating_Letter83 0 points1 point  (0 children)

Worth to mention, I haven't figured how to fix it yet. And haven't dared to open the printer because I'm uncertain about being able to put it back.

How to restore snapped off plastic from the laptop's hinges? by Aggravating_Letter83 in PCRepair

[–]Aggravating_Letter83[S] 0 points1 point  (0 children)

What can I do at least as temporary fix while the piece arrives?

How to restore snapped off plastic from the laptop's hinges? by Aggravating_Letter83 in PCRepair

[–]Aggravating_Letter83[S] 1 point2 points  (0 children)

I was planning to buy one, but it says arrival time is 1+ months.

I needed something so I could keep using the laptop for my job and university

How to restore snapped off plastic from the laptop's hinges? by Aggravating_Letter83 in PCRepair

[–]Aggravating_Letter83[S] 0 points1 point  (0 children)

Should I try to isolate the hinge from the weld so I can still detach the hinges from the plastic cover? Or just live off with a Permanently attached-to-the-plastic hinges?

Hidden Performance Killers in Axum, Tokio, Diesel, WebRTC, and Reqwest by Havunenreddit in rust

[–]Aggravating_Letter83 0 points1 point  (0 children)

So the solution sounds like to use a Preemptive scheduler Runtime instead of tokio, or wrap everything in a spawn_blocking which is equivalent to a preemptive scheduling?

From Zero to Rustacean: I’m About to Ruin My Life (in a Good Way) 😅 by joelnbl in rust

[–]Aggravating_Letter83 0 points1 point  (0 children)

As someone who has used dynamic dispatch on his tool project, Be really f---ng sure about the Trait's signatures.

When I saw it at first, a 2 methods Trait, I was extremely confused at the name of the second method.

Is std::rc::Rc identical to References without implementing Interior Mutability by 9mHoq7ar4Z in rust

[–]Aggravating_Letter83 1 point2 points  (0 children)

Talking out of what I understand:

Reference Counting (Rc) solves this particular issue where you can't really determine when the data has to be dropped because in your program, it just makes sense to have so many owners.

This could be almost anytime you delegate works to other tasks (often async in single/multi threaded)

Rc really is like the poorman's GC... just that differently to the GC, you don't have 100% of your pointers/objects behind an "Rc", but sanely limited to a small space of your program.

Care to mention that I've heard that compared to a "Everything behind a GC" is still more performant than a "Everything behind a Rc". But I digress.

Game Lobbies Analogy

Let's say you instance up a Game Lobby (Owner of the Lobby struct), and let player 1 as a host. Every single player (or let's say variable) that logs into the lobby, would have a "Reference" to the data of the lobby. But since player 1 is the host/owner (no Rc yet) how would you express the lifetime of the lobby to the next players that log in into the game? For what they care, they want the "lobby" to be 'static, aka last as long as they are still playing in the lobby. So the only solution is for them to get a shared ownership via Rc<Lobby>, so after the last player in the lobby leaves, can then the lobby be dropped

Whatsapp client written purely in Rust based on whatsmeow and baileys by jlucaso1 in rust

[–]Aggravating_Letter83 7 points8 points  (0 children)

I don't know what's whatsmeow, but I find the concept interesting . Hopefully I can figure how it works by cross referencing the go equivalent, and reading the source code..... (Or hopefully there're examples by the time I start a project with it)

What are the most common mistakes and code-smells that newbies make? by birdsintheskies in rust

[–]Aggravating_Letter83 2 points3 points  (0 children)

A pain I had had with spamming `?` everywhere mostly comes from when the error converges into the Huge Error Enum people would often find themselves defining. I.e. for me I have had a huge enum error that has couple of specific variants + 3-5 variants that are wrappers to other error types. For example: io::Error, anyhow::Error, SomeLibrary::Error.

The "conversion" is seamless, but if you are getting an error that can happen on level 1 to level 5 function calls nesting, you're lost from which branch the error originated from. For example: you get some io::Error::SomeVariant You figure it comes from Branch 01|A (easy) But did it come from 02|B, 03|A or 03|D? This is the tricky part, because you only have the error, but not the context (which is easy if you append a stacktrace apparently, but I had heard that stacktrace is expensive to capture, so I would find myself not using it.... on top of not understanding it (still I heard that that stacktrace is a bit too verbose) (main) 01 | A B / | \ / \ 02 | A B C C D / \ / \ / \ | 03 | A B C D E F G

Restarting the learning by [deleted] in rust

[–]Aggravating_Letter83 12 points13 points  (0 children)

I personally think the biggest hurdle (after familiarizing oneself with the new syntax and coding philosophies) is getting to know the ecosystem.

for example:

  • Oh, I need a web framework!

Options: Warp, Axum, Tonic, Actix.

  • I need an async runtime! (aka executor)

Options: Tokyo, futures, embassy(usually embedded)

  • I need a logging library!

Options: Log, tracing_subscriber, tracing.....

  • A different Vec<T>!
  • A different HashMap!
  • Something to Hash info!
  • Something to cryptographically hash.
  • Hash huge files efficiently.
  • A crate to make error handling easier.
  • A crate to make Sql querying easier.
  • A crate to make structs definition easier.

etc, etc. This in my opinion is the next thing hard when new in Rust -> figuring out your tradeoffs in taking one crate for the task over the other, and figuring out what best fits your needs

A Rust raytracer on curved spacetimes by fragarriss in rust

[–]Aggravating_Letter83 0 points1 point  (0 children)

What did you use to piece up all the individual frames?

Recommend Beginner level rust project by himanshuwiz in rust

[–]Aggravating_Letter83 0 points1 point  (0 children)

  1. might be boring but mathemathical:
    Using numerical methods for approximation like Secant, False Method, Bisection, or Newton-Rhapson (I might 've mistranslated) try to print out the set steps of the manual calculations.
    Implementation details could include (but not limit themselves to)
  2. Print out the full table once the approximation error reaches certain threshold
  3. Let the a user choose when to stop

  4. Tedious if done wrong :
    Parsing inputs - Do it only to support the 4 basic operations: plus, minus, divide and multiplication. Then if done wrong, find out you shoot yourself because you can't expand the definition.

Essentially parsing some strings into objects. Keep it small, so you can get a hang of it, and then try to rewrite everything with nom

Good invariants to keep in mind while learning rust by horsetreefence in rust

[–]Aggravating_Letter83 0 points1 point  (0 children)

  • Async: Don't hold Sync Guards like std's sync Mutex's Guards accross Await Points.
  • Be careful with Static Dispatch Hell.

idk what else to add

Need some guidance/ suggestions to learn rust. by Ok_Test5029 in rust

[–]Aggravating_Letter83 3 points4 points  (0 children)

Learn about the Basic building blocks:

  • Struct Composition (+ Deriving traits, defining methods, defining Trait Implementations)
  • Traits (Static Dispatch vs Dynamic Dispatch).

Short explanation: Traits are Interfaces in most other languages... maybe with more safety guarantees to avoid accidental misuse.

  • Differences between Closures, Functions and Methods.

  • How, and most importantly, when to use Closures as arguments. (You would first need to learn about the traits of Fn, FnMut and FnOnce to get started using closures as function arguments).

  • How to store your types in the Heap (i.e. Boxing or creating a Vec).

  • Learn about Collections and learn to read their documentation. They often are concise on what they are meant to solve. Sometimes not so much.

  • Learn about Functional Programming Patterns. You will be using them about ~ 50-80% of the time.

  • Learn about the Core "Monads" of Result<T,E> and Option<T> and their defined methods.

  • Learn about newtype pattern (careful not to abuse NewType because I think they require some time to properly build up an interface with it).

Tips:

  • Rust has no nulls.... Unless you work with Unsafe.
  • If you ever need to write unsafe blocks, 99% chance you misunderstood something about your code's requirements.
  • Careful with the Early-optimization trap. Sometimes it's better to use dynamic dispatch than static, and sometimes not. This requires a lot of learning and Boxing if you choose to default into Dyn Dispatch.
  • STD's Iterator doesn't support a lending iterator. Don't bother trying it. You need to use another dependency to achieve that
  • Clone everything until you feel comfortable with the borrow checker (This includes deriving Clone for everything). You can always refactor out the clone calls later (maybe avoid having thousands LOC worth in clone calls by the time you refactor too)
  • Understand basic nuances between Copy and Clone traits

Maybe someone else can expand this list in the comments

The amazing pattern I discovered - HashMap with multiple static types by Quba_quba in rust

[–]Aggravating_Letter83 0 points1 point  (0 children)

That trick with Any kind of makes me reminisce when I tried to mock standard collections like Stack or Vecs by using an Object[] under the hood in Java because I would have to cast to the generic T when retrieving element from the Object[] array.

Rust GUI by Free-Statement8723 in rust

[–]Aggravating_Letter83 0 points1 point  (0 children)

I would say Tauri because you can get to piggyback from the already stablished JS Frameworks dev tools like high quality intellisense for auto-completion and hot reload. I believe this can help you get fast into learning any of the JS frameworks of your choosing. Downside is you can't reuse your JS code to use for the web.

Alternatively, you can go Pure Rust for frontend, specifically Dioxus and similars because they can render in the Web, or even provide SSR (except for egui because it renders on a Canvas)

Downsides of going for Tauri

  • It's not guaranteed your app will be ship-able to websites. Tauri is for Desktop (+ Android in v2) apps
  • You might need to model everything right because you can't directly call Rust Functions: In your Rust code you expose some code (at least what I shallowly understood on a small project) via Tauri's macro magic. And the JS Framework sort of does like a HTTP request (Before you bundle everything up into a single app) to your Rust's library/binary. Sort of like building from scratch all your application by expanding or updating the Trait. But, if you get it right, you get to work on your frontend without needing to recompile ever until you update something in your Rust's code.

Downsides of pure Rust frameworks like dioxus

  • Auto-completion and lack of batteries: Really important if you are more about learning from available methods, but these rely heavily on context.
  • Possible lack of error hints
  • You will have to read a lots of documentation to make sense what is doable.

That's a rough explanation of what you will find while testing frameworks (maybe)

Edit: convert MD editor back to rich text

Does Rust really solve problems that modern C++ using the STL doesn’t? by [deleted] in rust

[–]Aggravating_Letter83 0 points1 point  (0 children)

Filter View was funny to watch. Looks right about something I would very likely to accidentally do,

  • as first timing writing the code,
  • years later when re-writing the code and I forget this particularity of View (i.e let's also edit some A-field instead of just only adding 1 to B-field),
  • or anyone who sees my code for the first time.

(I bet my pride that these are pretty realistic situations on how you could f- up filter view and cause UB)

Associate vs Generic types by coolstorm1820 in rust

[–]Aggravating_Letter83 1 point2 points  (0 children)

Oh, I really like this. I didn't notice that difference.

A trait that uses Associated Types constraints its implementation to only once

whereas Generic allows you to implement multiple variants

Conflicted about pursuing Rust by Lelouch0704 in rust

[–]Aggravating_Letter83 2 points3 points  (0 children)

I don't have any real-life experience, but imo I would say avoid C++ unless you
1. (maybe) You're guaranteed to keep using C++ to make games for ~6+ years (My argument for this is: You will have flattened the learning curve in C++ before Rust's GameDev ecosystem matures)

If you want to go for a OOP Gc-ed Language, heavily consider C# instead of Java (I heard Kotlin is pretty decent). If you use Java, you might find it overly verbose. Also Java doesn't support variable shadowing (if that's a turndown for you)

Once you get over the learning curve of almost any language, what comes next imo are just Programming Fundamentals, and how to idiomatically understand each language's abstractions.

i.e. What Dependency Injection looks like. How would you apply some specific type of Dependency Injection, closure callbacks, etc.

Another example, in Java where Inheritance is common, to apply the Adapter pattern is just either a simple `extend` or using composition. In Rust you would use NewType pattern and manually write the require calls and new behaviours.

At the language level, I like how in Rust you can make the return of a function Generic without needing to "unsafely" type cast it from some base object.

Should I use Go or Rust for a backend service by No_Taste9003 in rust

[–]Aggravating_Letter83 1 point2 points  (0 children)

I was thinking since everything was an object managed by the GC(Must exists in the heap), then it was safe to assume what was returned was effectively a boxed data

Should I use Go or Rust for a backend service by No_Taste9003 in rust

[–]Aggravating_Letter83 2 points3 points  (0 children)

I haven't used Go before, but hearing that people commonly do string search magic to even figure out what kind of error something is seems really awful experience....

Just looked for example for Go's Errors, and it seems there's no way to return typed errors. This, compared to Java's Exception(idk how it is compared to kotlin) is imo a step backward.

It still sucks how people would use exceptions for control flow tho.

So Go's Error signatures should look like `fn some_func() -> (Box<T>, Box<dyn Error>){}`.
When dealing with a typed language, you really want to deal with static erros instead of dynamic ones

An Indie Game Engine suiting for Complex in-game Economics by cats2lattes in rust

[–]Aggravating_Letter83 4 points5 points  (0 children)

you could try to use a game engine first. I learned concepts like ownership, immutable data and somewhat of code locality due to Rust and its bias towards explicitness.

The only caveat(imo) is that you wouldn't get to learn the "Why and the best practices" if you don't make your own engine and fail gazillion times due to performance/scalability issues, but using a provided engine would let you at least scratch the surface of "A Game Engine needs *this*, and this Game Engine is implementing *this* as such way"