2018년 1월 16일 화요일

Kotlin 스터디

KotlinConf 2017

* Introduction to Coroutines *

https://resources.jetbrains.com/storage/products/kotlinconf2017/slides/2017+KotlinConf+-+Introduction+to+Coroutines.pdf

- Synchronous
- Asynchronous

-> Callback

- Futures/Promises/Rx

-> returns promise for a future result immediately

- Coroutines

-> suspend: returns result when received
-> like regular code

- Coroutines are like very light-weight threads

http://github.com/kotlin/kotlinx-coroutines

* Deep Dive into Coroutines on JVM *

https://resources.jetbrains.com/storage/products/kotlinconf2017/slides/2017+KotlinConf+-+Deep+dive+into+Coroutines+on+JVM.pdf

- Continuation Passing Style(CPS)

-> Callback

- State Machine

- Communicating Sequential Processes(CSP)

* Kotlin Types: Exposed *

Int vs Int?

IntArray vs Array<Int>

Any vs Object

Boxing under the hood vs No boxing

Unit vs Nothing vs void

Unit

-> a type that allows only one value and thus can hold no information
-> the function completes successfully

Nothing :

-> a type that has no values
-> It means "this function never returns"

- Unit과 Nothing은 Kotlin에서 위와 같은 차이가 있지만 JVM에서 똑같이 void로 컴파일된다.

Nothing?

@Nullable -> Type? and @NotNull(@NonNull) -> Type

How to still prevent NPEs? - 자바 코드를 코틀린에서 사용하는 경우 문제가 발생

-> Annotate your Java types

compileKotlin {
  kotlinOptions {
    freeCompilerArgs += "-Xjsr305=strict"
  }
}

-> Specify types explicitly

Collections

-> Read-only : it is not immutable
-> Mutable

* Generating Kotlin Code *

KotlinPoet

A Functional Approach to Android Architecture using Kotlin

- Modeling Error and Success Cases

-- Result wrapper(Error or Success)
-- RxJava
-- KATEGORY

- Asynchronous Code and Threading

-- Java : ThreadPoolExecutor + exceptions + callbacks
-- RxJava : Schedulers + observable + error subscription
-- KATEGORY

Lazy evaluation

- Dependency Injection

-- Reader Monad: ReaderT, Monad Transformers

Exploring Kotlin's hidden costs - Part 1

Coroutine Theory

- Normal function

Call/Return

activation frame(stack)

- Coroutine

Suspend/Resume/Destroy

coroutine frame(heap) and stack frame

Kotlin Coroutines on Android: Things Wish I Knew at the Beginning

- Executor를 CoroutineDispatchers로 바꿀 수 있다.

- RxJava의 disposable 같은 것을 위해 "root" coroutine parent를 사용할 수 있다.

- CommonPool 의 크기를 조절할 수 있다.

- Async에서의 exception은 바로 발생되지 않는다.

- coroutine들을 협력적으로 cancel 하려면 CoroutineContext를 통한 parent-child 관계가 필요하다.

Async code using Kotlin Coroutines

RxJava to Kotlin coroutines

코루틴과 관련해서 Continuation에 대해서도 알면 좋을것 같다.

What's in a Continuation

Implementing a Stepping Debugger in JavaScript

Exploring Continuations: Resumable Exceptions

2018년 1월 10일 수요일

안드로이드 스터디

The Dex File Format

.java -> .class -> .dex

ART: Ahead-of-Time and Just-in-Time

D8, R8

Sinking Your Teeth Into Bytecode

sources + libraries -> compilers -> transforms -> d8 -> *.dex -> ART(Interperter, JIT, AOT) -> Machine code

- 리스트에 비디오 플레이 넣기

한번에 하나만 플레이 하도록 하기 위해 리스트 아이템 사이에 정보 전달이 필요하다.

https://medium.com/@v.danylo/implementing-video-playback-in-a-scrolled-list-listview-recyclerview-d04bc2148429

- RecyclerView는 어떻게 구현되어 있을까?

RecyclerView ins and outs - Google I/O 2016

http://blog.naver.com/PostList.nhn?from=postList&blogId=mail1001&categoryNo=14&currentPage=4

It's time to ditch Loaders in Android

