-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path181118_SH_function
More file actions
39 lines (27 loc) · 2.46 KB
/
181118_SH_function
File metadata and controls
39 lines (27 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 실질인자(actual parameter/argument) vs 형식인자((formal)parameter)
1. 형식인자 : 아래 x와 같이 함수 점의의 요소
function(x):
print(x+5)
2. 실질인자 : 아래 5와 같이 실제 입력 변수
function(5)
>>10
# 값으로 호출(by value) vs 참조로 호출(by referece)
pass by value : 형식 인자에 새로운 값이 할당되어도 실질 인자 변수에 영향 없음
pass by reference : 함수를 호출한 쪽에서도 실지 인자 변수의 값이 변함
(해석) pass by value 방식에서 pass by reference처럼 사용하려면, callee 의 결과값을 return 으로 호출하도록 해야함
# function vs. method
method is function for object-oriented word
method --> function (TRUE)
function --> method (FALSE)
# 참조
First and foremost, the "pass by value vs. pass by reference" distinction as defined in the CS theory is now obsolete because the technique originally defined as "pass by reference" has since fallen out of favor and is seldom used now.
--> "참조로 호출" 방식은 구식으로 잘 사용되지 않고있음.
Now, the authentic definition is:
When a parameter is passed by reference, the caller and the callee use the same variable for the parameter. If the callee modifies the parameter variable, the effect is visible to the caller's variable.
When a parameter is passed by value, the caller and callee have two independent variables with the same value. If the callee modifies the parameter variable, the effect is not visible to the caller.
Now, in modern languages, variables tend to be of "reference types" (another concept invented later than "pass by reference" and inspired by it), i.e. the actual object data is stored separately somewhere (usually, on the heap), and only "references" to it are ever held in variables and passed as parameters.
--> 최근에는 변수에 "참조" 방식을 사용.
(해석) python 에서 y = x 라고 하면, x 나 y 값이 서로 연동됨. 이는 "참조" 방식을 사용한다고 볼 수 있음. R 에서 y <- x 라고 하면, 서로 값이 동조하지 않음. 이는 최근에 변수를 "참조" 방식을 사용하는 것에 뒤처진 것임(?)
'method' is the object-oriented word for 'function'. That's pretty much all there is to it (ie., no real difference).
Unfortunately, I think a lot of the answers here are perpetuating or advancing the idea that there's some complex, meaningful difference.
Really - there isn't all that much to it, just different words for the same thing.