advent_of_code Advent Of Code 🌟 - 2023 DAY 6 SOLUTIONS -🌟
Jump
  • Walnut356 Walnut356 10 months ago • 100%

    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.

    1
  • nostupidquestions No Stupid Questions What Are Your Favorite Hidden Gem Android Apps?
    Jump
  • Walnut356 Walnut356 10 months ago • 100%

    Qownnotes

    It's a desktop app, but can sync with self-hosted cloud servers. It's also literally just text/markdown files.

    1
  • technology Technology An entire state's population just had its data stolen in a ransomware attack
    Jump
  • Walnut356 Walnut356 10 months ago • 100%

    For sure, but as long as clickbait works they'll keep doing it.

    4
  • anime Anime What have been your favourite animes you've seen?
    Jump
  • Walnut356 Walnut356 10 months ago • 100%

    I mean yeah, but why? Like what did you like about it?

    1
  • steamdeck Steam Deck [News] Steam Deck OLED review: Includes specs on new screen and other improvements
    Jump
  • Walnut356 Walnut356 10 months ago • 100%

    If they had made the deck more powerful, the old ones would suddenly have been obsolete.

    I'm pretty sure it has more to do with current chip technology not actually changing that much in the, what, 2 years since the deck first released?

    Also obsolete is a pretty strong word for what - if it had stronger internals - would likely end up being more expensive than current models.

    7
  • technology Technology An entire state's population just had its data stolen in a ransomware attack
    Jump
  • Walnut356 Walnut356 10 months ago • 66%

    To be fair, "an entire x" does have markedly different connotation than "x". The emphasis is that it's, well, the entirety of x. It's the difference between "i ate the cereal" and "i ate all the cereal".

    2
  • anime Anime What have been your favourite animes you've seen?
    Jump
  • Walnut356 Walnut356 10 months ago • 100%

    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?

    1
  • playstation PlayStation Modern Warfare 3 download is huge (200GB) due to “increased amount of content”
    Jump
  • Walnut356 Walnut356 11 months ago • 100%

    Make them optional lmao. I dont have a 4k screen, havent ever had one, and wont buy one for a very long time. Why am i storing these assets i will never use?

    15
  • programming Programming What got you into coding ? (aside from money)
    Jump
  • Walnut356 Walnut356 11 months ago • 100%

    Honestly, it's because a bunch of programs i used disappointed me (performance, functionality, [being a web app at all], etc.) and i figured it couldnt be that hard to do it better. In some cases i was right, in most i was wrong. As it turns out though, I really like programming so i guess i'm stuck here

    6
  • technology Technology Xbox's new policy — say goodbye to unofficial accessories from November thanks to error '0x82d60002'
    Jump
  • Walnut356 Walnut356 11 months ago • 66%

    I mean to be fair, those errors arent really meant for you (the end user) in the first place.

    1
  • programming Programming What′s new in C# 12: overview
    Jump
  • Walnut356 Walnut356 11 months ago • 100%

    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".

    2
  • programming Programming What′s new in C# 12: overview
    Jump
  • Walnut356 Walnut356 11 months ago • 100%

    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"

    4
  • python Python What is your favorite Python syntactic sugar?
    Jump
  • Walnut356 Walnut356 11 months ago • 100%

    Generators probably. It's the one thing i genuinely miss about python when i work in rust.

    2
  • linux Linux Most of us hate Microsoft, and yet many of us use VSCode
    Jump
  • Walnut356 Walnut356 12 months ago • 100%

    Ick. At the very least, i've seen it a LOT less in VSC. The fact that something as simple as rainbow brackets uses the freemium model in intellij sucks. I mean the fact that it's not a builtin setting is dumb too but that's beside the point

    1
  • comicstrips Comic Strips Spill by Chris Hallbeck
    Jump
  • Walnut356 Walnut356 12 months ago • 100%

    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.

    9
  • linux Linux Most of us hate Microsoft, and yet many of us use VSCode
    Jump
  • Walnut356 Walnut356 12 months ago • 33%

    The freemium and constant "are you sure you dont want to pay?" from some intellij plugins is insulting enough that it's hard to believe any developer would praise it. Presumably this doesnt happen in vscode because it cant happen in vscode, not because people arent shameless enough to do it there.

    -1
  • programming Programming The Absolute Minimum Every Software Developer Must Know About Unicode in 2023 (Still No Excuses!)
    Jump
  • Walnut356 Walnut356 12 months ago • 100%

    That depends on your definition of correct lmao. Rust explicitly counts utf-8 scalar values, because that's the length of the raw bytes contained in the string. There are many times where that value is more useful than the grapheme count.

    44
  • programming Programming *Permanently Deleted*
    Jump
  • Walnut356 Walnut356 12 months ago • 100%

    I think it was this issue. Looks like maybe it got fixed some time this year? Iunno, i'll look into it at some point

    1
  • golang Golang Rust Vs Go: A Hands-On Comparison
    Jump
  • Walnut356 Walnut356 12 months ago • 87%

    code that's been written today has been made obsolete by a language feature in the latest nightly build

    I mean couldnt you say that about any language? There's lots of old C code that's obsoleted by features in C11. There's lots of stuff written in python today that's obsoleted by stuff in the 3.13 alpha. It's just kinda how things go.

    Doesnt the edition system prevent this from being too big of an issue anyway?

    6
  • godot Godot Question about gdscript: Which is more efficient?
    Jump
  • Walnut356 Walnut356 12 months ago • 55%

    I did not dismiss it, I said measure the performance yourself.

    Then why does anyone ask anything? Just figure it out yourself. Oh you read a book or went to college? Why? Should have just reinvented computers yourself man. Taking advantage of collective knowledge is for suckers /s

    This means that the code performance is highly dependent on runtime conditions, and needs to be measured in the place where it's used.

    How is that helpful for OP? For example, if his question was about rust i'd say "options 1 or 2 should be identical for speed", but if it's python i'd say "match statements are just chained if/else chains, so a direct array index would be faster". For another example, in python attribute access is a function call. x.y in a loop is slower than assigning z = x.y outside of the loop and calling z in the loop.

    You can absolutely generalize and have rules of thumb for performance.

    If they already measured, then they would know which one is faster, because they measured it.

    Measurements can have unintuitive results based on the dataset used (which, for benchmarks, usually end up being artificial datasets). OP's measurements may not have been consistent with their working understanding, thus they ask outside sources to confirm the truth. Idk why you cant just give them the benefit of the doubt and like... answer the question they actually asked? The explanations for "why" that accompany that answer can also be incredibly helpful.

    And all of these optimizations are just as effective after you measure them to see if they're needed, and they're no longer premature.

    That implies that these optimizations are harder than doing it the "mundane" way. They're not.

    Here's a fun micro optimization for compiled languages: on modern CPUs

    x = x * (arr[0] * arr[1]) in a loop has better performance characteristics than

    x = (x * arr[0]) * arr[1]

    even though they do the same thing (in short, it's because of the data dependencies for out-of-order execution - compilers wont make this optimization automatically for floats). How much harder is it to write the first one compared to the second one? How much harder to read is the first compared to the second?

    So why would you not just make the first one your default? Now all your future uses of that pattern will perform better, for no extra effort except the amortized cognitive fee of changing your default option.

    Look at OPs question. Could the answer fall under a rule of thumb that they can apply as their default option for a scenario? I'm pretty sure it can. So who cares about "premature" or not?

    The particular question asked by the OP is very very unlikely to have any significant performance impact at all, unless it's in an extremely hot loop running millions of times per frame

    So instead of answering their question, you assume it isnt impacting performance and they're just asking for no reason?

    I literally had this exact question about python like 8 months ago. I had a file parser that needed to process different chunks based on a tag. Performance was critical, several thousand files, each ~3mb), the tag dispatch happened about 100,000-300,000 times per file. The original was implemented with if/else. I switched it to match because i thought it was faster, it wasnt. I looked at a lot of threads with answers like yours until stumbling upon dictionary dispatch (i.e. key = tag, value = first class function to call on the tag's data) and array dispatch.

    That change alone was a 15% performance improvement.

    You have no idea how their program works, what their hot loop is, if they're just asking out of curiosity, whatever. Just answer their fuckin question my dude. Platitudes are a waste of everyone's time.

    1
  • godot Godot Question about gdscript: Which is more efficient?
    Jump
  • Walnut356 Walnut356 12 months ago • 71%

    Rule number 2: stop dismissing performance questions just because of something some guy said decades ago. Performance matters, learning about performance matters, and answers like yours dont help anyone.

    Did they ask if they should optimize, or did they ask which one generates more performant assembly? Which one of those questions did you answer?

    Maybe they already measured and already knows this is a bottleneck. Maybe they are curious if match statements are a slow abstraction (e.g. in python, it's essentially a chain of if/else. In rust it's often compiled to an indexable table). Maybe the given example code is only partially representative of the actual code this is being applied to.

    It's so irritating to look up performance-related questions when this answer is at the top (and middle, and bottom) of every thread. I swear half the reason every piece of modern software runs like shit is because nobody bothered to learn how to optimize and now everyone just parrots that phrase instead of saying "i dont know".

    There's tons of little "premature" optimizations that you can do that arent evil. Choosing the right data structure (how random is the access? Are you using keys? Does it need to be sorted?). Estimating time complexity and load size (e.g. "i'm parsing [11 million | 2] files, i should probably [keep time complexity in mind | ignore time complexity completely]"). Structuring loops in a way that's easy for compilers to auto-vectorize - usually it's not any harder to read what the loop is doing, so why not do it right away?

    Yes i'm bitter =(

    6
  • programming Programming *Permanently Deleted*
    Jump
  • Walnut356 Walnut356 12 months ago • 80%

    Is pycharm's semantic highlighting still kinda ass? That's the biggest thing that stopped me from using it over vsc. As of like may this year i remember there still being active issue tracking for it.

    3
  • rust Rust Learning Rust
    Jump
  • Walnut356 Walnut356 12 months ago • 100%

    Counterpoint, i didnt like the rust book at all (as an inexperienced self taught ~6 months to a year into learning python at the time). Programming Rust and Rust In Action were far better.

    1
  • rust Rust The Urgent Need for Memory Safety in Software Products
    Jump
  • Walnut356 Walnut356 12 months ago • 75%

    Seems you missed the last line

    compiles to fast code

    2
  • steam Steam GODOT ussage this week
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    Iirc godot uses beta branches and semver, so the only updates you get are the ones that dont break anything.

    7
  • python Python Jupyter notebook
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    Obligatory shoutout to Qownnotes for being excellent, fully open source, and with owncloud integration.

    1
  • rust Rust Rust Analyzer Changelog #198
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    15532 on-type format (, by adding closing ) automatically

    Thank fucking god lmao. The PR specifically mentions the Some( case too, which is exactly where i encounter this the most.

    Overall very nice changes

    4
  • bookrecs Book Recommendations What are some good books for a beginner programmer?
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    Nah, i dont think that's true at all. Priority number 1 is learn the language that deals in what you're most interested in. Priority 2 is learning the language whose ecosystem you can tolerate.

    Why? Because you learn most when you enjoy what you're doing.

    I'm interested in performance and systems programming so i tried to start with c++. C++'s ecosystem and tooling are complete garbage and i spent more time fighting it than learning to program. I learned python for a specific project, but eventually started learning rust because i was frustrated with python's lack of low level functionality (and speed).

    Rust has a lot of modern features that c++ doesnt (and that arent buried behind 20 years of "do this, no wait that's bad, actually do this instead"). The tooling is excellent for beginners, and there's lots of core and standard library features that simplify some of the stupid things about low level programming. And you dont have to start with all the low level fiddly bits, you can start with variables, conditionals, and functions just like you would in python or whatever.

    As for book recommendations:

    NOT the official rust book. Imo it assumes you already know at least one other programming language. It doesnt always go into enough detail about advanced concepts, but other times goes into WAY too much detail for true programming beginners.

    The two that i liked the most were:

    Programming Rust by Blandy, Orendorff, and Tindall

    Rust in Action by Tim McNamara

    I've also heard good things about Command-Line Rust by Ken Youens-Clark, but i havent read it myself.

    Also, dont be afraid to read language-agnostic books that cover general computer science concepts like Dive Into Algorithms, Understanding The Machine or Data Structures The Fun Way after you've gotten your feet wet.

    5
  • programming Programming What are your programming hot takes?
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    You could say that about anything. Of course you have to learn something the first time and it's "unintuitive" then. Intuition is literally an expectation based on prior experience.

    Intuitive patterns exist in programming languages. For example, most conditionals are denoted with "if", "else", and "while". You would find it intuitive if a new programming language adhered to that. You'd find it unintuitive if the conditionals were denoted with "dnwwkcoeo", "wowpekg cneo", and "coebemal".

    5
  • programming Programming What are your programming hot takes?
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    “Unintuitive” often suggests that there’s something wrong with the language in a global sense

    I mean only if you consider "Intuition" to be some monolithic, static thing that's also identical for everyone. Everyone has their own intuition, and their intuition changes over time. Intuition is akin to an opinion - it's built up based on your own past experiences.

    just because it doesn’t look like the last one you used — as if the choice to use (or not use) curly braces is natural and anything else is willfully perverse on the part of the language designer.

    I don't think it's that deep. All people mean when they say it is that "[thing] defied my expectation/prior experience". It's like saying "sea food tastes bad". There's an implicit "to me" at the end, it's obvious i'm not saying "sea food factually tastes bad, and anyone who says they like it is wrong or lying".

    9
  • rust Rust UniFFI - automatically generate foreign-language bindings targeting Rust libraries
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    Here's the script. It's nothing fancy, and iirc it only works for top level functions/classes. That means you still have to take care of attributes and methods which is a little annoying, but for simple stuff it should save a bit of time.

    3
  • rust Rust Why Rust is the most admired language among developers?
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    For downsides, i'd like to add that the lack of function overloading and default parameters can be really obnoxious and lead to [stupid ugly garbage].

    A funny one i found in the standard library is in time::Duration. Duration::as_nanos() returns a u128, Duration::from_nanos() only accepts a u64. That means you need to explicitly downcast and possibly lose data to make a Duration after any transformations you did.

    They cant change from_nanos() to accept u128 instead because that's breaking since type casting upwards has to be explicit too (for some reason). The only solution then is to make a from_nanos_u128() which is both ugly, and leaves the 64 bit variant hanging there like a vestigial limb.

    10
  • programming Programming What are your programming hot takes?
    Jump
  • Walnut356 Walnut356 1 year ago • 95%

    Please don't say the new language you're being asked to learn is "unintuitive". That's just a rude word for "not yet familiar to me"...The idea that some features are "unintuitive" rather than merely temporarily unfamiliar is just getting in your way.

    Well i mean... that's kinda what "unintuitive" means. Intuitive, i.e. natural/obvious/without effort. Having to gain familiarity sorta literally means it's not that, thus unintuitive.

    I dont disagree with your sentiment, but these people are using the correct term. For example, python len(object) instead of obj.len() trips me up to this day because 99% of the time i think [thing] -> [action], and most language constructs encourage that. If I still regularly type an object name, and then have to scroll the cursor back over and type "len(", i cant possibly be using my intuition. It's not the language's "fault" - because it's not really "wrong" - but it is unintuitive.

    36
  • rust Rust UniFFI - automatically generate foreign-language bindings targeting Rust libraries
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    Pyo3 doesnt generate type hints at all iirc. There's some more info here

    The gist, as i recall, is that you're supposed to maintain a .pyi file in the rust project folder that gets automatically added in by maturin when building. I'm no regex wizard, but i was able to whip together a small script that generates simple function and class stubs that also have the rust docstring. Iirc they're planning on adding some official support for generating type hints, but i have no idea how far along it is or where it is on the priority list

    3
  • python Python The Python dictionary dispatch pattern
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    It's most useful when you're using some data you already have as the dictionary key. A usecase i had for this was a binary file parser with 10 types of event markers. It was originally coded with if/elif, but performance was a pretty big consideration. Using the event markers as keys to a dictionary dispatch improved performance by about 15% and made the code significantly more readable.

    2
  • gamedev Game Development [Humble Bundle] Solo Indie Game Dev Essentials Bundle
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    I can vouch, i got one of their previous bundles that includes some of these items. Their tutorials are great, much better than random youtube videos if you're serious about getting started. I only went through one of the courses so far, but when i get back to game dev it's one of the first resources on my list

    1
  • programming_languages Programming Languages August 2023 monthly "What are you working on?" thread
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    I read the book. It's not too difficult to replicate their test's functionality with rust tests, but i still ended up using their software suite a few times to verify some behavior and get a better understanding of the step-by-step logic for the alu and cpu

    2
  • programming_languages Programming Languages August 2023 monthly "What are you working on?" thread
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    Hopefully this month i can finally finish up nand2tetris. I did more or less all of it in rust to learn the language, and i feel like I'm now about as comfortable in it as i am in python. Learning how to build a computer from logic gates was sick, but debugging the compiler has been really draining. The way compilers work is neat, but all sorts of little problems keep coming up that force me to restructure large pieces of it over and over and i've lost almost all my momentum.

    I'm not sure what I'll move on to next, maybe something more front-facing like a gui library, or maybe I'll finally look into anything that might actually provide me skills that will get me a job lol.

    7
  • programming Programming Do they know one second is slow?
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    People in different socioeconomic situations/locations experience new technology at different points in time. Just because the internet existed doesnt mean they (or anyone in their immediate vicinity) had internet, state of the art computers, etc.

    2
  • programming_horror Programming Horror When your language doesn't allow arbitrary expressions in format strings
    Jump
  • Walnut356 Walnut356 1 year ago • 100%

    it makes what looks like formatting an arbitrary complex operation and that it doesn't improve readability that much.

    What's silly to me about that reasoning is that all workarounds are equally less convenient, have less readability, and the effect is identical to just letting me put whatever between the brackets. I genuinely dont understand the downside i guess.

    Calling .join on a vector can have side effects too, except the "we're concatting strings" is at the end rather than the beginning (and could obfuscate the fact that the end result is a string). It has just as much room for abuse as a long format!(). Even with just format!(), anything you could do inbetween the brackets, you can do outside the brackets in the arguments anyway. At least when it's between the brackets, i know exactly where it's going and when without having to juggle the string pieces and assemble them in my head.

    2