Organising Your Code
Its easy to start writing code without thinking about the organisation, but take some time to plan and it will reward you later. Sometimes a new project is so exciting you just want to start coding and making things work, thinking that you will sort out the structure at a later date. After all, who cares as long as it works, right?
Spending some time sorting out your file structure can save you a lot of time, as well as your sanity in future.
This simple step causes you to think about where your files will live and how you are going to categorize them. For example, if you are writing a blog, you might want to create a posts folder and put all your post files in there. It will make you think about where your files will be and make your url paths more logical in the end.
You don’t need to manually copy and paste these files in anymore. Use a package manager.
Use a package manager
There is a bit of work to be done before you can use the package managers, as in you may have to install them on your system first, but once you have installed them once you can reuse them on all your projects.
You start out by initialising the package manger in your project and then you can start adding the dependencies. The package manager will then go off and install the packages into a directory for you.
The other big benefit is that the packages are under version control. Packages are updated with bug fixes and enhancements, so to make the most of it you just need to run the update command and the packages will be automatically updated.
Use a methodology
The world has moved on from this and now people tend to think more logically about the way they code. There are many different methodologies that fit different circumstances so its best to do some research to see what suits your project. A common methodology for organising code is MVC (Model, View, Controller), where each part of your code performs a specific purpose. I’m not going into this in much detail now, but there is a wealth of information already available online.
Use a framework
Another way is to start with a framework, such as Laravel for PHP, or Foundation for frontend. These frameworks are a great starting point and mean that you have a place to start from and an existing folder structure to follow.
Frameworks are useful in the fact that they provide a lot of commonly used methods, but just research how they work first as, to get the most benefit, you need to work in they way they want, otherwise you will find yourself trying to undo the work they have done to make it work your way. Then there is no point using a framework.
I’ll say it again, use the benefits of a framework to your advantage.
All organised now?
Hopefully you will spend a bit of time planning before jumping in to your next project, even if it is a simple sketch on a bit of spare paper. You will thank yourself later, trust me!
Tagged with development
Published: Oct 27, 2017
Recently I decided to make a new section of my website for short stories. This presented my with a dilemma about how best to make...
Published: Sep 8, 2017
It has been a long time since I last updated the design of my site and as a Frontend Developer it didn’t seem right to...
Published: May 20, 2017
Published: Apr 1, 2017
My job title is frontend web developer, and I am confused. I am in a situation where there are now so many different options for...
Published: Aug 10, 2016
Its easy to start writing code without thinking about the organisation, but take some time to plan and it will reward you later. Sometimes a...