DEV Community

Cover image for Why You Need a Coding Scratch File
Kevin Hicks
Kevin Hicks

Posted on • Originally published at kevinhicks.software

Why You Need a Coding Scratch File

Sometimes the best place to write code for your project is outside it.

This may sound like a lie. How could writing code outside of a project be the best place for the project's code? How can it even help the project at all?

Working within a project, especially a large and complex one, other code can get in the way of what you are writing.

By removing the distraction of unrelated code, you can focus on your task.

When experimenting with designs or figuring out a tricky issue, it's quicker and easier to focus on the smallest amount of code needed. You don't have to worry about passing arguments around, multiple software layers, and other complexities. You also won't need as many manual steps or automated tests to test your code.

Sometimes you will need the rest of the project code, but removing it can be a huge productivity boost when you don't.

How does a scratch file help?

A scratch file allows you to write code that can be compiled, ran and debugged without the rest of your project or setting up a new one. You can copy the code to your project and delete the file when you finish. Scratch files also help avoid accidentally committing temporary code.

It's like a sticky note for the code you throw out when done with it.

Create your first scratch file.

Scratch files can usually be created inside your IDE. The process is different between IDEs, so search for "your IDE name + scratch file" to get started. It's also helpful to read everything your IDE can do with scratch files when you look this up.

Once you create the file, start writing code.

There are also options outside of IDEs for scratch files.
You could use a fiddle site (like jsfiddle) for your language. Some languages and frameworks have tools for this, such as artisan tinker for Laravel and LinqPad for C#. A default project for your language or framework could also serve as a scratch file if you need to work across multiple layers with no other custom code.

Learn about the scratch file options for your project and use what you prefer.

While not suitable for every situation, scratch files are a fantastic tool when focusing on a small amount of stand-alone code.

Top comments (1)

Collapse
 
alphaolomi profile image
Alpha Olomi

I currently work with Next.js mostly and several times i had to create different temporary(scratch apps ) next app to try some features packages and more

It really helps with focusing and reducing interference with other parts