Upgrade to Pro — share decks privately, control downloads, hide ads and more …

알아두면 쓸 데 있는 코틀린

알아두면 쓸 데 있는 코틀린

" IT 산업은 끊임없이 변화하는 특성을 가지며, 오늘 활용되는 기술이 내일은 사용되지 않을 수 있고, 반대로 이전에는 주목받지 않던 기술이 중요해질 수 있습니다. 다양한 기술에 익숙해지면 이러한 변화에 유연하게 대응할 수 있습니다. 또한, 다양한 지식과 능력은 개인의 전문성을 상승시키며, 새로운 직업 기회를 얻는 데에도 큰 도움이 됩니다.

위 내용은 `도서: 실용주의 프로그래머`에서 요약 발췌한 글입니다. 다양한 기술이나 지식을 갖추고 있을 때 유용한 점에 대해 말하고 있고, 이를 위해 `매년 새로운 언어를 최소 하나는 배워라`고 말하고 있습니다.

본 자료는 다양한 프로그래밍 언어의 습득이 개발자에 어떠한 가치를 부여하는지에 대한 인사이트를 제공하고자 합니다. 그리고 현대의 IT 트렌드에 맞춰, 코틀린의 매력을 소개하고 및 학습 방법을 제시합니다.

Arawn Park

August 25, 2023
Tweet

More Decks by Arawn Park

Other Decks in Programming

