[Python] Dynamic Typed Language vs. Static Typed Language

2023. 6. 11. 23:16·Programming
728x90
728x90

Python은 대표적인 dynamic (typing) langauge 이다.
(dynamic language는 대부분 interpreter language 임.)

 

좀 더 엄밀하게 애기하면,

  • Dynamic Language란 특정 동작이나 사항들이 runtime(실행 시간)에 결정되는 특징을 가진 Programming Language를 가르킴.
  • comile 시점이 아닌 runtime에 해석되고 실행되며, type이나 호출할 method나 접근할 attribute가 runtime에 해석(and 체크)된다는 특징을 가지고 있다.
  • 유연성이 높고 높은 생산성을 가지나, 성능은 static language 보다 떨어지며 코드가 길어질 경우 오류 탐지가 쉽지 않다는 단점을 가짐.

https://medium.com/android-news/magic-lies-here-statically-typed-vs-dynamically-typed-languages-d151c7f95e2b


Static (Typing) Language

Programming Language들 중에서 static typing을 사용하는 언어들의 경우

compile time 에 type에 대한 검사가 이루어짐!

 

Compiler language와 static typing language는 독립적인 개념이나

과거엔 compiler lanaguage의 대다수가 static language였음.

 

다음의 특징을 가짐.

  • variable은 특정 type을 갖도록 정의되며, 이는 일반적으로 compile time에 type이 고정됨.
  • 해당 variable의 type이 명시적(explicitly)으로 정해지는 경우가 대다수 (type inference에 의해 자동으로 결정되는 언어도 있음)
  • explicit casting(명시적 형변환)을 하는 경우를 제외하곤 해당 type이 변하지 않음.

C, C++, Java 등이 static language의 대표적 예들임.

 

Static Language에서
variable은 type이 지정되며,
decalration의 시점에
해당 type에 따른 적절한 크기의 memory location(실제 data가 저장되는 공간을 의미)에 binding 됨.

 

variable인 myVar에 이미 String이라는 타입이 지정됨.

 

Dynamic (Typing) Language

Dynamic language에서는 변수(variable)가 고정된 타입을 갖지 않으며,
실제로는 변수가 참조하는 객체(object)가 타입을 가진다.
즉, 타입 정보는 런타임에 객체 수준에서 체크 및 관리된다

 

대표적인 예로, Python, JavaScript, PHP, Ruby 등임.

 

아래의 내용은 Strong Typing과 Dynamic Typing이 사용되는 Python의 관점에서 설명한 내용임:

Variable은 단순히 특정 object (=memory가 할당되어 있고 특정 type을 가짐)를 참조하는 name (or reference) 에 불과함
(즉, Type이 없음).

 

Variable assignment (변수에 값을 할당)할 때 해당 variable이 가르키는 object가 결정되는 것임.

  • assignment를 다시 할 경우, 해당 variable이 가르키고 있는 object가 바뀌는 것임.
  • 만일 다른 type의 object를 assignment했다면 마치 variable의 type이 바뀐 것처럼 보임
    (엄밀하게 애기하면 type이 바뀌는 것이 아닌 참조 대상 object 자체가 바뀐 것임.)
  • object는 strong typing으로 object는 type이 바뀌지 않음.
  • 이 같은 dynamic language는 static language에 비해 수행속도가 느리다는 단점을 가지나 JIT컴파일어나 런타임 최적화 등을 통해 성능이 많이 개선되고 있음.

Python은 대표적인 dynamic language로서
Python Virtual Machine(PVM)을 통해 bytecode를 실행한다.
이로 인해 실행 성능 면에서는 native compiled language에 비해 불리하지만,
dynamic language의 편리함과 높은 생산성을 유지할 수 있다.

 

Dynamic Language에서 Variable은
어떤 object에 가르키는(참조하는) name (=reference)에 불과하며
type 등의 속성을 가지고 있지 않음.

https://youtu.be/u1bNTgstTm8?si=EqkoVLZShqM9_b3W

 

Dynamic typing language인 Python에서도 object는 type을 가진다

(Strong Typing에 의해 object의 implicit type conversion 이 제한됨).

  • 사실 strong typing은 타입 변환의 엄격함에 관련된 개념임.

strong type에 대한 설명: 2023.06.13 - [Programming] - [Python] Strong Typing이란? with Object

 

