여씨의 개발이야기

[개발일기] What is "Context" in programming? 본문

📕 Note

[개발일기] What is "Context" in programming?

yeossi 2022. 2. 27. 11:57

최근에 지인에게 프로그래밍을 하는데 Context라는 말이 너무 추상적이어서 이해를 못 하겠다는 질문을 받았다. 어영부영 "어떠한 행위를 할 때 필요한 정보"라고 설명을 해줬지만 프로그래밍을 처음 접하는 지인에게는 이것 또한 상당히 막연하고 추상적인 개념인 것 같았다. 그래서 좀 더 찾아보고 설명해주고자 구글링을 했는데 정말 어썸(ㅋ)한 설명을 stackoverflow에서 발견했다. 

https://stackoverflow.com/questions/6145091/the-term-context-in-programming/28073970

 

The term "Context" in programming?

I have been programming for some months now and a frequently used word is "context" in classes. Like ServletContext (Java), Activity (Android), Service (Java, Android), NSManagedContext (Objective-...

stackoverflow.com

질문 ) 
I have been programming for some months now and a frequently used word is "context" in classes. Like ServletContext (Java), Activity (Android), Service (Java, Android), NSManagedContext(Objective-C, iOS).
By looking in dictionaries I see that the word means: situation, environment, circumstances etc. However, because I am not a native English speaker I do not understand what I should translate it directly to. For instance, if I were to write a class that either was named SomeClassContext, or a method that had a context parameter, I would not understand when I should name it context because I do not understand it.
I have been searching for context on Stack Overflow, but no question/answers was able to help me.
I would be very happy if someone could provide me with the explanation.
대충 프로그래밍을 하면서 context라는 단어가 너무 많이 나와서 찾아보고는 있는데 본인은 영어권도 아닌 사람이라 설명 좀 해주세요! 라는 뜻인 것 같다. 

 

어썸!한 답변)
Let's say you go to the dentist to have a tooth pulled out.
당신이 치아를 뽑기 위해 치과에 간다고 예를 들어보자.

When the receptionist asks you for your name, that's information they need in order to begin the appointment. In this example, your name is contextual information. So in the context of visiting the dentist, you need to provide your name to get your tooth pulled.
접수하는 사람이 당신의 이름을 물어본다면 그건 접수를 하기 위해 필요한 정보일 것이다. 앞에서 당신의 이름은 contextual한 정보라고 볼 수 있다. 치과를 방문한다는 문맥(context)상에서 당신은 치아를 뽑기 위해서 이름을 알려줘야한다.

Now let's say you walk over to the bank.
이번에 당신은 은행에 간다고 하자.

At the bank, you ask to withdraw $100. The teller needs to establish your identity before giving you money, so you'll probably have to show them a driver's license or swipe your ATM card and enter your PIN number. Either way, what you're providing is context. The teller uses this information to move the transaction forward. They may then ask you which account you'd like to withdraw from. When you answer, "My savings account", that's even more context.
은행에서 당신은 100달러를 인출하려한다. 은행원은 당신에게 돈을 주기 위해 정체성을 성립하는 것이 필요하다. 그렇기 때문에 당신은 운전면허를 보여주거나 ATM 카드를 긁거나 당신의 PIN 번호를 입력해야한다. 이것들을 제공하는 것이 context이다. 은행원은 받은 정보를 이용해서 다음 단계의 일로 넘어간다. 은행원은 어떤 계좌에서 돈을 뽑을 것인 지 물어볼 것이다. 이 때, 당신은 "제 계좌입니다"라고 대답하면 그 대답은 추가적인 context가 되는 것이다.

The more context you give, the more knowledge the other party has to help deal with your request. Sometimes context is optional (like typing more and more words into your Google search to get better results) and sometimes it's required (like providing your PIN number at the ATM). Either way, it's information that usually helps to get stuff done.
당신이 더 많은 context를 제공할수록, 더 많은 지식들을 다른 쪽에 제공할 수록 당신의 request에 도움을 줄 것이다. 때때로, context는 선택적이다.(마치 구글에 더 많은 단어를 입력할수록 더 정확한 결과가 나오듯이) 또한 때때로, context는 필수적이다.(마치 ATM에 PIN 번호를 입력하는 것처럼) 어떻건간에 context는 일이 진행될 때 도움을 준다.

....

☆중요☆
Here's the interesting part: for a lot of software and APIs, the required context usually ends up as actual parameters in a method signature, and optional context goes somewhere else, like a flexible key-value map that can contain anything (and may be empty) or into thread-local storage where it can be accessed if needed.
여기 가장 흥미로운 부분이다 : 많은 소프트웨어와 API들에서, 필수적인 context는 일반적으로 메서드에서 실제 매개변수로 요구한다. 선택적인 context는 어디서든, 어떤 것이든 담을 수 있는 key-value 맵이나 어떤 곳에서든 필요할 경우에 접근 가능한 thread-local storage에서 사용할 수 있다.
☆중요☆

....

For example, HTTP headers contain contextual information. Each header relates to information about the request being made. Or when you're sending along a global transaction ID as part of a two-phase commit process, that transaction ID is context. It helps the transaction manager coordinate the work because it's information about the overall task at hand.
예로, HTTP 헤더는 contextual한 정보들을 포함하고 있다. 각 헤더는 수행 중인 요청에 대한 정보를 담고있다. 또는 당신이 two-phase commit process의 일부로 전역 트랜잭션 id를 보낸다면, 트랜잭션 id도 context이다. 이것은 트랜잭션 매니저가 작업을 조정하는데 큰 도움이 되는데, task의 전반적인 정보이기 때문이다. 

 

Comments