Idk I randomly felt like writing about refactoring, structuring your project and how I approach new projects.

Here's what I try to follow when building something new 👇

THREAD

1/n
1. Start with minimal folders! `src/index.js` is pretty much enough for playing around something and then add files as your project grows.

2. First code is always a mess! You have to keep on refactoring and rewriting files to make it less mess.

2/n
3. When getting started, I install a bunch of libraries and just try to get something working as quick as possible. So initially its just a bunch of libraries working together.

4. Once you get it working, remove unnecessary libraries one by one.

3/n
5. Give guessable names to folders (You will learn this better after exploring other open-source projects)

'src' for code, 'tests' for tests, 'scripts' for any custom scripts, 'dist' for what you want to distribute, etc.

4/n
6. Write tests!

Ok I guess this is going to be a thread inside a thread.

Sometimes, Initially, I don't have clear idea of what I'm building and I mostly be experimenting and changing the code upside down. During this time I avoid writing tests

5/n
And once I figure out where this project is going, I write tests! (Make sure you do it before v1.0.0 of your project)

While writings tests, Sometimes I know what a particular function is going to output on given input even before writing a function, in that case, I write..

6/n
...tests before writing code and then I write code until the test cases pass.

7/n
7. Adding code to project is easy, removing is hard so don't think about 'What you may need in the future', if you happen to need it in the future, you can add it in the future. A lot of projects get super hard to maintain while trying to make it maintainable in the future

8/n
8. REMOVE COMMENTED CODE YOU DON'T NEED IT... and even if you do, you can add it from GitHub history anyway so just remove it. 🤷

9/n
Extending the point number 7: Nobody and yes nobody, no matter how many years of experience, has a clear idea of what they are building while they are starting the project so what you think that you may need in the future, there's a good chance that you may never need it.

10/n
9. Ok maybe this is just me but after small refactors, I tend to forget to remove the not-anymore-needed functions. Just CTRL + SHIFT + F and check if it is being used somewhere and if not, remove it!

11/n
You can follow @saurabhcodes.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.