geth32
10-03-2008, 11:13 AM
can someone definde the term parameter for me please?! i know its simple stuff!
DrJim
10-04-2008, 12:08 AM
Simple stuff - but not always really explained well and not totally consistant between languages. In Alice, anyway, a "variable" is something that only exists within a method - while a "parameter" is a variable whose value is passed to the method when the method is called.
More rigorous definitions are welcomed :) - this is the best I can do.
DickBaldwin
10-05-2008, 07:14 AM
Simple stuff - but not always really explained well and not totally consistant between languages. In Alice, anyway, a "variable" is something that only exists within a method - while a "parameter" is a variable whose value is passed to the method when the method is called.
More rigorous definitions are welcomed :) - this is the best I can do.
Not trying to be picky, but an Alice property is similar to an "instance variable" or "object variable" in true OOP languages.
Actually, variables and parameters aren't necessarily "simple stuff."
In C and C++, when you pass a variable to a function "by reference," you don't actually pass the value stored in the variable. Instead, you pass the address of the variable so that it can be accessed and modified from within the function. When you pass a variable "by value," you pass a copy of the value stored in the variable. The contents of the original variable cannot be accessed and modified by the code in the function.
In C/C++, you can have global variables, local variables, class variables, and instance or object variables, which can be a mixture of ordinary variables and pointer variables. You Program behavior can be considerably different depending on the kind and flavor of variable you are working with in any particular expression. When you include pointer variables in the C/C++ discussion, things can become really complicated.
In Java, global variables aren't allowed. However, you can still have local variables and instance or object variables, which can be a mixture of primitive or reference variables.
All variables in Java are passed "by value." As long as you are passing primitive variables, the behavior is very similar to C and C++. However, when you pass a reference variable "by value" to a method, you are actually passing a copy of something that refers to an object (sort of an abstract address.) This makes it possible for the code in the method to access and potentially modify the contents of the object (depending on access restrictions). However, the code in the method cannot modify the contents of the original variable. This is similar to, but not identical to, passing a pointer variable "by value" in C/C++.
Variables and parameters can be difficult to understand but are relatively simple in comparision to concepts such as function overloading and overriding, base-class pointers, and runtime polymorphism.:)
Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free Scratch tutorials: http://www.dickbaldwin.com/tocHomeSchool.htm
Free Java/C#, etc. tutorials: http://www.dickbaldwin.com/toc.htm
DrJim
10-05-2008, 06:31 PM
Thanks Dick. :) Like I said earlier "More rigorous definitions are welcomed." and your's was great!
In Java, global variables aren't allowed.
In Alice, however, "world level" variables are allowed. A nice "cheat" back to BASICs. :)
Another "cheat" in Alice that can be confusing is that it restricts the definition of a "function" to a method that returns a value to the calling method.
zonedabone
11-13-2008, 03:32 PM
In a nutshell, a parameter is something that you use in an event so that when you drag that event somewhere to make it run, you can select what the parameter is. Use the parameter in the methods within your method to make it so that those variables are defined when you drag the enevnt somewhere. Usually, you'd use this in a characters customizable functions. It can be used to make a method such as [WALK [HOW FAR]] with how far as a parameter. you'd then add in the event that the person moves a distance of [how far] meters.