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
Ryo Kinjo
Courses Plus Student 4,703 PointsWhy do variables need Types?
Before I joined Treehouse, I had started programming a bit on C#. Now I know that you guys don't have any c# videos but I was wondering because you guys seem like people that know a lot about programming, you could help me out.
So my question is why do variables need Types? I mean in c# if I was create a new instance of something(lets say a button), I would write: Button myBtn = new Button(); So I get the whole myBtn = new Button(); part but why do you need the first "Button". I also noticed that in your iOs tutorials(Your a great teacher Amit) you also do something similar. When lets say you want to create an array you say: NSArray *myArray = [[NSArray alloc] initWithObjects:....] Like I said before I understand why you need the myArray = [[NSArray alloc] initWithObjects:...] but why do you need to declare the type? I mean cant the system recognize what you put in that variable? Im really confused.... Any help of feed back would be great! Thanks a ton!
3 Answers
manuel arvizu
Courses Plus Student 3,030 Pointsi hope this help you...
Jason Shillingford
6,443 PointsProgramming Languages are different, some may need you to specify what type of variable it is, so the computer knows what to expect, whereas some languages like php does alot of it for you.
James Barnett
39,199 PointsDatatypes exist mostly for 2 reasons:
- Conversation of memory, a number takes less memory to store than a string of text
- Operations a
+used against a string of text, should concatenate whereas a+used against a number should perform addition.