• 1 Post
  • 44 Comments
Joined 1 year ago
cake
Cake day: July 1st, 2023

help-circle
  • I’m no rust expert, but:

    you can use into_iter() instead of iter() to get owned data (if you’re not going to use the original container again). With into_iter() you dont have to deref the values every time which is nice.

    Also it’s small potatoes, but calling input.lines().collect() allocates a vector (that isnt ever used again) when lines() returns an iterator that you can use directly. You can instead pass lines.next().unwrap() into your functions directly.

    Strings have a method called split_whitespace() (also a split_ascii_whitespace()) that returns an iterator over tokens separated by any amount of whitespace. You can then call .collect() with a String turbofish (i’d type it out but lemmy’s markdown is killing me) on that iterator. Iirc that ends up being faster because replacing characters with an empty character requires you to shift all the following characters backward each time.

    Overall really clean code though. One of my favorite parts of using rust (and pain points of going back to other languages) is the crazy amount of helper functions for common operations on basic types.

    Edit: oh yeah, also strings have a .parse() method to converts it to a number e.g. data.parse() where the parse takes a turbo fish of the numeric type. As always, turbofishes arent required if rust already knows the type of the variable it’s being assigned to.







  • Claymore (the end was kinda mid)

    Genuinely curious - why do you like it? I see this at the top anime of all time. I watched it a few years ago and i thought it was absolutely horrible. Like 2 or 3 out of 10.

    I feel like the only reason i can see is “the main character is a bad guy” but that doesnt excuse trope-y terrible writing, flat characters, and mid-2000’s animation that aged horribly. Am i missing something?






  • Walnut356toProgrammingWhat′s new in C# 12: overview
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    1 year ago

    I’m not sure I understand your point about fall through having to be explicit

    As far as i understand it, every switch statement requires a break otherwise it’s a compiler error - which makes sense from the “fallthrough is a footgun” C perspective. But fallthrough isnt the implicit behavior in C# like it is in C - the absence of a break wouldnt fall through, even if it wasnt a compiler error. Fallthrough only happens when you explicitly use goto.

    But break is what you want 99% of the time, and fallthrough is explicit. So why does break also need to be explicit? Why isnt it just the default behavior when there’s nothing at the end of the case?

    It’s like saying “my hammer that’s on fire isnt safe, so you’re required to wear oven mitts when hammering” instead of just… producing a hammer that’s not on fire.

    From what i saw on the internet, the justification (from MS) was literally “c programmers will be confused if they dont have to put breaks at the end”.


  • Walnut356toProgrammingWhat′s new in C# 12: overview
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    1 year ago

    the ergonomics expected of modern languages.

    As someone learning c# right now, can we get some of those “modern ergonomics” for switch statements 💀

    I cant believe it works the way it does. “Fallthrough logic is a dumb footgun, so those have to be explicit rather than the default. But C programmers might get confused somehow, so break has to be explicit too”

    I miss fallthrough logic in languages that dont have it, and the “goto case” feature is really sick but like… Cmon, there’s clearly a correct way here and it isnt “there is no default behavior”


  • 60fps doesn’t matter

    60fps feels smooth, less than 60fps doesnt feel smooth. Even in non-shooters. I dont like the jittery look when i pan the camera or do anything. Computers are more than capable of it. I say this as a programmer who focuses on low level optimization. Almost all software runs like shit because devs dont care about performance and people are just used to it. I still have my mind blown on a near daily basis on how much I can squeeze out of my cpu. Not because i’m doing anything crazy or complicated, but because 90% of software has visible latency for clicking a button and eats tons of ram for no good reason.

    RAM should be used. For gaming it would be wasteful not to use it. If you aren’t using all your ram then you’re loading textures, shaders, and everything from disk, which is thousands of times slower and that would lead to … you guessed it, gamers bitching about lag

    That’s… Not really how it works at all. Using all of your ram is actually pretty bad. Because then if your computer needs more ram, something is getting dumped to the page file. On your hard drive. There’s no easier way to make your PC crawl than to make your cpu have to keep swapping shit to and from the page file.

    It’s entirely possible to have a better system for when to have those textures loaded to decrease overall ram usage, better/less wasteful data structures, culling techniques to decrease the number of things that have to be loaded and directly handled (e.g. in factorio if you have a belt with only 1 type of item on it, it wont track every individual item. It just averages the throughput to save on processing power.)

    I have 32 gigs. I want them to use it.

    The average consumer still has 8, i have 16 and run into problems with some modern games. I also shouldnt have to close other applications on my computer because your shit game cant handle its memory properly.




  • I feel like it’s like pointers.

    “Variable” refers to the label, i.e. a box that can contain anything (like *ptr is a pointer to [something we dont know anything about])

    Immutable describes the contents, i.e. the stuff in the box cant change. (like int* ptr describes that the pointer points to an int)

    Rust makes it very obvious that there’s a difference between constants and immutable variables, mainly because constants must be compile time constants.

    What do you call it when a variable cant change after its definition, but isnt guaranteed to be the same on each function call? (E.g. x is an array that’s passed in, and we’re just checking if element y exists)

    It’s not a constant, the contents of that label are “changing”, but the label’s contents cant be modified inside the scope of that function. So it’s a variable, but immutable.


  • Saying “non negotiable” doesnt actually hold up in small claims, nor against basic resistance in most cases.

    Look up your local laws, in some places carpets must be replaced at the expense of the landlord every X years, or if there is any kind of damage (caused by regular wear and tear) that could be a trip hazard. Pictures from move-in, carpets not being replaced when you moved in, etc. all help your case.

    Last place i lived, I spent 30 minutes arguing on the phone with my previous landlord over flooring and got my 700 dollars back. Turns out most of the time they only vaguely know the laws they’re quoting, so if you come with confidence, prep, and a willingness to take it to small claims, they’ll fold to save themselves the effort.