Transcript

  1. KotlinConf 23 Keynote Kotlin Handy to Know ,PUMJO$POGs,FZOPUF Github projects

    use Kotlin as their primary language Increase in Multiplatform libraries in 2002 of Android users are satisfied with Kotlin of the top 1,000 Android apps use Jetpack Compose of all kotlin users are satisfied with Kotlin of the top 1,000 Android apps are in Kotlin 1M 86 95 60 97 23 of the all daangn projects use Multiplatform 1 of the all daangn projects use Kotlin 10
  2. KotlinConf 23 Keynote Kotlin Handy to Know ௏ౣܽ਷੗߄৬੄࢚ഐ਍ਊࢿীୡ੼ਸݏ୸पਊ੸੉ҊрѾೞݴউ੹ೠ঱য੉׮ /* ೐۽ಌ౭ী

    ؀ೠ getter(), setter(), equals(), hashCode(), toString(), * copy(), componentN() ݫࣗ٘ܳ ஹ౵ੌ द੼ী ੗زਵ۽ ࢤࢿೠ׮ */ data class Person(val firstname: String, val lastname: String, val address: Address) // ಴ળ ۄ੉࠳۞ܻ੄ ೂࠗೠ API৬ Ҋର ೣࣻ੄ ب਑ਸ ߉ই рѾೞѱ ݾ੸ਸ ׳ࢿೡ ࣻ ੓׮ val filteredPersons = Persons.findByLastname("Matthews").filter { it.address.city == "Seoul" } // ױੌ಴അ ೣࣻח ١ഐ۽ ೣࣻ ੿੄৬ ߄٣ܳ ҳ࠙ೞৈ ૣѱ ಴അೡ ࣻ ੓׮ fun double(x: Int): Int = x * 2 val beDoubled = double(2) // օnull੉ ؼ ࣻ হח чਸ ୶੸ೞݴ, NullPointException ߊࢤਸ ߑ૑ೠ׮ val nullable: String? = null // օ੉ ؼ ࣻ ੓਺ val nonNullable: String = "" // օ੉ ؼ ࣻ হ਺ // ఋੑ Ѩࢎ৬ நझ౟о ೠ ো࢑੗ী ੄೧ ੉ܞ૑ݴ, ClassCastException ߊࢤਸ ߑ૑ೠ׮ val data = loadData() if (data is String) { data.uppercase(Locale.getDefault()) } // break ޙ੉ হযب غݴ, ৌѢഋ э਷ ౠ߹ೠ ఋੑҗ ೣԋ ॳݶ ݽٚ ч੉ ಣоغ঻ח૑ ഛੋೠ׮ val scoreRange = when(CreditScore.EXCELLENT) { CreditScore.BAD -> 300..629 CreditScore.FAIR -> 630..689 CreditScore.GOOD -> 690..850 } enum class CreditScore { BAD,FAIR,GOOD } Kotlin Showcase
  3. KotlinConf 23 Keynote Kotlin Handy to Know ࠺زӝ೐۽Ӓې߁ਸਤೠ௏ܖ౯ // GitHub

    API۽ ࢎਊ੗, ઑ૒, ੷੢ࣗ ؘ੉ఠܳ ஂٙೞӝ ਤೠ ஹನք౟੉׮ class GitHubOperations(val accessToken: String) { suspend fun fetchUser(username: String): User {..} suspend fun fetchOrganizations(user: User): List<Organization> {..} suspend fun fetchRepositories(user: User): List<Repository> {..} } Kotlin Showcase // GitHub ࢎਊ੗੄ ੿ࠁܳ ࠺زӝ੸ਵ۽ оઉয়ח ௏ܖ౯ ೣࣻ੉׮ suspend fun getGithubInfo(username: String, accessToken: String) = coroutineScope { val operations = GitHubOperations(accessToken) // ࢎਊ੗ ੿ࠁܳ оઉৡ׮ val user = operations.fetchUser(username) // ࢎਊ੗о ࣗࣘػ ઑ૒ٜҗ ੷੢ٜࣗਸ زदী ࠺زӝ੸ਵ۽ оઉৡ׮ val organizations = async { operations.fetchOrganizations(user) } val repositories = async { operations.fetchRepositories(user) } // ݽٚ ࠺زӝ ੘স੉ ৮ܐػ റ GithubInfo ё୓ܳ ࢤࢿ೧ࢲ ߈ജೠ׮ GithubInfo(user, organizations.await(), repositories.await()) }
  4. KotlinConf 23 Keynote Kotlin Handy to Know ݣ౭ಁ۞׮੐ // GitHub

    API۽ ࢎਊ੗, ઑ૒, ੷੢ࣗ ؘ੉ఠܳ ஂٙೞӝ ਤೠ ੋఠಕ੉झ৬ ҳഅ୓ٜ੉׮ interface GithubOperations { fun fetchUser(username: String): User fun fetchOrganizations(user: User): List<Organization> fun fetchRepositories(user: User): List<Repository> } class MockGithubOperations : GithubOperations { ... } class KtorGithubOperations(httpClient: HttpClient) : GithubOperations { ... } Kotlin Showcase // Ҋର ೣࣻܳ ࢎਊ೧ࢲ GitHub ੿ࠁܳ ઑ݀೧ࢲ ߈ജೠ׮ fun <T> getGithubInfo( username: String, operations: GithubOperations, assemble: (User, List<Organization>, List<Repository>) -> T): T { val user = operations.fetchUser(username) val organizations = operations.fetchOrganizations(user) val repositories = operations.fetchRepositories(user) return assemble(user, organizations, repositories) } // ೣࣻо ز੘ೞחؘ ೙ਃೠ ੄ઓҙ҅ܳ ੹׳ೞҊ, ۈ׮ܳ ా೧ GitHub ੿ࠁܳ ਗೞח ߑधਵ۽ ઑ൩ೠ׮ getGithubInfo("jumpit", KtorGithubOperations(ktor())) { user, orgs, repos -> // ױࣽೠ ৘: ࢎਊ੗ ੉ܴҗ ઑ૒੄ ࣻ, ୭Ӕ ழ޿੉ ੓ח ੷੢ࣗ੄ ࣻܳ ߈ജ "User: ${user.name}, Orgs: ${orgs.size}, Repos: ${repos.count { it.hasRecentCommit }}" }
  5. KotlinConf 23 Keynote Kotlin Handy to Know ݣ౭೒ۖಬ // Common

    Kotlin: ݽٚ ೒ۖಬী ҕਬغח ௏٘੉׮ interface GithubOperations { fun fetchUser(username: String): User fun fetchOrganizations(user: User): List<Organization> fun fetchRepositories(user: User): List<Repository> } class HttpClientGithubOperations(private val httpClient: HttpClient) : GithubOperations { ... } Kotlin Showcase // Android ೒ۖಬ ҳഅ ௏٘: Okhttp ۽ ز੘ೠ׮ actual class HttpClient(okhttp: OkHttpClient) { ... } // iOS ೒ۖಬ ҳഅ ௏٘: Ktor Client for Native ਵ۽ ز੘ೠ׮ actual class HttpClient(ktor: io.ktor.client.HttpClient) { ... } // JS ೒ۖಬ ҳഅ ௏٘: Ktor Client for JavaScript ۽ ز੘ೠ׮ actual class HttpClient(ktor: io.ktor.client.HttpClient) { ... } // JVM ೒ۖಬ ҳഅ ௏٘: Spring RestTemplate ۽ ز੘ೠ׮ actual class HttpClient(restTemplate: RestTemplate) { ... } // expect৬ actual ಁఢਸ ࢎਊೞݶ ೒ۖಬ ౠ੿ ҳഅਸ ҕਬ ۽૒ীࢲ ܻ࠙ೡ ࣻ ੓׮ // ੉ܳ ా೧ ௏٘ ੤ࢎਊࢿਸ ਬ૑ೞݶࢲ ೒ۖಬ ౠ੿ࢿਸ ࠁઓೡ ࣻ ੓׮ expect class HttpClient { fun exchage(request: Request): Response }
  6. &/%