약 4분

Elementary Data Types - WIP

Elementary Data Types - WIP
Photo by Merve Sehirli Nasir / Unsplash

Data

  • 처리 대상
  • 숫자, 문자, 복합 데이터, 메타 데이터(ex: 포인터)

Data Object

OOP에서의 객체(Object)와는 다른 개념이다!
  • 데이터 값을 포함하는 container 또는 memory location
  • 일반적으로 변수(Variable)라 부름
  • 6가지 기본 속성을 가짐
    • type, name, value(R-value), address(L-value), lifetime, scope
    • 다른 Data Object를 가리키는 pointer value를 특별히 Component라 부르기도 한다
      (value, 즉 R-value 속성의 일종)

Constants

  • 상수(Constant)도 변수의 일종
  • 하지만 반드시 초기화(value binding)되어야 함
  • 또한, 한번 초기화 된 다음에는 값이 변경될 수 없음
  • 상수의 종류:
    • literal: 생긴 것 자체가 이름이자 값
    • named constant: 값 외에 별도의 이름이 존재하는 상수
      • manifest constant: 컴파일 타임에 정적으로 값이 바인딩되는 named constant

Data Value

  • 특정한 값을 나타내는 비트 패턴
  • int a = 3;
    -> 메모리에 저장되는 비트패턴은 00000000000000000000000000000011

Type

  • 데이터를 분류해둔 것
  • 타입(Type) : 값(Value)의 집합 + 연산(Operation)의 집합
    • The value that data objects of that type may have (값 집합)
    • The operations that define the possible manipulations of data objects of that type (연산의 집합)
  • -> ADT

Data Type Specification

  • 이상적으로는, 모든 데이터 타입에 대해 명확한 명세(specification)가 주어져야 한다
    • 허용 가능한 값의 범위 + 적용 가능한 연산의 목록
    • 사용자 정의 타입(User-defined Type)도 마찬가지!!
  • 타입의 연산 정의를 어렵게 만드는 요인들:
    • 특정 입력에 대해서는 정의되지 않을 수 있음(UB, Undefined Behavior)
      • ex: array out-of bounds
    • 기본적으로, 암시적으로 주어지는 인수(Implicit Arguments)가 있을 수 있음
    • 부작용(Side Effect)
    • 자기 수정(Self-Modification)

Subtype

  • 어떤 타입의 값 집합의 일부를 취하는 새로운 타입
  • A is subtype of B if every value of A is a value of B
  • 반대로, B는 A의 supertype 이라 부른다!
  • Subtype 개념이 클래스로 확장된 경우를 상속(Inheritance)이라 부른다!!

Declaration

  • 선언문이란?
    • 언어 처리기(컴파일러 또는 인터프리터)에 데이터 객체의 이름과 타입 정보를 전달하는 문장(Statement)
    • 선언문은 수행된다고 하지 않고, Elaboration된다고 부름!!
    • 선언문의 위치와 종류에 따라, 데이터 객체의 영역(Scope)과 지속시간(Lifetime)이 결정됨!
  • 선언문의 종류
    • 대부분의 언어에서는 명시적 선언문을 사용
    • 일부 고전 언어에서는 암시적 선언문을 사용
      • FORTRAN에서 { I, J, K, L, M, N } 으로 시작하는 변수는 암시적으로 정수형
      • Perl의 경우: $(스칼라), @(배열), %(연관 배열, dictionary)
  • 변수 대신, 함수를 선언할 수도 있다!
    • ex: C언어의 function prototype
      • float sub(int x, float y);
  • 선언문의 역할:
    • 저장 형태 결정(Choice of Storage Representations)
    • 메모리 관리(Storage Management)
    • 타입검사(Type Checking)
    • 다형 연산 지원(Polymorphic Operations)

타입, 타입 검사, 타입 추론, 타입 변환(explicit, implicit), 할당, Lvalue, Rvalue, scala assignment(value copy), pointer assignment(pointer copy)

+ lifetime, scope, scope hole(shadowing), allocation 분류(static, dynamic{automatic allocation, manual allocation}, 타입 안전성(타입, 타입 검사 사이에 쓰기), granularity of typing{strongly typed, weakly typed, typeless}, type checking time{static type checking, dynamic type checking} - strongly typed라고 반드시 static type checking을 하는 것은 아님, Equality{data equality, type equivalence}, name equivalence, parameterized type(type을 parameter로 허용)

  • 6-2 강의자료, 필기 참고해서 정리하기

scala data, composite data, Numeric data, Integer, Floating-point Real Number(IEEE 754), Fixed-point Real Number, Enmueration, Boolean, Character, // Character String(composite data), // Pointer // File, I/O(Psudo-file, input stream, output stream, error stream)