ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 입문자를 위한 컴퓨터 프로그래밍 기초 용어
    컴퓨터 2019. 11. 8. 14:52

    identifier

    프로그래밍 언어에서 무슨 대상을 나타내는지, 무슨 명령을 하는지 구분이 되는 단어. Student 라는 클래스와 student라는 변수의 경우 대소문자로 구분이 되어 둘다 identifier로 쓰일 수 있다.  맨 앞글자가 대문자인지 소문자인지를 통해서 내가 원하는 것이 클래스인지 변수인지 구분이 되는 것이다. 반면에  #이나 ", ) 등을 단어에 포함시킬 경우 그 특수문자가 단어에 포함되는 것인지 문법적인 요소인지 구분하지 못하게 되어 그러한 단어들은 identifier로 쓰이기에 적절하지 않다.

     

     

    keyword

    프로그래밍 언어에서 원래부터 정해져 있는 단어들. class, def, print, __init__, for 등등.

     

     

    function

    행위에 대한 명령. 입출력 값의 존재 여부를 결정 할 수 있다.

    #입력 o, 출력 o :
    
        def func1(a, b):    
    
    	#a, b가 입력값이다.
    
            print("안녕하세요")     
    
    		#화면에 "안녕하세요"를 표시하라는 행위
    
           val = a + b               
    
    		# val이라는 변수를 만들고 거기에 a와 b를 합한 값을 할당하라는 명령
    
            return a + b             
    
    		# func1 이라는 함수에 a + b 라는 출력값을 할당하고 함수가 쓰여진 위치로 돌아가라 명령
    
        func1(3, 4)
    
    	# func1 함수에 3, 4 값을 입력값으로 넣고 호출. 화면에는 "안녕하세요"가 표시되고 func1(3, 4)의 값은 7이 될 것이다.
    
    
    
    #입력 o, 출력x :
    
        def func2(a, b):
    
            print("안녕하세요")
    
            val = a + b
    
            return
    
        func2(3, 4)
    
    	# func2에 아무 값도 할당되지 않는 것을 제외하고 func1과 동일하다
    
    
    
    #입력 x, 출력 o :
    
        def func3():
    
            print("안녕하세요")       
    
            return 8
    
        func3()
    
    	# 입력값을 받지 않고 print라는 행위를 하고 func3()이라는 함수에는 8이라는 값이 할당된다.
    
    
    
    #입력 x, 출력 x :
    
        def func4():
    
            print("안녕하세요")            
    
        func4()
    
    	# 입력을 받지도 출력값(반환값, 함수가 가지게 되는 결과값)을 같지도 않으면서 화면에 "안녕하세요"라는 표시를 하는 행위만 하게 된다.
    
    

     

    variable에 할당시 var = fun 이면 function 자체가 할당되고 variable을 function 처럼 사용가능하며 variable을 print 할 경우 namespace가 출력된다. var = fun() 형태로 할당할 경우 return 값이 저장된다.

    ex)

    def high_func(function):
        def low_fun():
            func = function()
            return func
    
        return low_fun
    # high_func는 함수를 인자로 받아서 함수를 반환한다. 함수의 결과값을 반환하려면 마지막에 "low_fun()"가 되어야 한다.
    
    
    def say_hi():
        return "hello"
    
    
    var1 = say_hi()
    
    var2 = say_hi
    
    var3 = high_func(say_hi)
    
    print(var1, var2, var3, var3(), sep="\n")
    # var3()는 low_fun()를 의미한다.

     

    output

    hello
    <function say_hi at 0x033D9A08>
    <function high_func.<locals>.low_fun at 0x033D9BB8>
    hello

     

     

    parameter

    함수나 객체를 정의할 때 입력값이 들어갈 자리. def fun1(a, b)에서 a와 b가 parameter이다.

    print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) 에서 sep, end 등 과 같이 외부의 값을 받아오는게 아니라 정해진대로 설정하는데 쓰이는 prameter도 있다.

     

    argument

    행위에 쓰일 대상이 되는 값, 변수 등. prameter에 들어가야 할 것들이 argument이다.

     

     

    variable

    자료를 저장(할당)할 수 있는 identifier로 된 저장공간. "=" 의 좌측에 있는 단어들이다. argument로 쓰여서 prameter에 들어갈 수 있다. 글자, 숫자, bool값, 리스트, 딕셔너리, 튜플, instance 등을 저장 할 수 있다. 함수를 할당 할 경우 함수가 저장되는 것이 아니라 함수의 결과값이 저장된다.

     

     

    value

    숫자, 문자, bool, 리스트, 딕셔너리 등 실질적인 자료. variable에 저장할 수 있다. argument로 쓰여서  parameter에 들어갈 수 있다.

     

     

    operator

    값에 변형을 가져오는 문자.

    계산 연산자: +, -, *, /, //, %

    할당 연산자: =

    비교 연산자: >, <, ==, =!, >=, <=, in (두 값을 True나 False 로 바뀜ex) 31 > 55 의 경우 31과 55라는 두 값이 ">" 연산자에 의해 False 라는 bool값으로 바뀐다.)

     

     

    double under bar function "__function__"

    특정 조건을 만족할 경우 호출된다. 함수의 내용은 원하는 대로 정의 가능하다.

     

     

    ":"

    뒤에 나오는 들여쓰기 된 부분이 자신에게 속하는 범위라는 것을 정하는 문자.

    def fun1(a, b):
    
        print("안녕하세요")
    
        a + b
    
        return a * b
    
    fun1(3, 5)

     

    들여쓰기 된 print부터 return까지의 범위가 def fun1에 속한다. 같은 범위 내에 있어야 변수등을 공유 할 수 있다.

        

     

    statement

    코드를 읽는 주체(컴퓨터)를 통제하는 명령문. 함수는 입력 받은 자료나 출력될 값, 또는 일어나게 될 행위에 대한 명령이다. 즉, 프로그램을 실행한 사람에게 보여질 것에 대한 처리명령인 반면에, statement는 컴퓨터가 코드를 읽어나가다가 모듈을 읽어들이거나 다른 문단으로 넘어가게 하거나, 반복적으로 읽게 하거나, 또는 statement 뒤에 나오는 코드가 클래스를 만들라는 명령인지 함수를 만들라는 명령인지 여부등을 컴퓨터에게 알려준다. 예로는 for, while, break, continue, return class, def, from, import 등이 있다. variable, function value 등은 컴퓨터가 사용할 도구, 재료이고 statement는 컴퓨터가 해야할 일을 컴퓨터에게 명령하는 것이다.

     

     

    class

    연관성이 있는 함수들, 그리고 연관성이 있는 자료들을 입력하기 위한 변수들묶어 놓은 것.

     

     

    method

    class에서 만든 함수. "클래스.method명" 형태로 호출한다.

     

     

    attribute

    class에 자료들을 입력하기 위한 변수. "클래스.attribute명" 형태로 값을 불러온다.

     

     

    property

    getter, setter(값에 접근하는 함수) 를 통해 접근해야 하는 특수한 attribute.

    https://whatisthenext.tistory.com/115

     

    decorator

    function(argument)을 argument로 하여 새로운 function(new)을 정의하고 반환하는 function(modifier)이 있을 때, 그 과정을 간단하게 표현해줄때 사용되는 "@" 문자. function 뿐 아니라 class를 받아서 변환된 class를 반환할 수도 있다. class(argument), function(modifier), class(new)

    ex)

    def 데코레이터(함수_또는_클래스):
    	def 래퍼(): # original을 변환한 결과
        	변환과정
            return 래퍼 # 정해진 형태
            
            
    @데코레이터        
    def original함수_또는_클래스():
    	내용
        
        
    original함수_또는_클래스() # 변환된 결과, 즉 래퍼함수가 호출된다.

     

    ex)

    def decorator_with_arguments(function):
        def wrapper_accepting_arguments(arg1, arg2):
            print("My arguments are: {0}, {1}".format(arg1, arg2)) # 이 라인이 new function에 추가됨
            function(arg1, arg2)
    
        return wrapper_accepting_arguments
    
    
    def cities(city_one, city_two):
        print("Cities I love are {0} and {1}".format(city_one, city_two))
    
    
    var = decorator_with_arguments(cities)
    
    # decorator_with_arguments에 괄호가 쓰였으므로 var에는 decorator_with_arguments의 return 값이 들어가게 된다.
    # 이때 return 값은 wrapper_accepting_arguments라는 함수이다.
    # 이때 이 함수의 정의는 decorator_with_arguments에서 cities라는 함수를 인자로 받기 때문에
    
    """
        def wrapper_accepting_arguments(arg1, arg2):
            print("My arguments are: {0}, {1}".format(arg1, arg2))
            cities(arg1, arg2)
    
        (function 자리에 cities가 들어간 것에 주목!)
    
    """
    # 가 된다. 저 정의로 된 함수가 var에 들어있는 것이고, var가 즉 그 함수처럼 행동한다.
    
    var("Suwon", "Seoul")

     

    output:

    My arguments are: Suwon, Seoul
    Cities I love are Suwon and Seoul

     

    데코레이터를 사용한 경우

    def decorator_with_arguments(function):
        def wrapper_accepting_arguments(arg1, arg2):
            print("My arguments are: {0}, {1}".format(arg1, arg2))
            function(arg1, arg2)
    
        return wrapper_accepting_arguments
    
    # modifier function의 이름을 써준다.
    @decorator_with_arguments
    def cities(city_one, city_two):
        print("Cities I love are {0} and {1}".format(city_one, city_two))
    
    
    # var = decorator_with_arguments(cities)
    # var("Suwon", "Seoul")  이 두줄이 필요 없어진다.
    
    # cities 함수의 정의가 바뀌었으니 argument로 넣지 않고 바로 그대로 쓴다.
    cities("Suwon", "Seoul")

    decorator는 def function에 가까운 것부터 순차적으로 실행된다.

     

    ex2)

    def decorator_maker_with_arguments(decorator_arg1, decorator_arg2, decorator_arg3):
        def decorator(func):
            def wrapper(function_arg1, function_arg2, function_arg3) :
                "This is the wrapper function"
                print("The wrapper can access all the variables\n"
                      "\t- from the decorator maker: {0} {1} {2}\n"
                      "\t- from the function call: {3} {4} {5}\n"
                      "and pass them to the decorated function"
                      .format(decorator_arg1, decorator_arg2,decorator_arg3,
                              function_arg1, function_arg2,function_arg3))
                return func(function_arg1, function_arg2,function_arg3)
                #3. wrapper는 print를 실행하고 return값인 함수를 호출한다.
                #4. wrapper의 parameter가 new function의 argument를 받아온다.
    
            return wrapper #2. new function 은 wrapper이다.
    
        return decorator
    
    #5. decorator maker는 modifier로 작용하여 new function인 decorator를 만든것과 비슷하다.
    #1. modifier는 decorator maker가 아니라 그의 리턴값인 decorator 함수이다. 
    pandas = "Pandas"
    @decorator_maker_with_arguments(pandas, "Numpy","Scikit-learn")
    def decorated_function_with_arguments(function_arg1, function_arg2,function_arg3):
        print("This is the decorated function and it only knows about its arguments: {0}"
               " {1}" " {2}".format(function_arg1, function_arg2,function_arg3))
    
    decorated_function_with_arguments(pandas, "Science", "Tools")

     

    코드 읽는 순서

    #1. 데코레이터 문자 뒤의 decorator maker 실행, decorator 변환
    @decorator_maker_with_arguments(pandas, "Numpy","Scikit-learn")
    
    #2. 새로운 decorator 생성
     def decorator(func):
            def wrapper(function_arg1, function_arg2, function_arg3) :
                "This is the wrapper function"
                print("The wrapper can access all the variables\n"
                      "\t- from the decorator maker: {0} {1} {2}\n"
                      "\t- from the function call: {3} {4} {5}\n"
                      "and pass them to the decorated function"
                      .format("Pandas", "Numpy", "Scikit-learn", # argument 전달됨.
                              function_arg1, function_arg2,function_arg3))
                return func(function_arg1, function_arg2,function_arg3)
    
            return wrapper
    

    ,,,

            def wrapper(function_arg1, function_arg2, function_arg3) :
                "This is the wrapper function"
                print("The wrapper can access all the variables\n"     # print 부분이 added function
                      "\t- from the decorator maker: {0} {1} {2}\n"
                      "\t- from the function call: {3} {4} {5}\n"
                      "and pass them to the decorated function"
                      .format("Pandas", "Numpy", "Scikit-learn",
                              function_arg1, function_arg2,function_arg3))
                return decorated_function_with_arguments(function_arg1, function_arg2,function_arg3) 
                # return 부분이 original function
                # decorated function이 변환됨(print 부분이 추가됨).
    
    
    @decorator_maker_with_arguments(pandas, "Numpy","Scikit-learn")
    def decorated_function_with_arguments(function_arg1, function_arg2,function_arg3):
        print("This is the decorated function and it only knows about its arguments: {0}"
               " {1}" " {2}".format(function_arg1, function_arg2,function_arg3))

    ,,,

    	def wrapper("Pandas", "Science", "Tools") :
                "This is the wrapper function"
                print("The wrapper can access all the variables\n"
                      "\t- from the decorator maker: {0} {1} {2}\n"
                      "\t- from the function call: {3} {4} {5}\n"
                      "and pass them to the decorated function"
                      .format("Pandas", "Numpy","Scikit-learn",
                              "Pandas", "Science","Tools"))
                return decorated_function_with_arguments("Pandas", "Science","Tools")
    
    decorated_function_with_arguments(pandas, "Science", "Tools")
    # 변환된 함수에 argument가 전달되고 실행됨.
    # print 부분 + original function 가 실행된다 =  new function
    # 데코레이션이 일어난 후에는 original function을 호출하면 변형된 것이 호출되고
    # modifier 내부에서 호출되는 것은 original 그대로이다.

     

    output:

    The wrapper can access all the variables
        - from the decorator maker: Pandas Numpy Scikit-learn
        - from the function call: Pandas Science Tools
    and pass them to the decorated function
    This is the decorated function, and it only knows about its arguments: Pandas Science Tools

     

     

    instance

    변수에 저장되어 실체화 된 것. class에 argument를 입력하여 그것에 대한 method와 attribute 가 구체적으로 결정되어 만들어진 함수, 변수들의 묶음. argument가 필요 없는 class는 변수에 할당만 하면 instance가 된다.

     

     

    object

    변수에 저장되어 사용될 대상. class-based object-oriented programming paradigm에선 class의 instance 통칭하는 말. class가 현대자동차 공장이라면, object는 자동차이고 instance는 소나타 그랜저 등이다.

    instance와 object는 같은 것을 가리키지만 instance는 변수에 할당될 시점의 실체화에 초점을 두고 object는 사용되어질 대상이라는 점에 초점을 둔다.

     

     

    module

    다른 사람이 미리 써 놓은, 가져다 쓸 수 있도록 만들어진 instance 또는 method 또는 variable.

    import 모듈
    
    import 모듈 as 이름
    
    #정해진 이름으로서 모듈을 사용할 수 있다.
    
    # "이름.메소드()" 로 사용한다.
    
    from 모듈 import 메소드
    
    #메소드만 가져온다.
    
    # "메소드()"로 일반 함수처럼 사용한다.
    
    from 모듈 import *
    
    # 모듈안의 모든 메소드와 변수를 가져온다.
    
    

     

     

    API

    application program interface

    프로그램에서 다른프로그램을 조종하기 위한 중간 역할. 설치하면 기존의 언어에선 만들 수 없던 함수 등이 생겨난다. 기상청 API를 예로 들자면 기상청 API를 설치하지 않고서는 아무리 나름대로 함수를 만들어 본들 날씨라는 자료에 접근 할 수 없을 것이다. 이때 필요한 것이 기상청 API이다. 설치하면 기상청 날씨 정보를 불러오는 함수가 생겨나게 된다. 기상청 API는 기상청의 자료를 제공하므로 기상청에서 만들것이고, 또한 인터넷을 통해 자료를 받아와야 하므로 API가 작동하기 위해선 로그인 과정이 필요하다.

     

     

    library

    모듈의 모음

     

     

    package

    모듈파일들이 있는 경로

     

     

    code

    프로그래밍 언어로 쓰여진 문자.

    ex) c, c++, python이라는 언어체계 안에서 쓰여진 print("hello world") 등의 영어 단어와 숫자 등의 문자. 기계어로 쓰여진 "1010001010010010001" 등.

     

     

    source

    사람이 작성한 complie 되기 이전의 코드. 사람이 직접 기계어를 입력했다면 그것도 source라고 할 수 있다.

     

     

    compiler

    사람이 작성한 source code 를 컴퓨터가 이해할 수 있는 기계어 code로 바꿔주는 프로그램. 파이썬 사이트에 들어가서 다운 받는 python 3.7 같은것이다. anaconda는 python의 한 모드이다. 아마도 anaconda는 기본 python과 다르게 다른 기본 함수들을 포함하고 있을 것이다.

     

     

    IDE 

    Integrated Development Environment

    IDLE Integrated Development and Learning Environment

    code를 작성, 수정하고, comepile 할 수 있는 프로그램. ex) pycharm. visual studio code.

    물론 compiler는 별도로 다운받아줘야 하지만 IDE 가 없을 경우에는 명령프롬프트를 통해서 compile 해야 하는 반면 IDE는 GUI를 통해 편리하게 compile 기능을 제공하는 것이다.

     

     

    framework

    프로그래밍에 필요한 잡다한 요소 모음. 프로그램이 사용자의 코드를 import 한다. Inversion of Control

    from pyxll import xl_func
    
    @xl_func
    
    def py_test(a, b, c):
    
        return (a + b) * c

    파이썬에서 정의한 함수가 외부 프로그램에서 쓰이고 있다.

     

     

    script language

    compiler가 내장응용프로그램을 조작하기 위한 언어. 별도의 compile 과정이 필요 없다. 그러므로 source를 누구나 볼 수 있다. 다른 언어들로 만들어진 프로그램은 프로그래머만 compiler를 가지고 있으면 되고 사용자들은 compile된 결과물인 응용프로그램을 사용하게 되지만 script language의 경우 사용자가 compiler를 가지고 있어야 한다.

    ex)javascript

     

     

    namespace

    identifier간 이름이 같아서 생기는 충돌을 막기 위해 만든, 한 구역 안에서 쓰이는 identifier와 그것이 가리키는 대상의 연결관계를 저장해 놓은 공간이다. identifier가 같아도 namespace가 다르다면 identifier간 충돌은 없게 된다.

     

    Binding

    변수가 다른 것을 가리키는 것. 할당. 변수에는 value, function, class, object 등이 할당 될 수 있다. 그러면 변수는 할당된 자료와 같은 역할을 한다.

     

     

    scope

    동일한 namespace가 적용되는 범위. 들여쓰기 계층 구조에서 안쪽에서 바깥 scope의 variable에 접근하는 것은 가능하지만 바깥에서 안쪽 scope의 variable에 접근 할 수는 없다. 안에서 바깥의 variable을 수정하기 위해선 global 문을 사용해야 한다.

     

     

    class 생성자, __init__, constructor

    class의 instance 생성과 동시에 호출되는 메소드이다. instance 생성시 argument를 받을 parameter를 만들어 놓을 수도 있다. (instace 생성 후에도 attribute나 메소드에 직접 접근하여 argument를 전달 하는 방법도 있다.)

     

     

    self

    class의 instance 생성시 instance 스스로를 argument로 받는 parameter.

    class Student:
    
        def study(self):
    
            print(self)
    
    Student.study("nice")
    
    # instantiation 하지 않고 method를 직접 실행하는 경우 self는 단순히 보통 parameter로 작용하여 nice를 받는다.
    
    a = Student()
    
    # instantiation 하는 경우, argument로 instance 스스로가 self parameter에 들어가게 된다.
    
    a.study()
    
    

     

    output:

    nice
    
    <__main__.Student object at 0x7fbcc198a750>

    인스턴스를 출력할 경우 instance의 namespace에 저장된 메모리 위치가 출력되는 모습이다.

     

     

    COM

    Component Object Model

    다른 프로그래밍 언어로된 프로그램을 조작하기 위한 기술. win32com.client module을 import 하여 사용한다. import 후 원래는 사용 불가능 했던 다른 프로그래밍 언어로 된 프로그램을 COM object로 만들어서 조작할 수 있다.

     

     

     

    ActiveX

    widget

    GUI 프로그램의 요소들. 버튼이나 텍스트 박스 등.

    OLE

    OCX

    plugin

    프로그램에 설치할 수 있는 추가기능

    qt

    GUI 프로그램 제작 framework toolkit

    pyqt

    파이썬에서 사용할 수 있는 qt

    toolkit

    프로그램

     

     

     

     

    '컴퓨터' 카테고리의 다른 글

    변수의 범위, scope, (static, 전역, 지역)  (0) 2019.12.11
    콜백함수, 람다  (0) 2019.11.17
    API, COM 모식도  (0) 2019.11.15
    클래스 데코레이터 예제  (0) 2019.11.13
    super(), inheritance 실행 순서  (0) 2019.11.12

    댓글

Designed by Tistory.