go
-
golang: 1급 시민(First-class citizen)이란?Back-End/Golang 2024. 4. 28. 22:20
프로그래밍 언어에서 "1급 시민" 또는 "1급 객체"라는 용어는 해당 언어의 요소가 다음과 같은 특성을 갖추었을 때 사용됩니다:변수나 데이터 구조 안에 담길 수 있음: 1급 객체는 변수에 할당될 수 있습니다. 예를 들어, 함수가 1급 객체인 언어에서는 함수를 변수에 할당할 수 있습니다.함수의 인자로 전달될 수 있음: 함수를 다른 함수의 인자로 전달할 수 있습니다. 이는 고차 함수(higher-order function)를 가능하게 합니다.함수의 결과로 반환될 수 있음: 함수에서 다른 함수를 결과로 반환할 수 있습니다. 이는 함수를 동적으로 생성하고 조작할 수 있음을 의미합니다.할당에 사용된 표현식 내에서 리터럴로 표현될 수 있음: 객체를 코드 내에서 직접적으로 리터럴 형태로 표현할 수 있어야 합니다. 예..
-
golang: Go 언어의 장점Back-End/Golang 2024. 4. 21. 22:31
Go 언어의 장점 요약 Go 언어의 장점들을 나열하고 그 이유를 설명하면 다음과 같습니다: 강력하고 정적 타입 시스템: 이유: Go는 컴파일 시 타입 체크를 수행합니다. 이는 런타임에 발생할 수 있는 오류를 최소화하고, 프로그램의 안정성과 유지 보수성을 향상시킵니다. 가비지 컬렉션 지원: 이유: 메모리 관리를 자동화하여 개발자가 메모리 누수와 같은 문제에 대해 걱정하지 않도록 합니다. 이로 인해 개발자는 애플리케이션 로직 구현에 더 집중할 수 있습니다. 동시성 프로그래밍 지원: 이유: '고루틴(goroutine)'과 채널을 사용하여 동시성을 쉽게 구현할 수 있습니다. 이는 멀티코어 프로세서의 이점을 최대화하고, I/O 대기 시간 등을 효율적으로 관리하여 애플리케이션의 성능을 향상시킵니다. 패키지 관리 시..
-
golang: 문자열 함수Back-End/Golang 2024. 4. 21. 13:39
Go 언어에서 문자열을 다루는 데 사용되는 주요 함수들은 대부분 strings 패키지 내에 있습니다. 여기서는 strings 패키지의 주요 함수들을 나열하겠습니다. 이 함수들은 다양한 문자열 조작 작업에 사용될 수 있습니다: Compare: 두 문자열을 비교하고, 첫 번째 문자열이 두 번째 문자열보다 작으면 -1, 같으면 0, 크면 1을 반환합니다. Contains: 하나의 문자열이 다른 문자열에 포함되어 있는지 확인합니다. ContainsAny: 주어진 문자들 중 하나라도 문자열에 포함되어 있는지 확인합니다. ContainsRune: 문자열이 특정 룬을 포함하고 있는지 확인합니다. Count: 하나의 문자열이 다른 문자열에 몇 번 등장하는지 세어 반환합니다. EqualFold: 두 문자열이 대소문자를 ..
-
golang: for-select 패턴Back-End/Golang 2024. 4. 19. 10:24
Go 언어는 효율적인 동시성 처리를 지원하는 강력한 메커니즘을 제공합니다. 이 중 for-select 패턴은 Go의 동시성을 활용하는 중요한 방법 중 하나로, 여러 동시 작업을 관리하고, 다양한 채널 간 통신을 조절하는 데 사용됩니다. 이 블로그 글에서는 for-select 패턴이 무엇인지, 어떻게 사용되는지, 그리고 이 패턴을 통해 어떤 문제를 해결할 수 있는지 상세히 설명하겠습니다. for-select 패턴이란? for-select 패턴은 Go의 for 루프와 select 문을 결합한 구조입니다. select 문은 여러 채널 오퍼레이션 중 하나가 준비될 때까지 기다리다가 준비된 오퍼레이션을 실행합니다. 이 패턴은 주로 비동기적으로 데이터를 수신하거나, 여러 채널에 걸쳐 동시에 이벤트를 처리할 필요가 ..
-
golang: 동시성에서 제한(Confinement)이란?Back-End/Golang 2024. 4. 19. 09:50
"동시성 코드로 작업할 때, 안전한 작동을 위한 몇 가지 옵션이 있다." 메모리 공유를 위한 동기화 기본 요소(예: sync.Mutex) 통신을 통한 동기화(예: 채널) 변경 불가능한 데이터 제한(Confinement)에 의해 보호되는 데이터 제한(Confinement)은 동시성 프로그래밍에서 데이터 접근을 제어하여, 고루틴 간의 간섭이나 경쟁 상태를 방지하는 기법입니다. 데이터를 고루틴이나 특정 코드 영역에 "제한"함으로써 안전하게 데이터를 공유할 수 있습니다. 언제 사용하나요? 제한은 특히 여러 고루틴이 동시에 실행되는 환경에서 중요합니다. 데이터를 여러 고루틴이 공유할 때 발생할 수 있는 문제(예: 경쟁 상태, 데드락)를 방지하기 위해 사용됩니다. 제한을 통해 각 고루틴이 데이터의 접근을 독립적으로..
-
Counting Sort(계수 정렬)Algorithm & Data Structure/Sort 2024. 4. 16. 22:30
카운팅 정렬(Counting Sort)은 특정 조건에서 매우 효율적인 정렬 방식을 제공하는 비교 기반 정렬이 아닌 알고리즘입니다. 그 특징과 구현에 대해 자세히 설명하겠습니다. Counting Sort란? 카운팅 정렬은 입력 배열에서 각 요소의 등장 횟수를 세고, 그 카운트를 기반으로 배열을 정렬하는 알고리즘입니다. 이 방법은 특히 배열의 원소가 특정 범위 내의 정수일 때 매우 효과적입니다. 이 정렬은 추가적인 메모리 공간을 사용해 입력 원소의 빈도 수를 카운팅하며, 이 정보를 이용하여 출력 배열을 직접 생성합니다. Counting Sort 사이클 설명 카운팅 정렬의 주요 사이클은 다음과 같은 단계로 이루어집니다: 카운팅 배열 초기화: 입력 배열의 각 요소 값에 대응하는 인덱스를 가진 카운팅 배열을 초기..
-
플라이웨이트 패턴(Flyweight Pattern)이란?Design Pattern/구조 디자인 패턴 2024. 4. 14. 16:26
플라이웨이트 패턴(Flyweight Pattern)은 객체 지향 디자인 패턴 중 하나로, 메모리 사용을 최적화하기 위해 공유를 통해 대량의 작은 객체들을 효율적으로 지원합니다. 이 패턴은 반복되는 상태를 공유 객체(플라이웨이트)로 분리하여, 여러 컨텍스트에서 재사용함으로써 메모리 소비를 줄이는 것을 목표로 합니다. 1. 플라이웨이트 패턴은 주로 어디에 쓰이나? 플라이웨이트 패턴은 주로 시스템에 많은 수의 객체가 필요할 때 사용되며, 이 객체들이 중복되는 상태를 많이 공유할 수 있을 때 유용합니다. 예를 들어, 텍스트 편집기에서의 문자 객체, 게임에서의 풍경 요소, GUI 툴킷의 그래픽 컴포넌트 등에서 자주 사용됩니다. 2. Java와 Go로 플라이웨이트 패턴을 구현할 때의 차이점 Java에서 플라이웨이트..
-
복합체 패턴(Composite Pattern)이란?Design Pattern/구조 디자인 패턴 2024. 4. 14. 16:16
복합체 패턴(Composite Pattern)은 클라이언트가 개별 객체와 복합 객체 모두를 동일하게 다룰 수 있도록 하는 구조적 디자인 패턴입니다. 이 패턴은 객체를 트리 구조로 구성하여 부분-전체 계층을 표현합니다. 이를 통해 클라이언트는 개별 객체와 복합 객체를 동일한 방법으로 처리할 수 있습니다. 가장 쉽게 폴더를 이해하면 좋습니다. 1. 복합체 패턴은 주로 어디에 쓰이나? 복합체 패턴은 파일 시스템의 디렉토리와 파일 관리, 사용자 인터페이스 컴포넌트, 메뉴 시스템 등과 같이 부분과 전체의 계층 구조가 명확한 시스템에서 널리 사용됩니다. 예를 들어, 메뉴와 서브메뉴 항목을 동일한 객체 인터페이스로 다루어 개발의 복잡성을 줄일 수 있습니다. 2. Java와 Go로 복합체 패턴을 구현할 때의 차이점 J..