23.4.11

커피 내리는 그냥 사람·2023년 4월 11일
0

입사 후 블로그

목록 보기
18/24

참고 블로그

업무 하면서 배우고 익힌 내용들

좋은 CTO님을 만나서 놓치고, 모르는 내용들을 많이 배우고 있다. 오늘은 그 내용을 좀 공부하고 정리하는 차원에서(까먹지 않기 위해) 이론을 정리해놓으려고 한다.

컴파일 vs 인터프리터

  • 컴파일 :
    - "컴퓨터는 고급 언어로 작성한 코드를 바로 인식하지 못하기 때문에 이를 번역해줄 과정이 필요했고, 이것이 우리가 아는 컴파일"
    - "컴파일러는 프로그램 전체를 스캔하여 이를 모두 기계어로 번역"
  • 인터프리터 :
    - 프로그램 실행시 한 번에 한 문장씩 번역
  • 결론 :
    - 컴퓨터가 읽을 수 있는 언어로 바꿔주는 것이다.(이를 컴파일)
    - 인터프리터가 한번에 한문장씩 번역후 실행 시키기 때문에 실행 시간이 상대적으로 느리다.

퍼블릭 메서드 vs 프라이빗 메서드, 상속 시 프라이빗 메서드 사용하는 방법

  • private: private로 선언된 attribute, method는 해당 클래스에서만 접근 가능
    - 내부 접속만 가능하다
  • protected: protected로 선언된 attribute, method는 해당 클래스 또는 해당 클래스를 상속받은 클래스에서만 접근 가능
    - 상속 받은 자식 요소만 사용 가능하다.
  • public: public으로 선언된 attribute, method는 어떤 클래스라도 접근 가능
    - 열려있다. 어디서든 접근이 가능하다.
    - 꼭 필요할 때만 사용한다. 코드의 복잡성이 올라간다.

파이썬 예제

  1. private
class MyClass:
    def __init__(self):
        self.__private_member = "private"

    def __private_method(self):
        print("This is a private method.")

    def public_method(self):
        print("This is a public method.")
        self.__private_method()

my_class = MyClass()
print(my_class.__private_member) # 접근 불가능
my_class.__private_method() # 접근 불가능
my_class.public_method() # 접근 가능
  1. public
class MyClass:
    def __init__(self):
        self.public_member = "public"

    def public_method(self):
        print("This is a public method.")
  1. protected
class MyClass:
    def __init__(self):
        self._protected_member = "protected"

    def _protected_method(self):
        print("This is a protected method.")

    def public_method(self):
        print("This is a public method.")
        self._protected_method()

class MySubclass(MyClass):
    def __init__(self):
        super().__init__()

    def public_method(self):
        print("This is a public method in the subclass.")
        self._protected_method()
        print(self._protected_member)

my_class = MyClass()
print(my_class._protected_member) # 접근 가능하지만 권장하지 않음
my_class._protected_method() # 접근 가능하지만 권장하지 않음
my_class.public
  • 결론
    - 이왕이면 쓰기 편하고 보기 예쁘고 효율적인 코드가 좋지 않을까? 이번에 업무를 하면서 알아낸 것은 protected.
    - 특정 클래스에서만 사용하는 메서드일 때는 잘 생각해두기.

RAM이란?

  • Random Access Memory
  • 사용자가 자유롭게 내용을 읽고 쓰고 지울 수 있는 기억장치. 컴퓨터가 켜지는 순간부터 CPU는 연산을 하고 동작에 필요한 모든 내용이 전원이 유지되는 내내 이 기억장치에 저장된다.[2] '주기억장치'로 분류되며 보통 램이 많으면 한번에 많은 일을 할 수 있기에 '책상'에 비유되곤 한다.[3]
    (by 나무위키)
  • 코드가 입력된다 -> HDD로 간다 -> RAM에 올라간다 -> CPU 레지스터로 간다 -> 프로그램 동작
profile
커피 내리고 향 맡는거 좋아해요. 이것 저것 공부합니다.

0개의 댓글