Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

1 Answer

Hard-coding is writing things into your code which build something into it. For example, if you always store your images in an img directory, it may be tempting to always add the string "img\" on to the front of all of your image filenames in the code, but what if you changed your mind and wanted to put them somewhere else at a later stage. You would need to go through every file and edit the code to change this. If you knew that the rate of VAT was 20% and you coded the multiplier 0.2 in your program to calculate the VAT, if the VAT rate changed you would have to search all the code to find it. This is why there was a potential problem with the Millennium Bug - lots of programmers had card-coded that years began with "19" but the years were soon going to start "20". The solution is to store things like this in variables in ONE place in your code. Then to change it, you just change the one instance. Sometimes you can create a file which contains these global variables so you know where to look if you want to change them.