this post was submitted on 13 Jun 2024
28 points (100.0% liked)

Learn Programming

1547 readers
6 users here now

Posting Etiquette

  1. Ask the main part of your question in the title. This should be concise but informative.

  2. Provide everything up front. Don't make people fish for more details in the comments. Provide background information and examples.

  3. Be present for follow up questions. Don't ask for help and run away. Stick around to answer questions and provide more details.

  4. Ask about the problem you're trying to solve. Don't focus too much on debugging your exact solution, as you may be going down the wrong path. Include as much information as you can about what you ultimately are trying to achieve. See more on this here: https://xyproblem.info/

Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
 

I'm trying to make minesweeper using rust and bevy, but it feels that my code is bloated (a lot of for loops, segments that seem to be repeating themselves, etc.)

When I look at other people's code, they are using functions that I don't really understand (map, zip, etc.) that seem to make their code faster and cleaner.

I know that I should look up the functions that I don't understand, but I was wondering where you would learn stuff like that in the first place. I want to learn how to find functions that would be useful for optimizing my code.

you are viewing a single comment's thread
view the rest of the comments
[–] pooberbee@lemmy.ml 3 points 2 weeks ago

Some of this is probably just getting to know your tools. Learn the language, look at others' code and interrogate what they did and why. The higher-order functions (scary-sounding term, but they're not actually scary) you mentioned are useful, go learn them and use them.

Some of it might also be (I haven't seen your code) getting a better understanding of the problem you're trying to solve. Figure out what all the separate pieces you need are, and then break those pieces into their pieces and so on, until you've got simple, self-contained chunks of functionality that you can give simple names to. Some of those might be functions, or you may find that they're simple enough that they don't need to be. Refactor and think about how to make the problem simpler. I think a lot of it is just staring at your work and dreaming of ways the make it simpler and easier to read.

If you really want to optimize for performance, that can come later once you really have a feel for it.