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 trialAdam Thompson
415 PointsWhy would I want to block others from changing variables, etc?
In the recent videos, techniques were provided to block coders from doing certain things, such as accessing or modifying a variable. Why would I want or need to block a coder from modifying a variable? If I've given him access to my code, it seems that I want/need him to change it, and it would be easier to just let him decide what he needs to do, rather than me decide in advance what he can and cannot do.
3 Answers
Nicholas Grenwalt
46,626 PointsYeah, this isn't for when you are having a buddy check out your code per se, but rather for when your code is out in the wild it is great practice. If you don't privatize your variables then you give them free range to take advantage of anything they like. For instance, let's say that you store a discount in a variable that had 10% and they went in and switched it to 100% prior to submitting it. Giving them access to your variables allows them to manipulate your code in ways that it wasn't designed for and possibly exploit vulnerabilities to their advantage or even allow them to send malicious content back to the server.
Adam Thompson
415 PointsIf I write a program in Java, the .java source files wouldn't be distributed out into the wild, would they? So how would someone access my variables?
HIDAYATULLAH ARGHANDABI
21,058 PointsYou need to seal your main variable and its structure there may be an important data that you may not want to change with first shot