Programming/JAVA, C++, Go, Rust(41)
-
Kotlin: Function with receivers
리시버를 지닌 함수 리터럴은 다음과 같은 형태입니다.A.(B) -> C예를들어 다음과 같이 정의될 수 있습니다.val sum: Int.(Int) -> Int = { other -> plus(other) }이 경우 함수 리터럴의 바디 안에서 전달된 리시버 객체는 this가 되어 this 없이 그 멤버들에 접근이 가능합니다.위 예에서도 Int의 plus에 접근하고 있습니다.리시버가 없는 경우Int의 확장함수 wrapper는 람다함수를 func로 받고 func에 this 즉, Int객체를 넘겨서 호출합니다.람다 함수 내에서는 매개변수 it으로 hashCode()에 접근 합니다. fun Int.wrapper(func: (num: Int) -> Unit) = func(this)fun main(args: Array..
2025.10.02 -
Kotlin generics
Grammarclass다음 예에서 T는 타입 파라미터이며 Box 클래스가 어떤 타입이던 속성으로 지닐 수 있게 합니다. class Box(val value: T) { fun getValue(): T = value}다음과 같이 사용할 수 있습니다.val intBox = Box(123)val strBox = Box("123")println(intBox.getValue()) // 123println(strBox.getValue()) // 123다음과 같이 타입추론도 가능합니다. val intBox = Box(123)where clause여러 타입 파라미터에 복합 제약을 주거나, 하나의 타입 파라미터에 여러 제약을 줄 때 사용합니다.다음 예에서 T는 CharSquence를 구현하고, R은 Appenda..
2025.10.02 -
backtrace 정보 출력
exception 발생 시 혹은 오류 발생 시 call stack 정보를 출력하고자 하는 경우가 발생합니다. 이럴때 C++에서 다음과 같이 코드를 작성할 수 있습니다.#include "back_trace.h"#include #include #include #include #include #include #include const uint32_t MAX_NUM_TRACE = 32;std::string BackTrace::get_backtrace() { void* callstack[MAX_NUM_TRACE]; int frames = backtrace(callstack, MAX_NUM_TRACE); char** messages = backtrace_symbols(callstack, frames..
2025.03.31 -
go get 오류 발생 시 대처
go get 시 다음과 같이 connection이 거절되는 오류가 발생할 수 있습니다. ✗ go get git.linecorp.com/VISION-PLATFORM/photato-server@v1.6.2 go: downloading git.yourcompany.com/organization/yourproject v1.0.0go: git.yourcompany.com/organization/yourproject@v1.0.0: verifying module: ... : reading https://sum.golang.org/lookup/git.yourcompany.com/.../yourpro..
2024.05.09 -
go profiler pprof 사용법About pprof go 프로그램을 프로파일링 하여 CPU나 memroy, 혹은 go 프로그램이 사용하는 go routine 개수와 같은 여러 자원들에 대해 동적 분석 결과를 수행하는 툴 입니다. Usage Recording 사용법은 매우 간단합니다. go 언어의 시작 부분에서 다음의 고루틴을 실행한 후, 프로그램 종료 직전에 pprof를 닫으면 됩니다. // import _ "net/http/pprof" ... go func() { http.ListenAndServe(":6060", nil) }() ... f, err := os.Create("heap_usage_profile.mprof") if err != nil { logger.Fatalf("heap_usage_profile.mprof: %v", ..
2024.02.06 -
Study stuff for Golang
https://tour.golang.org/ http://golang.site/ https://nomadcoders.co/go-for-beginners Coding Convention https://golang.org/doc/effective_go https://dave.cheney.net/practical-go/presentations/qcon-china.html https://github.com/golang/go/wiki/CodeReviewComments Project Structure https://github.com/golang-standards/project-layout https://github.com/bxcodec/go-clean-arch https://github.com/katzien/go..
2023.07.24