imparative의 가장 큰 특징 중 하나가 바로 expression
java - primitive type & constructed type(class, String)
java specification 8.1을 보면
ClassDeclaratio: NormalClass || interface || enum
Python은 everything is object
Classification of Polymorphisms
- University Polymorphism (단순함
: Subtype Polymorphism
: Parametic
: Polymorphism
- Ad-hoc Polymorphism (복잡한, 임시방편)
: Overloadding
: Paramter Coercion
Short-circuit
A||B일 때 A가 True이면 B는 볼 필요가 없으니 보지도 않고 진행하는 것을 의미
Lvalue and Rvalue
a=1 - lvalue 따른 이유
a = a + 1
에서 맨 왼쪽 a는 lvalue로 메모리 주소를 가리키고
가운데 a는 rvalue로 변수 a에 담긴 값을 의미한다
a++에서 a는 lvalue와 rvalue가 합쳐진 케이스
연산자에 따라 old value, new value를 의미
Numeric Coercion
== numeric promotion
비트 수가 작은 것이 큰 걸로 자동으로 캐스팅
파이썬의 실행문 statement가 있지만 -> imparative language의 특성
ML은 expression만 있다. side effect를 없애기 위해서다.
Expression with Side Effect
자바 코드로,
아래 예시에서 b는 5에서 3으로 바뀐다
Assignment: Definite VS Indefinite
자바는 메모리를 올리기 전에 잘못된 것이 없는지 확인 (static )
k가 초기값이 없는데 k가 출력되려고 해서 그렇다.
syntax 문제가 아닌 sementics 문제
같은 True 임에도 정적으로 걸러진다.
객체 위치는 stack에 올라가지만
그 객체 내에 변수들의 heap의 어딘가에 올라가 있다.
Reference != Pointer
from ctypes import c_int, addressof
addressof(c_int(변수))
java에는 pointerrk djqtek
just values that uniquely identify a particular object
절차 imperitive 지향 vs 객체 지향 oop
절차 지향: 작은 기능을 객체 별로 나누면 너무 많아져 버릴 때 사용 -> 소형 프로그래밍
객체 지향: 각 객체가 하는 역할이 많아도 많은 역할을 객체로 묶을 수 있음 -> 대형 프로그래밍
- 장점
- Modularity for easier troubleshooting
- reuse of code through inheritance
- Flexibility through polymorphism
- effective problem solving
Interface
+) implements interface == method prototype (이름만 적고 내부는 텅텅)
+) extends inheritance로 공통되는 기능은 super에서
다중 상속이 안 되니까 무엇이 interface로, 무엇을 class로 만들어야할 지 판단해야 함
interface는 텅텅 비어서 무한 상속 지원. 충돌할 일이 없으니까
Interface 자체를 함수의 파라미터로도 가능하다 : subtype polymorphism
JAVA. Python visibility
- public, protected, private members
Overriding
'CS > Programming Language' 카테고리의 다른 글
Heap Memory & Garbage Collection (0) | 2022.11.24 |
---|---|
ㄴㄹㄴㄹ (0) | 2022.11.22 |
Stack Memory (0) | 2022.11.20 |
Semantic Analyzer: Polymorphism (0) | 2022.11.15 |
Semantics Analyzer : Type (0) | 2022.11.11 |