Loader는 이제 그만.
Architecture Components를 사용하자.

2018년 1월 4일 목요일

안드로이드 스터디 - UI


Playing with Paths

- Cartesian coordinates vs polat coordinates
- Path, CornerPathEffect, DashPathEffect

https://gist.github.com/nickbutcher/b41da75b8b1fc115171af86c63796c5b#file-polygonlapsdrawable-kt

Understanding Android Adaptive Icons

Designing Adaptive Icons

Implementing Adaptive Icons

VectorDrawable Adaptive Icons

- What is WindowInsets?

Becoming a master window fitter

Spantastic text styling with Spans

SpannedString
SpannableString
SpannableStringBuilder

Appearance Affecting Spans vs Metric Affecting Spans

Character Affecting Spans vs Paragraph Affecting Spans

CharacterStyle
ParagraphStyle
UpdateAppearance
UpdateLayout



2017년 12월 12일 화요일

Swift 스터디 - Associated Types Versus Generics

https://doc.rust-lang.org/book/second-edition/ch19-03-advanced-traits.html

https://www.youtube.com/watch?v=XWoNjiSPqI8

http://www.russbishop.net/swift-associated-types

https://www.bignerdranch.com/blog/why-associated-type-requirements-become-generic-constraints/

https://pdfs.semanticscholar.org/30c6/1a232dbf78a1720b06946eab0c9cb0a645b2.pdf

type parameter가 늘어날수록 사용이 불편해진다.
Generic은 public interface에 포함된다. 따라서, type이  open된다.
type parameter가 여러개일 경우 이중 하나에만 특정지을 수 없다.(나머지도 항상 표시가 필요하다.)
새로운 type parameter를 추가하면 이전 코드가 깨진다.
type parameter로 표현하는 경우 SomeProtocol<String>과 SomeProtocol<UITableViewCell>처럼 여러 타입에 대한 구현을 가질 수 있다. 따라서, 프로토콜에서 관련 함수를 호출하려면 타입 캐스팅등이 필요하게 된다.

associatedtype을 사용하는 protocol은 generic constraint와 함께 사용된다. 그렇지 않을 경우 아래와 같은 에러 메시지를 보게 된다.
  "Protocol `SomeProtocol` can only be used as a generic constraint because it has Self or associated type requirements"

Covariant Parameter Types

function return values can changed to subtypes, moving down the hierarchy, whereas function parameters can be changed to supertypes, moving up the hierarchy

https://www.java-tips.org/java-se-tips-100019/24-java-lang/482-covariant-parameter-types.html

https://softwareengineering.stackexchange.com/questions/267310/overriding-methods-by-passing-as-argument-the-subclass-object-where-the-supertyp

https://mikeash.com/pyblog/friday-qa-2015-11-20-covariance-and-contravariance.html

Type Erasure

https://krakendev.io/blog/generic-protocols-and-their-shortcomings

https://www.bignerdranch.com/blog/breaking-down-type-erasure-in-swift/

https://www.slacktime.org/type-erasure/

https://academy.realm.io/posts/tryswift-gwendolyn-weston-type-erasure/

2017년 10월 23일 월요일

Conductor 소스 분석


Conductor
  • MainActivity: 최상단 activity
    • Conductor.attachRouter를 통해 Activity와 Activity 안의 container(FrameLayout으로 만든다.)와 savedInstanceState를 연결하는 Router를 만든다.
    • attachRouter: LifecycleHandler라는 Fragment를 만들어서 Activity에 연결한다. 실제 Router는 LifecycleHandler에서 만든다.
  • Router: stack을 통해 Controller의 go/back을 관리한다.
    • Router의 setRoot를 통해 최상단에 적용할 Controller를 연결한다. Controller는 RouterTransaction을 통해 Router에 연결된다.
  • Controller: inflateView를 통해 View를 연결한다.
  • ControllerChangeHandler: View의 변환시 Animation이나 Transition을 한다.