[Python] Strong Typing이란? with Object

Strong Typing 이란?Python은 object에 대해 Strong Typing을 채택하고 있다.이는 Object가 mutable type이냐 immutable type이냐에 상관없이 type이 변경되지 않음을 의미한다.  주의할 건, Object가 대상인 점이다. Str

dsaint31.tistory.com

 

자세한 내용은 다음을 참고: https://medium.com/android-news/magic-lies-here-statically-typed-vs-dynamically-typed-languages-d151c7f95e2b

 

Magic lies here - Statically vs Dynamically Typed Languages

Type Checking

medium.com


Python Virtual Machine이란

2023.06.05 - [Programming] - [Python] Interpreter and PVM (Python Virtual Machine)

 

[Python] Interpreter and PVM (Python Virtual Machine)

Interpreter and PVM (Python Virtual Machine)더보기대학을 막 졸업해서 초보 프로그래머로 일을 할 때 개인적으로 가지고 있던 편견 중 하나가 script language를 매우 하찮게 생각하면서 오직 compiler languages 만

dsaint31.tistory.com


같이보면 좋은 자료

https://youtu.be/u1bNTgstTm8?si=qx0zH1UJ1zotB6Ez


https://ds31x.tistory.com/563

 

Typing: dynamic vs. static and strong vs. weak

타입 검사는 프로그램의 type safety를 보장하기 위한 장치이며, 언제(컴파일/실행 시점) 검사하느냐와 얼마나 엄격하게 검사하느냐에 따라 프로그래밍 언어가 분류됨:Static vs Dynamic: 언제 타입을

ds31x.tistory.com

 

https://ds31x.tistory.com/135

 

[Python] Programming Language and Introduction of Python.

Computer and Programhttps://dsaint31.tistory.com/436: computer 의 정의와 program 의 정의 [CE] Computer and Program.1. 정의: 개인적으로 선호하는 Computer의 정의는 다음과 같음 (wikipedia).A computer is a machine that can be program

ds31x.tistory.com


 

728x90

'Programming' 카테고리의 다른 글

[WSL] Install WSL (Windows Subsystem for Linux)  (0) 2023.06.12
[Python] Python 소개?  (0) 2023.06.12
[Python] Keyword란? (Soft Keyword 포함)  (0) 2023.06.11
[Python] Comments and Docstrings  (0) 2023.06.11
[Basic] namespace, frame, and context  (0) 2023.06.11
'Programming' 카테고리의 다른 글
  • [WSL] Install WSL (Windows Subsystem for Linux)
  • [Python] Python 소개?
  • [Python] Keyword란? (Soft Keyword 포함)
  • [Python] Comments and Docstrings
dsaint31x
dsaint31x
    반응형
    250x250
  • dsaint31x
    Dsaint31's blog
    dsaint31x
  • 전체
    오늘
    어제
    • 분류 전체보기 (785)
      • Private Life (15)
      • Programming (55)
        • DIP (116)
        • ML (34)
      • Computer (119)
        • CE (53)
        • ETC (33)
        • CUDA (3)
        • Blog, Markdown, Latex (4)
        • Linux (9)
      • ... (368)
        • Signals and Systems (115)
        • Math (176)
        • Linear Algebra (33)
        • Physics (43)
        • 인성세미나 (1)
      • 정리필요. (61)
        • 의료기기의 이해 (6)
        • PET, MRI and so on. (7)
        • PET Study 2009 (1)
        • 방사선 장해방호 (5)
        • 방사선 생물학 (3)
        • 방사선 계측 (9)
        • 기타 방사능관련 (3)
        • 고시 (9)
        • 정리 (18)
      • RI (0)
      • 원자력,방사능 관련법 (2)
  • 블로그 메뉴

    • Math
    • Programming
    • SS
    • DIP
  • 링크

    • Convex Optimization For All
  • 공지사항

    • Test
    • PET Study 2009
    • 기타 방사능관련.
  • 인기 글

  • 태그

    Optimization
    ML
    random
    signal_and_system
    Probability
    SIGNAL
    opencv
    cv2
    Programming
    인허가제도
    function
    Vector
    SS
    linear algebra
    math
    Term
    numpy
    fourier transform
    signals_and_systems
    Python
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
dsaint31x
[Python] Dynamic Typed Language vs. Static Typed Language
상단으로

티스토리툴바