Someone who’s just getting started in programming asked me about the advantage of different approaches programming languages take.
For example, some allow the programmer to omit variable declarations and just use them (like PHP). Others require declaration but not necessarily with a type. And others require a full declaration of the variable (including its type).
So what’s the advantage of each approach? Why is it better to (not) declare a variable and/or its type? The ones that don’t require a type I believe allow for more efficiency for the programmer. You can just take a variable and use it rather than think about what type it may have at the moment of needing it. And potentially you can change its type later on.
But is there more to it than that?
What you are intesrted in knowing is a core distinction between programming languages. You are describing statically and dynamically typed languages. There are a huge number of resources on this. http://en.wikipedia.org/wiki/Type_system
http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)
THere is a lot more to it then what you described. Both have their advantages and disadvantages. Neither is better, but each one might excel at certain tasks.