LifecycleHandler

  • Fragment를 상속한다.
  • setRetainInstance(true)를 통해 activity가 recreate될 때 fragment도 같이 recreate되지 않도록 한다.
  • activeLifecycleHandlers를 통해 activity마다 하나의 LifecycleHandler를 연결한다.
  • application에 자신을 ActivityLifecycleCallbacks으로 등록한다.
  • pendingPermissionRequests: 퍼미션 요청하는 것에 대한 관리
  • routerMap을 통해 container(ViewGroup)마다 하나의 ActivityHostedRouter를 연결한다.

Router

  • ActivityHostedRouter and ControllerHostedRouter
  • ActivityHostedRouter는 LifecycleHandler와 연결하고, ControllerHostedRouter는 Controller와 연결한다.
  • InstanceState를 써서 data를 유지한다: KEY_BACKSTACK, KEY_POPS_LAST_VIEW
  • setRoot를 통해 최상단 RouterTransaction을 연결한다.
    • BackStack에 RouterTransaction을 넣는다.
    • ControllerChangeHandler.executeChange를 통해 RouterTransaction의 Controller에 연결되어 있는 View를 addView한다. 이전것은 removeView한다.
    • add와 remove를 위해 ControllerChangeHandler를 사용한다. RouterTransaction에 연결된 ControllerChangeHandler가 없으면 애니메이션없는 SimpleSwapChangeHandler를 사용한다.
  • Backstack
    • ArrayDeque을 통해 백스택 구현
    • Iterator<RouterTransaction> 및 reverseIterator 제공
  • Backstack에 controller가 들어가면 아래의 라이프 관련 함수가 호출된다.
    • onContextAvailable
    • inflate
  • Backstack에서 controller가 빠지면 아래의 라이프 관련 함수가 호출된다.
    • detach
    • destroy

ControllerChangeHandler

  • Controller로부터 View를 얻어온다: inflate
  • performChange를 통해 View의 push/pop을 실행한다.
  • AnimatorChangeHandler
    • performChange 함수에서 addView를 하고 animation을 시작한다.
    • animation은 subclass의 getAnimator를 통해 얻어온다.
    • FadeChangeHandler: AnimatorChangeHandler를 상속하여 getAnimator와 resetFromView를 구현
      • getAnimator: AnimatorSet를 사용하여 기존의 뷰는 알파를 0으로, 새로운 뷰는 알파를 0에서 1로 변경한다.
      • resetFromView: 애니메이션이 끝나면 호출되는 함수. 기존의 뷰의 알파를 1로 바꾼다.

Controller

  • instanceId: UUID.randomUUID().toString()
  • 화면의 구성을 위해 inflate가 호출된다.
    • onCreateView를 호출하여 View를 생성한다.
    • subclass에서 inflateView와 onViewBound를 구현한다.
  • detach시 onSaveViewState를, inflate시 onRestoreViewState를 호출해준다.

RouterTransaction

  • Controller와 (pushChangeHandler, popChangeHandler)의 연결고리를 Router에 제공한다.

Lifecycle 관리

  • LifecycleHandler는 ActivityLifecycleCallbacks를 구현한다.
    • ActivityLifecycleCallbacks는 Application에 선언되어 있는 인터페이스이다.
    • 콜백이 불리면 Router의 Lifecycle 관련 함수를 호출한다.
  • Router는 Lifecycle 관련 함수를 정의하고 있다.
    • 이 함수에서는 Controller의 Lifecycle 관련 함수를 호출한다.
    • child router가 있으면 이의 Lifecycle 관련 함수를 호출한다.
  • LifecycleListener
    • Controller에 등록해서 Lifecycle 이벤트를 받는다.

AutoDispose

  • ControllerScopeProvider
    • Controller에서 라이프 사이클이 바뀌면 BehaviorSubject를 통해 이벤트가 발생하도록 한다.
    • lifecycle에서 아이덴티티를 숨긴 lifecycleSubject.hide()를 리턴한다.
    • correspondingEvents에서 dispose를 하기 위해 대응되는 매핑(CORRESPONDING_EVENTS)을 리턴한다.
    • peekLifecycle에서 BehaviorSubject의 현재 값을 리턴한다.

Generic interfaces 요점

 https://go.dev/blog/generic-interfaces  Generic interface를 정의할 때 최소한의 제약만을 정의하고 실제 구현체들이 자신만의 필요한 제약을 추가할 수 있도록 하는 것이 좋다. pointer receiver를...