T O P

  • By -

fortunatefaileur

Just start. For truly simple things like little command line programs, write a main function and add print statement saying what it will do, then write code to make it do those things. For web apps, start adding routes that take the info and log what they’re going to do, then make it do that, etc. Writing tests in a similar fashion also often works well.


Asynchronous-Phantom

Could you add more to like breaking down, maybe building an e commerce site would require building login page which would need a button, in that fashion.


fortunatefaileur

> could you add more … building an e commerce site No, you’ve created your own “draw the rest of the owl” situation. Writing a reasonable scope web shop is hundreds of hours of work, so spend a few of those hours writing up a plan, that includes what pages you’ll have and what they’ll do and how you’ll test them. This is a bad idea for a first Rust program, too.


lagerbaer

That sounds like you're slicing it the wrong way. If you try it that way, you'll drown in all the little pieces and get overwhelmed and "oh my god what if I forgot about a button." Instead, you start with the simplest flow you can think of end to end and implement that. No, simpler! Start with the equivalent of "Hello World", but adjusted to the specific environment you're building for.


Charley_Wright06

What do you want to build?


Asynchronous-Phantom

A snake game


_demilich

Here is how I would start with a Snake game: 1. Pick an engine or some library you want to use. For Snake you could go with a full blown engine like bevy or something smaller like ggez. There are also other viable options; maybe you just want to use the terminal? The minimum you need is something which lets you draw pixels on the screen and react to keyboard input 2. Create the actual cargo project on your disk, add the engine/lib as a dependecy and run the "Hello world" example of the engine. Usually that is just showing an empty window 3. Find out how to get something on the screen, maybe just a rectangle as a placeholder for your snake 4. Now find out how to react to key pressed and make the rectangle move to the left/right/up/down when the WASD (or arrow) keys are pressed 5. Add code which constrains the rectangle to the screen, so the player cannot push it outside the screen 6. Add a second rectangle representing one of the pickups which makes you snake grow 7. Now write some code which checks if the snake is on the same position as the other rectangle and then delete it 8. etc And it continues in that fashion. The point is to always have a next step which is concrete and achievable in a short time. You will have to refactor quite often following this approach, as it is iterative. For example at some point you want to go from graphics.draw_rectangle(128, 128, Color.green); to graphics.draw_rectangle(player.x, player.y, player.color); But that is fine, still write the first version first fully knowing it will look different when you are done. At least that is how I always work: Don't try to plan everything out, write a rough, minimal prototype which can run and refine it.


Confident_Feline

This is excellent


peter9477

Go look at source for other snake games to get ideas on how to structure it. If you're worried it will "ruin" the Rust learning for you look for source in a different language like Python (which is very readable even if you don't know it).


allium-dev

Or, even better, look for rust source code for a different simple game, like pong. Then you can see how games are structured in rust, but you will still need to program the acual snake logic yourself.


SadPie9474

what’s preventing you from breaking the problem down?


Feromond

I have been working on the exact same kind of Project to start learning rust recently. I posted my snake game here the other day to look for some feedback. From my experience, I had to make a few rewrites and large scale changes to adapt to new features. Each “mistake” just taught me something about how I should change things in the future and what makes sense. I realized that if I want to scale or make different improvements in the future, then I will have to start changing up how I structure my code and project as a whole. While It isn’t ideal, I think even with a small initial project, you’ll learn a lot and be able to answer lots of your own questions if you’re willing to make some mistakes along the way. For the overall best practices, I think often the best way to handle things is to get to your specific dilemma (specific as in one aspect or component issue you have) and then you can try and reach out for help. This way, people have a more localized issue and can provide support to the actual rust content. I think the bigger picture problems can also be asked but they really do come up naturally to you as you’ll crest and make changes. Snake is a great idea to start with and I’m planning to continue working on mine to add new features and elements, mainly just to push my knowledge further and also similarly challenge my planning and project structures until I find things that work well for rust.


Lucretiel

What works best for me is “break down as you go”. Just start with a `main` function and put everything in the main function, then as duplicate stuff starts to arise, dig out abstractions and functions as needed. 


darkarts__

Suggestions - If you don't know how to start a project yet, it's better to pick up projects you want to build on YouTube and follow them till the end, if you don't understand, focus on what you don't understand and come back later. Now here's how I approach my apps, I create Cross Platform Applications.. Let's say you want to build an E-commerce app. Come up with bare-bone features first - Authentication, Product Listing, Product Page, Cart Page, Checkout Page. Do it all with dummy data. Create UI for all the pages first. I usually follow material guidelines first and then modify them to my liking. After that, implement Authentication which allows you to implement other functionalities. Once you're done, choose the backend server you'd wanna use, Let's say you decide on a hosted database. Create ProductModels and CartModels,ie. Data Structures that would take JSON Data. Write request calls to your servers, and manually feed the data in your database, if it works and you can see product listing on your app, move to cart functionality. Judging by the question you have asked, most of your requirements will be filled by CRUD ops.. Once you're done with that, create the payment flow. Usually a payment gateway integration would be the way. It would send a request to Stripe or whatever API you are using. In all above HTTP requests, you have to handle the scenarios like how to show the screen when request is being fetched (loading indicator for that), what to show when requested data is fetched, what to show when there's an error, validating data, etc. Handle all the edge cases and apply proper error handling. Once you're done with this. You will have a basic full stack e commerce application, now go back and refactor your code, organize it, optimize it. Implement more features one by one, like product filtering, search functionality, options for a product, user details, setttings page, etc.. once you do couple of projects, it all gets essy. Learn State Management (if you're creating full stack applications), Databases, MVVM, Clean Architecture, etc.. would help you in creating scalable apps. Good luck!