(240610) Medium Daily Digest

Godomin·2024년 6월 10일

Medium-Daily-Digest

목록 보기
20/24

https://medium.com/@kappdev/how-to-create-a-stunning-3d-border-in-jetpack-compose-e040fbb6b8de

https://medium.com/@kappdev/how-to-create-a-stunning-3d-border-in-jetpack-compose-e040fbb6b8de

요즘 다양하고 화려한 UI를 어떻게하면 안드로이드에서 그릴 수 있을까 관심이 많았는데, 이사람의 글에 관련된 정보가 많아서 좋다.

이렇게 된 테두리를 그린다.

먼저 그림자부분을 만들 수 있는 함수를 만들고,

offset을 +로 준 것과 -로 준 것을 합쳐서 shadow와 glare를 준다.

Dispatchers.Default vs Dispatchers.IO in kotlin Coroutine

https://medium.com/@manuaravindpta/dispatchers-default-vs-dispatchers-io-in-kotlin-coroutine-21a88e2fb41b

목적

  • Dispatchers.Default: CPU 바인딩 된 작업을 위해 설계 됨, CPU 코어 수와 일치하는 제한된 스레드 풀을 활용
  • Dispatchers.IO: 네트워크 요청, 파일 액세스, 데이터베이스 접근 등 I/O 바인딩 작업에 최적화

ThreadPool

  • Dispatchers.Default: 고정 크기, CPU 코어 수
  • Dispatchers.IO: 동적 스레드 풀, workload에 따라 동적으로 조정할 수 있음, 기본적으로 max(64, CPU 코어 수)

언제 사용하는가?

  • Dispatchers.Default: CPU를 많이 사용하는 계산 집약적인 작업
  • Dispatchers.IO: 네트워크 호출이나 디스크 액세스와 같은 외부 리소스를 기다리는 작업

How to create custom annotations in Kotlin

https://medium.com/@m.abuzaid.ali/how-to-create-custom-annotations-in-kotlin-f7ed238b52eb

Annotation은 프로그램 자체의 일부는 아닌 메타데이터 형식이다. 코드의 작동에 직접적인 영향을 미치지는 않지만 빌드 중 컴파일러와 다양한 도구에서 사용되며 리플렉션을 통해 런타임에 액세스할 수도 있다.

Annotation을 사용하는 이유

  1. 코드 가독성 및 유지 관리성 향상
  2. 코딩 규칙 및 안전 강화
  3. 프레임워크 및 라이브러리와의 통합
  4. Configuration 단순화

사용자 정의 annotation 만들기

  1. 클래스 선언
    annotation class Loggable

  2. 대상 지정 (선택 사항)
    @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
    annotation class Loggable

  3. 매개변수 추가 (선택 사항)
    annotation class Loggable(val level: String = "INFO")

  4. 사용

@Loggable(level = "DEBUG" ) 
class UserService
  1. 처리
fun checkLoggable(function: KFunction<*>) {
  function.findAnnotation<Loggable>()?.let {
    println("Function ${function.name} is loggable with level ${it.level}.") 
  }
}
    
// Usage
checkLoggable(::updateUser)

Retention policy and target

  1. Source: 소스 코드에만 사용할 수 있으며 컴파일러에 의해 삭제됨
  2. Binary: 컴파일된 클래스 파일에 유지되지만 런타임에는 사용할 수 없음
  3. Runtime: 런타임에 리플렉션을 통해 사용할 수 있음

Kotlin annotation

Reflection, kapt, ksp 등을 사용하여 처리 가능

0개의 댓글