KT Academy
作者:
發布:04-25 00:00
Effective Kotlin Item 36: Prefer composition over inheritance
Years of OOP taught us to overuse inheritance; prefer composition instead because it's safer and more explicit, though not always the right choice.
重點摘要
Inheritance often leads to fragile, implicit designs
Composition (delegation/combination) is safer and more explicit
Reserve inheritance for clear is-a relationships or controlled hierarchies
Decades of object-oriented programming have encouraged heavy use of class inheritance, but this often produces fragile and implicit designs. Favoring composition — building behavior by combining smaller objects, delegating responsibilities, and using explicit interfaces — yields safer, clearer, and more flexible systems. Composition reduces tight coupling, avoids deep hierarchies, and makes components easier to change, test, and reuse. That said, composition is not a universal panacea: inheritance still fits when you need a clear is-a relationship, shared behavior in a controlled hierarchy, or simpler polymorphic substitution. In practice, prefer composition in most cases because it makes dependencies explicit and limits unexpected interactions, but apply judgment and use inheritance when it offers a clearer, simpler solution.
Effective Kotlin 第36条:优先使用组合而非继承
多年的 OOP 让我们过度使用继承;应更多采用更安全且意图明确的组合,但并非在所有情况下都适用。
重點摘要
继承容易导致脆弱和隐含设计
组合(委托)更安全且意图明确
仅在明确 is-a 或受控继承层次时使用继承
多年来的面向对象编程习惯促使我们大量使用继承,但继承常会带来脆弱且隐含的设计。大多数情况下应优先采用组合——通过委托、明确的接口和小而专注的对象来组合行为,从而降低耦合、避免深层继承结构,并让修改与测试更容易。不过,当需要明确的 is-a 关系或在受控层次中共享行为时,继承仍然适用。实践中应以组合为首选,但根据具体情境权衡是否使用继承。
Effective Kotlin 第36項:偏好組合而非繼承
多年 OOP 習慣使我們過度使用繼承;應較常採用更安全且意圖明確的組合,但並非在所有情況都適用。
重點摘要
繼承易導致脆弱與隱含設計
組合(委派)更安全且意圖清楚
僅在明確 is-a 或受控繼承層次時使用繼承
多年來的物件導向程式設計習慣讓我們過度依賴繼承,但繼承常造成脆弱且隱含的設計。大多數情況下,應優先採用組合——透過委派、明確的介面和小而專注的物件來組合行為,這樣可以降低耦合、避免深層繼承結構,並讓變更與測試更容易。不過,當需要明確的 is-a 關係或在受控的繼承層次中共享行為時,繼承仍然適用。實務上應以組合為首選,但根據情境權衡是否使用繼承。
KT Academy
作者:
發布:06-16 00:00
Kt. Academy new logo: Phoenix
We changed our logo to a phoenix to express renewal, resilience and the values the academy stands for.
重點摘要
Announcement of a logo change to a phoenix motif
Phoenix symbolizes renewal, resilience and transformation
Logo update aligns visual identity with mission and digital presence
This short article explains why Kt. Academy chose to change its logo and why the phoenix was selected as the new symbol. The phoenix motif is presented as representing renewal, resilience, ongoing growth and the capacity to adapt in the face of change. The academy frames the change as a way to better reflect its mission, the learning community and future direction, while also modernizing and clarifying its visual identity across digital and multi-platform contexts. The article links the phoenix imagery to the values and aspirations the institution wants to communicate, emphasizing continuity through transformation rather than a break with the past.
Kt. Academy 新标志:凤凰
我们以凤凰作为新标志,象征重生、韧性与学院所坚持的价值。
重點摘要
宣布将标志更换为凤凰意象
凤凰象征重生、韧性与持续成长
标志更新旨在强化品牌识别并适应数位平台
本文说明 Kt. Academy 为什么决定更换标志,并解释将凤凰作为新标志的象征意义。凤凰在此代表重生、韧性、持续成长与转型,寓意在变化中保持适应力与创新精神,同时反映学院对教育使命、学习社群与未来发展的期待。更换标志也旨在更新视觉识别,使品牌在数位与多平台环境中呈现更清晰、一致且有力的形象,通过凤凰意象将价值观与愿景连结起来,强调变革中的延续性。
Kt. Academy 新標誌:鳳凰
我們以鳳凰作為新標誌,象徵重生、韌性與學院所秉持的價值。
重點摘要
宣布將標誌更新為鳳凰意象
鳳凰代表重生、韌性與持續成長
標誌更新以強化品牌識別並符合數位呈現
本文說明 Kt. Academy 為何決定更換標誌,並闡述將鳳凰作為新標誌的象徵意義。鳳凰在此代表重生、韌性、持續成長與轉型,象徵面對變化時的適應力與創新精神,也反映學院對教育使命、學習社群與未來發展的期許。更換標誌同時旨在更新視覺識別,使品牌在數位與多平台環境中呈現更清晰、一致且有力量的形象,透過鳳凰的意象連結價值觀與願景。
KT Academy
作者:
發布:07-18 00:00
Effective Kotlin — Item 46: Avoid Member Extensions
Member extensions let you declare extension functions inside another class, but their resolution rules and dual receivers make them surprising and error-prone, so prefer other alternatives.
重點摘要
Member extensions are extension functions declared as members of a class, giving both a dispatch receiver and an extension receiver.
They behave differently from regular members because extension resolution is static and can be surprising in inheritance and overload situations.
Because of their counterintuitive semantics and maintenance risk, prefer top-level extensions or ordinary member functions instead of member extensions.
Member extensions are extension functions defined inside a class, which provide two implicit receivers: the containing class (dispatch receiver) and the extended type (extension receiver). Although they let you write code that appears to inject behavior into another type while accessing the containing class's context, their lookup and dispatch rules are different from normal members: extension functions are resolved statically, and the interplay with inheritance and overloads can lead to surprising behavior. That cognitive overhead makes code harder to reason about and maintain. The recommended approach is to avoid member extensions in favor of clearer alternatives — put extensions at top level, use ordinary member functions, or explicitly pass the needed context — so you keep code semantics straightforward and less error-prone.
Effective Kotlin — 第46条:避免使用成员扩展(member extensions)
成员扩展是在类内声明的扩展函数,但它们的解析规则与双接收者机制会导致行为令人困惑,应尽量避免。
重點摘要
成员扩展是在类中为其他类型定义的扩展函数,包含容器(dispatch)和扩展(extension)两个接收者。
扩展函数的解析是静态的,与继承、重载或覆盖交互时可能产生出乎意料的行为。
由于语义不直观且增加维护难度,建议使用顶层扩展或普通成员函数替代成员扩展。
成员扩展是指在某个类内部为另一个类型定义的扩展函数,这种写法同时存在容器类(dispatch receiver)和被扩展类型(extension receiver)两个隐含接收者。虽然它能在容器上下文中为外部类型添加行为,但扩展函数采用静态解析,行为与普通成员不同,在继承与重载等情形下可能出现令人惊讶的结果,增加理解与维护成本。因此实务上应避免使用成员扩展,改用顶层扩展、明确的成员函数或显式传入上下文,以保持代码语义清晰且更易维护。
Effective Kotlin — 第46項:避免使用成員延伸(member extensions)
成員延伸是在類別內宣告的延伸函式,但其解析規則與雙接收者設計會導致行為出人意表,應避免使用。
重點摘要
成員延伸是在類別內為其他型別定義的延伸函式,具有容器(dispatch)與延伸(extension)兩個接收者。
延伸函式的解析是靜態的,與繼承、覆寫或多載交互時容易產生讓人誤解的行為。
因為語意不直觀且增加維護成本,建議改用頂層延伸、一般成員函式或明確傳入所需上下文。
成員延伸是指在某個類別內定義的延伸函式,此設計同時提供容器類別(dispatch receiver)與被延伸型別(extension receiver)兩個隱含接收者。雖然可以在容器上下文中為外部型別增加行為,但延伸函式的解析採靜態綁定,與一般成員函式不同,會在繼承、覆寫或多載情境下產生令人意外的結果。這種額外的認知負擔會讓程式碼較難理解與維護。因此實務上應避免使用成員延伸,改以頂層延伸、明確的成員函式或傳入所需上下文來達成相同目的,維持語意清楚且易於維護。
KT Academy
作者:
發布:07-25 00:00
Effective Kotlin Item 32: Consider factory functions instead of secondary constructors
Factory functions are a key pattern for creating objects and often provide clearer, more flexible alternatives to secondary constructors.
重點摘要
Factory functions construct and return instances outside constructors
They support descriptive names, caching, and returning subtypes
They improve API clarity, encapsulation, and evolution
Factory functions are functions (commonly top-level or defined in companion objects) that construct and return instances of a class. Effective Kotlin Item 32 advises favoring factory functions over secondary constructors because they can use descriptive names, encapsulate complex creation logic, control instance creation (for caching, singletons, or returning subclasses), and validate inputs before constructing an object. Unlike secondary constructors, factory functions can return null or alternative types, hide implementation details, and evolve the creation API without breaking callers. They also simplify testing and refactoring by separating construction from class internals and leveraging Kotlin features like named and default parameters. For these reasons, factory functions generally provide greater flexibility, clearer intent, and better maintainability when creating objects in Kotlin.
Effective Kotlin 第32条:考虑使用工厂函数而非次级构造函数
工厂函数是创建对象的重要模式,通常比次级构造函数更具可读性和灵活性。
重點摘要
在顶层或 companion 中定义以返回实例
可命名、支持缓存或返回子类型
提升 API 清晰度与封装,便于演进
工厂函数(通常为顶层函数或 companion object 内的方法)负责创建并返回对象。Effective Kotlin 第32条建议优先使用工厂函数而不是次级构造函数,因为工厂函数可以使用描述性名称表达意图,将创建逻辑与类内部隔离,在创建前验证参数,支持缓存、单例或返回子类或 null,从而隐藏实现细节并避免构造函数链的复杂性。该模式让 API 更清晰、演进更容易,也便于测试和重构。在大多数情况下,工厂函数相比次级构造函数提供了更高的灵活性与可维护性。
Effective Kotlin 第32條:考慮使用工廠函式而非次級建構子
工廠函式是建立物件的重要模式,通常比次級建構子更具可讀性與彈性。
重點摘要
在頂層或 companion 內定義以回傳實例
可命名、支援快取或回傳子類別
提升 API 清晰度與封裝,便於演化
工廠函式(通常為頂層函式或 companion object 內的方法)負責建立並回傳物件。Effective Kotlin 第32條建議優先使用工廠函式而非次級建構子,因為工廠函式可用具有說明性的名稱表達意圖,將建立邏輯與類別內部隔離,並能在建立前驗證參數、實作快取或回傳子類別或 null,從而隱藏實作細節並避免建構子連鎖的複雜性。此模式讓 API 更清楚、演化更容易,也利於測試與重構。在多數情況下,工廠函式提供比次級建構子更佳的彈性與可維護性。
KT Academy
作者:
發布:07-28 00:00
How does suspension work in Kotlin coroutines?
An in-depth explanation of how suspension operates in Kotlin coroutines.
重點摘要
Explains the mechanics of suspension in Kotlin coroutines.
Describes behavior at suspension points and how coroutines pause and resume.
Covers practical implications for writing and debugging asynchronous Kotlin code.
This article provides a deep, technical explanation of how suspension works in Kotlin coroutines. It clarifies what "suspension" means in this context, how execution flow is paused at suspension points and later resumed, and how coroutine state and local variables are preserved across suspension. The article examines how suspension points interact with coroutine dispatchers and threads, the lifecycle of a suspended coroutine, and practical considerations for writing and debugging asynchronous Kotlin code. Readers can expect conceptual descriptions alongside discussion of implementation-level behavior that affects performance and correctness when building concurrent applications with coroutines. The goal is to give developers a clear mental model of suspension so they can reason about control flow, avoid common pitfalls, and design safer, more efficient coroutine-based code.
Kotlin 协程中的挂起如何工作?
对 Kotlin 协程中挂起机制的深入解析。
重點摘要
解释 Kotlin 协程中挂起的工作机制。
描述挂起点处程序如何暂停与恢复执行。
讨论对编写与调试异步 Kotlin 代码的实际影响。
本文对 Kotlin 协程中的“挂起”机制进行了深入解析,说明何为挂起、在挂起点程序如何暂停与恢复,以及挂起期间协程状态与局部变量如何被保留。文章还讨论了挂起点与调度器/线程的相互作用、挂起协程的生命周期,以及这些行为对编写与调试异步 Kotlin 代码的实际影响。目的是帮助开发者建立清晰的控制流模型,理解实现层面对性能与正确性的影响,避免常见陷阱,从而设计出更安全、更高效的协程代码。
Kotlin 協程中的掛起如何運作?
對 Kotlin 協程中掛起機制的深入說明。
重點摘要
說明 Kotlin 協程中掛起的運作原理。
描述掛起點處程式如何暫停與恢復執行。
探討對撰寫與除錯非同步 Kotlin 程式的實務影響。
本文對 Kotlin 協程中的「掛起」機制進行深入說明,說明何謂掛起、在掛起點程式執行如何暫停與恢復,以及掛起時協程狀態與區域變數如何被保留。文章也討論掛起點與派發器或執行緒的互動、掛起協程的生命週期,以及這些行為對撰寫與除錯非同步 Kotlin 程式的實務影響。目標是協助開發者建立清晰的控制流模型,理解實作層面對效能與正確性的影響,避免常見陷阱,並設計更安全且高效的協程程式。
KT Academy
作者:
發布:08-06 00:00
Traits for testing in Kotlin
A trick is needed when using traits for testing in Kotlin.
重點摘要
Using Kotlin traits can affect test setup and behavior
A specific workaround is required to test code that relies on traits
The note highlights a practical adjustment when testing with traits
This short article calls attention to a specific trick required when using traits for testing in Kotlin. In Kotlin, traits (interfaces with default implementations) can introduce testing complications—for example, around instantiation, overriding default behavior, or integrating with mocking and test frameworks. The article emphasizes that a deliberate workaround or pattern is necessary to make tests behave as intended when traits are involved. Rather than presenting broad theory, it focuses on a practical adjustment developers should apply in test code so that trait-based components can be reliably exercised. Readers are reminded to consider how trait implementations interact with their chosen testing approach and to adopt the recommended trick to avoid subtle test failures or brittle setups.
在 Kotlin 测试中使用 traits
在 Kotlin 的测试中使用 traits 时,需要一个特定的技巧。
重點摘要
traits(带默认实现的接口)会影响测试配置
测试依赖 traits 的代码时需要采用特定做法
文章提醒在测试中调整以避免隐性错误
本文简短指出:在 Kotlin 的测试中使用 traits 时,需要采用一个特定的技巧。Kotlin 的 traits(即带默认实现的接口)可能带来测试方面的挑战,例如实例化、覆盖默认行为或与模拟/测试框架整合时的不同。因此文章强调应在测试代码中有意识地使用某种变通或模式,以便基于 traits 的组件能够被可靠地测试。要点是提醒开发者关注 traits 与测试方法的相互作用,并采用推荐的技巧来避免隐蔽的测试失败或测试脆弱性。
在 Kotlin 測試中使用 traits
在 Kotlin 的測試中使用 traits 時,需要一個特定的技巧。
重點摘要
traits(帶預設實作的介面)會影響測試配置
測試依賴 traits 的程式碼時需採用特定做法
文章提醒應在測試中調整以避免細微錯誤
本文簡短指出:在 Kotlin 的測試中使用 traits 時,需要採用一個特定的技巧。Kotlin 的 traits(即具有預設實作的介面)可能帶來測試上的挑戰,例如建立實例、覆寫預設行為或與 Mock/Test 框架整合時的差異。因此文章強調在測試程式碼中應有意識地使用某種折衷或作法,讓以 traits 為基礎的元件能被可靠地測試。重點在於提醒開發者考量 traits 與測試方式的互動,並採用建議的技巧以避免隱性測試失敗或測試脆弱性。
KT Academy
作者:
發布:08-22 00:00
Effective Kotlin Item 47: Avoid Unnecessary Object Creation
The most essential rule of performance optimization is to avoid unnecessary object creation.
重點摘要
Minimize creating objects you don't need
Reduce memory pressure and GC overhead
Prefer reuse and lightweight alternatives
This short item highlights a core performance principle for Kotlin (and many other languages): avoid creating objects unnecessarily. Unneeded allocations increase memory usage and put pressure on the garbage collector, which can degrade runtime performance. By minimizing ephemeral or redundant object creation—through reuse of instances, using primitive or lightweight representations where appropriate, lazy initialization, or pooling for expensive allocations—you reduce allocation churn and improve throughput and latency. The guidance is broad rather than prescriptive: evaluate where allocations occur, prefer immutable shared instances when safe, and choose designs that keep the number and lifetime of objects low. Adhering to this rule addresses one of the most common and impactful sources of performance overhead in application code.
Effective Kotlin 第47项:避免不必要的对象创建
性能优化最重要的规则就是避免创建不必要的对象。
重點摘要
减少不必要的对象分配
减轻内存与垃圾回收压力
优先考虑重用与轻量替代方案
本项关注一条核心性能原则:尽量避免不必要的对象创建。不必要的分配会提高内存占用并施加垃圾回收压力,从而影响运行效率。通过重用实例、使用原始或更轻量的表示、延迟初始化或对高成本分配使用对象池等手段,可以减少分配次数和对象存活时间,提升吞吐和响应速度。该建议为通用指导而非具体代码范例,强调识别代码中的分配热点并采用能降低对象数量与生命周期的设计,以应对应用性能中常见且影响显著的问题。
Effective Kotlin 第47項:避免不必要的物件建立
效能最佳化最重要的原則就是避免產生不必要的物件。
重點摘要
減少不必要的物件分配
降低記憶體與垃圾回收負擔
優先考慮重用與輕量替代方案
此項目集中介紹一項核心的效能原則:避免建立不必要的物件。不必要的分配會增加記憶體使用並對垃圾回收器造成壓力,進而降低執行效能。透過重用實例、採用原始或更輕量的表示、延遲初始化或對昂貴分配採用物件池等方式,可以減少分配頻率與物件壽命,改善吞吐與延遲。此建議偏向通則而非具體實作細節,重點在識別與評估程式中分配熱點,並採用能降低物件數量與存活時間的設計,以解決常見且影響重大的效能問題。
KT Academy
作者:
發布:08-30 00:00
Effective Kotlin Item 51: Use the inline modifier for functions with parameters of functional types
Marking a function inline lets the compiler substitute its body at call sites, avoiding lambda allocations and enabling non-local returns, which reduces runtime overhead.
重點摘要
Inline eliminates runtime allocation of function objects
Enables non-local returns from lambdas
Improves performance by inlining lambda code at call sites
This item explains how Kotlin's inline modifier for functions that take function-type parameters works and why it matters for performance. When a function is marked inline, the compiler substitutes the function body at each call site rather than creating function objects and invoking them indirectly. That eliminates lambda allocations and the overhead of additional call indirections, and enables features such as non-local returns from lambdas. In practice, inlining benefits short, frequently called higher-order functions (such as library utilities and small combinators) by reducing allocation and call costs, which can noticeably improve runtime efficiency. However, inlining increases the generated bytecode size and can affect compilation time, so developers should apply it judiciously where profiling shows measurable gains. Overall, inline is a practical tool to optimize high-level functional patterns in Kotlin while balancing code-bloat trade-offs.
Effective Kotlin 条目 51:对接受函数类型参数的函数使用 inline 修饰符
inline 会在调用点内联函数体,避免创建额外的函数或 lambda 对象并允许非局部返回,从而减少运行时开销。
重點摘要
避免运行时分配函数或 lambda 对象
允许 lambda 使用非局部返回(non-local return)
在调用点内联可降低调用与分配成本,提升性能
本条目解释在 Kotlin 中对带有函数类型参数的函数使用 inline 修饰符的工作原理及其对性能的重要性。inline 会在调用点内联函数体,避免创建额外的函数对象及闭包开销,并允许 lambda 使用非局部返回(non-local return)。对短小且频繁调用的高阶函数尤其有利,可显著降低分配与调用开销、提高运行效率。但内联会增大编译后代码体积并可能影响编译时间,因此应在经过分析或有实际性能收益时审慎采用,平衡效能与代码膨胀的取舍。
Effective Kotlin 條目 51:對接受函數型參數的函式使用 inline 修飾子
inline 會在呼叫點內聯函式內容,避免建立 lambda/函式物件並允許非區域返回,從而降低執行時開銷。
重點摘要
避免在執行時分配函式或 lambda 物件
允許 lambda 使用非區域返回(non-local return)
在呼叫點內聯可降低呼叫與分配成本,提升效能
本條目說明在 Kotlin 中對接受函數型參數的函式使用 inline 修飾子的原理與效能價值。inline 會在呼叫點嵌入函式內容,避免建立額外的函式物件與閉包開銷,並允許 lambda 使用非區域返回(non-local return)。對短小且頻繁呼叫的高階函式(例如工具函式與組合器)特別有利,可顯著降低記憶體分配與呼叫間接成本,提升執行效率。但內聯會增加編譯後的程式碼大小並可能影響編譯時間,因此應在有實測效益或經過分析後謹慎使用,權衡效能與程式碼膨脹。
KT Academy
作者:
發布:09-01 00:00
Coroutines under the hood
A deep dive into how suspension and continuations work under the hood.
重點摘要
Deep dive into suspension and continuations
Explains how suspension points preserve execution state
Builds a mental model for coroutine internals
This article is a deep dive into how suspension and continuations work under the hood. It examines the internal behavior of coroutines by describing how suspension points capture and preserve execution state, how continuations represent resumed computation, and how the coroutine runtime transfers control between suspended and resumed contexts. Rather than focusing on API usage, the piece builds an internal mental model that helps readers reason about control flow, state retention, and the lifecycle of suspended computations. The explanations aim to make the mechanics behind suspending functions transparent so developers can better understand debugging, performance characteristics, and interoperability with non-coroutine code. Overall, the article offers a concise technical exploration of coroutine internals, emphasizing conceptual clarity about suspension and continuation semantics.
协程底层原理
深入探讨暂停与延续如何在底层运作。
重點摘要
深入探讨暂停与延续的底层机制
说明暂停点如何保存与恢复执行状态
构建协程内部的认知模型
本文深入探讨协程(coroutines)内部运作,重点说明暂停(suspension)与延续(continuations)如何在底层保存与恢复执行状态。文章侧重内部机制与控制流程,说明暂停点如何捕捉状态、延续如何表示可恢复的计算,以及执行环境在暂停与恢复间如何转移控制权。目标是构建一个可用于调试、性能评估及与非协程代码互操作的认知模型,使开发者理解暂停函数的语义与生命周期,而非仅停留在 API 使用层面。
協程底層原理
深入探討暫停與延續如何在底層運作。
重點摘要
深入探討暫停與延續的底層機制
說明暫停點如何保存與恢復執行狀態
建立協程內部的心智模型
本文深入探討協程(coroutines)內部運作,重點說明暫停(suspension)與延續(continuations)如何在底層保存與恢復執行狀態。文章側重內部機制與控制流程,說明暫停點如何捕捉狀態、延續如何表示可恢復的計算,以及執行環境在暫停與恢復間如何移轉控制權。目的是建立一個可用於除錯、效能評估與與非協程程式碼互操作的心智模型,讓開發者理解暫停函式的語意與生命週期,而非僅停留在 API 使用層面。
KT Academy
作者:
發布:09-06 00:00
Effective Kotlin Item 52: Consider using inline value classes
Explains what value classes are and how to declare, use, and inline them in Kotlin.
重點摘要
Defines value classes and their purpose
Explains how inlining can eliminate runtime allocation
Covers syntax, interoperability and design considerations
Effective Kotlin Item 52 explains what value classes are in Kotlin, how to declare and use them, and when to mark them inline. It describes value classes as lightweight wrappers around a single property that let you create domain-specific types without the overhead of regular objects, and shows how inlining can remove runtime allocation by representing instances as the underlying value at runtime. The article covers syntax for defining value classes, interoperability and usage patterns, and considerations such as binary compatibility, API design, and when to prefer ordinary classes. It gives practical guidance for applying inline value classes to make code safer and clearer while minimizing runtime costs, and highlights trade-offs and scenarios where wrapping a primitive or another type is appropriate.
Effective Kotlin 第52条:考虑使用 inline value class
说明什么是 value class、如何声明与使用,以及何时将其 inline。
重點摘要
说明 value class 的定义与用途
演示 inline 如何消除运行时分配
涵盖语法、互操作性与设计考量
本文 Effective Kotlin 第52条介绍了 Kotlin 中的 value classes,说明其定义、声明与使用方法,并解释何时应将其标记为 inline。文章将 value class 描述为包裹单一属性的轻量类型,可用于在不创建常规对象的情况下表达领域类型,并演示 inline 如何在运行时以底层值表示实例以避免分配。内容还涉及定义语法、互操作性与使用模式,以及二进制兼容性、API 设计等设计考量,并给出在实际场景中使用 inline value class 的建议与权衡分析。
Effective Kotlin 第52條:考慮使用 inline value class
說明什麼是 value class、如何宣告與使用,以及何時將其 inline。
重點摘要
說明 value class 的定義與用途
示範 inline 如何避免執行時分配
涵蓋語法、互操作性與設計考量
本篇 Effective Kotlin 第52項介紹 Kotlin 的 value classes,說明其定義、宣告與使用方式,以及何時選擇將其 inline。文章指出 value class 是只包裝單一屬性的輕量型別,能在不建立常規物件的情況下表達領域型別,並示範 inline 如何在執行時以底層值表示實例以避免配置。內容也涵蓋語法、互操作性、使用範式與設計考量(如二進位相容性與 API 設計),並提供在何種情境下以 inline value class 取代一般類別的實務建議與取捨分析。
KT Academy
作者:
發布:09-13 00:00
Effective Kotlin Item 53: Eliminate Obsolete Object References
Eliminate references to objects you no longer need so the garbage collector can reclaim memory and prevent leaks.
重點摘要
Make objects unreachable when they are no longer needed so GC can reclaim them
Clear or remove references in long‑lived containers, caches, listeners, and static fields
Consider scoping, nulling references, or using weak/soft references to avoid leaks
This item explains why eliminating obsolete object references helps the garbage collector reclaim memory and reduces the risk of memory leaks. When variables or data structures continue to hold references to objects that are no longer needed, those objects remain reachable and cannot be collected, causing unnecessary memory retention. The guidance urges developers to ensure references in long‑lived containers, caches, listeners, or static fields are cleared when no longer required, and to consider weak or soft references where appropriate. By scoping variables tightly, nulling references, and removing entries promptly, you make objects eligible for collection sooner and avoid leaks that can degrade application performance and stability. Eliminating obsolete references is a small, practical step that supports automatic memory management.
Effective Kotlin 第53条:消除过时的对象引用
移除不再需要的对象引用,让垃圾回收器回收内存并避免内存泄漏。
重點摘要
在对象不再使用时确保它们不再被引用以便 GC 回收
清除长生命周期容器、缓存、监听器或静态字段中的残留引用
通过缩小作用域、置为 null 或使用弱/软引用来降低泄漏风险
本条说明应当消除不再使用的对象引用,以帮助垃圾回收器回收内存并降低内存泄漏的风险。如果变量或数据结构持续保有对已不需对象的引用,这些对象仍被视为可达(reachable),无法被回收,导致不必要的内存占用。建议在长生命周期的数据结构(例如容器、缓存、监听器或静态字段)中,当对象不再需要时及时清除或移除引用,必要时考虑使用弱引用或软引用。通过缩小引用作用域、及时置为 null 或移除条目,可以使对象更早成为可回收,从而避免影响应用性能与稳定性。
Effective Kotlin 第53條:消除過時的物件參考
移除不再需要的物件參考,讓垃圾回收器能回收記憶體並避免記憶體洩漏。
重點摘要
當物件不再使用時,確保它們不再被參考以便 GC 回收
清除長壽命容器、快取、事件監聽或靜態欄位中的殘留參考
透過縮小作用域、設為 null 或使用弱/軟參考來降低洩漏風險
本條指出應消除不再使用的物件參考,以協助垃圾回收器回收記憶體並降低記憶體洩漏風險。若變數或資料結構持續保有對已無需物件的參考,這些物件仍被視為可到達(reachable),無法被回收,導致不必要的記憶體佔用。建議在長期存在的結構(如容器、快取、監聽器或靜態欄位)中,於不再需要時及時清除或移除參考,必要時可採用弱或軟參考。透過縮小參考的作用域、及時設為 null 或移除條目,可以讓物件更快成為可回收狀態,避免效能與穩定性受損。
KT Academy
作者:
發布:09-20 00:00
Prefer sequences for large collections with multiple processing steps
Use sequences to avoid creating intermediate collections and reduce work when you apply multiple processing steps to large collections.
重點摘要
Lists evaluate operations eagerly and produce intermediate collections.
Sequences are lazy and pipeline operations to avoid intermediate allocations.
Prefer sequences for big collections with multiple transforms; use lists for simple or small cases.
List-based processing in Kotlin evaluates each intermediate operation eagerly, producing temporary collections after each step. Sequences provide lazy evaluation and build a processing pipeline so elements flow through all operations without creating those intermediates, reducing allocations and repeated work. For large collections with more than one transformation or filtering step, sequences often give better performance by avoiding extra iterations and memory churn. For single-step operations or small collections, lists are simpler and may be faster because they avoid the overhead of the lazy pipeline. Keep in mind that sequences change evaluation and debugging behavior, so measure performance when in doubt and choose sequences when multiple processing steps on big data justify their lazy approach.
针对多步处理的大型集合优先使用 Sequence
当对大型集合执行多个处理步骤时,使用 Sequence 可以避免产生中间集合并减少不必要的开销。
重點摘要
List(列表)会立即(eager)执行操作并产生中间集合。
Sequence 使用惰性(lazy)评估,将操作串成管道以避免中间分配。
对大型集合且有多次变换或过滤时优先用 Sequence;简单或小规模场景用 List 更合适。
在 Kotlin 中,列表的处理通常是立即评估的,每一步可能生成新的中间集合和额外分配;而 Sequence 采用惰性评估,把多个操作串成一条管道,使元素逐个通过所有步骤而不创建中间集合,从而减少重复遍历和内存开销。面对大型集合且需要多次转换或过滤时,Sequence 往往因避免中间分配而性能更优;对于单步操作或小数据量,List 因开销更小而更简单或更快。选择时应考虑惰性评估对行为和调试的影响,并通过测量来验证。
針對多步處理的大型集合優先使用 Sequence
當對大型集合執行多個處理步驟時,使用 Sequence 可避免產生中介集合並減少不必要的工作。
重點摘要
List(清單)會及時(eager)執行每個操作並產生中介集合。
Sequence 採用延遲(lazy)評估,將操作串成管線避免中介分配。
對大型集合且有多重轉換或篩選時優先用 Sequence;簡單或小型情況用 List 即可。
在 Kotlin 中,List 相關操作通常會即時執行,每一步都可能產生新的中介集合與額外分配;而 Sequence 採取延遲評估,將多個操作串成一條管線,元素逐一通過所有步驟而不建立中介集合,能減少重複迭代與記憶體分配。當面對大型集合且需執行多個轉換或篩選步驟時,Sequence 常能提升效能;若只是單一步驟或資料量小,List 因為較少開銷反而更簡潔且可能更快。實際選擇時應注意延遲評估對行為與除錯的影響,必要時以量測結果為準。
KT Academy
作者:
發布:09-27 00:00
Effective Kotlin Item 55: Consider associating elements to a map
Using associateBy to build a key-to-element map lets you replace repeated searches with fast map lookups.
重點摘要
Use associateBy to create a map from keys to elements
Map lookups are typically O(1) versus repeated linear searches
Pay upfront construction and memory costs when lookups are frequent
associateBy is a Kotlin standard-library function that builds a Map from a collection by applying a key selector to each element. The item recommends using associateBy when you need to find elements repeatedly: instead of performing many linear searches (e.g., collection.find { predicate }) you build a keyed map once and then perform fast direct lookups. This improves performance when the number of queries is large relative to the collection size. The trade-offs are the upfront cost to construct the map and additional memory to hold it, so associateBy is most beneficial when lookups are frequent or costly. In short, consider transforming a collection into a map for repeated element access to achieve faster, O(1)-style retrieval at the price of construction time and extra storage.
Effective Kotlin 第55条:考虑将元素关联到映射
使用 associateBy 将集合转换为以键映射元素的 Map,可用快速查找替代重复搜索。
重點摘要
用 associateBy 按键将集合建立为映射
Map 查找通常为 O(1),优于重复线性搜索
需权衡构建开销和额外内存消耗
associateBy 是 Kotlin 标准库函数,通过对每个元素应用键选择器,将集合转换为 Map。建议在需要频繁查找元素时使用 associateBy:与其多次执行线性搜索(如 collection.find { … }),不如先构建键到元素的映射,然后通过键进行快速直接查找,从而在大量查询场景中显著提高性能。代价是构建映射的前期时间和额外内存,因此只有当查找频次足够高以抵消这些开销时,此方法才最划算。总之,针对重复访问场景,应考虑把集合转成 Map 以获得更快的检索。
Effective Kotlin 第55條:考慮將元素關聯到映射
使用 associateBy 將集合轉為以鍵對應元素的 Map,可用快速查找取代重複搜尋。
重點摘要
用 associateBy 將集合依選取鍵建立映射
Map 查找通常為 O(1),優於重複線性搜尋
需評估建立成本與額外記憶體開銷
associateBy 是 Kotlin 標準函式,可依照指定的鍵選取器把集合轉成 Map。該建議指出,當你需要頻繁查找元素時,與其多次進行線性搜尋(例如 collection.find { … }),更應先建立一個鍵對元素的映射,之後以鍵做直接查找,能顯著提升效能。這種方式特別適合查詢次數多或單次搜尋成本高的情境。需要權衡的是建立映射的前置時間與額外記憶體使用,因此只有在多次查找能攤平這些成本時,associateBy 才最有價值。
KT Academy
作者:
發布:10-11 00:00
Effective Kotlin Item 56: Consider using groupingBy instead of groupBy
Use groupingBy to perform aggregations without building intermediate collections, which can improve performance compared with groupBy.
重點摘要
groupBy builds a Map<K, List<T>> and materializes lists for each key
groupingBy produces a Grouping to apply aggregations like eachCount or fold directly
Use groupingBy for aggregated results to reduce allocations; use groupBy when you need the full lists
Grouping is a Kotlin abstraction that produces a Grouping<K, T> allowing you to perform aggregation operations over elements keyed by a selector without first materializing collections for each key. groupBy builds a Map<K, List<T>>, collecting all elements into lists, which is convenient when you need those lists but allocates intermediate collections. groupingBy lets you call aggregation functions like eachCount, fold or aggregate directly on the grouping, so you can compute counts, sums or combined values in a single pass with lower memory and allocation overhead. Because it avoids creating per-key lists, groupingBy can be a simple performance optimization when you only need aggregated results rather than the full grouped lists. Use groupBy when you need the actual lists; prefer groupingBy for counting or folding to reduce allocations.
Effective Kotlin 第56条:考虑使用 groupingBy 而非 groupBy
groupingBy 可在不构建中间集合的情况下执行聚合,通常比 groupBy 更能提升性能。
重點摘要
groupBy 会构建 Map<K, List<T>>,为每个键创建列表
groupingBy 生成 Grouping,可直接执行 eachCount、fold 等聚合操作
仅需聚合结果时使用 groupingBy 可减少分配;需要完整列表时使用 groupBy
Grouping 是 Kotlin 的一种抽象,会生成 Grouping<K, T>,允许在不先物化每个键的集合下执行聚合操作。groupBy 会构建 Map<K, List<T>>,把元素收集到各自的列表,适合需要完整列表的场景,但会产生额外的内存分配。groupingBy 则可直接在分组上调用 eachCount、fold 或 aggregate 等函数,在一次扫描中计算计数、求和或合并值,因而在只需聚合结果时能减少临时集合与内存开销。若只需统计或折叠结果,推荐使用 groupingBy;若需要保留每个键的列表,则继续使用 groupBy。
Effective Kotlin 第56條:考慮用 groupingBy 取代 groupBy
groupingBy 可在不建立中間集合的情況下執行聚合,通常比直接使用 groupBy 更省效能。
重點摘要
groupBy 會建立 Map<K, List<T>> 並為每個鍵收集列表
groupingBy 產生 Grouping,可直接呼叫 eachCount、fold 等聚合函式
若只需聚合結果(例如計數或折疊),用 groupingBy 可減少分配與記憶體
Grouping 是 Kotlin 的一種抽象,會產生 Grouping<K, T>,可在不先建立每個鍵的暫存集合下執行聚合運算。groupBy 會建立 Map<K, List<T>>,當你需要各鍵的完整列表時很方便,但會產生額外記憶體與配置。相反地,groupingBy 可直接呼叫 eachCount、fold 等聚合函式,在單次掃描中計算計數或合併值,因而在只需聚合結果時能降低分配與提高效能。當你只要結果(例如計數或折疊)時,建議用 groupingBy;需要保留每個鍵的列表時則用 groupBy。
KT Academy
作者:
發布:10-13 00:00
Constructing a coroutine scope
How we generally define a coroutine scope on Android and on the backend.
重點摘要
Comparing scope definition between Android and backend
Focus on ownership and lifecycle management
Identifies common points where scopes are created
This short piece explains the general approaches to constructing a coroutine scope in two typical environments: Android and backend services. It outlines the rationale for choosing where and how a scope is created, emphasizing ownership and lifecycle concerns that differ by platform. On Android, scopes are usually tied to UI or component lifecycles to avoid leaks and ensure cancellation when components are destroyed; on backend systems, scopes are commonly associated with requests or the application lifecycle to manage concurrency and structured cancellation across work units. The article highlights practical considerations for defining scopes in each environment and points to the usual creation points developers use when organizing asynchronous work.
构建 coroutine scope
说明我们通常如何在 Android 与后端环境中定义 coroutine scope。
重點摘要
比较 Android 与后端的 scope 定义
强调所有权与生命周期管理
指出常见的 scope 创建位置
本文简要介绍在两种典型环境(Android 与后端)中构建 coroutine scope 的通用做法,说明选择 scope 创建位置的理由与方法。文中强调不同平台在所有权与生命周期上的差异:Android 通常将 scope 绑定到 UI 或组件生命周期,以避免内存泄露并在组件销毁时取消任务;后端则多把 scope 与请求或应用生命周期关联,以便管理并发任务和结构化取消。文章还指出开发者在组织异步工作时常用的创建点及相关考虑。
構建 coroutine scope
說明我們通常如何在 Android 與後端環境中定義 coroutine scope。
重點摘要
比較 Android 與後端的 scope 定義
強調擁有權與生命週期管理
指出常見的 scope 建立位置
本文簡要說明在兩種常見環境(Android 與後端)中構建 coroutine scope 的一般做法,說明為何以及如何選擇 scope 的建立位置。文章強調不同平台在擁有權與生命週期上的差異:Android 常將 scope 綁定在 UI 或元件生命週期上以避免記憶體漏洩並在元件銷毀時進行取消;後端則多將 scope 與請求或應用程式生命週期關聯,以便管理並發作業與結構化取消。並指出開發者在組織非同步工作時常用的建立位置與考量要點。
KT Academy
作者:
發布:10-27 00:00
Testing Kotlin Coroutines
How we test Kotlin Coroutines, including common Android and backend cases.
重點摘要
Covers testing Kotlin Coroutines across platforms
Includes common Android and backend scenarios
Focuses on making coroutine tests deterministic and fast
This article explains how to test Kotlin Coroutines, addressing both Android and backend cases. It outlines practical strategies and examples to make coroutine-based code testable and reliable, focusing on controlling concurrency and timing in tests. Topics include isolating suspending functions, using test-friendly dispatchers, simulating asynchronous behavior, and structuring unit and integration tests so they remain deterministic and fast. The article also discusses adapting tests for Android components and backend services, highlighting common pitfalls when dealing with delays, exceptions, and shared mutable state. Readers are given guidance on replacing production dispatchers in tests, verifying coroutine results, and keeping tests maintainable. The guidance aims to help developers write robust tests for coroutine code across platforms, improving confidence when refactoring or debugging asynchronous flows.
测试 Kotlin 协程
说明如何测试 Kotlin 协程,涵盖常见的 Android 与后端情形。
重點摘要
覆盖 Android 和后端的协程测试场景
强调控制执行与时间以实现确定性测试
提供可维护且快速的测试实践
本文说明如何测试 Kotlin Coroutines,涵盖常见的 Android 与后端情形。文章介绍实用策略与示例,说明如何在测试中控制协程的执行与时间,使测试具有确定性且执行迅速。内容包括如何隔离挂起函数、在测试中替换或模拟 Dispatcher、模拟异步行为,以及为单元与集成测试构建可重复的测试流程。同时讨论在处理延迟、异常与共享可变状态时的常见陷阱,并提供维护性建议。目标是帮助开发者在 Android 与后端服务中编写更可靠的协程测试,提高重构与调试时的信心。
測試 Kotlin 協程
說明如何測試 Kotlin 協程,涵蓋常見的 Android 與後端情境。
重點摘要
涵蓋 Android 與後端的協程測試案例
說明控制執行與時間以達到確定性測試
提供可維護且快速的測試建議
本文說明如何測試 Kotlin Coroutines,涵蓋常見的 Android 與後端情境。文章介紹實用策略與範例,說明如何在測試中控制協程執行與時間,以使測試具確定性且執行快速。內容包括如何隔離掛起函式、在測試中替換或模擬 Dispatcher、模擬非同步行為,以及為單元與整合測試構建可重複的測試流程。同時討論在處理延遲、例外與共享可變狀態時的常見陷阱,並提供維護性建議。目標是幫助開發者在 Android 與後端服務中編寫更可靠的協程測試,提升重構與除錯時的信心。
KT Academy
作者:
發布:11-17 00:00
Variables point to objects
A variable holds a reference to an object rather than containing the object itself.
重點摘要
Variables store references (pointers) to objects, not the objects themselves
Assigning copies the reference so multiple variables can refer to the same object
Mutating a shared object affects all variables that reference it; reassigning changes the reference
“Variables point to objects” describes a fundamental programming concept that is often misunderstood. A variable does not contain an entire object; instead it stores a reference (or pointer) to an object located elsewhere in memory. Assigning one variable to another copies that reference, so both names refer to the same object; mutating the object through one variable is visible through the other. Reassigning a variable changes which object it references without altering the original object. Confusion typically arises when programmers assume variables hold independent copies of objects rather than shared references. For example, modifying a list via one name will be seen through the other name; obtaining an independent copy requires explicit cloning or copying operations. Grasping this model is essential for reasoning about aliasing, parameter passing, side effects, and avoiding bugs from unintended shared mutation.
变量指向对象
变量保存的是指向对象的引用,而不是直接包含整个对象。
重點摘要
变量存储的是对对象的引用(指针),不是对象本身
赋值会复制引用,使多个变量指向同一个对象
通过任一引用修改对象会影响所有指向该对象的变量
本文说明“变量指向对象”这一基础但常被误解的特性。变量并不保存完整对象,而是持有指向对象的引用(或指针)。将一个变量赋值给另一个变量会复制引用,两个名称指向相同对象;通过任一变量修改对象,另一个也会看到。重新赋值只改变该变量指向的对象,不会修改原对象。误解通常来自认为赋值会复制对象本身。理解引用与别名有助于理清参数传递、副作用及避免因为共享修改而引发的错误。
變數指向物件
變數持有指向物件的參考,而非直接包含整個物件。
重點摘要
變數儲存的是對物件的參考(指標),不是物件本身
賦值會複製參考,造成多個變數指向相同物件
透過任一參考變更物件會反映到所有指向該物件的變數上
本文說明「變數指向物件」這個基礎但常被誤解的特性。變數並不儲存完整物件,而是持有指向物件的參考(或指標)。將一個變數賦值給另一個變數會複製參考,兩者指向相同物件;透過任一變數變更物件,另一個也會看見。重新賦值只改變該變數指向的對象,不會改動原物件。誤解通常來自以為賦值會複製物件本身。理解參考與別名有助於掌握參數傳遞、副作用與避免因共享變更而產生的錯誤。
KT Academy
作者:
發布:12-01 00:00
Advent of Kotlin — Week 1: JSON Stringify and Possible Well-Formed Parentheses
Week 1 examines JSON stringification and the problem of generating all possible well-formed parentheses sequences.
重點摘要
Introduces JSON stringification concepts in Kotlin
Explores generating all well-formed parentheses combinations
Combines practical serialization with algorithmic problem solving
Week 1 of the Advent of Kotlin presents two concise topics for Kotlin practitioners: how to stringify data to JSON and how to generate all possible well-formed parentheses sequences. The article outlines the practical concerns of turning values and structures into JSON-compliant strings—such as preserving types, escaping characters, and producing readable output—alongside illustrative examples. It also frames the combinatorial parentheses problem, describing the goal of enumerating valid sequences for a given number of pairs and discussing common algorithmic approaches such as recursion and backtracking with pruning. Aimed at developers who want to sharpen both practical serialization skills and algorithmic thinking, the piece pairs conceptual explanation with concrete examples so readers can see how serialization mechanics and recursive sequence generation work in real Kotlin code.
Advent of Kotlin 第1周:JSON 字符串化与可能的良好括号序列
第1周介绍将数据字符串化为 JSON 及生成所有可能的良好括号序列的问题。
重點摘要
讲解在 Kotlin 中进行 JSON 字符串化的重点
探讨生成所有合法括号组合的组合问题
结合序列化实现与算法思维的练习
Advent of Kotlin 第1周聚焦两项主题:JSON 字符串化与生成可能的良好括号序列。文章说明如何将值与结构转换为符合 JSON 规范的字符串,涉及类型保留、字符转义和可读性等实务考虑,并配以示例演示。与此同时,阐述括号组合的组合问题,说明目标是在给定括号对数下列举所有合法序列,并介绍常见的算法策略,比如递归与回溯及剪枝方法。整体内容旨在帮助 Kotlin 开发者同时提升序列化实现能力与算法设计思维,通过说明和示例展示两者在实际开发中的应用。
Advent of Kotlin 第 1 週:JSON 字串化與可能的良好括號序列
第 1 週介紹如何將資料字串化為 JSON,以及如何產生所有可能的良好括號序列。
重點摘要
說明在 Kotlin 中進行 JSON 字串化的要點
探討產生所有合法括號組合的組合問題
結合序列化實作與演算法思維的練習
Advent of Kotlin 第 1 週聚焦兩個主題:JSON 字串化與生成可能的良好括號序列。文章說明如何將值與結構轉換為符合 JSON 規範的字串,包含類型保留、字元轉義與可讀性等實務考量,並搭配範例示範。另闡述括號組合的組合問題,說明目標是在給定括號數下列舉所有合法序列,並介紹常見的演算法策略,例如遞迴與回溯和剪枝技巧。整體內容旨在讓 Kotlin 開發者同時強化序列化的實作能力與演算法設計思維,透過說明與範例呈現兩者如何在實務中運作。
KT Academy
作者:
發布:12-06 00:00
Advent of Kotlin: Week 2
Week 2 of the Advent of Kotlin focuses on tree algorithms.
重點摘要
Second week of the Advent of Kotlin series
Theme centers on tree algorithms
Places tree algorithms in the context of Kotlin development
This entry marks Week 2 of the Advent of Kotlin series and identifies tree algorithms as the week’s theme. It signals a focused look at algorithms that operate on tree data structures — hierarchical models used widely in computing — and highlights their relevance to Kotlin programmers. Tree algorithms commonly encompass tasks such as traversal, search, insertion, deletion and balancing; they underpin data structures like binary trees, heaps and search trees and appear across domains from compilers to databases. While concise, the announcement communicates the series’ intent to concentrate on these topics during the week, positioning readers to explore how tree-related techniques and patterns can be expressed and implemented in Kotlin.
Advent of Kotlin:第二周 — 树算法
Advent of Kotlin 第二周的主题是树算法。
重點摘要
Advent of Kotlin 系列的第二周
本周聚焦:树算法
强调树算法在 Kotlin 开发中的相关性
本文为 Advent of Kotlin 系列的第二周,说明本周主题为“树算法”。标题简要指出将关注用于树状数据结构的算法;树算法通常包括遍历、查找、插入、删除与平衡等操作,应用于二叉树、堆、搜索树等结构,并在编译器、数据库等领域广泛使用。尽管原文内容简短,但明确传达了该周会集中探讨与树相关的主题,提示读者关注如何在 Kotlin 中表达与实现这些技术与模式。
Advent of Kotlin:第二週 — 樹狀結構演算法
Advent of Kotlin 第二週的主題為樹狀結構演算法。
重點摘要
Advent of Kotlin 系列的第二週
本週主題:樹狀結構演算法
強調樹演算法與 Kotlin 開發的關聯
此篇為 Advent of Kotlin 系列的第二週,指出本週主題為「樹狀結構演算法」。標題簡潔地表明將把焦點放在處理樹形資料結構的演算法上;樹演算法通常涉及遍歷、查找、插入、刪除與平衡等操作,應用於二元樹、堆、搜尋樹等結構,並廣泛出現在編譯器、資料庫與其他系統中。雖然原文簡短,但明確傳達本週專注樹相關主題,讓讀者準備探討如何在 Kotlin 中表達與實作這類技術與模式。
KT Academy
作者:
發布:12-14 00:00
Advent of Kotlin: Week 3 — k-means clustering
Week 3 focuses on implementing and explaining k-means clustering for Kotlin developers.
重點摘要
Week 3 of the Advent of Kotlin series centers on k-means clustering
Covers the algorithm's core steps and practical considerations
Orients the discussion toward implementing k-means in Kotlin
Week 3 of the Advent of Kotlin series is dedicated to k-means clustering. The article presents k-means as a fundamental unsupervised learning method for partitioning data into k clusters, outlining its key steps—choosing initial centroids, assigning points to the nearest centroid, recomputing centroids and iterating until convergence—and discussing practical issues such as initialization and stopping criteria. Framed for Kotlin developers, the piece connects algorithmic concepts to implementation concerns and data structures in Kotlin, helping readers judge when k-means is appropriate for exploratory data analysis or preprocessing. The intent is to provide a clear conceptual grounding and guidance on how to approach implementing k-means within Kotlin projects.
Advent of Kotlin:第三周 — k-means 聚类
第三周聚焦于为 Kotlin 开发者讲解并实现 k-means 聚类算法。
重點摘要
第三周主题为 k-means 聚类
介绍算法的核心步骤与实践注意点
将算法概念与 Kotlin 实现要点相结合
Advent of Kotlin 系列的第三周以 k-means 聚类为主题。文章介绍 k-means 作为一种基础的无监督学习方法,用于将数据划分为 k 个簇,并概述其主要流程:选择初始质心、将数据点分配到最近质心、重新计算质心并迭代直到收敛,同时讨论初始化和收敛判定等实践问题。内容面向 Kotlin 开发者,把算法概念与 Kotlin 的数据结构及实现要点结合,帮助读者判断何时适合使用 k-means,并提供实施方向与入门指引,使读者获得概念性理解与实作取向的帮助。
Advent of Kotlin:第三週 — k-means 分群
第三週主題聚焦於為 Kotlin 開發者說明並實作 k-means 分群演算法。
重點摘要
第三週主題為 k-means 分群
說明演算法的核心步驟與實務考量
以 Kotlin 為導向連結概念與實作要點
Advent of Kotlin 系列的第三週以 k-means 分群為主題。文章說明 k-means 作為一種基本的無監督學習方法,用來將資料分成 k 個群集,並概述其主要流程:選取初始群心、將資料點指派給最近群心、重算群心並重複直到收斂,同時討論初始化與收斂判斷等實務考量。內容針對 Kotlin 開發者,將演算法概念與 Kotlin 的資料結構與實作關鍵連結,協助讀者判斷何時使用 k-means 並提供實作上的取向與指引,讓讀者建立概念性理解與實務導向的入門基礎。
KT Academy
作者:
發布:12-21 00:00
Advent of Kotlin: Week 4 — Parsing JSON
Week 4 focuses on parsing JSON in Kotlin, presenting practical guidance for handling JSON data.
重點摘要
Focuses on parsing JSON with Kotlin
Part of the Advent of Kotlin weekly series
Provides practical guidance for developers
Week 4 of the Advent of Kotlin centers on parsing JSON using Kotlin. The article outlines why JSON parsing is commonly needed in Kotlin projects and highlights general approaches and considerations for reading, mapping, and validating JSON data. It aims to give practical, developer-oriented guidance that helps avoid common pitfalls such as malformed input or type mismatches. As a concise entry in the Advent series, this week’s piece emphasizes pragmatic advice and clear examples so readers can choose suitable parsing strategies and integrate them into their Kotlin codebases with greater confidence.
Advent of Kotlin:第4周 — 解析 JSON
第4周聚焦在 Kotlin 中解析 JSON,提供实用的处理建议与示例。
重點摘要
关注 Kotlin 的 JSON 解析
作为 Advent of Kotlin 系列的一部分
提供实用建议以避免常见问题
Advent of Kotlin 第4周的主题是使用 Kotlin 解析 JSON。文章概述了何时需要解析 JSON、常见的处理思路与注意事项,并以实用为导向,提醒开发者避免格式异常或类型不匹配等常见问题。作为系列中的一篇短文,本周内容通过清晰的示例与实践建议,帮助读者在 Kotlin 项目中选择合适的解析策略并更可靠地处理 JSON 数据。
Advent of Kotlin:第四週 — 解析 JSON
第四週聚焦於在 Kotlin 中解析 JSON,提供實務導向的處理建議。
重點摘要
專注於 Kotlin 中的 JSON 解析
為 Advent of Kotlin 系列的一週內容
提供實務與範例以協助開發者
Advent of Kotlin 第四週聚焦於在 Kotlin 中解析 JSON,說明何時與為何需要進行 JSON 解析並介紹常見的處理方向與考量。文章以實務為導向,提醒開發者注意如格式錯誤或型別不符等常見問題,並透過清晰範例與建議,協助讀者選擇合適的解析策略並將其整合到 Kotlin 專案中,提升處理 JSON 資料的可靠性與可維護性。
KT Academy
作者:
發布:01-02 00:00
Advent of Kotlin Solutions
Solutions for the Advent of Kotlin challenges.
重點摘要
Presents solutions to Advent of Kotlin challenges
Includes Kotlin code examples and brief explanations
Aims to help readers verify approaches and learn idiomatic Kotlin
This page, titled "Advent of Kotlin Solutions", presents solutions for the Advent of Kotlin challenges. It collects worked answers intended to help readers understand problem approaches and verify implementations. The article focuses on demonstrating Kotlin-based solutions, offering code snippets, short explanations, and practical notes about algorithmic choices and Kotlin idioms. It serves as a reference and learning aid for Kotlin learners and participants of the Advent event who want to compare strategies, check correctness, or pick up idiomatic patterns. While concise, the solutions emphasize clarity and reproducibility so readers can run and adapt the examples in their own projects. Overall, the piece is meant to document and share concrete solutions to the Advent of Kotlin problems, supporting both education and practical coding.
Advent of Kotlin 解答
提供 Advent of Kotlin 的一系列解题方案与示例。
重點摘要
提供 Advent of Kotlin 的解答
包含 Kotlin 示例代码与简短说明
帮助读者核对解法并学习惯用写法
这篇标题为“Advent of Kotlin Solutions”的页面提供 Advent of Kotlin 的解题方案。内容以 Kotlin 示例代码与简短说明为主,介绍解题思路、实现要点与语言惯用法,帮助读者核对结果并学习更合适的做法。该页面适合作为参赛者或 Kotlin 学习者的参考资料,便于比较策略、理解解法要点,并可直接运行或改写示例以应用到实际项目。总体而言,此页旨在记录并分享 Advent of Kotlin 的具体解答,支持教学与实践两方面的需求。
Advent of Kotlin 解答
提供 Advent of Kotlin 的一系列解題方案與範例。
重點摘要
提供 Advent of Kotlin 的解答
以 Kotlin 範例程式與說明為主
協助讀者驗證解法並學習語法慣用法
這篇標題為「Advent of Kotlin Solutions」的文章提供 Advent of Kotlin 的解題方案。內容以 Kotlin 範例程式與簡短說明為主,說明解題思路、實作要點與語法慣用法,協助讀者驗證結果並學習更合適的做法。文章適合作為參賽者或 Kotlin 學習者的參考資料,便於比較策略、了解解法重點,並能直接執行或改寫範例以應用於實際專案。總體而言,該頁旨在記錄並分享 Advent of Kotlin 的具體解答,支援教學與實作兩方面的需求。
KT Academy
作者:
發布:02-01 00:00
Funny programming videos
A collection of funny videos for programmers.
重點摘要
Humorous videos aimed at developers
Highlights everyday quirks and frustrations of coding
Good for quick breaks and sharing with teammates
This page presents a simple collection of funny videos aimed specifically at programmers. The videos use humor to highlight the everyday quirks, frustrations, and absurdities of software development and developer culture. They are intended to make viewers laugh, provide a brief break from coding, and offer a light-hearted perspective on common technical problems and workplace situations. Suitable for individual viewing or sharing with teammates, the collection helps relieve stress and fosters camaraderie through shared recognition of programming experiences. Many of the clips rely on observational comedy about coding tasks, team interactions, and tooling, making them especially relatable to software practitioners. They can brighten a workday, spark conversation, or serve as an icebreaker at meetups. The collection requires no technical prerequisites and is accessible to programmers at different experience levels who appreciate humor about their craft.
搞笑编程视频
为程序员汇集的一系列搞笑视频。
重點摘要
面向程序员的幽默视频
呈现开发日常的趣事与挫折
适合休息时观看或与同事分享
本页收录了一系列针对程序员的搞笑视频,透过幽默呈现软件开发日常的趣事、挫折与荒诞之处。这些短片旨在逗乐观众、提供编码间隙时的轻松休憩,并以轻松视角回应常见的技术与团队情境。内容通俗易懂,适合个人观看或与同事分享,能减轻压力并通过共同认同促进社群间的话题交流。无需专业前置知识,各种经验层级的开发者都能会心一笑。
好笑的程式設計影片
一系列為程式設計師蒐集的搞笑影片。
重點摘要
針對程式設計師的幽默短片
反映開發日常的趣事與挫折
適合休息時觀看或與同事分享
本頁收錄了一系列針對程式設計師的搞笑影片,透過幽默呈現軟體開發日常的趣事、挫折與荒謬處。這些短片旨在逗樂觀眾、提供編碼間歇時的輕鬆休憩,並以輕鬆視角回應常見的技術與團隊情境。內容通俗易懂,適合個人觀看或與同事分享,能減輕壓力並透過共同認同促進社群間的話題交流。無須專業前置知識,各種經驗層級的開發者都能會心一笑。
KT Academy
作者:
發布:02-21 00:00
SharedFlow and StateFlow
SharedFlow and StateFlow are powerful coroutine-based classes known as replacements for Subject, LiveData, and similar observable constructs.
重點摘要
Replace Subject and LiveData-like observable patterns
Built on Kotlin coroutines for structured concurrency
SharedFlow for events, StateFlow for observable state
SharedFlow and StateFlow are coroutine-based primitives in Kotlin commonly used to replace older observable patterns such as Subjects from reactive libraries and Android LiveData. SharedFlow offers a hot, multicasted stream for broadcasting events to multiple collectors with configurable replay and buffering behavior, making it suitable for transient events. StateFlow acts as a state-holder that always exposes the current value and notifies collectors on updates, which fits UI state management. Both integrate with Kotlin coroutines for structured concurrency, improving testability and consistency compared with many legacy constructs, and are considered essential tools for modern Kotlin developers building reactive or stateful components.
SharedFlow 与 StateFlow
SharedFlow 与 StateFlow 是基于 coroutines 的强大类,通常被视为替代 Subject、LiveData 等可观察模式的方案。
重點摘要
可替代 Subject 与 LiveData 等观察模式
与 Kotlin coroutines 深度整合
SharedFlow 用于事件广播,StateFlow 用于状态持有
SharedFlow 与 StateFlow 是 Kotlin coroutines 的两个核心类,常用来替代来自响应式库的 Subject 和 Android 的 LiveData。SharedFlow 提供热流与多播能力,可配置重放与缓冲策略,适合广播瞬时事件;StateFlow 则作为状态容器,始终暴露当前值,并在变化时通知收集者,适用于 UI 状态管理。两者与 coroutines 紧密结合,提高代码的可测试性与一致性,是现代 Kotlin 开发中不可或缺的工具。
SharedFlow 與 StateFlow
SharedFlow 與 StateFlow 是基於 coroutines 的強大類別,常被視為替代 Subject、LiveData 等可觀察模式的方案。
重點摘要
可替代 Subject 與 LiveData 類型的觀察模式
與 Kotlin coroutines 緊密整合
SharedFlow 適合事件廣播,StateFlow 適合狀態管理
SharedFlow 與 StateFlow 是 Kotlin coroutines 的兩個核心類別,常被視為替代 RxJava 的 Subject 與 Android 的 LiveData。SharedFlow 提供熱流與多播功能,可配置 replay 與緩衝策略,適合廣播短暫事件;StateFlow 則以狀態容器為主,永遠揭露當前值並在變更時通知收集者,適合 UI 狀態管理。兩者與 coroutines 緊密整合,提高程式可測試性與一致性,是現代 Kotlin 開發中重要的工具。
KT Academy
作者:
發布:04-05 00:00
Kotlin Coroutines: Deep Dive book is finally ready!
Learn about our recently published book dedicated to Kotlin Coroutines.
重點摘要
New book release focused on Kotlin Coroutines
Announcement invites readers to learn more
Brief release notice linking to the full article
This short announcement introduces the newly published book "Kotlin Coroutines: Deep Dive" and invites readers to learn more about it. It states that the book is dedicated to Kotlin Coroutines and that it has been released, serving primarily as a release notice. The post directs interested readers to the linked article for additional information about the book’s content and availability. The announcement does not include detailed publication metadata such as the author, chapter structure, or length; its main purpose is to inform the audience that the book is now available and to encourage developers and learners interested in Kotlin concurrency to follow the link for the complete release and further details.
Kotlin Coroutines: Deep Dive 书籍终于推出!
了解我们最近出版、专门探讨 Kotlin 协程的一本新书。
重點摘要
新书已发布,聚焦 Kotlin 协程
公告邀请读者了解详细内容
简短发布说明并提供完整文章链接
本公告介绍新近出版的《Kotlin Coroutines: Deep Dive》一书,并邀请读者进一步了解其内容。文章说明此书专注于 Kotlin 的协程主题,已正式发行,旨在让有兴趣的开发者或学习者知晓该出版资讯并前往链接查阅完整介绍。公告未列出作者、章节或其他详细出版信息,核心在于宣告书籍已准备就绪,并鼓励读者通过完整文章获取更多信息与获取方式。
Kotlin Coroutines: Deep Dive 書籍終於推出!
了解我們最近出版、專門探討 Kotlin 協程的一本新書。
重點摘要
新書已出版,聚焦 Kotlin 協程
公告邀請讀者進一步了解內容
簡短發布說明並提供完整文章連結
本篇公告介紹新近出版的《Kotlin Coroutines: Deep Dive》一書,並邀請讀者進一步了解其內容。文章說明這本書專注於 Kotlin 的協程主題,現已發行,目的在於讓有興趣的開發者或學習者知道此出版資訊並前往連結查閱完整介紹。公告未提供作者、章節或其他詳盡出版資料,重點在於宣布書籍已經準備就緒並鼓勵讀者閱讀完整文章以獲取更多資訊與取得方式。
KT Academy
作者:
發布:04-14 00:00
Funny programming comics
A collection of humorous comics for programmers.
重點摘要
A curated set of humorous comics aimed at programmers
Short, visual jokes that are quick to consume
Easy to share and enjoy during work breaks
This article presents a compact collection of humorous comics created for programmers. The comics are intended to entertain readers who work with code by portraying situations and perspectives familiar to people in software development. As a short, lighthearted compilation, it offers visual jokes and cartoons that celebrate and gently poke fun at the routines of programming. The collection can be used for a quick laugh, a moment of solidarity among colleagues, or as a small break from technical work. Their visual format makes them quick to consume and easy to share, so readers can appreciate the humor between tasks. The compilation requires no technical prerequisites to enjoy: the cartoons rely on common developer experiences, making them approachable for a wide range of readers and useful as a simple way to brighten a developer’s day.
有趣的编程漫画
一个面向程序员的幽默漫画合集。
重點摘要
面向程序员的搞笑漫画汇集
以简短图文呈现,便于快速阅读
适合在休息时观看或与同事分享
本文汇集了一系列面向程序员的搞笑漫画,通过简短的漫画图像展现与编程相关的幽默情境,让从事软件开发的人在繁忙或疲惫时获得轻松一刻。这些漫画以易读且快速传达笑点的形式呈现,适合在工作间隙浏览或与同事分享,无需长篇说明即可产生共鸣。不论是初学者还是资深开发者,都能在这些漫画中看到熟悉的日常场景并会心一笑。总体而言,文章为读者提供了一个便捷的入口,可以快速享受并传播与编程日常相关的幽默内容。
有趣的程式設計漫畫
一系列針對程式設計師的幽默漫畫彙整。
重點摘要
針對程式設計師的搞笑漫畫集合
以簡短圖文呈現、容易快速閱讀
適合休息時段觀看或與同事分享
本文彙整了一系列針對程式設計師的搞笑漫畫,透過簡短的漫畫圖像呈現程式工作中的幽默面向,讓從事軟體開發的人能在繁忙或疲乏時獲得輕鬆一刻。這些漫畫以易於閱讀、迅速傳達笑點的形式集合,適合在休息時段觀看或與同事分享,無需長篇說明即可引起共鳴。不論是初學者或資深工程師,都能從中找到熟悉情境的笑點。整體上,這篇文章提供一個方便的入口,讓讀者快速享受並傳遞與程式開發日常相關的幽默內容。
KT Academy
作者:
發布:04-28 00:00
Persistent memory - Introduction
Join this journey to explore persistent memory and build a persistent dictionary.
重點摘要
An invitation to learn persistent memory
Explore concepts and practical usage
Build a persistent dictionary as a hands-on project
This short guide invites readers to learn about persistent memory and follow a practical path that includes exploring core concepts and constructing a persistent dictionary. Persistent memory is described as a form of storage that preserves data across power cycles, sitting between conventional volatile memory and traditional storage. The journey combines conceptual explanations with a hands-on project: by studying how persistent memory behaves and implementing a dictionary that retains its contents, readers gain both understanding and practical experience. The material is intended for those curious about emerging memory technologies and for developers who want to apply persistence directly within applications. Overall, the article pairs explanation with a small, actionable project to make the topic approachable and useful.
持久性内存 - 介绍
加入这段旅程,探索持久性内存并构建一个持久字典。
重點摘要
邀请学习持久性内存
结合概念与实践进行探索
通过构建持久字典获得动手经验
本指南邀请读者学习持久性内存,并通过实践项目构建一个持久字典以探索其工作方式。持久性内存可以在断电后保留数据,位于易失性内存与传统存储之间。文章以概念讲解与动手实作并重,读者在理解原理的同时,通过实现一个可保留内容的字典获得实际经验。该材料适合对新型内存技术感兴趣或希望在应用中直接实现数据持久化的开发者,整体以易上手且可操作的方式呈现。
持久性記憶體 — 介紹
加入這趟旅程,一起探索持久性記憶體並建構一個持久字典。
重點摘要
邀請學習持久性記憶體
結合理論與實作探討運作原理
透過建立持久字典獲得實務經驗
本教程邀請讀者學習持久性記憶體,並透過實作建立一個持久字典來探索其運作。持久性記憶體能在斷電後保留資料,介於揮發性記憶體與傳統儲存之間。文章結合概念說明與動手專案,讓讀者在理解原理的同時,透過構建可在重啟後保留內容的字典獲得實務經驗。內容適合對新型記憶技術感興趣或希望將資料持久化直接整合到程式中的開發者,整體以易於上手的方式呈現,強調學習與應用並重。
KT Academy
作者:
發布:05-05 00:00
In-memory dictionary
Let's begin our journey to understand persistent memory by building an in-memory dictionary.
重點摘要
Introduce persistent memory through a practical project
Use an in-memory dictionary as a concise, concrete example
Explore design, durability, and performance trade-offs
The article opens a practical introduction to persistent memory by proposing the construction of an in-memory dictionary as a learning project. It frames the dictionary as a compact, concrete example that lets readers confront the differences between volatile RAM and byte-addressable persistent memory, explore how data structures and storage semantics must adapt for durability, and reason about issues like consistency, recoverability, and performance trade-offs. By building and examining an in-memory dictionary, learners can incrementally test design choices, observe failure modes, and gain intuition for when and how to use persistent memory in real applications. The approach emphasizes hands-on experimentation paired with conceptual explanation to make persistent memory accessible to developers and systems designers. It is intended for readers familiar with systems programming who want to bridge theory and practice when dealing with new non-volatile memory technologies.
内存字典
讓我們從构建一个内存字典开始,踏上理解持久性内存的旅程。
重點摘要
通过实作项目介绍持久性内存
以内存字典作为简洁且具体的示例
讨论设计、持久性与性能之间的取舍
本文以构建一个「内存字典」作为切入点,开启对持久性内存(persistent memory)的实践式介绍。通过这一具体且紧凑的示例,读者可以对比易失性 RAM 与字节可寻址的持久性内存的差异,思考为确保数据持久性需如何调整数据结构与存储语义,并关注一致性、恢复能力与性能等权衡。通过实现与检视字典的设计与故障情形,学习者能够逐步验证设计选择、观察失效模式,并建立在真实应用中使用持久性内存的直觉。该方法强调动手实验与概念讲解并重,旨在帮助系统开发者将理论与实践连接起来。
記憶體內字典
讓我們從建立一個記憶體內字典開始,一起踏上理解持久性記憶體的旅程。
重點摘要
以實作專案引介持久性記憶體概念
用記憶體內字典作為具體且緊湊的範例
關注資料結構、耐久性與效能權衡
本文以建立一個「記憶體內字典」作為切入點,開始帶領讀者理解持久性記憶體(persistent memory)。透過這個具體且緊湊的範例,讀者可以比較揮發性 RAM 與位址可存取的持久記憶體的不同,思考資料結構與儲存語意為了耐久性需如何調整,並關注一致性、還原與效能等權衡。透過實作與檢視字典的設計與錯誤情境,學習者能逐步驗證設計抉擇、觀察失效模式,並建立在實務中使用持久性記憶體的直覺。本文強調以實作為主的學習路徑,將概念與實務結合,讓系統開發者更容易上手。
KT Academy
作者:
發布:05-12 00:00
Introducing persistent memory
Learn the basics of persistent memory: its characteristics, how it works, and the benefits of byte addressability.
重點摘要
Introduces the fundamentals of persistent memory
Explains how persistent memory works and its key characteristics
Highlights benefits of byte-addressability for programming
Persistent memory (PMem) bridges volatile DRAM and persistent storage by providing non-volatile, byte-addressable memory that applications can access with near-memory latency. This article introduces the fundamentals: defining what persistent memory is, describing its distinguishing characteristics (persistence across power cycles, direct CPU load/store access, and capacity/performance trade-offs), explaining at a high level how it operates within a system (persistence mechanisms, access semantics, and interaction with CPU and storage stack), and emphasizing the practical benefit of byte addressability for simpler programming and more efficient data structures. Readers will gain an overview of why PMem matters, how it differs from traditional storage and memory, and the kinds of design patterns and performance improvements it enables, without diving into vendor-specific details or low-level implementation minutiae.
介绍持久性内存
一起学习持久性内存的基础、特性、工作原理,以及字节可寻址的优势。
重點摘要
介绍持久性内存基础
说明工作原理与关键特性
强调字节可寻址的好处
本文介绍持久性内存(persistent memory)的基本概念、特性、工作原理,以及字节可寻址(byte addressability)所带来的优势。文章说明持久性内存不同于传统易失性内存与块式存储的要点,指出其在断电后仍能保留数据、可通过 CPU 以负载/存取方式访问,以及在容量与延迟间的折衷。作者以高层次描述其运作与访问语义,并强调字节可寻址如何简化编程、提升数据结构与性能利用。文章提供概览与应用意义,避免深入厂商或实现细节。
介紹持久性記憶體
一起學習持久性記憶體的基礎、特性、運作方式,以及位元組可位址性的美好之處。
重點摘要
介紹持久性記憶體基礎概念
說明運作原理與主要特性
強調位元組可位址性的優勢
本文介紹持久性記憶體(persistent memory)的基本概念、特性、運作原理,以及位元組可位址性(byte addressability)帶來的優點。文章說明持久性記憶體不同於傳統揮發性記憶體與塊式儲存的要點,指出其在斷電後仍保留資料、能以 CPU 負載/儲存存取、以及在容量與延遲之間的折衷。作者以高層描述運作方式與存取語義,並強調位元組可位址性如何簡化程式設計、提升資料結構與效能利用。文章提供概覽與應用意義,避免深入廠商或實作細節。
KT Academy
作者:
發布:05-17 00:00
Code or No-code?
Each approach shines in different areas—code for control and customization, no-code for speed and accessibility—and that trade-off fuels their ongoing clash.
重點摘要
Code offers fine-grained control and deep customization
No-code enables rapid development and lower barriers to entry
Tension stems from trade-offs between control, speed, scalability, and governance
Code and no-code approaches excel in different dimensions, which explains why they are often portrayed as rivals. Traditional coding provides fine-grained control, flexibility, and deep customization that suit complex, performance-sensitive, or highly unique business requirements. No-code platforms prioritize speed, lower technical barriers, and visual building blocks that accelerate prototyping and let non-developers contribute. The friction arises because teams must trade control for speed: choosing code typically requires more expertise and development effort but yields greater long-term adaptability, while choosing no-code speeds delivery but can limit extensibility, governance, and introduce vendor lock-in. Rather than absolute winners, code and no-code are complementary options. The right choice depends on project goals, team skills, time-to-market, and maintenance expectations; hybrid strategies and clear decision criteria help balance the trade-offs.
代码还是无代码(No-code)?
两者在不同方面各有优势——代码提供控制与定制,无代码提供速度与可访问性,这种取舍导致持续的对立。
重點摘要
代码带来精细控制与高度定制
无代码加速开发并降低参与门槛
冲突来自控制、速度、可扩展性与治理之间的权衡
代码与无代码在不同维度表现突出,因此常常被拿来比较。传统编码提供精细的控制、灵活性和高度定制,适合复杂或对性能有较高要求的项目;无代码平台以速度、低门槛和可视化构建为优势,便于快速原型开发和非工程师参与。两者的对立源于必须在控制与速度之间做出取舍:选择代码通常需要更多专业投入和成本,但带来更好的长期适应性;选择无代码可以更快交付,却可能在可扩展性、治理和平台锁定方面受限。两者并非绝对对立,而是互补,应根据项目目标、团队能力、上市时间与维护预期来选择,或采用混合策略以平衡利弊。
寫程式還是無程式(No-code)?
兩者各有強項:程式碼帶來控制與客製化,無程式帶來速度與可及性,這樣的取捨造成持續的競爭。
重點摘要
程式碼提供細緻控制與高度客製化
無程式強調快速開發與低門檻參與
衝突源自於控制、速度、擴展性與治理間的取捨
程式碼與無程式各自在不同面向表現優勢,因此常被視為對立。傳統寫碼能提供細緻的控制、彈性與深度客製化,適合複雜或對效能有較高要求的專案;無程式平台則以速度、較低的技術門檻與視覺化組件為優勢,便於快速原型與非工程師參與。兩者的緊張關係來自於取捨:選擇程式碼通常需要更多專業與成本,換來長期的擴展性與掌控;選擇無程式能加快交付,卻可能在可延伸性、治理與平台綁定上受限。兩者並非絕對誰勝誰負,應根據目標、團隊能力、上市時程與維運期望來抉擇,或採混合策略以平衡利弊。
KT Academy
作者:
發布:05-19 00:01
Persistent Dictionary
Convert an in-memory dictionary to persistent storage while introducing key PMDK concepts.
重點摘要
Persist an in-memory dictionary using persistent memory techniques
Introduce fundamental PMDK concepts for durability and consistency
Explain considerations like persistent pointers and transactions
This short piece proposes making an existing in-memory dictionary persistent and uses that example to introduce concepts from PMDK (the Persistent Memory Development Kit). It emphasizes the goal of preserving in-memory data across restarts by leveraging persistent memory primitives and techniques. The article frames the work as both a practical conversion — mapping volatile data structures to persistent equivalents — and an opportunity to explain PMDK fundamentals such as durable allocation, persistent pointers, and transactional updates to ensure consistency. Readers are guided to think about how to adapt typical in-memory operations to the guarantees and patterns required for persistent memory, including concerns about atomicity, recovery, and proper allocation strategies provided by PMDK.
持久化字典
将内存中的字典转换为持久存储,并介绍 PMDK 的关键概念。
重點摘要
把内存字典转为持久化数据结构
介绍 PMDK 的基本概念以保证持久性和一致性
涉及持久指针与事务等实现考量
本文以将内存中的字典持久化为例,介绍 PMDK(Persistent Memory Development Kit)的一些核心概念。目标是利用持久内存的特性在程序重启后保留原本驻留内存的数据。文章同时强调实践层面的转换——如何把易失性的数据结构映射为持久化等价物——以及概念层面的要点,如耐久分配、持久指针与事务性更新,以保证数据一致性与可恢复性。读者可藉此理解如何将常见的内存操作调整为符合持久内存的保证与使用模式。
持久化字典
把記憶體內的字典轉為可持久化儲存,並說明 PMDK 的關鍵概念。
重點摘要
將記憶體字典轉換為持久性資料結構
說明 PMDK 的基本概念以確保持久與一致性
涵蓋持久指標與交易等設計考量
本文以把記憶體中的字典變為持久化儲存為出發點,同時介紹 PMDK(Persistent Memory Development Kit)的核心概念。重點在於如何利用持久記憶體的機制保存原本易失的資料,使資料能跨重啟存活。文章把工作分為實作層面──將暫存資料結構對應到持久化型態──以及概念層面──說明 PMDK 所提供的耐久配置、持久指標與交易性更新等機制,以確保資料的一致性與可回復性。讀者將被引導思考如何將一般的記憶體操作調整為符合持久記憶體保證與使用模式。
KT Academy
作者:
發布:05-24 00:00
Why Kotlin Should Be Your Next Programming Language
An overview of what Kotlin is and why it may be a strong choice for your next language.
重點摘要
Introduces what Kotlin is and its positioning
Summarizes reasons developers might adopt Kotlin
Provides a high-level guide to evaluate Kotlin
This article introduces Kotlin and explains why it should be your next programming language. It gives a concise overview of what Kotlin is and presents the main reasons developers might choose it, emphasizing practical benefits such as modern language design, improved safety, concise syntax, and strong interoperability with existing ecosystems. The piece frames Kotlin as a compelling option for both new projects and developers expanding their skills, highlighting its productivity advantages, growing tooling and community support, and applicability across multiple platforms. Rather than serving as a tutorial, the article is a persuasive, high-level guide to help readers evaluate Kotlin’s fit for their needs and to encourage exploration of the language as a practical next step in their programming journey. It invites further reading and hands-on experimentation.
为何 Kotlin 应该成为你的下一个编程语言
概述 Kotlin 是什么以及它为何值得成为你的下一步选择。
重點摘要
介绍 Kotlin 的定位与重点
归纳采纳 Kotlin 的主要理由
以高层视角帮助评估是否采用
本文介绍 Kotlin 并说明为何它应成为你的下一个编程语言。文章简要概述 Kotlin 的核心定位与吸引力,归纳开发者可能选择 Kotlin 的主要原因,例如现代化的语言设计、提升代码安全性、语法简洁以及与既有生态的互通等。本文以高层次的说理为主,帮助读者评估 Kotlin 是否适合新项目或扩展技能,而非提供操作性教程,并鼓励读者进一步阅读与动手实践。
為何 Kotlin 應該成為你的下一個程式語言
概述 Kotlin 是什麼以及它為何值得成為你下一個選擇。
重點摘要
介紹 Kotlin 的定位與主旨
整理採用 Kotlin 的主要理由
以高階觀點協助評估是否採用
本文介紹 Kotlin 並說明為何應該成為你的下一個程式語言。文章概述 Kotlin 的核心定位與吸引力,說明採用 Kotlin 的主要理由,如現代語言設計、提升程式安全性、語法簡潔與與既有生態系統的互通性等。內容以高階說服為主,協助開發者評估 Kotlin 是否適合新專案或擴展技能,而非技術教學,並鼓勵讀者進一步探索與實作。
KT Academy
作者:
發布:05-26 00:00
Persistent memory design choices and use-cases
An overview of the key design decisions and practical uses for persistent memory.
重點摘要
Trade-offs between durability, consistency, and performance
Programming models: direct access vs. transactional libraries
Use-cases include in-memory databases, caches, logs, and fast recovery
Persistent memory (PMem) bridges the gap between volatile RAM and durable storage by providing byte-addressable, low-latency persistent storage. Design choices for PMem focus on durability semantics, consistency models, crash recovery, and the trade-offs between performance and safety. Architects must decide how to map data structures into persistent regions, whether to rely on explicit cache flushes and fences or to use higher-level transactional libraries, and whether to employ logging, copy-on-write, or other consistency techniques. Programming models range from direct load/store access with explicit persistence primitives to managed libraries offering transactions and persistent allocators. Common use-cases include in-memory databases, persistent caches, write-ahead logs, and systems requiring fast restart and recovery where avoiding expensive serialization is beneficial. Proper co-design of hardware and software, and clear failure-mode handling, are essential to exploit PMem’s advantages while ensuring correctness.
持久化内存的设计选择与用例
了解持久化内存的关键设计抉择与实际应用场景。
重點摘要
在持久性、一致性与性能之间权衡
程式模型可为直接存取或使用事务性库
适用于内存数据库、持久缓存、日志与快速恢复
持久化内存(persistent memory)结合了内存与存储的特性,提供字节可寻址且具有耐久性的低延迟存储。针对 PMem 的设计决策集中在耐久性语义、一致性模型、崩溃恢复策略以及性能与安全性的权衡。架构师需要决定如何将数据结构映射到持久区域、是直接依赖缓存刷新与屏障,还是采用更高层的事务库,以及是否采用写日志、写时复制等一致性技术。程式模型从直接 load/store 并辅以显式持久化原语,到提供事务与持久分配器的管理库都有。常见用例包括内存数据库、持久缓存、预写日志和需要快速重启恢复的系统,这些场景中避免昂贵序列化可以显著提升恢复速度与效率。
持久化記憶體的設計選擇與應用場景
理解持久化記憶體的關鍵設計取捨與實際應用。
重點摘要
在耐久性、一致性與效能間做取捨
程式模型可採直接存取或事務性函式庫
常見於記憶體資料庫、持久快取與日誌/快速復原
持久化記憶體(persistent memory)結合了記憶體與儲存的特性,提供位元組可直接存取且具耐久性的低延遲存儲。設計取捨包含耐久性語意、一致性模型、崩潰復原策略與效能與安全性的權衡。工程師需決定如何將資料結構映射到持久區域、採用事務性函式庫、寫日誌或寫時複製等技術,以及如何調整軟硬體以配合硬體特性。程式模型從直接 load/store 並搭配 flush/fence,到提供事務與持久配置器的高階函式庫皆有。常見應用場景包括記憶體資料庫、持久快取、寫前日誌與快速重啟/復原系統,能在不需昂貴序列化的情況下保有資料耐久性。
KT Academy
作者:
發布:05-27 00:00
How to write a technical book?
A guide for writing technical books.
重點摘要
Subject: writing technical books
Format: single-line description
Content: no further details provided
This webpage, titled "How to write a technical book?", contains only a single-line description: "A guide for writing technical books." No author or further content is provided at the linked URL. Because the original text is limited to that brief statement, the article appears to be a placeholder or stub indicating intent to provide guidance on composing technical books but without presenting sections, methods, or examples. The available information only establishes the subject (writing technical books) and the purpose (to guide readers), and offers no specifics about scope, audience, structure, or steps. Readers seeking actionable instructions will need to consult other resources or the full article if the linked page is expanded. The provided link (https://kt.academy/article/writing-technical-books) is the only source cited.
如何写技术书籍?
一本关于如何写技术书籍的指南。
重點摘要
主题:撰写技术书籍
形式:仅一句简短描述
内容:未提供更多细节
该网页标题为「How to write a technical book?」,正文仅有一句话说明:“A guide for writing technical books.”,未署名且未提供其他内容或章节。由于原文仅包含此短句,文章目前更像是一个占位或摘要,表明作者意图提供关于撰写技术书籍的指引,但并未说明具体范围、目标读者、章节结构或操作步骤。需要可执行的写作方法或示例时,读者需等待原文扩展或参考其他资源。链接为:https://kt.academy/article/writing-technical-books。
如何撰寫技術書籍?
一本關於如何撰寫技術書籍的指引。
重點摘要
主題:撰寫技術書籍
格式:僅有一句簡短描述
內容:未提供進一步細節
該網頁標題為「How to write a technical book?」,內容僅以一句話說明:「A guide for writing technical books.」,未署名且未提供其他內容或章節。由於原文僅有這短句,該文章目前更像是一則佔位或摘要,表明欲提供撰寫技術書籍的指引,但未說明具體範圍、目標讀者、章節架構或具體步驟。若需可操作的寫作方法或範例,讀者仍需等待原文擴充或參考其他資源。連結為:https://kt.academy/article/writing-technical-books。
KT Academy
作者:
發布:05-31 00:00
Software Testing Standards (Aligned with ISTQB)
Aligning testing activities with ISTQB standards helps teams perform efficiently and cope with project scope and deadlines.
重點摘要
Align testing practices with ISTQB to improve efficiency
Workshop covers testing stages from definition through maintenance
Standards help teams manage scope and deadlines
Aligning testing activities with ISTQB standards helps teams work more efficiently and manage project scope and deadlines. This workshop walks through the full software testing lifecycle, beginning with test definition and progressing through planning, design, execution, and into maintenance. By mapping practices to the ISTQB framework, participants can apply standardized terminology, structured test design, and clearer roles, which improves consistency and traceability across project phases. The session focuses on practical alignment rather than prescriptive rules, showing how standard-based testing supports timely delivery, reduces rework, and makes maintenance more predictable. Attendees will receive an overview of each stage and guidance on how consistent processes help testing efforts remain focused and aligned with project constraints.
软件测试标准(与 ISTQB 对齐)
将测试活动与 ISTQB 标准对齐,可以提升执行效率并帮助应对项目范围与进度限制。
重點摘要
与 ISTQB 对齐可提升测试效率
工作坊涵盖从定义到维护的测试阶段
标准化有助于管理范围和进度
将测试活动与 ISTQB 标准对齐,可以提升执行效率并帮助应对项目范围与进度限制。本工作坊将逐步讲解软件测试各阶段,从定义开始,经过规划、设计与执行,直至维护。通过采用标准化术语与结构化方法,团队可以建立可重复的流程、提高跨阶段一致性,并增强从需求到维护的可追溯性。本课程侧重实务对齐,说明如何在项目约束内保持测试工作的可预测性与聚焦,帮助减少返工并有利于长期维护。
軟體測試標準(符合 ISTQB)
將測試活動與 ISTQB 標準對齊,可提升執行效率並協助因應專案範圍與時程限制。
重點摘要
依 ISTQB 對齊測試可提升效率
工作坊從定義到維護逐步說明測試階段
標準化有助於管理範圍與時程
將測試活動與 ISTQB 標準對齊,能提升執行效率並幫助應對專案範圍與時程限制。此工作坊將循序介紹軟體測試的各階段,從定義開始,經由規劃、設計與執行,最後到維護。透過採用標準化術語與結構化做法,團隊可建立可重複的流程、提升跨階段一致性,並強化從需求到維護的可追溯性。本課程以實務對齊為主,說明如何在專案限制內維持測試工作的可預測性與聚焦,協助減少返工並利於長期維護。
KT Academy
作者:
發布:06-07 00:00
Leveraging AI in Software Testing
AI is reducing manual effort in development, so it's beneficial to adopt AI-based algorithms in software testing.
重點摘要
AI is increasingly present in daily life and development
AI can eliminate some manual testing efforts
AI-based algorithms can be applied to software testing
Artificial intelligence is becoming more present in everyday life and is improving software development by reducing manual effort. Adopting AI in testing can increase efficiency and free teams to focus on higher-level tasks. The piece explains how AI-based algorithms can be utilized in software testing: for example, they can help automate repetitive checks, assist in generating and prioritizing test cases, and surface patterns that may indicate defects. It also implies the need for human oversight to validate outputs and manage limitations such as false positives. Overall, integrating AI into testing workflows offers opportunities to accelerate feedback cycles, improve coverage, and reduce tedious manual work, and the article intends to explore practical ways to employ AI techniques within the testing process.
在软件测试中利用 AI
AI 正在减少开发中的一些手动工作,因此在测试工作中采用基于 AI 的算法是有益的。
重點摘要
AI 正逐步融入日常生活与开发活动
AI 可消除部分手动测试工作
可将基于 AI 的算法应用于软件测试
文章指出,AI 正在进入我们的日常生活,并通过减少手动工作来改善开发活动,因此在任务中采用 AI 是有益的。文中说明如何在软件测试中利用基于 AI 的算法,包括自动化重复性检查、协助生成与优先排序测试用例,以及帮助发现可能的缺陷模式等。与此同时,仍需人工监督以验证 AI 输出、处理误报并确保模型负责任地使用。总体来看,将 AI 集成到测试流程中有助于加速反馈、提升覆盖率并减少枯燥的手工工作,文章并将探讨可行的应用方式与注意事项。
在軟體測試中運用 AI
AI 正在減少開發中的部分手動工作,因此在測試工作中採用基於 AI 的演算法是有益的。
重點摘要
AI 日益融入日常生活與開發流程
可透過 AI 減少部分手動測試工作
可將基於 AI 的演算法應用於軟體測試
本文指出,AI 正逐漸融入日常生活,並透過減少手動工作來改善開發活動,因此值得在工作中加以採用。文章說明如何在軟體測試中利用基於 AI 的演算法,包括自動化重複性檢查、協助產生與優先排序測試案例,以及發現可能的缺陷模式等。雖然 AI 可以提升效率與覆蓋率,但仍需測試人員進行監督與驗證,以處理誤報並確保模型負責任地使用。整體而言,將 AI 整合進測試流程有助於加快回饋迴圈、減少繁瑣作業,文章將探討具體可行的應用方式與注意事項。
KT Academy
作者:
發布:06-14 00:00
Best Principles for Successful Test Automation (API and UI)
Aligning testing activities with ISTQB standards helps teams work efficiently and meet project scope and deadlines.
重點摘要
Align testing with ISTQB standards
Cover all testing stages from definition to maintenance
Aim for efficiency to meet scope and deadlines
This workshop emphasizes aligning test automation (API and UI) with ISTQB standards to improve efficiency and handle project scope and deadlines. It presents a structured walkthrough of software testing stages, beginning with definition and progressing through planning, design, execution, and ongoing maintenance. By following recognized standards, teams can standardize practices, reduce rework, and better estimate effort and timelines. The session focuses on practical principles that help integrate automated testing into the development lifecycle, ensure coverage across interfaces, and maintain tests over time. The goal is to equip participants with an understanding of end-to-end testing stages and how adherence to established testing principles supports predictable delivery and sustained quality.
成功测试自动化(API 与 UI)的最佳原则
将测试活动与 ISTQB 标准对齐,有助于提升效率并应对项目范围和交付期限。
重點摘要
依照 ISTQB 标准规划测试
覆盖从定义到维护的测试阶段
以效率为重以满足范围与期限要求
本次工作坊强调将 API 与 UI 的测试自动化与 ISTQB 标准相结合,以提高执行效率并应对项目范围和交付期限的挑战。课程将循序讲解软件测试的各个阶段,从需求定义开始,经过测试计划、设计与执行,直至后续维护与更新。通过采用公认的标准,团队能够统一实践、减少返工并更准确地评估工时与进度。讲座侧重实践性原则,帮助参与者理解如何在开发生命周期中融入自动化测试、保障不同接口的覆盖并维持测试的长期可维护性与质量。
成功測試自動化(API 與 UI)的最佳原則
將測試活動與 ISTQB 標準對齊,可提升效率並因應專案範圍與時程要求。
重點摘要
依據 ISTQB 標準規劃測試
涵蓋定義到維護的測試階段
以效率為導向以符合範圍與時程
本工作坊強調將 API 與 UI 的測試自動化與 ISTQB 標準對齊,以提升執行效率並有效因應專案範圍與交付時程。課程系統性地說明軟體測試的各個階段,從需求與定義開始,經過計畫、設計、執行,直到長期的測試維護。透過遵循既有標準,團隊可建立一致的作業方式、降低返工、提升估算與排程準確度。內容聚焦於實務原則,幫助將自動化測試整合進開發流程、確保不同介面的測試覆蓋,並維持測試的可持續性與品質。
KT Academy
作者:
發布:07-29 00:01
Function references
In Kotlin you can reference functions (including constructors, getters, and extensions) to replace lambda expressions.
重點摘要
Use function references to pass existing functions instead of lambdas.
Supports constructors, property getters, extensions and regular functions.
Common syntax uses the :: operator to form references.
Function references in Kotlin let you pass existing functions as values and thereby replace many explicit lambda expressions. Instead of writing a lambda wrapper you can refer to a top-level or member function, an extension, a property getter, or even a constructor and supply that reference where a function value is expected. The most common syntax uses the double-colon operator (e.g., ::foo or ClassName::constructor). References can be bound or unbound depending on context and preserve the referenced callable's implementation. They simplify code, reduce duplication, and make intent clearer by pointing directly to named callables; when overloads or ambiguous types arise, explicit type information can disambiguate the reference.
函数引用
在 Kotlin 中,可以用函数引用(包括构造函数、getter、扩展函数等)替代 lambda 表达式。
重點摘要
将已有函数作为值传递以替代 lambda。
支持构造函数、属性 getter、扩展与成员函数。
常用 :: 操作符来创建函数引用。
在 Kotlin 中,函数引用允许把已有的可调用实体作为值传递,从而替代许多显式的 lambda 表达式。你可以引用顶层或成员函数、扩展函数、属性 getter,甚至构造函数,并在需要函数值的地方使用。常见语法使用双冒号 (::) 创建引用;引用可根据上下文为绑定或非绑定。函数引用保留被引用调用项的实现,使代码更简洁、减少重复并更明确地表达意图。如遇重载或类型歧义,可通过显式类型信息来消除歧义。
函式參考
在 Kotlin 中,可以用函式參考(包括建構子、getter、擴充函式等)取代 lambda 表達式。
重點摘要
將既有函式作為值傳遞以取代 lambda。
可參考建構子、屬性 getter、擴充與成員函式。
常用 :: 運算子建立函式參考。
在 Kotlin 中,函式參考可將既有的可呼叫單位當作值傳遞,用以取代許多 lambda 表達式。你可以參考頂層或成員函式、擴充函式、屬性 getter,甚至建構子,並在需要函式值的地方使用。常見寫法以雙冒號 (::) 建立引用;根據情境可為綁定或非綁定引用。函式參考保留被引用呼叫項的實作,能讓程式更簡潔、減少複製並清楚表達意圖。若有多載或型別不明,可透過明確型別來解決歧義。
KT Academy
作者:
發布:08-11 00:00
Essential programming nomenclature
Find out what you need to know before you start writing programming documentation, books, or articles.
重點摘要
Identify what you must know before writing
Clarify terminology, audience, scope and conventions
Prepare examples and verify terminology to avoid ambiguity
This short advisory note urges prospective authors to identify and learn what they need before writing programming documentation, books, or articles. It emphasizes preparatory work: clarifying audience and purpose, learning domain-specific terminology and conventions, choosing consistent naming and style, and preparing accurate examples and explanations. By understanding the necessary vocabulary, tools, assumptions, and scope in advance, writers can produce clearer, more reliable technical texts that avoid confusion and reduce rework. The guidance applies to varied formats—from quick documentation to comprehensive books—and encourages planning and fact-checking before drafting. It also suggests aligning examples with commonly used toolchains, maintaining consistent code style and naming across chapters, and verifying terminology against authoritative sources to prevent ambiguity.
程序命名与术语要点
在开始撰写程序文档、书籍或文章之前,先了解你需要知道的事项。
重點摘要
事前确认所需知识
厘清术语、读者与范围
准备示例并查证术语
这篇简短提示告诉拟写程序文档、书籍或文章的作者:在动笔前先弄清需要掌握的事项。建议确认读者与目的、学习领域专用术语与惯例、规划内容范围与示例,并保持命名与风格一致、选择合适的工具与示例语言、事前查证术语来源以避免模糊。通过事前调查与准备,写作能更清晰、准确并节省返工,适用于简短说明到完整专著等各类技术文本。值得投入。
程式命名與術語要點
在開始撰寫程式文件、書籍或文章之前,先瞭解你需要知道的事。
重點摘要
事前確認所需知識
釐清術語、讀者與範圍
準備範例並查證術語
這篇簡短提示告訴擬寫程式文件、書籍或文章的作者:在動筆前先弄清需要掌握的事項。建議確認讀者與目的、學習領域專用語彙與慣例、規劃內容範圍與範例,並保持命名與風格一致、選擇合適的工具與範例語言、事先查證術語來源以避免模糊。透過事前調查與準備,寫作能更清晰、正確並節省返工,適用於簡短說明到完整專書等各類技術文本。值得投資。
KT Academy
作者:
發布:08-18 00:00
Object-oriented or functional? Two ways to see the world
The difference between the OOP and FP paradigms is deeply rooted in how we see the world.
重點摘要
OOP models systems as interacting objects with state and behavior
FP models computation as composition of pure functions on immutable data
The paradigms reflect different philosophical views that affect design trade-offs
Object-oriented programming (OOP) and functional programming (FP) represent two distinct ways of interpreting and structuring software, rooted in different metaphors for the world. OOP frames systems as collections of interacting objects that encapsulate state and behavior, favoring identity, mutation, and message-passing. FP frames computation as the evaluation and composition of pure functions operating on immutable data, favoring stateless transformations and predictable composition. Philosophically, OOP emphasizes modeling entities and their lifecycles, while FP emphasizes declarative transformation of data and avoidance of side effects. These differing emphases lead to different design patterns, modularity strategies, and trade-offs around state management, concurrency, and reasoning about code. Choosing between them often depends less on absolute correctness than on which conceptual lens—objects with behaviors or composable functions—best matches the problem domain and the developer’s intuition.
面向对象还是函数式?两种看待世界的方式
OOP 与 FP 范式之间的差异深植于我们看待世界的方式。
重點摘要
OOP 把系统建模为具有状态与行为的对象互相作用
FP 把计算看作对不可变数据的纯函数组合与变换
不同的哲学取向导致在设计与状态处理上的不同权衡
面向对象(OOP)与函数式(FP)代表两种不同的软件观,根源在于看待世界的隐喻差异。OOP 将系统视为由具有状态与行为的对象交互构成,强调标识、可变性与消息传递;FP 则将计算看作纯函数对不可变数据的组合与变换,强调无副作用与可预测的组合性。从哲学上看,OOP 更侧重于建模实体及其生命周期,FP 更注重以声明式方式处理数据并避免副作用。不同取向会影响设计模式、模块化策略以及在状态管理、并发和代码推理上的权衡。选择哪种范式往往取决于哪种概念视角更契合问题领域和开发者的直觉。
物件導向或函數式?兩種看世界的方式
OOP 與 FP 範式之間的差異深植於我們看待世界的方式。
重點摘要
OOP 將系統視為具有狀態與行為的物件互動
FP 將計算視為對不可變資料的純函數組合與轉換
不同哲學觀點帶來設計、模組化與狀態處理的取捨
物件導向(OOP)與函數式(FP)代表兩種不同的軟體觀,根源在於看待世界的隱喻差異。OOP 將系統視為由具有狀態與行為的物件互動所構成,強調識別、變異與訊息傳遞;FP 則將計算看成純函數對不可變資料的組合與轉換,強調無副作用與可預測的組合性。哲學上,OOP 側重於建模實體與其生命週期,FP 則重視宣告性地處理資料與避免副作用。這些不同的觀點導致設計模式、模組化策略與對狀態管理、併發與程式推理的不同取捨。選擇何者往往取決於哪種概念化鏡頭更貼合問題領域與開發者直覺。
KT Academy
作者:
發布:08-26 00:03
Lambda expressions
Learn how to use lambda expressions, what special support they receive, and which pitfalls they can introduce.
重點摘要
How to write and invoke lambda expressions
Special language and runtime support that makes lambdas ergonomic
Common traps and pitfalls when using lambdas
Lambda expressions are concise function literals that let you pass behavior as values. This article introduces how to write and invoke lambdas, explains the special support languages and runtimes provide (such as syntactic conveniences, type inference, conversions and optimizations), and surveys common pitfalls they can generate. It discusses parameter and return handling, capturing surrounding state, interoperability with existing APIs, and issues that arise around mutable captures, lifetimes, nullability and unexpected performance characteristics. The piece also outlines practical guidance: when lambdas improve clarity, when to prefer named functions, and basic debugging and testing strategies. Examples and patterns are used to illustrate trade-offs so readers can adopt lambdas safely and avoid subtle bugs.
Lambda 表达式
学习如何使用 lambda 表达式、语言或运行时提供的特殊支持,以及它们可能产生的陷阱。
重點摘要
如何编写与调用 lambda 表达式
语言与运行时对 lambda 的特殊支持
使用 lambda 时常见的陷阱与问题
Lambda 表达式是简洁的函数字面量,可以将行为作为值传递。本文介绍如何编写和调用 lambda,说明语言与运行时为提升可用性所提供的特殊支持(例如语法糖、类型推断、转换与优化),并梳理使用中可能遇到的陷阱。内容涵盖参数与返回处理、捕获外部状态、与现有 API 的互通,以及因捕获可变状态、生命周期、可空性或意外的性能影响而产生的问题。文章还给出实用建议:何时使用 lambda 有助于清晰、何时应使用具名函数,以及基础的调试与测试策略,通过示例展示折衷,帮助读者安全、可维护地采用 lambda。
Lambda 表達式
學習如何使用 lambda 表達式、語言/執行環境提供的特殊支援,以及它們可能造成的陷阱。
重點摘要
如何撰寫與呼叫 lambda 表達式
語言與執行環境對 lambda 的特殊支援
使用 lambda 時常見的陷阱與注意事項
Lambda 表達式是簡潔的函式字面值,能把行為作為值傳遞。文章說明如何撰寫與呼叫 lambda,並解釋語言與執行環境為了方便使用所提供的特殊支援(如語法糖、型別推斷、轉換與優化),同時指出可能出現的陷阱。內容涵蓋參數與回傳處理、捕獲外部狀態、與既有 API 的互通性,以及因捕獲可變狀態、生命週期、可為空性或效能差異而引發的問題。並提供實務建議:何時用 lambda 能提升可讀性、何時應改用具名函式、以及基本的偵錯與測試策略,透過範例幫助讀者在實作時保持安全與可維護性。
KT Academy
作者:
發布:09-09 00:04
Type-safe DSL Builders in Kotlin
How to define type-safe DSL builders in Kotlin.
重點摘要
Describes building type-safe domain-specific languages in Kotlin
Emphasizes compile-time safety for DSL constructs
Relies on Kotlin language features to structure builders
This short piece explains how to define type-safe DSL builders in Kotlin. It focuses on creating domain-specific languages whose structure and usage are checked at compile time, reducing runtime errors and improving developer ergonomics. The approach typically leverages Kotlin features such as lambda-with-receiver, extension functions, and builder-style APIs to provide concise, readable DSL syntax while preserving strong typing. By organizing configuration or build logic into dedicated builder blocks, authors can expose a fluent, declarative surface to users while keeping invariants enforced by the type system. The goal is safer, clearer DSLs that combine Kotlin’s expressive syntax with compile-time guarantees.
Kotlin 中的类型安全 DSL 构建器
演示如何在 Kotlin 中定义类型安全的 DSL 构建器。
重點摘要
介绍如何构建类型安全的领域专用语言(DSL)
着重通过编译期类型检查提升安全性
借助 Kotlin 特性来组织和暴露建构器接口
本文介绍了在 Kotlin 中定义类型安全 DSL 构建器的方法,旨在让 DSL 的结构与用法在编译期得到校验,从而减少运行时错误并提升开发体验。常见做法是利用 lambda-with-receiver、扩展函数和构建器风格的 API,把配置或构建逻辑封装为简洁的代码块,为使用者提供声明式且可读的 DSL 语法,同时让类型系统维护必要的不变性检查。总体目标是将 Kotlin 的表达能力与编译期保证结合,构建更安全、更清晰的 DSL。
Kotlin 的型別安全 DSL 建構器
示範如何在 Kotlin 中定義型別安全的 DSL 建構器。
重點摘要
說明如何建立型別安全的領域專屬語言(DSL)
強調以編譯期型別檢查減少執行期錯誤
利用 Kotlin 語言特性來設計建構器介面
本文說明在 Kotlin 中如何定義型別安全的 DSL 建構器,目的在於讓 DSL 的結構與使用在編譯期被檢查,降低執行期錯誤並提升開發便利性。通常會透過 lambda-with-receiver、延伸函式與建構器式 API 等 Kotlin 特性,將設定或建構邏輯包裝成簡潔的區塊語法,對使用者呈現宣告式、可讀的 DSL 介面,同時讓型別系統維持必要的不變式檢查。最終目標是結合 Kotlin 表達力與編譯期保證,打造更安全、清晰的 DSL。
KT Academy
作者:
發布:09-14 00:00
Type modelling in Kotlin
Type safety is often undervalued in software projects and causes enormous financial losses worldwide.
重點摘要
Type safety is undervalued in most software projects.
Neglecting type safety causes substantial financial losses globally.
Changing a few bad habits can make software significantly more reliable.
Type modelling in Kotlin stresses that type safety is frequently underappreciated in software development and that this neglect contributes to considerable financial loss around the world. The piece argues that modest changes in developer habits—such as relying less on loose runtime checks, encoding domain invariants in types, and avoiding conflation of distinct concepts into primitive types—can materially improve reliability. Kotlin’s expressive type system enables developers to model domain concepts explicitly, move invalid states to compile time, and surface errors earlier in the lifecycle. By investing in clearer type design, leveraging null-safety and algebraic types where appropriate, and preferring typed interfaces over unstructured data, teams can reduce defects and maintenance costs. The core message is pragmatic: small, deliberate shifts in how types are used yield outsized gains in correctness and cost efficiency.
在 Kotlin 中的类型建模
类型安全在大多数软件项目中被低估,造成全球范围的巨大经济损失。
重點摘要
类型安全在大多数项目中被低估。
忽视类型安全会导致严重的经济损失。
改变几个不良习惯可以显著提高软件可靠性。
Type modelling in Kotlin 指出,类型安全在大多数软件项目中被低估,导致全球范围的巨大经济损失。文章认为,只需改变几个常见的不良习惯——例如依赖松散的运行时检查或在单一基本类型中混用不同概念——就能提升系统可靠性。Kotlin 的类型系统有助于明确建模领域概念,将不合法状态移至编译期并更早发现错误。通过更谨慎的类型设计、合理使用空值安全与代数类型,以及以类型化接口替代无结构数据,团队能够降低缺陷率和维护成本。核心信息是务实的:在类型使用上做出小幅调整,即可带来软件正确性和成本效率的显著改善。
在 Kotlin 中的型別建模
型別安全在多數軟體專案中被低估,造成全球龐大的經濟損失。
重點摘要
型別安全在多數專案中被低估。
忽視型別安全會導致巨大的經濟損失。
改變幾個不良習慣即可提升軟體可靠度。
Type modelling in Kotlin 指出,型別安全在多數軟體專案中被低估,導致全球龐大經濟損失。文章主張,只要改變幾個常見的不良習慣──例如過度依賴執行時檢查或在單一基本型別混用不同概念──就能提升系統可靠度。Kotlin 的型別系統能協助明確建模領域概念,將不合法狀態移到編譯期並提早發現錯誤。透過更謹慎的型別設計、善用空值安全與代數型別,以及以型別化介面取代無結構資料,團隊可以降低缺陷率與維運成本。核心訊息是實際且具體的:小幅調整開發習慣,就能為軟體正確性與成本效益帶來顯著改善。
KT Academy
作者:
發布:09-23 00:05
Scope functions
Learn what let, also, apply and with do and how to use them in your applications.
重點摘要
Scope functions let you run a block with an object in scope.
They differ by how the object is referenced (it vs this) and by return value.
Common uses include null-safe chaining, configuration, side effects, and grouping operations.
Scope functions in Kotlin — let, also, apply and with — provide concise ways to execute a block of code with an object in scope. They differ primarily in how the object is referenced inside the block ('it' for let/also, 'this' for apply/with) and in what they return (the block result vs the original object). let is often used for null-safe chaining and temporary transformations; also is useful for performing side effects while returning the same object; apply is convenient for configuring an object during initialization and returning it; with is suited for grouping multiple operations on an object when you don’t need chaining. Choosing among them depends on whether you need the object as 'it' or 'this', whether you want the block result or the original object returned, and whether you prefer expression chaining or statement-style grouping.
范围函数
了解 let、also、apply 与 with 的作用,以及如何在应用中使用它们。
重點摘要
在代码块内以对象为范围执行操作以简化表达。
区别在于如何引用对象(it 或 this)以及返回值的不同。
常见用途包括空安全链式、对象配置、副作用操作与集中处理。
在 Kotlin 中,scope functions(let、also、apply、with)提供在局部范围内操作对象的简洁语法。它们的主要区别在于代码块内如何引用对象(let/also 使用 it,apply/with 使用 this)以及返回值是代码块的结果还是原对象。let 常用于空安全和临时转换;also 适合执行副作用同时返回原对象;apply 用于对象初始化或配置并返回自身;with 方便在不需要链式调用时对对象进行多项操作。选择时应考虑是否需要 it 或 this、是否需要返回块结果或原对象,以及是否偏好链式或陈述式写法。合理使用能使代码更简洁且更具可读性。
範圍函式
了解 let、also、apply 與 with 的用途,以及如何在應用程式中使用它們。
重點摘要
在區塊內以物件為範圍執行程式碼以簡化寫法。
差異在於如何參考物件(it 或 this)與回傳值類型。
常用於 null 安全串接、物件設定、副作用操作與集中處理。
在 Kotlin 中,scope functions(let、also、apply、with)提供在區域中操作物件的簡潔語法。它們的主要差別在於區塊內如何參考物件(let/also 使用 it,apply/with 使用 this)以及回傳值是區塊結果還是原物件。let 常用於 null 安全與臨時轉換;also 適合執行副作用但回傳原物件;apply 用於物件初始化或設定並回傳自身;with 則適合在不需要鏈式呼叫時對物件集中操作。選擇時應依據是否需要 it 或 this、是否要回傳運算結果或原物件,以及是否偏好串接或敘述式寫法。妥善運用這些函式能使程式更簡潔且具可讀性。
KT Academy
作者:
發布:09-28 00:00
Effective Kotlin Item 1: Limit Mutability
Limiting mutability reduces bugs and complexity, and Kotlin provides language features to make immutability the default and easy to enforce.
重點摘要
Prefer immutable data by default and minimize use of var
Expose mutable state only through narrow, controlled APIs
Kotlin features (val, read-only interfaces, immutable collections, copy) help enforce immutability
Limiting mutability reduces bugs, makes code easier to reason about, and simplifies testing and concurrency. Kotlin encourages immutability by default with val, read-only interfaces and immutable collection types; developers should prefer immutable data, expose mutable state through narrow, controlled APIs, and use defensive copies when necessary. Limiting the scope of vars, using private setters, local variables, and data class copy methods further contain change and make intent explicit. For concurrent code, immutable objects avoid race conditions and reduce synchronization needs. Practical guidance includes returning read-only views, accepting immutable inputs, favoring pure functions and stateless objects, and avoiding mutable global state—patterns that improve maintainability and make refactoring safer while leveraging Kotlin’s built-in support for immutability.
Effective Kotlin 条目 1:限制可变性
限制可变性可以减少错误与复杂性,Kotlin 提供语言特性以默认不可变并便于体现不可变意图。
重點摘要
默认优先不可变数据,尽量少用 var
仅通过受控、狭窄的 API 暴露可变状态
使用 Kotlin 的 val、只读接口、不可变集合与 copy 语义来强化不可变性
限制可变性能减少错误、简化推理与测试。Kotlin 通过 val、只读接口与不可变集合鼓励默认不可变,建议优先使用不可变类型,将可变性封装在最小范围并通过受控 API 暴露,必要时采用防御性复制。缩小 var 的作用域、使用 private setter 与 data class 的 copy 方法可控制变更;在并发场景下,不可变对象可避免竞态并减少同步开销。实务上应返回只读视图、接受不可变输入、倾向纯函数与无状态对象,并避免全局可变状态,从而提升可维护性与重构安全性。
Effective Kotlin 條目 1:限制可變性
限制可變性能降低錯誤與複雜度,而 Kotlin 提供語言特性以使不可變成為預設並便於強制執行。
重點摘要
預設使用不可變資料,盡量避免 var
以受控且狹窄的 API 暴露可變性
使用 Kotlin 的 val、唯讀介面、不可變集合與 copy 支援不可變性
限制可變性能降低錯誤、簡化推理與測試。Kotlin 透過 val、唯讀介面與不可變集合鼓勵預設不可變,建議以不可變型別為優先,將可變性封裝於最小範圍並透過受控 API 暴露,必要時使用防禦性複製。縮小 var 範圍、使用 private setter 與 data class 的 copy 方法可控制變更;在並發情境下,不可變物件能避免競態條件並減少同步需求。實務建議包括回傳唯讀檢視、接受不可變輸入、傾向純函式與無狀態物件,以及避免全域可變狀態,以提升可維護性與重構安全性。
KT Academy
作者:
發布:10-07 00:05
Context receivers
All you need to know about the new and powerful Kotlin feature: context receivers.
重點摘要
Introduce Kotlin's context receivers as implicit contextual providers
Explain benefits: reduced boilerplate and clearer API expression
Cover usage patterns, trade-offs, and practical adoption advice
This article provides a focused, practical introduction to Kotlin's context receivers, a language feature that lets functions and types declare additional implicit receivers that supply contextual dependencies. It explains why context receivers matter: they let APIs express required environments without passing parameters explicitly, reduce boilerplate, and improve code organization and readability. The piece outlines common usage patterns, how context receivers complement extension functions and traditional receivers, and where they fit in DSL design and layered abstractions. It also covers practical considerations for adoption — readability trade-offs, composition patterns, and typical pitfalls — and illustrates concepts with examples and recommendations to help developers use the feature safely and effectively. Overall, it aims to give readers the essential knowledge to understand, evaluate, and start using context receivers in Kotlin projects.
Context receivers
你需要了解的 Kotlin 新且强大的特性:context receivers。
重點摘要
介绍 context receivers 作为提供上下文的隐式接收器
强调可减少样板代码并提升 API 的表达性与可读性
覆盖使用场景、设计模式与采纳时的实践建议
本文为 Kotlin 新特性 context receivers 提供了简明且实用的入门与实践指南,阐述该机制如何让函数与类型声明额外的隐式接收器以提供执行上下文,从而无需显式传递多个参数,减少样板代码并改善 API 的表达性与可读性。文章说明常见的使用模式,讨论 context receivers 与扩展函数、传统接收器的互补关系,并评估采纳时的考虑要点(可读性权衡、组合方式与常见陷阱)。通过示例与实务建议,帮助开发者判断何时采用该特性并在项目中安全实施。
Context receivers
你需要知道的 Kotlin 新強大特性:context receivers。
重點摘要
說明 context receivers 作為提供執行上下文的隱式接收器
強調可減少樣板碼並提升 API 的表達性與可讀性
涵蓋使用情境、設計模式與導入時的注意事項
本文是對 Kotlin 新增功能 context receivers 的完整入門與實務指南,說明這項語言機制如何讓函式與型別宣告額外的隱式接收器以提供執行上下文,從而免去直接傳遞多個參數、降低樣板碼並改善 API 的表達性與可讀性。文章說明常見使用情境與設計模式,討論 context receivers 與擴展函式、傳統接收器的互補關係,並評估導入時的考量(可讀性、組合方式與常見陷阱)。透過範例與實務建議,幫助開發者判斷何時採用該特性並安全地在專案中實作。
KT Academy
作者:
發布:10-12 00:00
Effective Kotlin — Item 5: Specify your expectations for arguments and state
How do we specify requirements and expectations in Kotlin?
重點摘要
Make expectations for function arguments and object state explicit
Validate inputs and invariants at boundaries to prevent misuse
Prefer clear types and design that makes contracts visible
This item addresses how to specify and enforce requirements and expectations in Kotlin code. It advocates making preconditions and invariants explicit so callers and implementers share a clear contract: document expected argument ranges and state, and validate them at module boundaries to catch misuse early. The guidance covers idiomatic ways to express expectations—through types, documentation, and runtime checks—so that assumptions are not hidden and invariants are easier to maintain. It also discusses pragmatic trade-offs between strict runtime enforcement and ergonomics, recommending focused checks where responsibilities cross boundaries while using type-level constraints and immutability to reduce the need for repeated checks. Overall, explicit expectations improve code safety, readability, and maintainability by clarifying who must ensure which conditions.
Effective Kotlin 第5条:为参数与状态指定期望与要求
我们如何在 Kotlin 中指定对参数与状态的要求与期望?
重點摘要
明确指定函数参数与对象状态的期望
在模块或 API 边界验证输入与不变条件
使用清晰类型与不可变性降低隐含假设
本条讨论在 Kotlin 中如何表述与执行对参数与状态的要求,主张将前置条件与不变条件明确化,让调用方与实现方共享一致的契约:在 API、文档或类型上表达预期,并在边界处进行验证以尽早捕获错误。建议采用类型约束、充分的文档以及必要的运行时检查,避免隐含假设导致难以维护的缺陷,同时说明在严格运行时强制与使用便利之间的权衡:在边界集中过滤错误、并以不可变性与类型设计减少重复检查。总体目标是通过明确的期望提高代码的安全性、可读性与可维护性。
Effective Kotlin 第五條:為參數與狀態指定預期與要求
我們如何在 Kotlin 中指定對參數與狀態的要求與期望?
重點摘要
明確指定函式參數與物件狀態的預期
在模組或 API 邊界驗證輸入與不變條件
以清晰型別與不可變性減少隱含假設
本條討論在 Kotlin 中如何表述與執行對參數與狀態的要求,主張將前置條件與不變條件明確化,讓呼叫方與實作方共享一致的契約:在 API、文件或型別上表達預期,並於邊界處進行驗證以儘早捕捉錯誤。建議採用型別層級的約束、良好文件與必要的執行時檢查,避免隱含假設造成難以維護的錯誤,同時說明在嚴格檢查與使用便利間的取捨:於邊界處集中檢查、以不可變性與明確型別降低重複檢查需求。總體目標是透過明確的預期提升程式的安全性、可讀性與可維護性。
KT Academy
作者:
發布:10-19 00:00
Effective Kotlin — Item 7: Prefer a nullable or Result result type when the lack of a result is possible
Avoid throwing exceptions for expected absence; represent missing results with nullable or Result types so the type system expresses possibility explicitly.
重點摘要
Return nullable or Result types instead of throwing exceptions for normal absence
Encoding absence in the type signature makes callers handle it explicitly
Using types improves clarity, predictability, and safer control flow
Item 7 of Effective Kotlin recommends returning a nullable type or a Result<T> when a function can legitimately have no value, rather than signaling that absence by throwing exceptions. Representing optionality in types makes APIs clearer and forces callers to consider the missing-case explicitly, avoiding use of exceptions for normal control flow. Nullable and Result types integrate with Kotlin’s null-safety and tooling, enabling safer code, easier reasoning about outcomes, and more predictable error propagation. This approach reduces surprising runtime failures, simplifies testing and handling of success/failure cases, and generally leads to more idiomatic and robust Kotlin code by making the possibility of no result first-class and visible in the function’s signature.
Effective Kotlin 第7条:在可能没有结果时,优先使用 nullable 或 Result 作为返回类型
避免通过抛出异常来表示预期的“无结果”;应使用 nullable 或 Result 类型让类型系统明确表达这种可能性。
重點摘要
遇到可能无结果的情况,返回 nullable 或 Result 而非抛出异常
在类型签名中表达缺值,促使调用方明确处理
以类型表示可选性能提升代码可读性和可预测性
Effective Kotlin 的第7条建议:当函数可能合法地没有结果时,应优先返回 nullable 类型或 Result<T>,而不是通过抛出异常来表示。把缺失的结果用类型来表达,可以让 API 更直观,并强制调用方显式处理这种情况,避免将异常当作正常控制流。nullable 与 Result 能与 Kotlin 的空安全机制和工具链协同,带来更安全的代码、更容易理解的结果传递和更可预测的错误传播,减少意外运行时失败,同时有利于测试和编写更惯用的 Kotlin 代码。
Effective Kotlin 第7條:當可能沒有結果時,優先使用 nullable 或 Result 作為回傳型別
避免以拋出例外表示預期的「沒有結果」;應以 nullable 或 Result 型別讓型別系統明確表達此可能性。
重點摘要
遇到可能沒結果的情況,回傳 nullable 或 Result 而非拋例外
在型別簽章中表達缺值,促使呼叫端明確處理
以型別表示可選性可提升程式可讀性與可預測性
Effective Kotlin 的第7條建議:若函式可能合法地沒有回傳值,應優先回傳 nullable 型別或 Result<T>,而不是透過拋出例外來表示。將缺值以型別呈現,可讓 API 更具表意性並強制呼叫端處理此情況,避免把例外當作一般控制流程手段。nullable 與 Result 可與 Kotlin 的語言特性(例如 null-safety 與工具鏈)整合,帶來更安全的程式、較易理解的執行結果傳播與較少意外的執行期錯誤,進而提升程式的可測試性與慣用性。
KT Academy
作者:
發布:10-24 00:00
Effective Kotlin Item 10: Design for readability
Do we really want our applications concise, or do we rather want them readable?
重點摘要
Weigh conciseness against readability when designing code.
Favor clarity even if it requires more explicit code.
Readable design reduces misunderstandings and maintenance costs.
Item 10 of Effective Kotlin poses a simple but important question: do we want our applications to be concise, or do we want them to be readable? The piece argues that readability should take precedence over compactness. Prioritizing readability means choosing code and designs that are easy to understand, maintain, and reason about—even if they require a few more lines or explicit constructs. Concise code can be attractive, but terseness that sacrifices clarity increases the risk of misunderstandings, bugs, and higher maintenance costs. The recommendation is to design APIs, modules, and idioms that communicate intent plainly and reduce surprise for future readers. In practice that means favoring expressive names, straightforward control flow, and conventions that make behavior predictable, so teams can work more efficiently and safely with the codebase.
Effective Kotlin 第10条:为可读性而设计
我们真的想让应用程序简洁,还是更希望它们可读?
重點摘要
设计时要在简洁与可读性之间取舍。
宁可使用更明确的代码也别牺牲清晰度。
可读性有助于减少误解和维护成本。
Effective Kotlin 第10条提出一个看似简单却重要的问题:我们要让应用程序变得简洁,还是让它们更易读?文章主张应把可读性放在优先位置,宁可使用更多明确的代码或说明来表达意图,也不要以高度简洁换取可理解性的降低。提高可读性有助于减少误解与错误、降低维护成本,并让团队更容易推断行为与意图。实际做法包括采用描述性命名、直观的流程和一致的设计约定,这些选择使未来阅读或修改代码的人能更快掌握程序含义。
Effective Kotlin 第10條:以可讀性為設計目標
我們是真的想要應用程式精簡,還是更希望它們易讀?
重點摘要
在設計時權衡簡潔與可讀性。
寧可用更明確的程式碼也不要犧牲清晰度。
可讀性有助於降低誤解與維護成本。
Effective Kotlin 第10條提出一個看似簡單但重要的問題:我們要讓應用程式變得簡潔,還是讓它們更易讀?文章主張應以可讀性為優先,寧可用更多明確的程式碼或敘述來表達意圖,也不要以高度簡潔犧牲理解力。提高可讀性有助於降低誤解和錯誤、減少維護成本,並讓團隊更容易推斷行為與意圖。實務上,可讀性體現在具描述性的命名、直觀的流程與一致的設計慣例,這些選擇讓未來閱讀或修改程式的人能更快掌握程式語意。
KT Academy
作者:
發布:11-07 00:00
Functional Kotlin book is finally ready!
An announcement about a recently published book focused on functional Kotlin features.
重點摘要
Announcement of a newly published book
Focus on functional features in Kotlin
Article directs readers to learn more via the provided link
The short article announces that a new book dedicated to functional features in the Kotlin language has been recently published. It serves primarily as a release notice, summarizing that the book's focus is on functional programming concepts as they apply to Kotlin and directing interested readers to the linked article for further information. Rather than providing in-depth excerpts or chapter details, the post functions as an entry point for developers who want to explore functional patterns and language features in Kotlin. Readers looking for availability, contents, or purchasing information are encouraged to follow the link to the full announcement to obtain complete details directly from the source.
Functional Kotlin 书籍终于准备好!
本文为一则发布,介绍一本近期出版、聚焦于 Kotlin 函数式特性的书籍。
重點摘要
宣布新书已发布
聚焦 Kotlin 的函数式特性
文章引导读者通过链接了解详情
这篇文章宣布一本专注于 Kotlin 函数式(functional)特性的书籍已于近期出版。文章以简短的发布通告为主,说明该书的重点是将函数式编程的概念应用于 Kotlin,并指引有兴趣的读者通过提供的链接获取更多信息。文章并未提供详细章节或摘录,而是作为想了解此主题的开发者获取新资源的入口;如需完整内容、可用性或购买信息,请参阅原文链接。
Functional Kotlin 書籍終於出版!
本文為一則宣告,介紹一本近期出版、專注於 Kotlin 函式化特性的書籍。
重點摘要
公告新書已出版
主題為 Kotlin 的函式化特性
文章引導讀者點選連結了解更多
這篇文章宣布一本專注於 Kotlin 函式化(functional)特性的書籍已經出版。內容以發布通告為主,說明該書聚焦於在 Kotlin 中運用函式式編程的概念與語言特性,並引導讀者透過內文提供的連結取得進一步資訊。文章本身並未詳列章節或摘錄內容,而是作為關注此主題的開發者了解新資源的起點;若需書籍的完整內容、取得或購買資訊,請參考原文連結。
KT Academy
作者:
發布:11-15 00:00
Kotlin Coroutines use cases for Data/Adapters Layer
Use coroutines to bridge callback-based or blocking APIs in the data/adapters layer by converting callbacks to suspending functions and isolating blocking calls.
重點摘要
Wrap callback APIs into suspend functions or callbackFlow
Run blocking calls on Dispatchers.IO using withContext
Expose cancellable suspend APIs and follow structured concurrency
Coroutines are an effective tool in the Data/Adapters layer to bridge callback-based or blocking libraries with a suspending, coroutine-friendly API. Typical approaches include wrapping callback-style APIs into suspend functions using suspendCoroutine or flows (callbackFlow) so callers can use structured concurrency and cancellation; executing blocking or legacy blocking calls on Dispatchers.IO with withContext to avoid blocking main or computation threads; and exposing clear, cancellable suspend functions from adapters so higher layers remain coroutine-native. Adapters should translate errors, manage resource cleanup and respect coroutine cancellation. Overall, choose suspension over blocking when possible, isolate blocking calls on the IO dispatcher, and adapt callbacks to suspend/flow interfaces to keep the data layer composable and testable.
Kotlin 协程在 Data/Adapters 层的使用情境
在数据/适配器层使用协程,可将 callback 或阻塞式 API 转为 suspend/Flow 接口,并将阻塞调用隔离到 IO dispatcher。
重點摘要
使用 suspendCoroutine 或 callbackFlow 封装 callback
用 withContext(Dispatchers.IO) 执行阻塞调用
提供可取消的 suspend API,并遵循结构化并发
在 Data/Adapters 层使用 Kotlin 协程,可以将 callback 或阻塞式 API 转为协程友好的 suspend/Flow 接口。常见做法是用 suspendCoroutine 或 callbackFlow 封装 callback,并通过 withContext(Dispatchers.IO) 将阻塞调用移到 IO dispatcher,避免阻塞主线程或计算线程。适配器应返回明确且可取消的 suspend 函数、处理错误与资源清理,并遵守结构化并发与取消机制。总体原则是优先使用非阻塞的 suspend/Flow,隔离必要的阻塞调用,使数据层易于组合与测试。
Kotlin 協程在 Data/Adapters 層的使用情境
在資料/適配器層使用協程,可將 callback 或阻塞式 API 轉為 suspend/Flow 介面,並將阻塞呼叫隔離到 IO dispatcher。
重點摘要
用 suspendCoroutine 或 callbackFlow 包裝 callback
以 withContext(Dispatchers.IO) 執行阻塞呼叫
提供可取消的 suspend API,遵守結構化並發
在 Data/Adapters 層使用 Kotlin 協程,可以把 callback 或阻塞式 API 轉為協程友善的 suspend/Flow 介面。常見做法是用 suspendCoroutine 或 callbackFlow 包裝 callback,並以 withContext(Dispatchers.IO) 將阻塞呼叫移到 IO dispatcher,避免阻塞主線程或計算線程。Adapter 應回傳明確且可被取消的 suspend 函式、處理錯誤與資源清理,並遵守結構化並發與取消機制。整體原則是優先使用非阻塞的 suspend/Flow,隔離必要的阻塞呼叫,讓資料層易於組合與測試。
KT Academy
作者:
發布:11-24 00:00
Kotlin Coroutines Use Cases for the Domain Layer
Examines how Kotlin Coroutines can be applied in the Domain Layer and the trade‑offs of embedding coroutine APIs versus keeping the domain layer framework‑agnostic.
重點摘要
Discusses patterns for using coroutines inside domain logic
Weighs trade‑offs between direct coroutine usage and keeping domain agnostic
Emphasizes design concerns like boundaries, testability, and context management
This article examines how Kotlin Coroutines can be applied in the Domain Layer of an application. It outlines common patterns and trade‑offs between integrating coroutine APIs directly into domain code and keeping the domain layer independent of concurrency frameworks. Key design concerns discussed include maintaining clear boundaries between layers, managing execution context and thread confinement, preserving testability, and avoiding leakage of platform‑specific types into domain logic. The piece advocates pragmatic choices—favoring suspend functions or small coroutine‑aware boundaries rather than pervasive framework types—to balance readability, decoupling, and testability. It also highlights practical considerations around error handling, cancellation behavior, and dispatcher provision, aiming to help architects and developers decide when and how to use coroutines without compromising domain purity.
在领域层使用 Kotlin Coroutines 的应用场景
探讨如何在领域层应用 Kotlin Coroutines,以及将协程 API 直接纳入与保持领域层框架无关之间的权衡。
重點摘要
介绍在领域逻辑中使用协程的常见模式
权衡直接使用协程与保持领域层无框架依赖的利弊
强调边界清晰、可测试性与上下文管理等设计要点
本文探讨如何在应用的领域层使用 Kotlin Coroutines,说明在何种情形下将协程 API 直接纳入领域逻辑或让领域层与并发框架分离的权衡。文章指出关键设计要点,包括保持层次边界清晰、处理执行线程与协程上下文、维持可测试性以及避免将平台特定类型泄露到领域层。文中建议务实做法,例如使用 suspend 函数或在明确边界处处理协程细节,而不是在整个领域层广泛使用框架类型,以平衡可读性、测试性与低耦合。同时还讨论了错误处理、取消机制与 dispatcher 注入等实务考量,帮助架构师与开发者在不牺牲领域纯粹性的前提下合理采用协程。
在領域層使用 Kotlin Coroutines 的應用情境
探討如何在領域層應用 Kotlin Coroutines,以及直接使用協程 API 與讓領域層保持框架無關之間的取捨。
重點摘要
說明在領域邏輯中使用協程的常見模式
比較直接使用協程與保持領域層無框架依賴的利弊
強調邊界清晰、可測試性與上下文管理等設計考量
這篇文章探討如何在應用程式的領域層使用 Kotlin Coroutines,說明在何種情況將協程 API 直接納入領域邏輯或讓領域層與並行框架分離的取捨。文章指出關鍵設計考量,包括維持層次邊界清晰、處理執行緒與協程上下文、保有可測試性,以及避免將平台特定型別洩漏到領域層中。文中主張務實做法,例如以 suspend 函式或在明確邊界處理協程細節,而非在整個領域層廣泛使用框架型別,以平衡可讀性、測試性與低耦合。文章亦提及錯誤處理、取消行為與 dispatcher 注入等實務面向,協助開發者在不犧牲領域純粹性的前提下合理採用協程。
KT Academy
作者:
發布:11-28 00:15
A bird's-eye view of Arrow: working with functions in Arrow Core
Learn essential Arrow Core functions for composition, memoization, recursion and function generation.
重點摘要
Composition helpers to combine and transform functions
Memoization utilities to cache function results
Recursion support and programmatic function generation
This article provides a concise overview of the core function utilities in Arrow Core. It explains how Arrow supplies small, composable helpers to build and combine functions, enable memoization to cache results, support recursion patterns, and generate new functions programmatically. The piece highlights the practical benefits of using these primitives — simplifying composition, improving performance through caching, and expressing recursive algorithms in a functional style — and sketches how they fit together in real code. Intended as a practical reference, the survey shows when to prefer built-in combinators over hand-rolled solutions and how function generators can reduce boilerplate. Readers learn the conceptual roles of composition, memoization, recursion, and function factories and come away able to apply Arrow’s utilities to structure clearer, more reusable function-based code.
Arrow 一览:在 Arrow Core 中处理函数
了解 Arrow Core 中用于函数组合、记忆化、递归与函数生成的核心函数。
重點摘要
函数组合的辅助工具
记忆化以缓存函数结果
递归支持与程序化生成函数
本文概述 Arrow Core 中与函数操作相关的核心工具,介绍用于函数组合、结果缓存(记忆化)、递归支持与程序化生成函数的常用函数。文章说明这些原语如何让函数更易组合、通过缓存提升性能,以及以函数式风格表达递归逻辑的好处,并示范何时选择内建组合子以减少手写样板代码。作为实用参考,读者可据此理解各类函数工具的角色,并在实际代码中应用 Arrow 的工具来编写结构更清晰、可重用的函数化代码。
Arrow 一覽:在 Arrow Core 中處理函式
了解 Arrow Core 中用於函式組合、記憶化、遞迴與函式產生的核心函數。
重點摘要
函式組合的輔助工具
記憶化以快取函式結果
遞迴支援與程式化產生函式
本文概覽 Arrow Core 中與函式操作相關的核心工具,介紹用於函式組合、結果快取(記憶化)、遞迴支援與程式化產生函式的常用函數。文章說明這些原語如何讓函式更易組合、透過快取提升效能,以及以函式式風格表達遞迴邏輯的好處,並示範何時選用內建組合子以減少手寫樣板程式碼。適合作為實務參考,讀者可據此理解各類函式工具的角色,並在實際程式中應用 Arrow 的工具來撰寫結構更清晰、可重用的函式化程式碼。
KT Academy
作者:
發布:11-30 00:00
Kotlin Coroutines for the Presentation / API / UI Layer
Create a lifecycle-aware CoroutineScope and start coroutines to run UI, API and presentation tasks without blocking the main thread.
重點摘要
Use lifecycle-aware scopes (viewModelScope, lifecycleScope) for UI work
Prefer structured concurrency and proper cancellation to avoid leaks
Run IO/network on Dispatchers.IO and update UI on Dispatchers.Main
This short guide describes how to use Kotlin Coroutines in the Presentation/API/UI layer by creating appropriate CoroutineScopes and launching coroutines in a lifecycle-aware manner. In typical UI apps, prefer scope implementations tied to lifecycle owners (for example viewModelScope or lifecycleScope) so work is cancelled automatically and resources are not leaked. Apply structured concurrency: launch coroutines from a defined scope, propagate cancellation, and use SupervisorJob only where failures should be isolated. Offload blocking or long-running tasks to Dispatchers.IO or Default, and perform UI updates on Dispatchers.Main. Expose suspend functions or Flow/StateFlow from lower layers and collect them in the UI. Handle exceptions with try/catch, CoroutineExceptionHandler, and ensure predictable cleanup to maintain responsive, safe UI and API interactions.
Kotlin 协程在 Presentation/API/UI 层的使用
在可观测的生命周期 CoroutineScope 中启动协程,以非阻塞方式处理 UI、API 与展示逻辑。
重點摘要
使用与生命周期绑定的 scope(如 viewModelScope、lifecycleScope)
采用结构化并发和正确的取消机制以避免泄漏
IO/网络任务使用 Dispatchers.IO,UI 更新在 Dispatchers.Main
本文介绍在 Presentation/API/UI 层如何创建和使用 Kotlin 协程:将任务放在与生命周期绑定的 CoroutineScope(例如 viewModelScope 或 lifecycleScope)以防止资源泄漏;遵循结构化并发,从特定 scope 启动协程并正确传播取消,必要时用 SupervisorJob 隔离失败;把耗时或阻塞操作切到 Dispatchers.IO/Default,在 Dispatchers.Main 更新界面。建议通过 suspend 函数或 Flow/StateFlow 从下层暴露数据,由 UI 层收集并处理异常(try/catch、CoroutineExceptionHandler),并确保按需取消与清理以保持界面响应和行为可预期。
Kotlin 協程在 Presentation/API/UI 層的使用
在可觀察生命週期的 CoroutineScope 中啟動協程,以非阻塞方式處理 UI、API 與呈現邏輯。
重點摘要
使用與生命週期綁定的 scope(如 viewModelScope、lifecycleScope)
以結構化並發與取消管理避免記憶體洩漏與不確定行為
IO/網路工作用 Dispatchers.IO,UI 更新在 Dispatchers.Main
本文說明在 Presentation/API/UI 層如何建立與使用 Kotlin 協程:將工作放在與生命週期綁定的 CoroutineScope(例如 viewModelScope 或 lifecycleScope)以避免洩漏與無效執行;採用結構化並發,從指定 scope 啟動協程並正確傳播取消,必要時使用 SupervisorJob 隔離失敗;將阻塞或耗時工作交給 Dispatchers.IO/Default,並在 Dispatchers.Main 更新 UI。建議上層以 suspend 函式或 Flow/StateFlow 暴露資料,UI 層負責收集與錯誤處理(try/catch、CoroutineExceptionHandler),並確保適時取消與清理以維持介面回應性與穩定性。
KT Academy
作者:
發布:12-06 00:15
A birds-eye view of Arrow: Error Handling
Learn about error handling in Arrow and how to effectively work with Either.
重點摘要
Overview of error handling concepts in Arrow
Either as the primary abstraction for fallible computations
Practical guidance for using Either effectively
The article provides a concise, high-level overview of error handling in Arrow and focuses on the Either type as the primary abstraction for computations that can fail. It explains why using functional error types matters, how Either models success and failure, and how Arrow’s utilities help you construct, combine and transform fallible computations in a predictable, composable way. The piece outlines practical strategies to adopt Either in real codebases, discusses common patterns for mapping, chaining, and lifting errors into functional flows, and highlights trade-offs compared with exception-based approaches. Throughout, readers are guided toward cleaner, more explicit error handling that improves testability and reasoning about failure. The article is intended as an accessible introduction for Kotlin developers exploring Arrow’s error-handling capabilities and for teams aiming to adopt functional error patterns.
鸟瞰 Arrow:错误处理
了解 Arrow 的错误处理,以及如何有效使用 Either。
重點摘要
介绍 Arrow 的错误处理概念
说明 Either 如何表示成功或失败
提供在实际中使用 Either 的建议
本文以鸟瞰视角介绍 Arrow 的错误处理,重点说明 Either 作为表示成功或失败的类型,以及如何在函数式风格中使用它来处理可能失败的运算。文章阐述采用函数式错误类型的理由,并提供实务建议,包括如何组合、转换与传播错误,使处理流程更可预测与可测试,同时说明与异常机制的取舍。阅读后,开发者与团队可以更有把握地在 Kotlin/Arrow 项目中引入与运用 Either,提高错误处理的明确性与可维护性。
鸟瞰 Arrow:錯誤處理
了解 Arrow 的錯誤處理,以及如何有效運用 Either。
重點摘要
介紹 Arrow 的錯誤處理概念
說明 Either 如何表示成功或失敗
提供在實務中運用 Either 的建議
本文以鳥瞰角度介紹 Arrow 的錯誤處理,重點說明 Either 作為表示成功或失敗的型別,以及如何在函式式風格中使用它來處理可能失敗的運算。文章說明採用功能性錯誤型別的理由,並提供實務建議,包括如何組合、轉換與傳播錯誤,使處理流程更可預測與可測試,也說明與例外機制的取捨。閱讀後,開發者與團隊能更有把握地在 Kotlin/Arrow 專案中導入與運用 Either 來提升錯誤處理的明確性與可維護性。
KT Academy
作者:
發布:12-07 00:00
Kotlin Coroutines use cases introduction
A brief announcement introducing a series of articles about common Kotlin Coroutines use cases.
重點摘要
Announces a new article series
Focuses on common Kotlin Coroutines use cases
Serves as the series' introductory note
This brief announcement introduces a series of articles that focus on common Kotlin Coroutines use cases. The piece serves as an opening note to the series, outlining that subsequent articles will examine practical scenarios where coroutines are applied in Kotlin development. It frames the series' intent to gather and present recurring coroutine patterns, typical problems they address, and real-world usage examples for developers. While concise, the introduction sets expectations for readers that the forthcoming content will concentrate on pragmatic coroutine use cases rather than language theory. It aims to guide readers through common decision points and practical trade-offs when choosing coroutine-based solutions in application code.
Kotlin Coroutines 使用场景导读
简短宣布一系列关于常见 Kotlin Coroutines 使用场景的文章,作为整体系列的导言。
重點摘要
宣布新的文章系列
聚焦常见的 Kotlin 协程使用场景
作为系列的开篇说明
本文为一则简短宣布,介绍一系列关于常见 Kotlin Coroutines 使用场景的文章。作为系列导言,它说明后续篇章将集中于实践中常见的协程应用,整理反复出现的模式、常见问题与实际示例,帮助开发者在项目中判断何时采用协程及相关取舍。此介绍以务实为主,设定读者期待:后续内容将侧重于实际运用,而非纯粹的语言理论,作为希望在日常开发中有效使用协程的 Kotlin 开发者的参考资料。
Kotlin Coroutines 使用情境導讀
簡短宣告一系列關於常見 Kotlin Coroutines 使用情境的文章,作為整體系列的導言。
重點摘要
宣告新的文章系列
聚焦常見的 Kotlin 協程使用情境
作為系列的開場說明
本文為一則簡短宣告,介紹一系列關於常見 Kotlin Coroutines 使用情境的文章。作為系列導言,它說明後續篇章將集中於實務上常見的協程應用,整理重複出現的模式、常見問題與實際範例,協助開發者在專案中判斷何時採用協程及相關取捨。此介紹以務實為主,設定讀者期待:後續內容將側重於實際運用,而非純粹語言理論,作為想在日常開發中有效運用協程的 Kotlin 開發者的參考。
KT Academy
作者:
發布:12-09 00:00
Slowing down your code with Coroutines
The article examines how to use coroutines to intentionally slow code execution and why doing so can be useful.
重點摘要
Shows how coroutines can introduce controlled delays
Explains motivations for slowing code such as testing and rate limiting
Notes practical concerns when adding delays to asynchronous flows
This short article explores how coroutines can be used to deliberately slow down program execution and explains why a developer might want to do that. It outlines the ways coroutines can introduce controlled delays into asynchronous code and discusses primary motivations — for example, to simulate latency during testing, to implement rate limiting, or to coordinate timing in user-facing features. The piece also highlights considerations when adding delays, such as maintaining responsiveness, avoiding deadlocks or unexpected ordering, and ensuring correctness of concurrent operations. Overall, it presents slowing via coroutines as a pragmatic tool for debugging, testing, and controlling execution timing when used with care.
用协程放慢你的代码
文章探讨如何使用协程有意放慢代码执行,以及这样做的理由。
重點摘要
说明协程如何引入可控的延迟
讨论放慢执行的动机,如测试和限速
提示在异步流程中加入延迟的实务考量
本文介绍如何利用协程在异步代码中刻意放慢执行,并解释开发者为何会采用这种做法。文章描述协程引入可控延迟的方式,指出主要用途,比如在测试中模拟网络或处理延迟、实现速率限制或协调界面时间行为。同时提醒在加入延迟时需顾及响应性、避免死锁或意外的执行顺序问题,并确保并发操作仍然正确。总体而言,将协程用于放慢执行是一种有其用途但需小心应用的手段。
用 Coroutine 放慢程式執行
本文探討如何使用協程刻意放慢程式執行,以及為什麼這樣做會有用。
重點摘要
示範協程如何引入可控制的延遲
說明放慢程式的動機,例如測試與速率限制
提醒在非同步流程中加入延遲的實務注意事項
本文說明如何利用協程在非同步程式中刻意放慢執行步調,並解釋開發者為何會需要這麼做。文章描述協程引入可控延遲的方式,並指出主要用途,例如在測試時模擬延遲、實作輸出速率限制或協調使用者介面的時間行為。同時提醒在加入延遲時需注意維持回應性、避免死鎖或導致執行順序錯亂,以及確保並發操作的正確性。總體上將協程放慢視為一種有用但需謹慎使用的工具。
KT Academy
作者:
發布:12-12 00:01
Functions in Kotlin
Learn about what functions can offer us in Kotlin.
重點摘要
Introduces core capabilities of Kotlin functions
Explains how functions improve code organization and reuse
Covers practical function-related features and usage
This article introduces functions in Kotlin and explains what they can offer developers. It outlines the role of functions as the primary building blocks for organizing behavior, handling input and output via parameters and return values, and enabling modular, reusable code. The piece summarizes common function-related features that Kotlin provides — such as concise syntax, expression bodies, default and named arguments, higher-order functions and lambdas, and extension functions — and shows why these capabilities matter for writing clearer, more maintainable applications. Emphasis is placed on practical learning: by studying Kotlin functions and their patterns, developers can adopt functional and modular styles that simplify logic, reduce duplication, and interoperate smoothly with existing Java codebases.
Kotlin 的函数
了解 Kotlin 的函数能为我们带来的功能和好处。
重點摘要
说明函数在代码组织中的核心作用
强调函数能提高代码的可读性与可重用性
介绍 Kotlin 在函数设计上的实用特性
本文介绍了 Kotlin 中的函数,讲述函数如何作为组织行为的基础单元,通过参数与返回值处理数据,并帮助构建模块化且可复用的代码。文章概述了 Kotlin 在函数方面的常见能力,例如简洁的函数语法、表达式主体、默认与命名参数、高阶函数与 lambda、以及扩展函数等,并说明这些特性如何促使代码更清晰、更易维护。文章强调实践学习:理解并运用这些函数特性,可以让开发者采用更简洁的函数式与模块化风格,减少重复代码并与 Java 平台良好互操作。
Kotlin 的函式
了解 Kotlin 的函式能為我們帶來的功能與好處。
重點摘要
說明函式在程式結構中的核心角色
強調函式可提升程式可讀性與可重用性
介紹 Kotlin 在函式上的實用語法與特性
本文介紹 Kotlin 中的函式,說明函式如何作為組織行為的基礎單位,透過參數與回傳值處理資料,並協助建立模組化且可重複使用的程式碼。文章概述 Kotlin 在函式設計上的常見能力,例如簡潔的函式語法、表達式主體、預設與命名參數、高階函式與 lambda、以及延伸函式等,並說明這些特性如何幫助撰寫更清楚、易維護的應用程式。重點在於實務學習:理解並運用這些函式特性,能讓開發者採用更簡潔的函式式與模組化風格,減少重複程式碼並與 Java 互操作。
KT Academy
作者:
發布:12-16 00:00
Kotlin Essentials book is finally ready!
Learn about our recently published book dedicated to the essential Kotlin features.
重點摘要
Announcement of a newly published book focused on Kotlin essentials
The book is dedicated to the language's core features
Readers are invited to learn more about the publication
This brief announcement presents the recent publication of a new book titled "Kotlin Essentials," dedicated to the essential features of the Kotlin programming language. The article invites readers to learn about the book and its focus on core language elements, offering a concise introduction to what the publication covers. It positions the book as a focused resource for anyone seeking a clear overview of Kotlin's fundamental constructs and key features. The piece aims to inform interested readers that the book is now available and encourages them to explore the publication for further details and explanations about Kotlin essentials.
《Kotlin Essentials》一书终于准备好!
了解我们最近出版的专注于 Kotlin 必要特性的书籍。
重點摘要
宣布新书已正式出版
书籍聚焦于 Kotlin 的核心必要特性
鼓励读者进一步了解该出版物
本文简要宣布新书《Kotlin Essentials》已正式出版,该书专注于 Kotlin 编程语言的必要特性。文章邀请读者了解这本书及其关注的核心语言要点,提供对出版物涵盖内容的概览,表明它是了解 Kotlin 基础构造与关键功能的集中资源。公告的目的是告知感兴趣的读者该书现已可得,并鼓励大家前往查看书籍以获取更多细节与说明。
《Kotlin Essentials》一書終於出版!
了解我們最近出版、專注於 Kotlin 必要特性的全新書籍。
重點摘要
宣布新書正式出版
內容專注於 Kotlin 的核心與必要特性
邀請讀者進一步了解該書與其內容
本文簡短宣布新書《Kotlin Essentials》已經出版,該書專注於 Kotlin 程式語言的必要與核心特性。文章邀請讀者了解這本書所涵蓋的重點,強調其對語言基礎概念的介紹與整理,作為想掌握 Kotlin 基本結構與重要功能的參考來源。此公告主要提供資訊,告知讀者該書現已發行,並鼓勵有興趣的人進一步查看出版內容以獲取更多詳情與說明。
KT Academy
作者:
發布:12-19 00:15
A birds-eye view of Arrow: Data Immutability with Arrow Optics
Learn to use Arrow Optics to support working on immutable objects.
重點摘要
Introduces Arrow Optics as a tool for immutable data manipulation
Shows how composing optics simplifies updates to nested structures
Emphasizes reducing boilerplate when working with immutable objects
This article provides an overview of Arrow Optics and how they help when working with immutable data. Arrow Optics are composable abstractions (such as lenses, prisms, and traversals) that let you focus on parts of a data structure to get, set, or modify values without mutating the original object. By composing optics you can concisely express updates to deeply nested fields, keeping code clear and safe from unintended side effects. The piece highlights practical benefits for functional-style Kotlin code: clearer intent, less boilerplate for copy-and-update patterns, and safer transformations of immutable models. It serves as an introduction for developers who want to adopt optics in their projects to manage immutable state more ergonomically.
鸟瞰 Arrow:使用 Arrow Optics 实现数据不可变性
学习使用 Arrow Optics 来支持对不可变对象的操作。
重點摘要
介绍 Arrow Optics 作为不可变数据处理的工具
说明组合 optics 可简化对嵌套结构的更新
强调减少处理不可变对象时的样板代码
本文概述了 Arrow Optics,并说明它们如何帮助在不可变数据上进行操作。Arrow Optics 是可组合的抽象(例如 Lens、Prism、Traversal 等),可以聚焦数据结构的某一部分以获取、设置或修改值,同时不改变原始对象。通过组合不同的 optics,可以简洁地表达对深层嵌套字段的更新,保持代码清晰并避免意外副作用。对于采用函数式风格的 Kotlin 开发者,使用 optics 可提升意图表达、减少复制与更新的样板代码,并更安全地转换不可变模型,是了解和应用不可变状态管理的实用入门。
一覽 Arrow:使用 Arrow Optics 實現資料不變性
學習使用 Arrow Optics 來支援對不可變物件的操作。
重點摘要
介紹 Arrow Optics 作為不可變資料處理的工具
說明組合 optics 可簡化對巢狀結構的更新
強調減少處理不可變物件時的樣板程式碼
本文概述了 Arrow Optics,說明它們如何協助在不可變資料上進行操作。Arrow Optics 是可組合的抽象(例如 Lens、Prism、Traversal 等),可以聚焦資料結構的某一部分以取得、設定或修改值,同時不改變原始物件。透過組合不同的 optics,可以簡潔地表達對深層巢狀欄位的更新,保持程式碼清晰並避免非預期的副作用。對採用函式風格的 Kotlin 開發者而言,使用 optics 可提升意圖表達、減少複製與更新的樣板程式碼,並更安全地轉換不可變模型,是進入不可變狀態管理實務的良好入門。
KT Academy
作者:
發布:01-09 00:00
Running Kotlin coroutines on Project Loom's virtual threads
How to use Project Loom to improve Coroutines performance.
重點摘要
Run Kotlin coroutines on Project Loom virtual threads
Potential performance gains for coroutine-based workloads
Considerations for dispatcher integration and trade-offs
This short article explains how to run Kotlin coroutines on Project Loom's virtual threads and how that can improve coroutines' performance. It describes the basic idea of using JVM-managed lightweight threads (virtual threads) as an execution substrate for coroutine work, and outlines the potential benefits—particularly for workloads that involve many blocking operations or high concurrency—by reducing context-switching and thread-management overhead. The piece also notes practical considerations when integrating virtual threads with coroutine dispatchers, including compatibility, scheduler behavior, and the need to measure real-world effects before adopting the approach in production. Overall, it serves as guidance for Kotlin developers curious about leveraging Project Loom to optimize coroutine-based code.
在 Project Loom 的虚拟线程上运行 Kotlin 协程
说明如何利用 Project Loom 的虚拟线程来提升 Coroutines 的性能。
重點摘要
在 Project Loom 的虚拟线程上运行 Kotlin 协程
可能为协程工作负载带来性能提升
调度器整合、兼容性与权衡应予以考量
本文介绍如何在 Project Loom 的虚拟线程上运行 Kotlin 协程,以提升协程的执行性能。文章说明虚拟线程作为 JVM 管理的轻量级线程,可作为协程的底层执行环境,并指出在大量阻塞操作或高并发场景中,虚拟线程可能降低上下文切换和线程管理开销,从而带来性能收益。文中还提到在将虚拟线程与 coroutine dispatcher 整合时的实际考量,包括兼容性、调度行为及潜在的权衡,并建议在生产环境采用前进行实际测试与量测。总体上为希望利用 Project Loom 优化协程代码的 Kotlin 开发者提供指引。
在 Project Loom 的虛擬執行緒上執行 Kotlin 協程
說明如何利用 Project Loom 的虛擬執行緒來提升 Coroutines 的效能。
重點摘要
在 Project Loom 的虛擬執行緒上執行 Kotlin 協程
對協程工作負載可能帶來效能提升
整合 dispatcher 與須注意的取捨與相容性
本文說明如何在 Project Loom 的虛擬執行緒上執行 Kotlin 協程,以改善協程的執行效能。文章闡述虛擬執行緒作為 JVM 管理的輕量級執行單元,可作為協程的底層執行環境,並說明在大量阻塞操作或高併發場景下,使用虛擬執行緒有助於降低上下文切換與執行緒管理開銷。文章同時提醒在整合 coroutine dispatcher 時的實務考量,包括相容性、排程行為與可能的取捨,並建議在投入生產前以實際量測判斷效果。整體上為有興趣利用 Project Loom 優化協程程式的 Kotlin 開發者提供指引。
KT Academy
作者:
發布:01-10 00:01
Your first program in Kotlin
Learn how to write your first Kotlin program, apply it in real projects, and inspect what Kotlin compiles to.
重點摘要
Create and run a minimal Kotlin program
Integrate Kotlin into real-world projects and build systems
Inspect compiled outputs (JVM bytecode, JS bundles, native binaries)
This brief guide shows how to write your first Kotlin program, how to use that code in real-life projects, and how to explore what Kotlin is compiled to. It covers creating a minimal program and running it with an IDE, the Kotlin command-line compiler, or the REPL, then integrating Kotlin into build tools like Gradle or Maven for applications. It also explains how to inspect compiled artifacts—JVM .class files, JavaScript bundles from Kotlin/JS, or native binaries from Kotlin/Native—using decompilers, compiler flags, or IDE features. The goal is to help beginners get code running quickly, place Kotlin within actual projects, and understand the generated output across platforms so they can reason about runtime behavior and deployment.
你的第一个 Kotlin 程序
介绍如何编写第一个 Kotlin 程序、在实际项目中使用,以及如何查看 Kotlin 的编译结果。
重點摘要
创建并运行最小的 Kotlin 程序
将 Kotlin 集成到真实项目和构建系统中
查看编译输出(JVM class、JavaScript、原生二进制)
本文介绍如何编写你的第一个 Kotlin 程序、如何在实际项目中使用,以及如何查看其编译结果。内容包括创建最小可执行程序、在 IDE 或命令行(如 kotlinc、REPL)中运行,并通过 Gradle 或 Maven 等构建工具将 Kotlin 整合到应用中。同时说明如何检查编译产生的产物,例如 JVM 的 .class 文件、Kotlin/JS 生成的 JavaScript、或 Kotlin/Native 的原生二进制,并借助反编译器或编译器选项查看生成代码,帮助初学者快速上手并理解 Kotlin 在不同平台上的实际输出。
你的第一個 Kotlin 程式
說明如何撰寫第一個 Kotlin 程式、在實務專案中使用,以及如何檢視 Kotlin 的編譯結果。
重點摘要
建立並執行最小的 Kotlin 程式
將 Kotlin 整合到實際專案與建置系統中
檢視編譯輸出(JVM class、JavaScript、原生二進位)
本文說明如何撰寫你的第一個 Kotlin 程式、如何在實際專案中使用,以及如何檢視編譯結果。內容包括建立最小可執行程式、在 IDE 或命令列(如 kotlinc、REPL)中執行,並透過 Gradle 或 Maven 等工具整合到應用中。也介紹如何檢查編譯輸出,例如 JVM 的 .class 檔、Kotlin/JS 產生的 JavaScript、或 Kotlin/Native 的原生二進位,並利用反編譯器或編譯器選項觀察生成的程式碼,幫助初學者快速上手並理解 Kotlin 在不同平台上的實際產出。
KT Academy
作者:
發布:01-12 00:00
Kotlin bites on Twitter 1
A collection of concise Kotlin knowledge bites presented as tweets.
重點摘要
Short, focused Kotlin tips
Formatted as tweet-sized entries
First installment of the series
This page collects concise pieces of Kotlin knowledge presented in the format of tweets. Each entry is designed to deliver a single idea, tip, or reminder in a compact, easily shareable form suitable for quick reading and reference. The collection targets Kotlin developers and learners who prefer bite-sized technical notes rather than long-form articles. As the first installment, it introduces the concept of delivering practical Kotlin insights in tweet-length items, offering a way to consume and revisit small, actionable points about the language, idioms, or tooling without requiring extended attention. The format encourages regular, incremental learning and quick recall.
Kotlin 推文小贴士 1
以推文形式呈现的 Kotlin 短知识集合。
重點摘要
简短聚焦的 Kotlin 提示
以推文长度编写,便于分享
系列的第一期
本页面收集了以推文形式呈现的 Kotlin 短知识,每条内容都聚焦于单一观点、技巧或提醒,字数精简,方便快速阅读与回顾。目标读者为希望利用碎片时间学习或复习 Kotlin 要点的开发者与学习者。作为系列的第一期,它展示了如何用推文长度的条目传达实用且可操作的 Kotlin 知识点,鼓励通过短小、持续的学习方式来提升记忆与实际应用能力。
Kotlin 推文小知識 1
以推文形式呈現的 Kotlin 短知識集合。
重點摘要
短而集中的 Kotlin 技巧
以推文長度呈現,方便分享
系列的第一篇章
此頁面蒐集以推文形式呈現的 Kotlin 短知識,每則內容聚焦單一觀念、技巧或提醒,篇幅精簡便於快速閱讀與複習。目標讀者為希望以零碎時間學習或回顧語言要點的 Kotlin 開發者與學習者。作為系列的第一篇,本集合示範如何用推文長度的條目傳達實用且可操作的 Kotlin 觀念,鼓勵以短、小步驟的方式持續吸收技術內容,提升記憶與應用的便利性。
KT Academy
作者:
發布:01-18 00:01
The power of Kotlin for-loop
Learn about the amazing capabilities of Kotlin for-loop.
重點摘要
Introduces the capabilities of Kotlin's for-loop
Highlights concise, expressive syntax
Encourages practical use to appreciate expressiveness and safety
This short article introduces the capabilities of Kotlin's for-loop and explains why it is considered powerful. It presents the for-loop as a central control structure in Kotlin, outlines its concise and expressive syntax, and emphasizes how it can iterate over ranges, collections, and sequences in a readable way. The piece is aimed at programmers who want to understand how Kotlin's for-loop differs from and improves upon traditional loop constructs, with a focus on clarity and idiomatic usage. Readers are encouraged to try Kotlin for-loops in practical code to appreciate their expressiveness and safety. Overall, the article serves as a compact primer that highlights the for-loop's role in writing concise, maintainable Kotlin code and invites further exploration of Kotlin language features.
Kotlin for 循环的威力
了解 Kotlin for 循环的强大功能。
重點摘要
介绍 Kotlin for 循环的功能
强调语法简洁且富有表达力
鼓励在实践中体会其可读性与安全性
这篇短文介绍 Kotlin 的 for 循环功能,说明其被视为强大的原因。文章指出 for 循环在 Kotlin 中是重要的控制结构,语法简洁且具表达力,能够清晰地遍历范围、集合与序列。本文旨在让程序员了解 Kotlin for 循环与传统循环的差异与优势,强调可读性与惯用写法,并鼓励读者在实际代码中尝试以体会其表达力与安全性,作为进一步探索 Kotlin 特性的入门说明。
Kotlin for 迴圈的威力
了解 Kotlin for 迴圈的強大功能。
重點摘要
介紹 Kotlin for 迴圈的功能
強調語法簡潔且具表達力
鼓勵在實作中體會其可讀性與安全性
這篇短文介紹 Kotlin 的 for 迴圈功能,說明其被視為強大的原因。文章指出 for 迴圈在 Kotlin 中是重要的控制結構,語法簡潔而具表達力,能清楚地遍歷範圍、集合與序列。本文目的是讓程式設計師了解 Kotlin for 迴圈與傳統迴圈的差異與優勢,強調可讀性與慣用寫法,並鼓勵讀者在實際程式中嘗試以體會其表達力與安全性,作為進一步探索 Kotlin 特性的入門說明。
KT Academy
作者:
發布:01-23 00:01
Operator overloading in Kotlin
Kotlin implements operators as specially named functions annotated with the operator modifier, allowing types to provide custom operator behavior.
重點摘要
Operators are implemented as functions marked with the operator modifier.
Language-defined operator names (plus, minus, get, set, compareTo, invoke, etc.) map to syntax.
You can provide custom behavior by declaring operator functions in classes or extensions.
In Kotlin, operators are not separate language constructs but ordinary functions with specific names that the compiler recognizes when marked with the operator modifier. Common operators like +, -, [], ==, <, and function-call syntax correspond to function names such as plus, minus, get, set, compareTo, and invoke. These operator functions can be declared as member or extension functions, enabling types to define how standard operators behave for their instances. While you cannot invent new operator symbols, you can overload existing operators by implementing the appropriate operator-named functions, following Kotlin's rules for parameter lists and return types. Proper operator overloading improves expressiveness and readability when used consistently and in keeping with conventional semantics.
Kotlin 的运算符重载
Kotlin 将运算符映射为具有特定名称并加上 operator 修饰的函数,从而允许类型自定义运算符行为。
重點摘要
运算符由带 operator 修饰的具名函数来实现。
plus、minus、get、set、compareTo、invoke 等名称对应到语法运算符。
可以在类或扩展函数中声明 operator 函数以实现自定义行为。
在 Kotlin 中,运算符不是独立的语法元素,而是由具有特定名称并加上 operator 修饰的普通函数实现。常见运算符(如 +、-、[]、==、<、函数调用语法)分别对应 plus、minus、get、set、compareTo、invoke 等函数名。这些 operator 函数可以作为成员函数或扩展函数存在,从而让类型定义在使用标准运算符时的行为。虽然无法创建新的运算符符号,但可以通过实现相应名称的 operator 函数来重载现有运算符,并需遵循 Kotlin 对参数与返回类型的规则以保持语义一致性和可读性。
Kotlin 的運算子多載
Kotlin 將運算子對應到具名函式,使用 operator 修飾可讓型別自訂運算子行為。
重點摘要
運算子以加上 operator 關鍵字的具名函式來實作。
像 plus、minus、get、set、compareTo、invoke 等名稱對應到語法運算子。
可在類別或擴充函式中宣告 operator 函式以自訂行為。
在 Kotlin 中,運算子不是獨立語法,而是由具有特定名稱且加上 operator 修飾的普通函式來實現。常見的運算子(例如 +、-、[]、==、<、函式呼叫語法)分別對應到 plus、minus、get、set、compareTo、invoke 等函式名稱。這些 operator 函式可以是成員或擴充函式,使型別可以定義其實例在使用標準運算子時的行為。雖然無法新增自定符號,但可透過實作相應名稱的 operator 函式來多載現有運算子,並應遵守 Kotlin 對參數與回傳型別的規範,以維持可讀性與語意一致性。
KT Academy
作者:
發布:02-01 00:01
Enum classes in Kotlin
Enum classes represent a fixed set of named constants and the article explains how to declare and use them in Kotlin.
重點摘要
Defines a type with a fixed set of named constants
Shows how to declare and access enum entries
Explains common usage in control flow and modeling finite value sets
This article introduces enum classes in Kotlin, explaining that they represent a type with a fixed set of named constants and describing how to declare and use them. It outlines declaration syntax, how to access enum entries, and how enums are used in control flow such as when-expressions or switch-like constructs. The article notes that enums can carry associated data and behaviors, enabling more expressive modeling of domain values, and it emphasizes practical benefits like clearer code, improved type safety, and prevention of invalid values. Examples demonstrate declaring enum entries, iterating over values, and referencing specific constants from code. Overall, the piece gives a concise conceptual overview and basic usage patterns so developers can choose enums to model finite sets of related values in Kotlin applications.
Kotlin 中的 enum 类
enum 类用于定义一组固定的命名常量,文章说明了如何在 Kotlin 中声明并使用它们。
重點摘要
用于定义一组固定的命名常量
说明声明语法与访问枚举项
演示在控制流程与建模有限值集合中的应用
本文介绍 Kotlin 的 enum class,说明它用于定义一组固定的命名常量,并示范如何声明与使用。文章说明基本语法、如何访问枚举成员及在控制流程(例如 when)中的运用,并指出 enum 可以携带数据与行为,使领域值建模更具表达力。文中强调 enum 有助于代码更清晰、提高类型安全并避免无效值,并通过示例展示声明、枚举与访问的方式。总体上提供了概念性概述与基本使用模式,帮助开发者在 Kotlin 项目中使用 enum 来建模有限的相关值集合。
Kotlin 的 enum 類別
enum 類別用來定義一組固定的命名常數,文章說明如何在 Kotlin 中宣告與使用它們。
重點摘要
用以定義一組固定的命名常數
說明宣告語法與存取列舉成員
示範在控制流程與建模有限值集合的使用
本文介紹 Kotlin 的 enum class,說明它用來定義一組固定的命名常數,並示範如何宣告與使用。文章說明基本語法、如何存取列舉成員及在控制流程(例如 when)中運用,並指出 enum 可攜帶資料與行為,讓領域值表徵更具表達力。文中強調 enum 有助於程式更清晰、提高型別安全並避免無效值,並透過範例示範宣告、列舉與存取方式。總結則提供概念性說明與實用使用模式,幫助開發者在 Kotlin 專案中以 enum 建模有限的相關值集合。
KT Academy
作者:
發布:02-08 00:15
Kotlin Generic Variance Modifiers
What 'out' and 'in' are, and how you may use them without even realizing it.
重點摘要
'out' and 'in' are Kotlin variance modifiers for generics
They constrain how type parameters are used (producer vs consumer)
Developers often rely on them implicitly through API design
This short piece introduces Kotlin's generic variance modifiers, 'out' and 'in', and explains their practical purpose. It describes how 'out' marks a type parameter for output-only (producer) positions and 'in' marks it for input-only (consumer) positions, enforcing safe subtyping relationships and preventing incompatible assignments. The article emphasizes that many developers encounter and use these modifiers indirectly—through method signatures, return types, and collection APIs—without consciously thinking about variance. By calling attention to the roles of 'out' and 'in', the text aims to make readers more aware of how Kotlin applies variance rules, how those rules affect assignment and compatibility, and how intentionally using them can clarify intent and improve type safety in generic APIs.
Kotlin 泛型变异修饰符
说明 out 与 in 是什么,以及你可能在不经意间就已经在使用它们。
重點摘要
out 与 in 是 Kotlin 的泛型变异修饰符
分别限制类型参数的输出(生产者)或输入(消费者)位置
开发者常通过 API 使用它们而未必有明确意识
本文介绍了 Kotlin 中的泛型变异修饰符 out 和 in,并解释了它们的实际作用。out 表示该类型参数仅用于输出(生产者)位置,in 则表示仅用于输入(消费者)位置,从而建立安全的子类型关系并防止不兼容的赋值。文章指出,开发者经常通过方法签名、返回类型或集合 API 间接使用这些修饰符,往往并未刻意意识到变异概念。通过说明 out 与 in 的角色,旨在让读者了解 Kotlin 如何应用变异规则,以及如何通过有意识地使用这些修饰符来更清楚地表达意图并提升泛型 API 的类型安全性。
Kotlin 泛型變異修飾詞
說明 out 與 in 是什麼,以及你可能在不自覺中就已經在使用它們。
重點摘要
out 與 in 是 Kotlin 的泛型變異修飾詞
分別限制型別參數的輸出(生產者)或輸入(消費者)位置
許多情況下開發者會透過 API 使用它們而無明確意識
本文介紹 Kotlin 中的泛型變異修飾詞 out 與 in,並說明其實際用途。out 用於標示只能作為輸出(生產者)使用的型別參數,in 則標示只能作為輸入(消費者)使用的型別參數,藉此建立安全的子型別關係並避免不相容的指派。文章強調,開發者常透過方法簽名、回傳型別或集合 API 間接接觸並使用這些修飾詞,往往沒有特別意識到變異概念。提醒讀者注意 out 與 in 的角色,可幫助理解 Kotlin 如何施行變異規則,以及如何藉由刻意使用這些修飾詞來表達意圖並提升泛型 API 的型別安全性。
KT Academy
作者:
發布:02-13 00:15
Covariant Nothing Object
A pattern many of us use but few discuss.
重點摘要
A recurring, under‑discussed programming pattern is identified.
The pattern is widely used in practice yet rarely named explicitly.
The article calls for more awareness, naming and discussion of it.
This short article draws attention to the "Covariant Nothing Object," identified as a programming pattern that many developers employ but seldom name or discuss. Rather than presenting a deep technical tutorial, the piece highlights that this recurring pattern exists across codebases, outlines why it tends to arise, and notes the practical consequences of keeping it implicit. The author argues for making the pattern explicit through clearer naming and documentation so teams can better reason about type relationships, default or absent values, and design trade‑offs. Ultimately the article invites practitioners to acknowledge and examine this overlooked practice so its benefits and pitfalls can be understood and communicated more effectively.
协变的 Nothing 对象
一种我们都在用但很少有人谈论的模式。
重點摘要
提出一个常见却鲜少讨论的编程模式。
该模式在实践中广泛存在,但通常没有被明确命名。
文章呼吁通过命名与文档化来提升对该模式的关注与讨论。
这篇短文将“协变的 Nothing 对象”作为一个概念提出来,指出它是许多开发者在代码中使用但很少明确讨论的模式。文章并非深入技术教程,而是强调这一反复出现的实践现象,概述其产生背景与潜在后果,并主张应通过更清晰的命名与文档将其显性化。通过这样做,团队可以更好地讨论类型关系、默认或缺失值的处理以及设计权衡。作者借此邀请从业者关注并检视这一被忽视的习惯,以便更有效地理解和传达其利弊。
共變的 Nothing 物件
一種我們都在用、但很少人談論的模式。
重點摘要
指出一個常見但鮮少討論的程式設計模式。
該模式在實務中廣泛存在,卻通常沒有明確命名。
文章呼籲提高重視、以命名與文件化來促進討論。
這篇短文提出「共變的 Nothing 物件」這個概念,指出它是一種許多開發者在程式碼中實際使用但很少明說的模式。文章並非技術教學,而是強調這個反覆出現的實務現象,概述其產生的原因與隱含後果,並主張應以更清楚的命名與文件化將其顯性化。藉此,團隊能更清楚地討論型別關係、預設或缺失值的處理,以及設計取捨。作者藉此邀請從業者正視並檢視這個被忽略的習慣,以便更有效地理解與溝通其利弊。
KT Academy
作者:
發布:02-20 00:15
Variance modifiers limitations
Variance modifiers restrict how type parameters can be used by limiting positions for reads and writes.
重點摘要
Covariant (out) type parameters cannot be used as function parameter types.
Contravariant (in) type parameters cannot be used as return types.
Compiler workarounds (casts, annotations) exist but may break type safety.
Variance modifiers (such as covariant/out and contravariant/in) constrain how a generic type's parameters may be used: out/covariant parameters are allowed in consumer positions like returns but forbidden as function parameters, while in/contravariant parameters are allowed as inputs but cannot be returned. These restrictions preserve type safety by preventing unsafe reads or writes through a typed reference. When the language rules are too strict for a particular design, developers can relax them with techniques like use-site variance (declaring variance at the usage site), star projections, explicit casts, wrapper types, or language-specific escape hatches (for example Kotlin's @UnsafeVariance) to bypass checks. Such workarounds regain flexibility but carry the risk of runtime failures or lost static guarantees, so they should be used sparingly and with clear justification.
类型变异修饰符的限制
变异修饰符限定了类型参数能被使用的位置,会区分读与写的允许性。
重點摘要
协变 (out) 类型参数不能作为函数的参数类型使用。
逆变 (in) 类型参数不能作为返回类型使用。
可以用显式强转或注解(例如 Kotlin 的 @UnsafeVariance)绕过,但会破坏类型安全。
变异修饰符(如协变 out、逆变 in)限制泛型类型参数的使用场景:out 允许作为输出/返回但禁止作为函数参数,in 则允许作为输入但不能返回。这样的限制可以在编译期保证类型安全,防止通过某个引用进行不安全的读写。若规则太严格,可采用 use-site variance(在使用处声明变异)、星号投影、显式强转、包装类型或语言特定的逃生手段(例如 Kotlin 的 @UnsafeVariance)来绕开检查。这些方式能增加灵活性,但会牺牲静态安全性并可能导致运行时错误,故应谨慎使用并明确理由。
型別變異修飾子的限制
變異修飾子限制了型別參數可使用的位置,會區分讀取與寫入的允許性。
重點摘要
協變 (out) 型別參數不能作為函式的參數類型使用。
逆變 (in) 型別參數不能作為回傳類型使用。
可用顯式轉型或註解(例如 Kotlin 的 @UnsafeVariance)繞過,但會危及型別安全。
變異修飾子(如協變 out、逆變 in)會限制泛型型別參數可被使用的位置:out 允許當作輸出/回傳,但禁止當作函式參數;in 則允許當作輸入,但不能回傳。這類限制能維護編譯期的型別安全,避免不安全的讀寫操作。若語言規則過於嚴格,可採用 use-site variance(使用時指定變異)、星號投影(star projection)、顯式轉型、包裝型別或語言提供的逃生方法(如 Kotlin 的 @UnsafeVariance)來放寬檢查。但這些做法會降低靜態保證,可能導致執行時錯誤,應謹慎使用並有充分理由。
KT Academy
作者:
發布:02-27 00:01
Basic values in Kotlin
An introduction to Kotlin's values, data types, and basic operations.
重點摘要
Introduces values as core program data
Explains data types and their role
Covers fundamental operations and operators
This article introduces the basic concepts of values, types, and operations in Kotlin. It explains what a value is, how types classify and constrain values, and how operations manipulate them. The text outlines common categories of types and describes how basic operators — such as arithmetic, comparison, and logical operators — are used to perform calculations and control logic. It also covers how Kotlin's type system affects coding patterns and why understanding types matters for program correctness and readability. Aimed at developers new to Kotlin, the article focuses on core principles and practical usage so readers can recognize values in code, choose appropriate types, and apply fundamental operations confidently. By mastering these basics, readers will have a foundation for more advanced Kotlin features.
Kotlin 的基本值
了解 Kotlin 中的基本值、类型与运算。
重點摘要
介绍 Kotlin 中的值概念
说明类型的分类与作用
涵盖基本运算与运算符
本文介绍 Kotlin 的基本值、类型与运算,说明什么是值、类型如何对数据进行分类与约束,以及运算如何对值进行处理。文章概述常见类型类别与基本运算符(如算术、比较与逻辑运算),并说明类型系统如何影响编程模式与程序正确性。面向 Kotlin 初学者,文章强调核心概念与实用做法,帮助读者在阅读与编写代码时识别值的角色、选择合适类型并正确应用基本运算,为进一步学习更高级特性建立坚实基础,同时强调理解类型与运算对维护与调试的重要性。
Kotlin 的基本值
了解 Kotlin 中的基本值、型別與運算。
重點摘要
介紹 Kotlin 中的值概念
說明型別的分類與角色
涵蓋基本運算與運算子
本文介紹 Kotlin 的基本值、型別與運算,說明何謂值與型別如何分類與限制資料,以及運算如何對值進行處理。文章概述常見型別類別與基本運算子(如算術、比較與邏輯運算),並說明型別系統如何影響程式設計慣例與程式正確性。本文面向 Kotlin 初學者,著重核心概念與實務用法,幫助讀者在閱讀與撰寫程式時辨識值的角色、選擇適當型別並正確應用基本運算,為進階語法與功能打下穩固基礎。文章以簡明說明與實務重點引導學習,強調理解型別與運算對維護與除錯的重要性。
KT Academy
作者:
發布:03-01 00:00
Kotlin bites on Twitter 2
A collection of Kotlin bites of knowledge, in a form of tweets.
重點摘要
Tweet-sized Kotlin tips and insights
Designed for quick reading and easy sharing
Serves as concise reminders or starting points for deeper study
Kotlin bites on Twitter 2 is a concise compilation of Kotlin knowledge presented in tweet-sized entries. The collection gathers short, focused tips, observations, and explanations about Kotlin, formatted for quick consumption and easy sharing. Intended for developers who prefer brief, digestible reminders or quick introductions to concepts, the pieces are compact and singular in focus, making them suitable as daily learning snippets or referenceable reminders. Because each item is shaped like a tweet, the emphasis is on clarity and brevity rather than exhaustive tutorials; readers seeking deeper coverage would use these bites as starting points to explore topics further. As a follow-up installment suggested by the “2” in its title, this collection continues the pattern of delivering bite-sized Kotlin knowledge in a compact, social-media-friendly form.
Kotlin bites on Twitter 2
以推文形式呈现的一系列 Kotlin 知识精选。
重點摘要
以推文形式呈现的 Kotlin 知识
短小聚焦,便于快速吸收与分享
适合作为学习提示或主题起点
Kotlin bites on Twitter 2 是以“推文”形式呈现的 Kotlin 知识精选,将短小、聚焦的技巧、观点与说明浓缩为便于吸收与分享的片段。每则内容强调清晰与简洁,适合作为开启主题的索引、日常学习提示或快速复习的参考,而非全面深入的教学;标题中的“2”表明这是延续先前风格的后续辑。
Kotlin bites on Twitter 2
以推文形式呈現的一系列 Kotlin 知識精選。
重點摘要
以推文形式呈現的 Kotlin 知識
短小聚焦,方便快速吸收與分享
適合作為學習提示或主題起點
Kotlin bites on Twitter 2 是以「推文」形式呈現的 Kotlin 知識精選,將短小、聚焦的技巧、觀點與說明濃縮為便於吸收與分享的片段。每則內容強調清晰與簡潔,適合作為開啟主題的索引、日常學習提示或快速複習的參考,而非全面深入的教學;標題中的「2」顯示這是延續先前風格的後續輯。
KT Academy
作者:
發布:03-06 00:15
Interface Delegation
One of Kotlin's lesser-known features that can sometimes be really useful.
重點摘要
Lesser-known Kotlin feature
Delegates interface implementation to another object
Can reduce boilerplate and enable composition
Interface Delegation is presented as one of Kotlin’s lesser-known features that developers may find useful. The feature lets a class delegate the work of implementing an interface to another object, enabling composition of behavior and reducing repetitive boilerplate in some designs. This can simplify class implementations, support clearer separation of responsibilities, and make it easier to reuse or swap behaviors at runtime. The article highlights that although the mechanism is not widely used or widely known, it can be practical in appropriate scenarios and worth considering when designing Kotlin APIs or implementations. The linked article provides a concise introduction and invites practical experimentation to see where delegation fits best in real code.
接口委派
Kotlin 中较少为人所知但在某些情况下非常有用的特性。
重點摘要
Kotlin 中不太知名的特性
将接口的实现委托给另一个对象
可减少样板代码并支持行为组合
文章指出 Interface Delegation 是 Kotlin 中较少人知道的特性,但在某些情境下很有用。它允许类将接口的方法实现委托给另一个对象,从而减少重复代码、促进行为组合与职责分离。尽管不是广泛使用的手段,这种委派机制在设计 API 或实现时可作为继承与组合之外的可选方案。读者可以参考原文并在实际代码中尝试,评估何时使用委派最为合适。
介面委派
Kotlin 中較少人知道但在某些情況下很有用的語法功能。
重點摘要
Kotlin 的少為人知功能
將介面實作委派給另一個物件
可減少樣板程式並促進行為組合
文章指出 Interface Delegation 是 Kotlin 中較少人知道的語法,但在某些情境很有用。它允許類別將介面的方法實作委託給另一個物件,能減少重複程式碼、促進行為組合與責任分離。雖非普遍採用,這種委派機制在設計 API 或實作時,能作為繼承與組合之外的可行選項。讀者可參考原文示例與鏈結,實際試驗何時使用委派較為適合。
KT Academy
作者:
發布:03-13 00:01
Nullability in Kotlin
How Kotlin's null-safety works and how to handle nullable values to avoid runtime null pointer exceptions.
重點摘要
Distinct nullable and non-nullable types enforced by the compiler
Safe-call (?.), Elvis (?:), and not-null assertion (!!) operators for handling nulls
Explicit null handling reduces NullPointerExceptions and improves safety
Kotlin's null-safety model prevents many runtime null pointer errors by distinguishing nullable types (e.g., String?) from non-nullable types (e.g., String) at the type system level. The compiler enforces checks so you must explicitly handle nullable values before use. Common ways to work with nullable values include the safe-call operator (?.) to access properties or methods only when the receiver isn't null, the Elvis operator (?:) to provide a default when a value is null, and the not-null assertion operator (!!) to assert non-nullness (throwing an exception if wrong). Kotlin also supports safe casts and scope functions like let/run to operate on non-null branches. These mechanisms make null handling explicit, reduce unexpected NullPointerExceptions, and improve code readability and safety while calling out interoperability caveats with Java platform types.
Kotlin 中的可空性
Kotlin 的 null-safety 说明如何处理可空值以避免运行时的 NullPointerException。
重點摘要
类型区分可空与不可空,由编译器检查
使用安全调用 (?.)、Elvis (?:) 和非空断言 (!!) 处理 null
显式的 null 处理降低 NullPointerException 风险
Kotlin 通过类型系统将可空(如 String?)与不可空(如 String)区分开来,编译器要求在使用可空值前显式处理,从而减少运行时 NullPointerException。处理可空值的常见手段包括安全调用(?.)仅在接收者非空时访问、Elvis 运算符(?:)提供默认值,以及非空断言(!!)在断言失败时抛出异常。还可使用安全类型转换与 let/run 等作用域函数在非空分支处理值。这些机制使 null 的处理更明确、更安全,但与 Java 互操作时仍需注意平台类型可能带来的风险。
Kotlin 中的可空性
Kotlin 的 null-safety 說明如何處理可空值以避免執行時的 NullPointerException。
重點摘要
型別區分可空與不可空,由編譯器檢查
使用安全呼叫 (?.)、Elvis (?:) 與非空斷言 (!!) 處理 null
顯式的 null 處理降低 NullPointerException 風險
Kotlin 透過型別系統把可空(如 String?)與不可空(如 String)分開,編譯器要求在使用可空值前明確處理,藉此減少執行時的 NullPointerException。處理可空值的常見方式包括安全呼叫(?.)在接收者非空時才存取、Elvis 運算子(?:)用來提供預設值,以及非空斷言(!!)在斷言錯誤時拋出例外。此外也可用安全轉型與 let/run 等作用域函式在非空分支中處理值。這些機制讓 null 的處理更為顯式與安全,但在與 Java 互通時仍需留意平台型別可能帶來的風險。
KT Academy
作者:
發布:03-20 00:15
Property delegation
Explains what property delegation is, how it operates, and how to implement a custom property delegate.
重點摘要
Defines the concept of property delegation
Describes how delegation routes property behavior
Outlines how to implement a custom property delegate
This article addresses three core questions about property delegation: what it is, how it works, and how to implement a custom property delegate. It offers a conceptual explanation of delegation and why developers use it, describes the mechanism by which property behavior is handled by a delegate rather than directly on the owning object, and provides practical implementation guidance for creating custom delegates, including the interfaces and behaviors to consider. The piece aims to combine theory with implementation direction so readers understand the rationale for delegation, recognize scenarios where it is useful, and gain the knowledge needed to design and implement reusable property delegates in their code.
属性委托
说明什么是属性委托、它如何运作,以及如何实现自定义的属性委托。
重點摘要
定义属性委托的概念
描述委托处理属性行为的机制
说明如何实现自定义属性委托
本文针对“属性委托”三个核心问题展开说明:什么是属性委托、其运作原理是什么,以及如何实现自定义的属性委托。文章先从概念层面解释委托的用途与角色,随后描述属性访问如何被委托给代理对象处理,最后提供实现指南,说明在创建自定义委托时需要考虑的接口契约与行为设计。通过理论与实现方向的结合,读者可以理解委托的优势与适用场景,并获得构建可重用委托组件的实践指引。
屬性委託
說明什麼是屬性委託、其運作方式,以及如何實作自訂的屬性委託。
重點摘要
定義屬性委託的概念
說明委託處理屬性行為的運作
說明如何實作自訂屬性委託
本文針對「屬性委託」三個核心問題進行說明:什麼是屬性委託、其運作原理為何,以及如何實作自訂的屬性委託。文章先從概念面解釋委託的用途與角色,進而描述屬性存取如何被委由代理物件處理,最後提供實作指引,說明建立自訂委託時需注意的介面契約與行為設計。透過理論說明與實作導引,讀者可理解委託帶來的好處與適用情境,並獲得建立可重用委託元件的實務方向。
KT Academy
作者:
發布:03-27 00:15
Lazy property delegate
A lazy delegate defers a property's initialization until its first access, reducing upfront work and enabling cached values.
重點摘要
Initializes a property on first access
Defers expensive or optional setup to when it's actually needed
Can provide thread-safety modes for concurrent use
A lazy property delegate is a language facility (commonly seen in Kotlin as lazy { ... }) that delays creating or computing a property's value until the property is first read. This approach reduces startup cost and avoids unnecessary work for values that may never be used. Typical real-life use cases include expensive computations, heavy object construction, IO-bound resources, caches, and view or configuration binding that should be created only when required. Many implementations also offer options for thread-safety so the initialization can be synchronized, published to multiple threads, or left non-thread-safe depending on the application's needs. Overall, lazy delegates help improve performance and resource usage by postponing initialization and optionally caching the result.
Lazy 属性委托
Lazy 委托会在属性首次访问时才进行初始化,降低启动成本并可缓存结果。
重點摘要
在首次访问时初始化属性
将昂贵或可选的初始化延迟到实际需要时
可配置线程安全模式以支持并发使用
Lazy 属性委托是一种延迟初始化机制(如 Kotlin 的 lazy { … }),只有在属性第一次被读取时才创建或计算其值。该方式可以减少启动开销,避免为可能不会使用的值消耗资源。常见的实际用途包括昂贵的计算或对象构建、IO 相关资源、缓存,以及只在需要时才绑定的视图或配置项。许多实现还提供线程安全选项,可以选择同步初始化、允许多线程发布或不做同步,以便在安全性与性能之间做出权衡。总体上,lazy 委托通过推迟初始化并可缓存结果,帮助提升性能并优化资源使用。
Lazy 屬性委託
Lazy 委託會在屬性首次存取時才進行初始化,減少啟動負擔並能將結果快取起來。
重點摘要
在首次存取時才初始化屬性
將昂貴或可選的初始化延後到實際需要時
可設定執行緒安全性以配合並行場景
Lazy 屬性委託是一種會延遲屬性初始化的機制(例如 Kotlin 的 lazy { … }),只有在第一次讀取該屬性時才建立或計算它的值。此做法可以降低啟動成本,避免為未使用到的值浪費資源。實際應用場景包括昂貴的計算或物件建立、IO 資源、快取、以及只在特定情況下才需要綁定的視圖或設定項目。多數實作也提供執行緒安全的選項,可選擇同步初始化、允許多執行緒發布,或不做任何同步,根據應用需求權衡效能與安全性。整體而言,lazy 委託有助於改善效能與資源使用,並保持程式碼簡潔。
KT Academy
作者:
發布:04-19 00:00
Kotlin Revolutionary Announcement
An announcement from Kotlin that will change the way we all write code.
重點摘要
A brief announcement claiming it will change how code is written
The excerpt provides no technical details or timeline
Developers should consult the full announcement to assess impact
Kotlin has published an announcement described as revolutionary, saying it will change how developers write code. The source text here is brief and does not provide technical details or an implementation timeline. The declaration, however, signals potentially broad effects across Kotlin's ecosystem: developer workflows, tooling, libraries, and language idioms could be affected. Because specifics are not included in this excerpt, readers should consult the official announcement to understand the scope, compatibility considerations, migration paths, and any required tooling updates. Teams that use Kotlin may want to monitor the full release, evaluate impacts on existing codebases, and plan experiments or pilots to assess benefits and risks. Overall, the message is a strong call to attention: Kotlin is making a change significant enough that many developers will likely need to adapt how they write code.
Kotlin 革命性公告
Kotlin 发布了一则将改变我们编写代码方式的公告。
重點摘要
公告声称将改变代码的编写方式
摘录内容简短,未包含技术细节或时间表
建议阅读完整公告以评估对项目和兼容性的影响
Kotlin 发布了一则自称会改变我们编写代码方式的革命性公告。本文摘录很简短,未提供技术细节、时间表或迁移步骤,因此无法对具体实现作出判断。此类声明通常会影响工具链、开发流程、库的兼容性与编程惯例。建议使用 Kotlin 的团队与开发者阅读官方完整公告,评估对现有项目的影响、兼容性风险与必要的升级或试点计划。在获得更多信息前,先以观察与小规模验证为主,避免在不充分理解变更细节前对生产系统做出重大调整。
Kotlin 革命性公告
Kotlin 發布了一則將改變我們撰寫程式方式的公告。
重點摘要
公告自稱會改變程式撰寫方式
摘錄內容簡短,未提供技術細節或時程
建議閱讀完整公告以評估對現有專案的影響
Kotlin 發布了一則自稱會改變我們撰寫程式方式的革命性公告。本文摘錄十分簡短,未提供技術細節、時間表或遷移步驟,因此無法就具體實作做出判斷。這類宣告通常會影響工具鏈、開發流程、函式庫相容性與程式設計慣例。建議使用 Kotlin 的團隊與開發者閱讀官方完整公告,評估對現有專案的影響、相容性風險與必要的升級或試驗計畫。在獲得更多資訊之前,先以觀察與小規模驗證為主,以免在未充分理解變更細節前大幅改動生產系統。
KT Academy
作者:
發布:04-24 00:00
Best practices
Let's review the Kotlin Coroutines best practices.
重點摘要
Review Kotlin Coroutines best practices
Emphasize structured concurrency and scopes
Focus on cancellation, exceptions, and dispatchers
This short article reviews best practices for using Kotlin Coroutines and offers practical guidance for writing safe, maintainable, and efficient coroutine code. It highlights core principles such as structured concurrency and proper use of coroutine scopes, choosing appropriate dispatchers for IO versus CPU-bound work, handling cancellation and exception propagation correctly, and avoiding blocking calls inside coroutines. The review also addresses resource and lifecycle management as well as testing and performance considerations for coroutine-based code. Emphasizing idiomatic patterns—like scoped coroutine builders, centralized error handling, and explicit cancellation—the article aims to help developers reduce bugs, improve responsiveness, and keep concurrent interactions predictable and easier to reason about.
最佳实践
让我们回顾 Kotlin 协程的最佳实践。
重點摘要
回顾 Kotlin 协程的最佳实践
强调结构化并发与协程作用域
关注取消、异常处理与 dispatcher 的选择
本文回顾 Kotlin 协程的最佳实践,提供编写安全、可维护且高效协程代码的实用建议。内容包括结构化并发与协程作用域、为 IO 与 CPU 任务选择适当的 dispatcher、正确处理取消与异常传播、避免在协程中进行阻塞调用,以及资源与生命周期管理等要点。文章还提到协程相关的测试与性能考虑,并强调采用惯用且明确的模式——例如作用域化的协程构造、集中化错误处理与显式取消——以减少错误、提高响应性并确保协程行为可预测。
最佳實務
讓我們回顧 Kotlin 協程的最佳實務。
重點摘要
回顧 Kotlin 協程的最佳實務
強調結構化併發與協程作用域
關注取消、例外處理與 dispatcher 的使用
本文回顧 Kotlin 協程的最佳實務,提供撰寫安全、可維護且高效協程程式的實作建議。內容涵蓋結構化併發與協程作用域、為 IO 與 CPU 工作選擇適當的 dispatcher、正確處理取消與例外傳播、避免在協程中使用阻塞呼叫,以及資源與生命週期管理等議題。文章亦提到協程相關的測試與效能考量,並強調採用慣用且明確的模式──如作用域化的協程建構子、集中化的錯誤處理與顯式取消,以降低錯誤、提升回應性並確保協程行為可預期。
KT Academy
作者:
發布:05-02 00:15
Observable and Vetoable delegates
They let you react to or veto property changes by running custom handlers when a property's value is about to change or has changed.
重點摘要
observable: runs a callback after a property value changes
vetoable: runs a callback before change and can reject it
useful for validation, synchronization, UI updates, and logging
Observable and vetoable delegates in Kotlin are property delegates that run callbacks when a property changes. Delegates.observable invokes a handler after a value has been set, supplying the property descriptor, old value, and new value so you can react (for example, update UI, emit events, or log changes). Delegates.vetoable invokes a handler before the change is committed and returns a Boolean — returning false prevents the assignment — which makes it useful for validation, enforcing invariants, or blocking invalid state transitions. Real-world uses include input validation in forms, keeping dependent state synchronized, triggering side effects like persistence or notifications, and centralized change logging. Because they are implemented as standard delegates, they are concise, composable, and keep change-related code in one place.
Observable 与 Vetoable 委托
这两种委托允许你在属性变更前后运行自定义处理;observable 在变更后回调,vetoable 在变更前可否决赋值。
重點摘要
observable:在值设置后执行回调
vetoable:在值更改前评估并可拒绝该更改
常用于验证、状态同步、UI 更新和变更记录
Observable 与 Vetoable 是 Kotlin 的属性委托,用于在属性改变时触发回调。Delegates.observable 在值设置后调用回调,提供属性、旧值和新值,便于更新界面、发送事件或记录变更;Delegates.vetoable 在变更提交前调用回调,通过返回布尔值决定是否接受新值,从而可以进行输入验证或阻止非法状态转换。现实场景包括表单验证、保持相关状态同步、触发持久化或通知以及集中记录变更。作为委托实现,它们使变更处理更集中、语法更简洁。
Observable 與 Vetoable 委派
這兩種委派讓你在屬性變更前後執行自定義處理;observable 在變更後觸發,vetoable 在變更前決定是否接受。
重點摘要
observable:在值設定後呼叫回調
vetoable:在值變更前評估並可拒絕該變更
實務用於驗證、同步狀態、更新 UI 與記錄變更
Observable 與 Vetoable 是 Kotlin 的屬性委派,用來在屬性變更時執行處理邏輯。Delegates.observable 在值設定後呼叫回調,提供屬性、舊值與新值,適合更新 UI、發出事件或記錄變更;Delegates.vetoable 在變更提交前呼叫回調,回傳布林以決定是否接受新值,適合驗證輸入、維持不變式或阻止非法狀態轉換。實務上常見應用包括表單驗證、保持相依狀態同步、觸發持久化或通知,以及集中記錄變更。由於以委派實作,相關邏輯可集中管理且語法簡潔。
KT Academy
作者:
發布:05-08 00:15
Map as a property delegate
Using a Map to delegate properties forwards property access to map entries, so the puzzler's result follows directly from delegation and map semantics.
重點摘要
A Map can serve as a property delegate for object properties.
Property reads and writes are forwarded to corresponding map entries.
The puzzler's surprising result is explained by delegation and map behavior.
Using a Map as a property delegate means that reading or writing a delegated property is implemented by accessing a corresponding entry in the map. This lets you store property values externally in a key–value structure and reuse a single map to back multiple properties. When applied to the famous puzzler, an outcome that looks surprising is actually a direct consequence of how delegation forwards operations to the map combined with the map's lookup and mutation semantics. In other words, the result is not a language bug but an expected effect of combining property delegation with Map behavior; understanding the forwarding rules and the map's contents explains why the puzzler behaves as it does. The article demonstrates the pattern and argues the result should not be unexpected.
将 Map 作为属性委托
将 Map 用作属性委托会把属性访问转发到 Map 条目,因此那个著名谜题的结果并不意外。
重點摘要
Map 可以作为对象属性的委托来源。
属性的读取与写入会映射到 Map 的键值访问。
谜题的结果可由委托机制与 Map 行为共同解释。
将 Map 作为属性委托意味着被委托属性的读写通过访问 Map 中对应的条目来实现,这使得可以用一个键值结构为多个属性提供存储。应用到那个著名的谜题时,表面看起来令人惊讶的结果,实际上是委托将操作转发给 Map 以及 Map 本身的查找和变更语义共同导致的。换言之,这一结果并非语言缺陷,而是将属性委托与 Map 语义结合时的预期行为;理解转发规则和 Map 的内容就能解释谜题的表现。
將 Map 作為屬性委派
把 Map 當成屬性委派會把屬性的存取轉發到 Map 的鍵值,因此那個著名謎題的結果並不令人意外。
重點摘要
Map 可以作為物件屬性的委派來源。
屬性的讀寫會對應到 Map 的鍵值存取。
謎題的結果可由委派與 Map 的行為共同解釋。
把 Map 當成屬性委派代表:屬性的讀寫會對應到 Map 裡的鍵值存取,因此可以用單一的鍵值結構支援多個屬性。所謂著名謎題看似意外的結果,其實是屬性委派把操作轉發給 Map,以及 Map 自身查找與變更規則共同導致的。文章示範如何以 Map 作為委派並說明,理解委派的轉發行為與 Map 的內容後,謎題的結果便是合乎預期,而非語言錯誤。
KT Academy
作者:
發布:05-10 00:00
Why you should consider migrating your Gradle scripts to Kotlin DSL
Migrating Gradle scripts to Kotlin DSL can simplify build configuration and streamline your development workflow.
重點摘要
Better IDE support and autocompletion for build scripts
Stronger typing and safer, compile-time checked configuration
Improved readability and easier refactoring of build logic
The article explains why migrating Gradle scripts to the Kotlin DSL is worth considering. By expressing build logic in Kotlin, teams gain the advantages of a statically typed, modern language: improved IDE assistance (autocomplete, navigation), compile-time checks that reduce configuration errors, and clearer, more maintainable scripts that are easier to refactor and share. These improvements can streamline development workflows, reduce runtime build issues, and make team collaboration on build logic more efficient. The piece frames migration as a practical modernization step and suggests evaluating migration effort versus benefits, possibly adopting a gradual transition. Overall, Kotlin DSL is presented as a way to make Gradle builds more robust, readable, and productive for teams.
为何应考虑将 Gradle 脚本迁移到 Kotlin DSL
将 Gradle 脚本迁移到 Kotlin DSL,可简化构建配置并优化开发流程。
重點摘要
更好的 IDE 支持与自动补全
静态类型与编译时检查提高配置安全性
更清晰的构建逻辑,便于重构与维护
本文阐述了将 Gradle 脚本迁移到 Kotlin DSL 的理由与好处。使用 Kotlin 编写构建脚本,可利用静态类型和现代语言特性,带来更完善的 IDE 辅助(补全、跳转)、编译期检查以减少配置错误,以及更易读、易重构的构建逻辑。上述改进有助于简化开发流程、减少运行时问题并提升团队在构建配置上的协作效率。文章建议审慎评估迁移成本与收益,并可采用渐进式迁移以降低风险。总体而言,Kotlin DSL 有助于让 Gradle 构建更稳健、可维护并提高生产力。
為何應考慮將 Gradle 腳本移轉到 Kotlin DSL
將 Gradle 腳本遷移到 Kotlin DSL,可簡化建置設定並精簡開發流程。
重點摘要
提升 IDE 支援與自動補完
靜態類型與編譯時檢查降低設定錯誤
更易閱讀與重構的建置邏輯
本文說明將 Gradle 腳本遷移到 Kotlin DSL 的理由與益處。以 Kotlin 編寫建置腳本可利用靜態類型與現代語言特性,帶來更佳的 IDE 補完與導覽、編譯時檢查以降低設定錯誤,以及更易讀與可重構的建置邏輯。這些改變有助於簡化開發流程、提升團隊協作與維護效率。文章並建議以務實方式評估遷移成本與收益,採取漸進遷移以減少風險。總體而言,Kotlin DSL 提供一條讓 Gradle 建置更穩定、易於維護與增進生產力的路徑。
KT Academy
作者:
發布:05-16 00:00
The second edition of Kotlin Coroutines: Deep Dive is finally ready!
Learn about the new release of the famous book about Kotlin Coroutines.
重點摘要
Second edition of Kotlin Coroutines: Deep Dive has been released.
Article announces the new release and links to more information.
Readers and Kotlin developers are invited to learn about the release.
This brief announcement reports that the second edition of the well-known book "Kotlin Coroutines: Deep Dive" is now ready. Published on kt.academy, the article points readers to the new release and provides a link for further information. The notice serves to inform the Kotlin community—developers, engineers, and learners interested in coroutines—that a subsequent edition of a respected resource has been prepared and is available to explore. While the announcement itself is concise, it directs anyone seeking authoritative material on Kotlin coroutines to consult the linked article for details on availability and how to access the book.
《Kotlin Coroutines: Deep Dive》第二版终于准备好了!
了解这本著名 Kotlin 协程书籍的新版本发布讯息。
重點摘要
《Kotlin Coroutines: Deep Dive》第二版已准备好并发布。
文章在 kt.academy 上宣布新版本并提供链接。
邀请对 Kotlin 协程感兴趣的读者了解此次发布。
这则简短公告说明,知名书籍《Kotlin Coroutines: Deep Dive》的第二版已准备就绪并对外发布。公告刊登于 kt.academy,文中附有相关链接,供读者了解新版本的发布信息。声明的目的是通知 Kotlin 社区——包括开发者与学习者——有一份后续版本的参考资料可供查阅,并引导有兴趣的人前往文章了解可用性与获取方式。公告内容简洁明了,主要在于提示新版本发布并提供后续详情来源。
《Kotlin Coroutines: Deep Dive》第二版終於準備好了!
了解這本著名 Kotlin 協程書籍的新版本發行資訊。
重點摘要
《Kotlin Coroutines: Deep Dive》第二版已發布準備就緒。
文章在 kt.academy 上公告新版本並提供連結。
邀請對 Kotlin 協程有興趣的讀者了解此釋出資訊。
本文簡短公告指出,知名的《Kotlin Coroutines: Deep Dive》書籍第二版已經準備就緒並對外發佈。該公告刊登於 kt.academy,並附上相關連結,供讀者進一步閱讀與查詢。此篇消息旨在通知 Kotlin 社群──包含開發者與學習者──有一份續版資源可供參考,並引導有意了解或取得此書的人前往文章查看可用性與取得方式。公告內容簡潔,重點在於告知新版本已發行並提供後續資訊來源。
KT Academy
作者:
發布:05-29 00:00
Understanding Flow
This article explores how flow and its processing really work.
重點摘要
Explores the concept of flow
Examines how flow is processed
Clarifies implications for systems
This short article sets out to examine what "flow" means and how its processing actually works. It approaches flow as a concept to be analyzed rather than prescribing a single implementation, aiming to identify the mechanisms and stages through which information or control moves across components. The piece highlights the importance of understanding state, timing, and coordination in the processing path and considers how those factors affect correctness and performance. By framing flow in conceptual terms, the article prepares readers to recognize where processing occurs, how different parts interact, and which trade-offs matter when designing, debugging, or optimizing systems that rely on structured flows.
理解 Flow
我们将探索 flow 及其处理机制如何真正运作。
重點摘要
探讨 flow 的概念
审视 flow 的处理方式
说明对系统的影响
本文旨在说明“flow”的意义以及其处理流程如何运作。文章预告将澄清 flow 在系统中如何被传递与处理、涉及哪些阶段与互动,以及这些过程对正确性与性能的影响。作者不会给出单一实现方式,而是把 flow 作为一个概念来分析,说明信息或控制如何穿越组件、状态与时序如何左右结果,以及在设计或排错时应注意的关键点。阅读后,读者应能以系统化的观点识别处理发生的位置、协调方式与必要取舍,从而更有效地设计与理解依赖 flow 的系统。
理解 Flow
我們將探索 flow 及其處理機制如何真正運作。
重點摘要
探討 flow 的概念
檢視 flow 的處理方式
說明對系統的影響
本文旨在說明「flow」的意義以及其處理流程如何運作。文章預告將釐清 flow 在系統中如何被傳遞與處理、涉及哪些階段與互動,以及這些過程對正確性與效能的影響。作者不會給出單一實作方式,而是把 flow 當成一個概念來分析,說明資訊或控制如何穿越元件、狀態與時序如何左右結果,以及在設計或排錯時應注意的關鍵點。閱讀後,讀者應能以系統化的觀點辨識處理發生的位置、協調方式與必要取捨,進而更有效地設計與理解依賴 flow 的系統。
KT Academy
作者:
發布:06-12 00:01
The Beauty of Kotlin's Type System
How the type system makes Kotlin so flexible, safe, and intuitive.
重點摘要
Type system enables language flexibility
Type checking improves program safety
Types make APIs and code more intuitive
This article examines how Kotlin's type system underpins many of the language's most valued qualities: flexibility, safety, and intuitiveness. It argues that a thoughtfully designed type system shapes how code is written and composed, guiding developers toward clearer abstractions and preventing certain classes of mistakes before they occur. By tying language design and developer ergonomics to type-level guarantees, the piece explains why Kotlin feels both expressive and reliable in everyday use. Understanding these relationships helps programmers make better design choices and leverage the language's type mechanisms to produce more predictable, maintainable code. The article aims to show that the elegance of Kotlin often stems from its type system and the way it informs APIs, tooling, and developer expectations.
Kotlin 类型系统之美
类型系统让 Kotlin 既灵活、安全又直观。
重點摘要
类型系统提高语言的灵活性
类型检查增强程序的安全性
类型使 API 与代码更直观
本文讨论了 Kotlin 的类型系统如何成为语言优势的核心,阐明其如何带来灵活性、安全性与直观性。文章强调,周到的类型设计会影响代码的编写与组合方式,引导开发者形成更清晰的抽象,并在运行前防止某些类别的错误。类型层面的约束不仅塑造了语言设计,还提升了工具和接口的可预测性与可维护性。理解这些联系有助于程序员在设计与实现时做出更合适的选择,从而编写出更可靠、表达力更强且便于理解的代码。
Kotlin 型別系統之美
型別系統使 Kotlin 兼具彈性、安全與直覺性。
重點摘要
型別系統增強語言彈性
型別檢查提升程式安全
型別讓 API 與程式更直覺
本文探討 Kotlin 的型別系統如何成為語言特性的重要基礎,說明它如何同時帶來彈性、安全性與直覺的使用經驗。文章指出,良好的型別設計會影響程式的撰寫與組合方式,引導開發者建立更清晰的抽象並在執行前避免某些錯誤。型別層面的保證不僅塑造語言設計,也改善工具與 API 的可預測性與可維護性。理解這些關係能幫助開發者在設計與實作時做出更恰當的選擇,從而寫出更可靠且易於理解的程式碼。
KT Academy
作者:
發布:06-19 00:00
Lindy Effect in the Surnames Problem
A programming simulation tracks how the number and longevity of surnames in a population reflect the Lindy effect: older surnames tend to persist longer.
重點摘要
Simulates surname dynamics in a population using code-driven births, deaths, and inheritance.
Observes that surname longevity correlates with age, illustrating the Lindy effect.
Shows population-level surname counts stabilize while some names persist far longer.
This article uses programming to simulate how the number of surnames in a population evolves and to illustrate the Lindy effect. By modeling births, deaths, and the transmission of family names across generations, the simulation tracks how surname counts change over time and how individual names survive or go extinct. Results show that while the total number of distinct surnames may reach a steady-range behavior at the population level, older surnames have a higher chance of continued survival—consistent with the Lindy principle that the future longevity of an item is proportional to its current age. The piece highlights how simple stochastic models can reveal why some family names endure for many generations while others disappear relatively quickly.
姓氏问题中的林迪效应
通过程序模拟人口中姓氏的数量与延续,呈现出年久姓氏更可能长期存在的林迪效应。
重點摘要
用程序模拟出生、死亡和姓氏传承的动态过程。
发现姓氏的存续概率与其存在时间相关,体现林迪效应。
总体姓氏数量在群体层面趋于稳定,但部分姓氏能长期存续。
本文通过编程模拟人口中姓氏数量的演变,以展示林迪效应。模拟考虑出生、死亡以及姓氏随代际传递的机制,追踪姓氏数量随时间的变化以及个别姓氏的灭绝或延续情况。结果表明,尽管在总体上不同姓氏的数量会在群体中趋于某种稳定范围,但已经存在较长时间的姓氏更有可能继续存在,这与林迪原则一致:存在时间越长的事物,其未来继续存在的概率越高。文章说明了简单的随机模型如何解释为何一些姓氏能够跨越多代长期流传。
姓氏問題中的林迪效應
透過程式模擬族群中姓氏數量與存續,顯示年久的姓氏較可能長期存在,符合林迪效應。
重點摘要
以程式模擬出生、死亡與姓氏遺傳的動態過程。
觀察到姓氏的存續機率與其存在年齡呈正相關,體現林迪效應。
總姓氏數在族群層級上呈現穩定趨勢,但部分姓氏能長期存在。
本文以程式模擬族群內姓氏數量的演化,並用以說明林迪效應。透過模擬出生與死亡事件以及姓氏隨世代傳承的機制,追蹤不同姓氏如何滅絕或延續。結果指出,雖然整體的不同姓氏數量會在族群中達到某種穩定範圍,但存在時間較久的姓氏仍較可能繼續存活,與林迪原則相符:一項事物存在的時間愈長,其未來存在的機率相對愈高。文章示範了簡單隨機模型如何解釋為何部分姓氏能跨越多代而流傳下來。
KT Academy
作者:
發布:06-26 00:00
Eliminating coroutine races
Make one coroutine await another coroutine or a flow subscription to prevent race conditions.
重點摘要
Await a coroutine or flow subscription to enforce ordering
Coordinate asynchronous tasks to avoid race conditions
Preserve cancellation behavior and avoid deadlocks
This short guide addresses how to make one coroutine await another coroutine or a flow subscription so asynchronous operations run in a deterministic order and avoid race conditions. When coroutines or flow subscriptions interact without coordination, dependent work can start prematurely, causing unpredictable results. Waiting means suspending execution until the prerequisite coroutine completes or until a flow subscription has established the expected state, which yields safer and more predictable concurrency. The approach involves explicit synchronization or sequencing of subscriptions and tasks, taking care to preserve cancellation semantics and to prevent deadlocks. Thoughtful structuring of coroutine-to-coroutine and coroutine-to-flow interactions reduces subtle timing bugs while keeping systems responsive.
消除 coroutine 竞态
让一个 coroutine 等待另一个 coroutine 或 flow 的订阅完成,以避免竞态条件。
重點摘要
等待 coroutine 或 flow 订阅以保证执行顺序
协调异步任务以避免竞态发生
注意取消行为并防止死锁
本文说明如何让一个 coroutine 等待另一个 coroutine 或 flow 的订阅完成,从而避免竞态条件。当多个 coroutine 或 flow 订阅相互依赖而未做协调时,依赖任务可能过早运行,导致不可预测的结果。通过在执行中挂起直到先决任务完成,或在订阅建立后再执行后续工作,可以确保异步流程按预期顺序执行。常见做法包括显式同步或对订阅进行顺序化,并注意保留取消语义与避免死锁。合理组织 coroutine 与 flow 的交互能减少隐蔽的时序错误,同时保持系统响应性。
消除 coroutine 競態
讓一個 coroutine 等待另一個 coroutine 或 flow 的訂閱完成,以避免競態條件。
重點摘要
等待 coroutine 或 flow 訂閱以確保執行順序
協調非同步工作以避免競態發生
注意取消行為與避免死鎖
本文說明如何讓一個 coroutine 等待另一個 coroutine 或 flow 的訂閱完成,以避免競態條件。當多個 coroutine 或 flow 訂閱互相依賴時,若未同步就可能發生競態,導致行為不穩定。透過在執行中掛起直到依賴完成,或在訂閱建立後再進行後續工作,可以確保非同步流程按預期順序執行。作法包括明確的同步或對訂閱進行順序化,同時要維持取消邏輯並避免死鎖。妥善設計 coroutine 與 flow 的互動可以降低難以察覺的時序錯誤,同時保留系統的回應性。
KT Academy
作者:
發布:07-03 00:15
Kotlin Contracts
Practical review of Kotlin Contracts — a feature many developers use without realizing it.
重點摘要
Practical overview of Kotlin Contracts
Explains why the feature is often used implicitly
Covers examples, common pitfalls and guidance
This article offers a practical review of Kotlin Contracts, a language feature that many developers use without being fully aware of it. The piece explains the purpose of contracts and presents example-driven discussion of typical use cases. It describes how contracts can help the compiler reason about function effects, improve control-flow and type/nullability inference, and reduce boilerplate in some scenarios. The review also addresses common misunderstandings and trade-offs, indicating when explicit checks or annotations might be preferable to relying on contracts. Aimed at Kotlin developers, the article seeks to make implicit uses visible and to provide actionable guidance for applying contracts deliberately to improve correctness, readability, and maintainability of code.
Kotlin Contracts
实务性回顾 Kotlin Contracts —— 一个常被隐性使用却很少被察觉的功能。
重點摘要
实务性介绍 Kotlin Contracts
说明为何开发者常无意识地使用该功能
含示例、误区澄清与使用建议
这篇实务性回顾聚焦 Kotlin Contracts —— 一个常被隐性使用却很少被察觉的功能。文章说明 Contracts 的目的与典型应用场景,通过示例展示它如何让编译器了解函数调用的副作用,从而改善流程判断与类型/空值推断,减少样板代码。文中也澄清常见误解、指出使用时的权衡,以及何时应以明确检查或注释替代合约。整篇以实作为导向,旨在帮助开发者识别代码中已存在的合约用法,并有意识地运用以提升正确性与可维护性。
Kotlin Contracts
實務性回顧 Kotlin Contracts —— 一個常被隱性使用但鮮少察覺的功能。
重點摘要
實務性介紹 Kotlin Contracts
說明為何開發者常無意間使用此功能
提供範例、誤解釐清與使用建議
這篇實務性回顧聚焦 Kotlin Contracts —— 一個常被隱性使用但鮮少察覺的功能。文章說明 Contracts 的目的與典型應用情境,透過範例展示它如何讓編譯器了解函式呼叫的副作用,進而改進流程判斷與型別/空值推斷,減少樣板程式。文中也釐清常見誤解、指出使用時的取捨,以及何時應以明確檢查或註記取代合約。整篇以實作導向為主,旨在幫助開發者辨識程式中已存在的合約用法,並有意識地運用以提升正確性與可維護性。
KT Academy
作者:
發布:07-10 00:00
Books for 2023 Company Workshops Attendees Promotion
A special promotion offers books to attendees of company workshops organized in 2023.
重點摘要
Applies to company workshops held in 2023
Books provided to workshop attendees
Aims to support learning and extend training impact
This announcement describes a special promotion offering books to attendees of company workshops organized in 2023. The offer applies to corporate workshops held during the 2023 calendar year and targets participants who attend those sessions. The promotion is intended to support learning, reinforce workshop material, and extend the practical value of in-person training by supplying curated reading resources to attendees. Companies that organize qualifying workshops can include the books as part of their program for participants. Specific eligibility criteria, fulfillment procedures, and any related terms are determined by the promotion's organizer; interested organizers should consult the original promotion page for details. The initiative aims to make take-home learning resources available to workshop participants and to encourage continued study after the event.
2023 公司研讨会参会者书籍促销
面向 2023 年举办的公司研讨会,提供给参会者的书籍特别促销。
重點摘要
适用于 2023 年举办的公司研讨会
为参会者提供书籍
旨在支持学习并延长培训成效
本公告说明一项针对 2023 年举办的公司研讨会的特别促销,为参加这些研讨会的与会者提供书籍。本优惠适用于 2023 年日历年内举办的企业研讨会,旨在支持学习、强化课程内容,并通过精选阅读资源延伸实务培训效果。符合资格的公司可将书籍纳入参会者安排。具体资格、兑换与相关条款由促销主办单位制定,欲知详情请参阅原始促销页面。本措施旨在让参会者带回实用学习资料,并鼓励会后持续学习。
2023 公司工作坊參加者書籍促銷
針對 2023 年舉辦的公司工作坊,提供給參加者的書籍特別促銷。
重點摘要
適用於 2023 年舉辦的公司工作坊
向參加者提供書籍
旨在支援學習並延長課程影響
本篇公告說明一項面向 2023 年舉辦公司工作坊的特別促銷,提供書籍給參加該等工作坊的與會者。此優惠適用於 2023 年曆年內舉辦的企業工作坊,目的在於支援學習、補強工作坊課程內容,並透過精選閱讀資源延伸實務訓練成效。符合資格的公司可將書籍納入參與者配套。具體資格、兌換與相關條款由促銷主辦單位訂定,欲知詳情請參閱原始促銷頁面。此措施旨在讓參加者帶回實用學習資料,並鼓勵會後持續研習。
KT Academy
作者:
發布:07-17 00:01
Objects in Kotlin
Object expressions, object declarations, and companion objects let you create anonymous instances, singletons, and class-level members in Kotlin.
重點摘要
Object expressions create anonymous, one-off objects.
Object declarations define named singletons for shared state or utilities.
Companion objects provide class-level members and factory-like methods.
Objects in Kotlin cover three related constructs: object expressions, object declarations, and companion objects. Object expressions create anonymous objects on the fly, useful for single-use implementations and listener callbacks without declaring a named class. Object declarations define a singleton: a named, lazily initialized instance that holds state or utility functions. Companion objects are special object declarations tied to a class that provide class-level members, factory methods, and implement static-like behavior while remaining full Kotlin objects. Each form has different lifecycle and visibility: expressions are ephemeral, declarations live for the program's lifetime, and companions are accessed through the containing class. Common usage includes replacing static members, grouping utilities, and creating concise overrides or adapters. Understanding when to use each helps write idiomatic, concise Kotlin code.
Kotlin 中的对象
对象表达式、对象声明与伴生对象分别用于创建匿名对象、单例和类级成员。
重點摘要
对象表达式用于创建匿名、一次性对象。
对象声明定义命名单例以保存共享状态或工具函数。
伴生对象为类提供类级成员与工厂方法。
本文说明 Kotlin 中的三种 object 形式:object expression(对象表达式)、object declaration(对象声明)与 companion object(伴生对象),以及它们的使用场景和差异。对象表达式用于创建匿名对象,适合一次性实现或回调;对象声明定义单例,可用作全局或工具函数容器;伴生对象隶属于类,提供类级成员和工厂方法,模拟静态行为。三者在生命周期与可见性上不同,合理使用可使 Kotlin 代码更简洁、符合习惯。
Kotlin 的物件
物件表達式、物件宣告與伴生物件分別用於建立匿名物件、單例與類別級成員。
重點摘要
物件表達式用於建立匿名、一次性物件。
物件宣告定義命名單例以儲存共用狀態或工具函式。
伴生物件為類別提供類級成員與工廠方法。
本文介紹 Kotlin 的三種 object 構造:object expression(物件表達式)、object declaration(物件宣告)與 companion object(伴生物件),以及它們的用途與差異。物件表達式用於建立匿名物件,適合一次性實作或回呼;物件宣告定義單例,可作為全域或工具函式容器;伴生物件則隸屬於類別,提供類級成員和工廠方法,模擬靜態行為。三者在生命週期與可見性上不同,選擇合適形式能讓 Kotlin 程式更簡潔與慣用。
KT Academy
作者:
發布:07-24 00:00
Advanced Kotlin is finally ready!
Learn about our recently published book dedicated to the advanced Kotlin features.
重點摘要
Newly published book about advanced Kotlin
Focuses on advanced Kotlin features and techniques
Invitation for readers to learn more
This brief announcement presents a recently published book dedicated to advanced Kotlin features. It informs readers that the book is now available and invites them to learn more about its focus on advanced aspects of the language. Aimed at Kotlin developers seeking deeper understanding, the book concentrates on advanced features and techniques. The article serves as a concise pointer, raising awareness of the release and directing interested readers to the book’s page for further information. It is positioned for developers and teams who want to deepen their Kotlin knowledge and keep up with the language’s more sophisticated capabilities. Though short, the announcement emphasizes availability and encourages experienced Kotlin users to consult the new resource to expand their expertise. The article acts as an entry point for readers to evaluate whether the book matches their learning needs.
Advanced Kotlin 终于准备好了!
了解我们最近发布的、专门介绍 Kotlin 进阶功能的新书。
重點摘要
新书已发布
聚焦 Kotlin 的进阶功能与技术
邀请读者了解更多
这则简短公告介绍了一本最近发布、专门探讨 Kotlin 进阶功能的新书。文章说明新书已发行,并邀请读者进一步了解其针对语言进阶方面与相关技术的聚焦内容。该出版物面向希望深化 Kotlin 能力的开发者和团队,作为了解进阶语法、用法与概念的参考来源。公告简洁明了,并提供链接以引导有兴趣的读者查看书籍页面并获取更多信息,鼓励具备基础经验的 Kotlin 使用者参考此资源以扩展专业知识。
Advanced Kotlin 終於準備好了!
瞭解我們最近出版、專門探討 Kotlin 進階功能的新書。
重點摘要
新書已出版
專注於 Kotlin 的進階功能與技術
邀請讀者進一步瞭解
這則簡短公告介紹了一本最近出版、專門探討 Kotlin 進階功能的新書。文章說明新書已發行,並邀請讀者進一步了解其針對語言進階面向與相關技術的聚焦內容。此出版物定位於希望深化 Kotlin 能力的開發者與團隊,作為了解進階語法、用法與概念的參考來源。公告簡潔明確,並提供連結以引導有興趣的讀者查看書籍頁面與取得更多資訊,鼓勵具備基礎經驗的 Kotlin 使用者參考此資源以擴充專業知識。
KT Academy
作者:
發布:07-31 00:15
Kotlin and Java interoperability: Types
See surprising transitions that happen to types when you interoperate between Kotlin and Java.
重點摘要
Surprising type transitions can occur at the Kotlin–Java boundary.
Type representations may differ between the two languages.
Understanding these shifts helps prevent interoperability bugs.
This short article highlights the surprising transitions that can occur to types when Kotlin and Java interoperate. Because Kotlin and Java use different type systems and conventions, a value's static and runtime representation may change at language boundaries. The piece outlines examples of how types are mapped and transformed when calling code across the two languages, analyzes why those transitions happen, and points out practical consequences for correctness and safety. It emphasizes that developers should pay attention to how types are translated at the interop boundary, test cross-language interactions, and apply explicit annotations or checks where necessary to avoid subtle bugs. It is useful reading for developers working with mixed Kotlin–Java codebases and for anyone troubleshooting unexpected type behavior at runtime.
Kotlin 与 Java 互操作:类型
观察在 Kotlin 与 Java 互操作时,类型会出现令人意外的转换。
重點摘要
Kotlin 与 Java 的边界处可能发生意外的类型转换。
两者在类型表示与检查上存在差异。
理解这些转换有助于避免互操作性问题。
本文说明在 Kotlin 与 Java 互操作时,类型会出现令人意外的转换。由于两者在类型系统和表示方式上存在差别,值在语言边界处的静态类型与运行时表示可能会发生变化。文章通过示例演示类型如何被映射与转换,并解释这些转换的原因及其对正确性与安全性的实际影响,提醒开发者在跨语言调用时关注类型行为、对跨语言交互进行测试,并在必要时添加明确注解或检查以避免细微且难以发现的错误。对于同时维护 Kotlin 与 Java 代码库的开发者,这是一篇有价值的参考。
Kotlin 與 Java 互操作:型別
觀察在 Kotlin 與 Java 互操作時,型別會出現令人意外的轉換。
重點摘要
Kotlin 與 Java 邊界處會發生意外的型別轉換。
兩者在型別表示與檢查上可能不同步。
理解這些轉換有助於避免互操作性錯誤。
本文說明在 Kotlin 與 Java 互操作時,型別會出現令人意外的轉換。由於兩者在型別系統與表示方式上存在差異,值在語言邊界處的靜態型別與執行時表示可能會改變。文章透過範例示範型別如何被映射與轉換,並說明造成這些轉換的原因與實務影響,提醒開發者在跨語言呼叫時留意型別行為、針對邊界互動進行測試,必要時加入明確註記或檢查,以避免出現微妙而難查的錯誤。對於同時維護 Kotlin 與 Java 專案的開發者,這篇文章具有實用參考價值。
KT Academy
作者:
發布:08-07 00:15
Kotlin and Java interoperability: Properties and annotations
A Kotlin property is compiled into a Java getter, setter, field and possibly other JVM elements, so annotating or targeting a specific JVM element requires care.
重點摘要
A Kotlin property maps to multiple JVM elements (getter, setter, field, etc.).
Annotations or usages must target the specific JVM element you intend.
Failing to specify the element can lead to ambiguity about where the annotation is applied.
Kotlin properties are not a single JVM artifact: a single Kotlin property is compiled into several Java-level elements such as a getter, setter, a backing field and potentially additional synthetic members. Because of that multiplicity, applying an annotation or otherwise targeting a property from Java interop requires you to identify which JVM element you mean. If you do not explicitly target the getter, setter, field, or other generated element, the annotation may end up on a different JVM artifact than you expect. The practical implication is to use element-specific targets when you need an annotation or behavior to appear on a particular generated JVM element in order to get predictable interoperability with Java.
Kotlin 与 Java 互操作:属性和注解
Kotlin 的属性会被编译为 Java 的 getter、setter、字段以及可能的其他 JVM 元素,因此在注解或使用特定 JVM 元素时需明确目标。
重點摘要
Kotlin 属性对应多个 JVM 元素(getter、setter、field 等)。
给属性注解或使用时需针对具体的 JVM 元素。
未指定目标可能导致注解落在非预期的 JVM 成员上。
Kotlin 的属性在编译到 JVM 时会生成多个不同的 Java 成员,例如 getter、setter、备份字段以及可能的合成方法。正因为这种一对多的关系,当你需要对某个具体的 JVM 元素进行注解或从 Java 侧使用它时,必须明确指定目标元素,否则注解可能会出现在非预期的位置,从而影响互操作的行为。因此在需要精确控制 JVM 层输出时,应使用针对具体元素的注解目标来确保预期效果。
Kotlin 與 Java 互操作:屬性與註解
Kotlin 的屬性會編譯成 Java 的 getter、setter、欄位以及其他可能的 JVM 元件,因此在註解或指定 JVM 元件時需特別注意。
重點摘要
Kotlin 屬性會對應到多個 JVM 元件(getter、setter、field 等)。
要註解或使用特定 JVM 元件時,必須明確指定目標元素。
未指定目標會導致註解落在非預期的 JVM 成員上。
Kotlin 的屬性在編譯後並非單一對應;它會生成 Java 層級的 getter、setter、備援欄位(field),以及可能的其他合成成員。由於這種一對多的對應關係,當你要在 JVM 層級加註解或從 Java 側存取特定成員時,必須明確指出你想要作用的那一個元素。若不指定目標(例如 getter、setter 或 field),註解可能會被放到非預期的成員上,導致互操作行為與預期不符。因此在需要精確控制 JVM 輸出時,應使用針對特定元素的註解目標。
KT Academy
作者:
發布:08-14 00:15
Kotlin and Java Interoperability: Useful Annotations
Annotations that determine how Kotlin code is compiled to the JVM and affect Java interoperability.
重點摘要
Annotations influence the emitted JVM bytecode
They help control Java–Kotlin interoperability
They affect member naming, visibility, and staticness
This article introduces useful Kotlin annotations that influence how Kotlin code is compiled for the JVM. It explains why these annotations matter for Java interoperability and how they change the generated bytecode and API surface seen by Java. The discussion covers common effects such as controlling generated member names to match Java expectations, determining whether methods or properties are emitted as static or instance members, adjusting field and accessor visibility, and influencing generic signatures at the JVM level. The piece emphasizes how small annotation choices can change the ABI, simplify calling Kotlin from Java, and avoid surprises in mixed-language projects. It provides a concise, practical overview aimed at developers who need to tune Kotlin-to-JVM compilation for better interoperability and API stability.
Kotlin 与 Java 互操作性:实用注解
介绍决定 Kotlin 在 JVM 上如何编译并影响与 Java 互操作性的注解。
重點摘要
注解会影响生成的 JVM 字节码
可改善 Kotlin 与 Java 的互操作性
会改变成员名称、可见性与是否为静态
本文介绍了若干实用的 Kotlin 注解,说明它们如何决定代码在 JVM 上的编译结果,以及为何对与 Java 的互操作性至关重要。内容涵盖这些注解对生成字节码的影响,例如控制生成的成员名称以符合 Java 期望、决定方法或属性是否以静态成员输出、调整字段与访问器的可见性、以及影响泛型签名等 JVM 层面的细节。文章强调,恰当的注解使用会改变 ABI、简化 Java 对 Kotlin 的调用并避免混合语言项目中的兼容性问题,提供实用且精炼的参考。
Kotlin 與 Java 互操作性:實用註解
介紹決定 Kotlin 在 JVM 上如何編譯、並影響與 Java 互操作性的註解。
重點摘要
註解會影響產生的 JVM 位元組碼
可改善 Kotlin 與 Java 的互操作性
會改變成員名稱、可見性與是否為靜態
本文介紹數個常用的 Kotlin 註解,說明它們如何決定程式在 JVM 上的編譯結果,以及為何對與 Java 的互操作性很重要。說明涵蓋註解對產生的位元組碼的影響,例如控制產生的成員名稱以符合 Java 預期、決定方法或屬性是否以靜態成員輸出、調整欄位與存取器的可見性,以及影響泛型簽名等 JVM 細節。文章強調,適當使用註解可改變 ABI、讓 Java 呼叫 Kotlin 更簡單,並在混合語言專案中避免相容性問題,提供實務導向的簡潔參考。
KT Academy
作者:
發布:08-21 00:15
Kotlin and Java interoperability: Traps and gotchas
Examines the parts of Kotlin–Java interoperability that can be surprising or counterintuitive for developers.
重點摘要
Identifies surprising interoperability behaviors
Explains why mismatches occur and their impact
Offers guidance to avoid subtle cross-language pitfalls
This article surveys the aspects of Kotlin–Java interoperability that can surprise developers or behave counterintuitively. It summarizes common areas where expectations built from one language may not hold when interacting with the other, explains why such mismatches occur, and highlights practical consequences for code correctness and maintenance. The piece aims to demystify interoperability by describing typical pitfalls, clarifying language-specific semantics that affect cross-language calls, and offering guidance to avoid subtle bugs. Readers are encouraged to pay attention to type mapping, nullability semantics, runtime behavior differences, and tooling hints that reveal potential mismatches. Overall, the article's goal is to help Java and Kotlin developers recognize surprising interactions early, make safer design choices when mixing the languages, and reduce maintenance overhead caused by hidden interoperability traps.
Kotlin 与 Java 的互操作:陷阱与注意事项
探讨 Kotlin 与 Java 互操作中可能让开发者感到意外或违反直觉的部分。
重點摘要
指出可能令人惊讶的互操作行为
说明差异产生的原因与实际影响
提供避免跨语言陷阱的建议
本文概述 Kotlin 与 Java 互操作(interoperability)中那些可能让开发者感到意外或违背直觉的部分。文章指出在跨语言协作时,仅凭单一语言的预期可能不成立,从而引发错误或增加维护成本;它解释这些差异产生的原因,并强调实际影响与预防重点。读者可以通过本文了解常见陷阱、语义差别,以及如何采取更安全的设计与工具检查,以提前发现问题并降低因隐藏互操作问题带来的负担。
Kotlin 與 Java 的互操作:陷阱與注意事項
探討 Kotlin 與 Java 互操作中可能讓開發者感到意外或違反直覺的部分。
重點摘要
指出可能令人驚訝的互操作行為
說明差異產生原因與實務影響
提供避免跨語言陷阱的建議
本文概述 Kotlin 與 Java 互操作(interoperability)中那些可能讓開發者感到意外或直覺相反的部分。文章指出在跨語言協同時,基於單一語言的預期可能失效,進而導致錯誤或增加維護成本;它說明造成這些差異的原因,並強調實務上的影響與預防要點。讀者可透過本文了解常見陷阱、語義差異,以及如何採取較安全的設計與工具檢查,以提早發現問題並降低因隱藏互操作問題所帶來的負擔。
KT Academy
作者:
發布:08-28 00:00
Effective Kotlin Item 2: Eliminate critical sections
Synchronize access to mutable state to prevent race conditions and secure its integrity.
重點摘要
Mutable state must be synchronized to avoid race conditions.
Reduce or eliminate critical sections to lower contention and improve performance.
Prefer immutability or thread confinement; use minimal, careful synchronization when needed.
Synchronizing access to mutable state is essential to prevent race conditions, maintain data consistency, and ensure predictable behavior in concurrent Kotlin programs. When multiple threads or coroutines can change shared variables, unsynchronized access can lead to lost updates, corrupted state, and subtle bugs. Securing mutable state can be achieved by reducing or eliminating critical sections—minimizing the code protected by locks—or by adopting alternative designs such as immutability, thread confinement, and using well-designed concurrent primitives (locks, synchronized blocks, atomic variables, and thread-safe collections). Narrowing critical sections improves performance by reducing contention; choosing immutable data structures or confining mutable state to single threads avoids the need for locks altogether. Effective Kotlin guidance emphasizes preferring designs that avoid shared mutable state when possible, and when synchronization is unavoidable, applying careful, minimal locking to keep code correct and performant.
Effective Kotlin 第2项:消除临界区
对可变状态进行同步访问以避免竞态条件并确保数据完整性。
重點摘要
可变状态需同步以防止竞态和数据不一致。
缩小或消除临界区可以降低争用并提升性能。
优先采用不可变或线程封闭,必要时使用最小且谨慎的同步。
在并发 Kotlin 程序中,对可变状态进行同步访问是必要的,以避免竞态条件、数据不一致和难以发现的错误。可以通过缩小或消除临界区来保护状态,例如减少锁定范围,或采用不可变数据、线程封闭,以及使用原子操作或线程安全的集合等并发工具。缩小临界区能降低争用、提高性能;若能避免共享可变状态则无需加锁。Effective Kotlin 建议优先通过设计避免共享可变状态,必要时以最小且谨慎的同步策略确保正确性与性能。
Effective Kotlin 第2項:消除臨界區
對可變狀態進行同步存取以避免競態條件並確保資料完整性。
重點摘要
可變狀態需同步以避免競態與資料不一致。
縮小或消除臨界區能降低鎖競爭並提升效能。
優先採用不可變、執行緒封閉;必要時採最小且謹慎的同步。
在並行 Kotlin 程式中,對可變狀態進行同步存取是必要的,以避免競態條件、資料不一致與難以偵測的錯誤。可以透過縮小或消除臨界區來保護狀態,例如減少鎖定範圍,或改採不可變資料、執行緒封閉、以及使用原子操作或執行緒安全的集合等並發工具。縮小臨界區能降低競爭、提升效能;若能避免共享可變狀態則不需鎖定。Effective Kotlin 建議優先以設計避免共享可變狀態,必要時以最小化且謹慎的同步策略確保正確性與效能。
KT Academy
作者:
發布:09-04 00:01
Sealed classes and interfaces in Kotlin
Sealed classes and interfaces restrict which types can inherit from them so all subclasses are known at compile time and can be handled exhaustively.
重點摘要
Restrict subclassing to a controlled set known at compile time
Enable exhaustive when expressions for safer pattern matching
Useful for modeling finite state, result types, or algebraic data types
Sealed classes and sealed interfaces in Kotlin let you define a closed hierarchy of types: only a fixed, known set of subclasses can extend a sealed type. Subclasses are typically declared in the same file as the sealed type, and can be objects, data classes, or regular classes. Because the compiler knows all possible subclasses, when expressions over sealed types can be checked for exhaustiveness, reducing runtime errors and improving maintainability. Sealed types are commonly used to model finite states, command/results, or algebraic data types in application logic and APIs. They help make intent explicit, make pattern-matching safer, and simplify control flow by forcing the developer to handle every variant or add an explicit else branch.
Kotlin 的 sealed 类别与接口
密封(sealed)类与接口限制可继承的类型,使所有子类在编译时已知并可被穷尽处理。
重點摘要
在编译时限定可继承的子类集合
配合 when 可获得穷尽检查,增强安全性
常用于表示有限状态、结果或代数数据类型
密封类与密封接口允许你定义封闭的类型层次:只有一组已知的子类可以继承密封类型,子类通常与密封类型声明在同一文件中。子类可以是 object、data class 或普通类。由于编译器知道所有可能的子类型,对密封类型使用 when 表达式时可以进行穷尽性检查,从而减少运行时错误并提高可维护性。密封类型常用于描述有限状态、命令/结果或代数数据类型,能够使 API 意图更明确并增强类型安全。
Kotlin 的 sealed 類別與介面
密封(sealed)類別與介面限制哪些型別可繼承,讓所有子類在編譯時即已知且可被窮盡處理。
重點摘要
在編譯時限定可繼承的子類集合
搭配 when 可取得窮盡檢查,提升安全性
常用於表示有限的狀態、結果或代數資料型別
密封類別與密封介面讓你定義受限的類別階層:只有預先定義的一組子類能繼承密封型別,子類通常與密封型別放在同一檔案中。子類可以是 object、data class 或一般類別。由於編譯器知道所有可能的子型,對密封型別使用 when 表達式時可以進行窮盡性檢查,降低執行期錯誤並提高可維護性。密封型別常被用來描述有限狀態、命令/結果或代數資料型別,使 API 意圖明確並強化型別安全。
KT Academy
作者:
發布:09-07 00:00
The second edition of Effective Kotlin: Best Practices is finally ready!
Learn about the new release of the famous book about the best practices for Kotlin development.
重點摘要
Second edition of Effective Kotlin has been released
A well-known guide focused on Kotlin best practices
Announcement available on the Kotlin Academy article
The announcement presents the release of the second edition of Effective Kotlin: Best Practices, a well‑known book that collects practical recommendations and patterns for Kotlin development. The new edition updates and refines guidance to reflect Kotlin’s evolution and community experience, aiming to help developers write safer, clearer, and more idiomatic code. The article briefly introduces the release and directs readers to the full announcement on the Kotlin Academy site for details. Developers and teams who follow Kotlin best practices can consult the book as a concise reference for design decisions, engineering trade-offs, and everyday coding patterns. The second edition reinforces established techniques while adapting examples and recommendations to current Kotlin language and library practices. Readers are invited to learn more via the linked article and consider the book when adopting or reviewing Kotlin development standards.
《Effective Kotlin: Best Practices》第二版终于发布!
了解这本知名 Kotlin 最佳实践指南的新版本发布情况。
重點摘要
《Effective Kotlin》第二版已发布
专注于 Kotlin 的最佳实践与实用建议
公告与详情刊载于 Kotlin Academy 文章
本文宣布《Effective Kotlin: Best Practices》第二版已发布,这本知名的 Kotlin 最佳实践指南提供实用建议与示例。新版对既有指引进行了更新与微调,以反映 Kotlin 语言与生态的发展,旨在帮助开发者编写更安全、可读且更具惯用性的代码。文章简要介绍了新版本并引导读者到 Kotlin Academy 的公告页面以获取详细信息;对于遵循 Kotlin 最佳实践的个人与团队而言,此书是审视设计选择与日常代码风格的重要参考。
《Effective Kotlin: Best Practices》第二版終於發布!
了解這本知名 Kotlin 最佳實務指南的新版本發布情況。
重點摘要
《Effective Kotlin》第二版已發布
聚焦 Kotlin 的最佳實務與實用建議
公告與詳情刊載於 Kotlin Academy 文章
本文宣布《Effective Kotlin: Best Practices》第二版已發布,這本知名的 Kotlin 最佳實務指南提供實用建議與範例。新版對既有指引進行更新與微調,以反映 Kotlin 語言與生態的演進,目標是幫助開發者撰寫更安全、可讀且更具慣用性的程式碼。文章簡短介紹了新版本並引導讀者至 Kotlin Academy 的公告頁面以取得詳細資訊;對遵循 Kotlin 最佳實務的個人與團隊而言,此書是檢視設計選擇與日常程式風格的重要參考。
KT Academy
作者:
發布:09-08 00:00
The story behind the lighthouse
An account of the origin and meaning of the lighthouse used on the new edition of Effective Kotlin.
重點摘要
Explains the origin of the lighthouse image
Describes design choices and symbolic meaning
Connects the motif to the book's guidance theme
This short article recounts the story behind the lighthouse illustration chosen for the new edition of Effective Kotlin. It traces how the image was selected and what it symbolizes for the book — serving as a visual metaphor for guidance, clarity, and safe navigation through Kotlin best practices. The piece outlines the design decisions, the rationale for adopting a lighthouse motif on the cover, and how the imagery connects to the book's aims of helping developers find reliable techniques amid complexity. Without delving into exhaustive technical detail, the article highlights collaboration between authors and designers, the intent to make the cover both meaningful and approachable, and how the lighthouse ties into the edition's themes. Readers interested in book design or the communication of programming ideas through imagery will find the account concise and illuminating.
灯塔背后的故事
说明新版本 Effective Kotlin 所采用灯塔图像的来由与含义。
重點摘要
说明灯塔图像的来源
讨论设计选择与象征意义
阐明图像如何呼应书籍的指引主题
这篇短文说明了新版本 Effective Kotlin 封面所采用灯塔意象的来由与意义。文章介绍图像如何被挑选、其象征含义(作为指引、清晰与在复杂情境中提供安全航向),以及设计团队与作者之间的沟通与决策过程。文中强调灯塔图像如何契合书籍旨在为开发者提供可靠实践与方向的核心理念,并指出设计目标是使封面既有象征性又亲切易懂。对于关心书籍视觉传达或程序设计理念如何通过图像表达的读者,本篇提供了简明且有说服力的说明。
燈塔背後的故事
說明新版本 Effective Kotlin 所採用燈塔圖像的來源與意義。
重點摘要
說明燈塔圖像的由來
探討設計取捨與象徵意涵
說明圖像如何呼應書籍的指引主題
這篇短文說明了新版本 Effective Kotlin 封面所採用燈塔意象的由來與意義。文章描述圖像如何被挑選、其象徵意涵(作為指引、清晰與在複雜情境中提供安全航向),以及設計與作者間的溝通與決策過程。文中強調燈塔圖像如何呼應書籍希望為開發者提供可靠做法與方向的宗旨,並指出設計理念力求讓封面既具象徵性又親切易懂。對關心書籍視覺傳達或程式設計理念如何透過圖像表現的讀者,此文提供簡明且具說服力的說明。
KT Academy
作者:
發布:09-11 00:15
Using Multiplatform Kotlin
Focuses on leveraging Kotlin's multiplatform capabilities and defining shared common elements.
重點摘要
Leverage Kotlin's multiplatform features
Define and share common elements across platforms
Streamline cross-platform development and maintenance
The article distills the core idea of employing Kotlin's multiplatform capabilities to define and share common elements across target platforms. It emphasizes structuring code so that platform-agnostic logic, data models, and interfaces are implemented once and reused, reducing duplication and easing maintenance. By focusing on a clear separation between shared modules and platform-specific implementations, teams can maintain consistent behavior while adapting to platform particulars. The approach encourages identifying the smallest set of common artifacts that benefit from centralization, then exposing them through well-defined boundaries so platform-specific code can integrate without redundancy. Overall, using Kotlin multiplatform in this way streamlines cross-platform development, improves code consistency, and accelerates delivery by concentrating shared concerns into reusable components. It also helps enforce clearer architecture and testing strategies for shared logic.
使用 Kotlin 多平台
说明如何善用 Kotlin 的多平台能力并定义共享元素。
重點摘要
善用 Kotlin 的多平台能力
定义并共享跨平台的公共元素
减少重复并提升维护与测试效率
本文核心在于善用 Kotlin 的多平台能力来定义并共享跨平台的公共元素,让与平台无关的逻辑、数据模型与接口在共享模块中实现一次即可重复使用,降低重复与维护成本。通过区分共享与平台专属实现,团队能维持行为一致性并针对平台差异做适配,集中共享构件有助于提升开发效率与测试可行性。
使用 Kotlin 多平台
說明如何善用 Kotlin 的多平台能力並定義共用元素。
重點摘要
善用 Kotlin 的多平台能力
定義並共享跨平台的共用元素
降低重複、提升開發效率與一致性
本文核心在於善用 Kotlin 的多平台能力來定義並共享跨平台的共用元素,讓平台無關的邏輯、資料模型與介面在共用模組中實作一次即可重複使用,降低重複與維護成本。透過區分共用與平台專屬實作,團隊能維持行為一致性並針對平台差異做適配,集中共用構件有助於提升開發效率與測試可行性。
KT Academy
作者:
發布:09-18 00:15
Implementing a Multiplatform Kotlin Library
Use Kotlin's multiplatform capabilities to distribute the same code to multiple platforms.
重點摘要
Write shared code once and reuse it across platforms
Reduce duplication and streamline maintenance
Keep platform-specific code minimal for UIs and APIs
This short piece explains how Kotlin's multiplatform capabilities let developers distribute the same codebase to multiple platforms. By centralizing shared logic in a multiplatform library, teams can avoid duplicating business rules and core functionality, improve consistency, and simplify testing and maintenance. Platform-specific layers remain for user interfaces and native APIs, while the common module handles reusable logic and data processing. The approach is aimed at teams that want to retain single-source logic across different runtime environments, shorten iteration cycles, and reduce the effort of keeping behavior aligned across targets. Overall, Kotlin multiplatform provides a strategy to share code broadly while isolating the parts that must be implemented per platform.
实现 Multiplatform Kotlin 库
利用 Kotlin 的 multiplatform 能力,将相同代码分发到多个平台。
重點摘要
一次编写,在多平台复用
减少重复代码,简化维护
将平台特有实现限制在 UI 与原生 API
本文介绍如何使用 Kotlin 的 multiplatform 功能,将相同的代码库分发到多个平台。通过把共享逻辑集中到 multiplatform 库中,可以避免重复实现核心功能、提升一致性,并简化测试与维护。平台特有的部分(如界面和本地 API)仍需单独实现,而通用的业务逻辑和数据处理则放在共享模块中。该方法适用于希望在不同运行环境间保持单一源码、加快迭代并降低同步成本的团队。总体而言,Kotlin multiplatform 提供了在多平台间共享代码并隔离平台特性的可行策略。
實作 Multiplatform Kotlin 函式庫
利用 Kotlin 的 multiplatform 能力,將相同程式碼分發到多個平台。
重點摘要
一次撰寫,共用至多個平台
減少重複程式碼並簡化維護
僅在 UI 或平臺 API 保留特定實作
本文說明如何使用 Kotlin 的 multiplatform 功能,將相同的程式碼庫分發到多個平台。透過將共用邏輯集中在 multiplatform 函式庫中,可以避免重複實作核心功能、提升行為一致性,並簡化測試與維護工作。需要保留平台特有的部分(例如介面與原生 API),而可重複使用的商業邏輯與資料處理則放在共用模組中。這種做法適合想在不同執行環境間維持單一來源邏輯、加快開發迭代並降低同步成本的團隊。總之,Kotlin multiplatform 提供一種在多平台間分享程式碼同時隔離平台特有部分的策略。
KT Academy
作者:
發布:09-25 00:15
Implementing Multiplatform Kotlin Mobile
How in Kotlin we can implement Android and iOS projects with shared logic.
重點摘要
Use a shared Kotlin module for common business logic
Keep platform-specific native UI on Android and iOS
Leverage KMM tooling to produce platform artifacts
This article describes how to implement Android and iOS projects that share logic using Kotlin Multiplatform Mobile (KMM). The core idea is to place business logic, data access, and core utilities in a common Kotlin module that is compiled for each platform, while keeping the user interface layers native to Android and iOS. Typical practices include exposing the shared code as a Kotlin library for Android and as a native framework for iOS, using expect/actual declarations to handle platform-specific implementations, and relying on Gradle and KMM tooling to build and integrate artifacts. This approach reduces duplicated code, simplifies maintenance, and enables reuse of core features across both mobile platforms while preserving platform-specific UI and integration.
实现 Kotlin 多平台移动应用
介绍如何在 Kotlin 中实现具有共用逻辑的 Android 与 iOS 专案。
重點摘要
通过共用 Kotlin 模块集中业务逻辑
为每个平台保留原生界面层
借助 KMM 工具生成可集成的 Android 与 iOS 构件
本文介绍如何使用 Kotlin Multiplatform Mobile(KMM)在 Android 与 iOS 项目之间共用逻辑。核心思路是将业务逻辑、数据层与公共工具放入一个共用的 Kotlin 模块,分别编译为 Android 的库与 iOS 的原生框架,并在需要时通过 expect/actual 处理平台特定实现。开发流程通常依赖 Gradle 与 KMM 工具链来构建并集成产物,同时在两端保留原生 UI 层以维持平台体验。该方法可减少代码重复、降低维护成本,并实现跨平台核心功能的复用。
實作 Kotlin 多平台行動應用
說明如何用 Kotlin 在 Android 與 iOS 專案間共用邏輯實作。
重點摘要
建立共用 Kotlin 模組放置商業邏輯
各平台保留原生 UI 層以維持使用者體驗
使用 KMM 工具產生 Android 與 iOS 的可整合產物
本文說明如何使用 Kotlin Multiplatform Mobile(KMM)在 Android 與 iOS 專案中共用邏輯。做法是將商業邏輯、資料存取與核心工具放在共用的 Kotlin 模組,由工具編譯成 Android 可用的函式庫與 iOS 可用的原生框架,並在必要時以 expect/actual 實作平台差異。開發流程通常透過 Gradle 與 KMM 工具鏈產出可整合的產物並與各自的原生 UI 層結合。此方式可減少重複程式碼、簡化維護,並在保留平台特有介面與整合性的前提下實現核心功能重用。
KT Academy
作者:
發布:09-26 00:00
Kotlin for Developers series updated to Kotlin 1.9 and ready for 2.0
All the books from the series Kotlin for Developers are ready for Kotlin 2.0!
重點摘要
Series updated for Kotlin 1.9
All books declared ready for Kotlin 2.0
Announcement signals maintained learning resources
The Kotlin for Developers book series has been updated to Kotlin 1.9 and is announced as ready for Kotlin 2.0. The brief notice indicates that all titles in the series have been reviewed to align with recent language changes and compatibility expectations for the upcoming major release. Although the announcement does not enumerate specific revisions, it communicates that the publisher has actively maintained the books to reflect Kotlin's evolution. Developers and readers interested in preparing for Kotlin 2.0 or studying the current language state are advised to consult the updated volumes directly for concrete examples and guidance. The update underscores that the series remains a current reference as Kotlin advances toward its next major version.
Kotlin for Developers 系列已更新到 Kotlin 1.9 并准备支持 2.0
Kotlin for Developers 系列的所有书籍已准备好支持 Kotlin 2.0!
重點摘要
系列已为 Kotlin 1.9 进行更新
所有书籍声明已准备支持 Kotlin 2.0
教材已随 Kotlin 发展进行维护
Kotlin for Developers 系列书籍已针对 Kotlin 1.9 进行了更新,并宣布已准备好支持即将发布的 Kotlin 2.0。该简短公告表明系列中的所有卷册已审阅以符合语言的最新变化并与新版本兼容,便于开发者了解当前状况并规划升级或学习安排。尽管公告未列出具体改动,但传达了出版方对教材的维护和同步意图。有升级或学习需求的读者应直接查阅更新后的书籍以获取具体示例与说明,作为向 Kotlin 2.0 过渡的参考。
Kotlin for Developers 系列已更新至 Kotlin 1.9 並準備支援 2.0
Kotlin for Developers 系列的所有書籍已準備好支援 Kotlin 2.0!
重點摘要
系列已針對 Kotlin 1.9 進行更新
所有書籍宣告已準備好支援 Kotlin 2.0
出版方已維護教材以配合語言演進
Kotlin for Developers 系列書籍已針對 Kotlin 1.9 進行更新,並宣告已準備好支援即將到來的 Kotlin 2.0。公告指出系列中所有書籍已對應語言的最新變動並與新版本相容,方便開發者檢閱現況並規劃升級或學習。雖然原文簡短未列出具體修改項目,但傳達出版方已維護教材以配合 Kotlin 的演進。建議有升級或學習需求的讀者直接參考更新後的各卷以取得具體範例與說明,作為準備向 Kotlin 2.0 過渡的參考。
KT Academy
作者:
發布:10-02 00:00
Effective Kotlin Item 35: Consider Using Dependency Injection
This item explains what dependency injection is, why it matters, and how to apply it in Kotlin.
重點摘要
Defines dependency injection conceptually
Explains why dependency injection is important
Describes how to use dependency injection in Kotlin
This item introduces dependency injection as a design approach where components receive their dependencies from external sources rather than creating them internally. It outlines why dependency injection matters — improving modularity, separation of concerns, and making code easier to configure and replace — and emphasizes its role in writing maintainable applications. The piece then focuses on applying these ideas in Kotlin, showing how to structure code to accept dependencies, how that simplifies testing and composition, and how Kotlin language features can make dependency wiring clearer and less verbose. Rather than prescribing a specific framework, the guidance encourages developers to consider dependency injection as a general technique that helps manage object creation and coupling in Kotlin projects.
Effective Kotlin 第35条:考虑使用依赖注入
本文说明什么是依赖注入、为何重要,以及如何在 Kotlin 中使用它。
重點摘要
解释依赖注入的概念
说明依赖注入的重要性
讲解如何在 Kotlin 中应用依赖注入
本文介绍依赖注入(DI)这一设计方法——由外部提供组件所需的依赖,而非由组件自身创建。文章阐述 DI 如何提升模块化与关注点分离,使配置与替换更便捷,并能简化测试与维护。随后聚焦 Kotlin 的实践,讨论如何构建接收依赖的类、如何利用 Kotlin 特性使依赖管理更清晰,以及这种做法如何帮助降低耦合度。文章并不强推具体框架,而是建议把 DI 作为一种通用技巧,应用于提升 Kotlin 项目的可维护性和可测试性。
Effective Kotlin 第35條:考慮使用依賴注入
本文說明什麼是依賴注入、為何重要,以及如何在 Kotlin 中使用它。
重點摘要
說明依賴注入的概念
闡述依賴注入的重要性
說明在 Kotlin 中如何應用依賴注入
本文介紹依賴注入(DI)——一種由外部提供元件所需依賴,而非由元件自行建立的設計方法。文章說明 DI 能提高模組化與關注點分離,讓配置與替換更容易,並有助於測試與維護。接著聚焦在 Kotlin 的實作面,討論如何設計接受依賴的類別、以何種方式簡化測試,以及 Kotlin 語言特性如何讓依賴管理更清晰與簡潔。文章不限定特定框架,而是建議將 DI 視為一項通用技術,用以降低耦合並改善專案可維護性。
KT Academy
作者:
發布:10-09 00:01
Extensions in Kotlin
Extensions let you add functionality to existing types without modifying their source code or using inheritance.
重點摘要
Add methods and properties to existing types without altering their definition
Declared with a receiver type and resolved statically at call site
Useful for utility functions and improving API readability
This article explains what extensions in Kotlin are and how to use them. Extensions allow developers to define new functions and properties for existing classes or interfaces without changing their original source code or creating subclasses. They are declared by specifying a receiver type (the type being extended) and behave like regular functions from the caller's perspective, though their dispatch is static rather than virtual. The piece outlines typical use cases such as adding utility methods, creating clearer APIs, and grouping helper functions nearby related types. It also notes practical constraints to keep in mind — for example, extensions cannot access private members of the extended type and their resolution depends on static type information. Examples demonstrate declaration and invocation patterns to show common usage.
Kotlin 的扩展 (Extensions)
扩展允许在不修改类源码或使用继承的情况下,为现有类型新增功能。
重點摘要
为已有类型添加方法与属性而不更改类型定义
通过接收者类型声明,调用时按静态类型解析
适合实现工具函数并提升 API 可读性
本文介绍了 Kotlin 中的扩展(extensions)及其使用方法。扩展使开发者可以为已有的类或接口定义新的函数和属性,而无需修改源代码或创建子类。扩展通过指定接收者类型来声明,对调用方而言像普通函数,但其分派是静态的,会根据静态类型选择具体实现。文章列举了典型场景,如添加工具方法、简化调用并提升 API 清晰度,同时提醒实务限制,例如扩展无法访问被扩展类型的私有成员。示例展示了扩展的声明与调用方式,说明了常见的使用模式。
Kotlin 的擴充 (Extensions)
擴充允許在不修改類別原始碼或繼承的情況下,為現有型別新增功能。
重點摘要
可為既有型別新增方法與屬性而不更改定義
以接收者類型(receiver)宣告,呼叫時以靜態方式解析
適用於工具函式與改善 API 可讀性
本文說明 Kotlin 中的擴充(extensions)是什麼以及如何使用。擴充允許開發者為既有的類別或介面定義新的函式與屬性,而不需修改原始碼或建立子類別。擴充以接收者型別宣告,從呼叫方看來像普通函式,但其派發(dispatch)為靜態,會依靜態型別決定要呼叫哪個擴充。文章說明常見用途,例如加入工具方法、使 API 更直觀,並指出實務上的限制,例如擴充無法存取被擴充型別的私有成員。範例示範了如何宣告與呼叫擴充以呈現常見用法。
KT Academy
作者:
發布:10-12 00:01
Kotlin for developers series is finally ready!
We are happy to announce that the Kotlin for developers series is finally complete.
重點摘要
Announcement states the series is complete
Series targeted at Kotlin developers
Official notice posted on kt.academy
We are happy to announce that the "Kotlin for developers" series is now complete. The brief announcement, posted on kt.academy, communicates that the set of materials aimed at developers learning and using Kotlin has been finished and is available as a cohesive collection. Although the message is concise, it signals that readers can now consult the completed series as a structured resource for studying Kotlin language features, idioms, and practical application patterns. The completed collection is intended to serve both newcomers seeking an organized learning path and experienced programmers looking for a reference. Interested developers should visit the linked page to access the full series and any accompanying information about formats or availability.
Kotlin for developers 系列终于准备就绪!
我们很高兴宣布 Kotlin for developers 系列已完整完结。
重點摘要
公告表明系列已完整发布
面向 Kotlin 开发者的教材与参考
官方公告发布于 kt.academy
我们很高兴宣布“Kotlin for developers”系列已完整完结。该公告发布于 kt.academy,表明面向开发者的教学与参考内容已成套发布。公告虽简短,但意味着整套资源现已可供查阅,既适合初学者入门,也可作为有经验开发者的参考手册,涵盖语言特性与实践示例。请至链接页面获取完整系列与相关信息。
Kotlin for developers 系列終於完成!
我們很高興宣布 Kotlin for developers 系列已經完整完成。
重點摘要
公告指出系列已經完成
內容以 Kotlin 開發者為對象
官方公告刊登於 kt.academy
我們很高興宣布「Kotlin for developers」系列已經完整完成。該公告刊登於 kt.academy,說明原先針對開發者的教學與參考內容已成套發表。公告雖簡短,卻意味整套資源現已可供查閱,適合新手作為入門學習,也可作為有經驗開發者的參考手冊,涵蓋語言特色與實作範例。歡迎有興趣的讀者至連結頁面取得完整系列與相關資訊。
KT Academy
作者:
發布:10-16 00:15
Kotlin Reflection: Method and Property References
An overview of Kotlin reference class hierarchy and how method and property references work in reflection.
重點摘要
Describes the general hierarchy of Kotlin reference classes
Explains representation and usage of method references
Details behavior and use of property references in reflection
This article outlines the general hierarchy of Kotlin reference classes and explains how method and property references are represented and used in Kotlin's reflection system. It describes how reference types form a layered class structure that models callable entities, and how developers can obtain and manipulate references to functions and properties at runtime. The piece highlights practical distinctions among reference kinds, the behavior of bound versus unbound references, and how property references expose accessors. It emphasizes using references to inspect, invoke, and interoperate with members dynamically, and discusses typical scenarios where reflection-based references are useful. Overall, the article serves as a concise guide to understanding the structure and behavior of Kotlin’s callable reference types and their role in reflective programming.
Kotlin 反射:方法与属性引用
概述 Kotlin 引用类的层级结构,以及方法与属性引用在反射中的表示与使用。
重點摘要
说明 Kotlin 引用类的一般层级结构
解释方法引用的表示与用法
说明属性引用的行为与访问细节
本文概述了 Kotlin 引用类的一般层级,并说明方法与属性引用在反射系统中的表示与使用。文章描述引用类型如何以分层类结构来建模可调用实体,以及开发者如何在运行时获取和操作函数与属性的引用。内容强调不同引用种类之间的差异、绑定与非绑定引用的行为,以及属性引用如何暴露访问器等细节,并说明这些引用在检查、调用与动态互操作时的实际用途。总体而言,本文为理解 Kotlin 可调用引用类型的结构与行为以及它们在反射编程中角色提供了简明指南。
Kotlin 反射:方法與屬性參考
概述 Kotlin 參考類別的階層結構,以及方法與屬性參考在反射中的表示與使用方式。
重點摘要
說明 Kotlin 參考類別的一般階層結構
解釋方法參考的表示與使用
說明屬性參考的行為與存取細節
本文概述了 Kotlin 參考類別的一般階層,並說明方法與屬性參考在反射系統中的表示與使用方式。文章說明參考類型如何以分層類別結構來建模可呼叫實體,以及開發者如何在執行時取得與操作對函式與屬性的參考。內容強調不同參考種類之間的差異、綁定與非綁定參考的行為,以及屬性參考如何暴露存取器等細節,並說明這些參考在檢查、呼叫與動態互操作時的實際用途。整體而言,本篇提供理解 Kotlin 可呼叫參考類型結構與行為的簡明指南,適合想掌握反射與參考用法的讀者。
KT Academy
作者:
發布:10-17 00:00
Kotlin books for conferences and universities
Special offers are available for conferences and universities that want to give away books.
重點摘要
Special offers available for events and institutions
Targeted specifically at conferences and universities
Designed for organizers who want to give away books
This short announcement notifies conference organizers and university staff that there are special offers related to Kotlin books for groups that wish to distribute them as giveaways. The message is aimed at events and educational institutions interested in providing attendees or students with physical or digital copies, and it directs interested parties to the linked page for details. While the notice does not specify exact terms, quantities, or pricing, it highlights that tailored arrangements exist for bulk or promotional distribution to support outreach or educational initiatives. Organizers looking to include Kotlin books in their attendee or student materials are invited to consult the provided link to learn about eligibility and how to take advantage of these offers.
面向会议和高校的 Kotlin 书籍
我们为想要赠送书籍的会议和高校提供特别优惠。
重點摘要
为会议与高校提供专属优惠
适用于希望发放赠书的活动和机构
请参阅链接页面以获取详细信息
此简短公告告知会议组织者和高校人员,对于希望将 Kotlin 书籍作为赠品分发的团体,有专门的特别优惠可供利用。公告并未列明具体条款、数量或价格,仅说明存在为活动与教育机构提供的优惠安排,以便在会议或课程中向参与者或学生分发书籍。想了解资格、获取方式或更多细节的人士,应访问所给链接以查阅完整说明和联系方式。
供會議與大學使用的 Kotlin 書籍
我們針對想要贈送書籍的會議與大學提供特別優惠。
重點摘要
針對會議與大學的特別優惠
適用於想要發放贈書的活動與機構
請依連結頁面查詢詳細資訊與條件
這則簡短公告說明,對於希望將 Kotlin 書籍作為贈品發放的會議主辦單位與大學,現有專門的特別優惠。內容並未列出具體數量、價格或其他條件,但明確指出有為活動與教育機構量身安排的方案,方便在會議或課程中分發給參與者或學生。欲了解是否符合資格及如何申請或取得優惠的詳細步驟,建議前往原文連結查閱完整說明與聯絡方式。
KT Academy
作者:
發布:10-23 00:15
Kotlin Reflection: Class references
Covers all essential aspects of class references and presents a practical example of object serialization.
重點摘要
Explains the essential aspects of class references in Kotlin reflection
Demonstrates a practical object serialization example
Focuses on real-world usage and core behaviors
This short article presents the core concepts of class references within Kotlin's reflection capabilities and pairs that explanation with a practical object serialization example. It aims to cover the essential aspects developers need to understand when working with class references, explaining their role in reflective operations and how they can be applied in a serialization scenario. Rather than exhaustive coverage of every API detail, the piece concentrates on the most important behaviors and usage patterns that are directly applicable to real-world tasks, helping readers grasp when and why to use class references and how they can support converting objects to serialized forms in practical applications.
Kotlin 反射:类引用
涵盖类引用的所有要点,并演示一个实用的对象序列化示例。
重點摘要
阐述 Kotlin 反射中类引用的关键概念
展示实用的对象序列化示例
侧重于实际使用场景与核心行为
本文简介 Kotlin 反射中类引用的核心概念,并以一个实用的对象序列化示例说明其应用。文章覆盖了在处理类引用时需要理解的主要要点,说明它们在反射操作中的作用以及如何支持序列化工作。内容并非穷尽所有 API 细节,而是聚焦于对开发者在实际项目中最有用的行为和使用模式,帮助读者把握何时以及为何使用类引用,并演示其在对象转序列化场景中的实际应用。
Kotlin 反射:類別參考
說明類別參考的所有重點,並示範一個實用的物件序列化範例。
重點摘要
說明 Kotlin 反射中類別參考的重點
提供實作導向的物件序列化範例
聚焦於實務使用與核心行為
本文簡要介紹 Kotlin 反射中類別參考的核心概念,並搭配一個實用的物件序列化範例說明應用情境。內容涵蓋使用類別參考時需要掌握的主要觀念,說明它們在反射操作中的角色,以及如何在序列化情境中發揮作用。文章不以詳盡列舉所有 API 為目標,而是聚焦於對開發者在實務中最有幫助的行為與使用模式,協助讀者理解何時以及為何使用類別參考,並示範其在物件轉序列化的實務應用。
KT Academy
作者:
發布:10-30 00:15
Kotlin Reflection: Type References
Using type references, demonstrated with a practical random-value generator that produces values based on the referenced type.
重點摘要
Type references allow passing and inspecting type information at runtime via Kotlin reflection.
The article shows how to map type references to value producers to generate appropriate random values.
Practical patterns make it easier to build reusable generators for primitives, collections, and parameterized types.
This article explains how Kotlin's type references can be used with reflection to carry and inspect type information at runtime, and demonstrates the approach with a practical random-value generator. It describes mapping type references to specific value producers so the generator returns values appropriate to the requested type, and shows how the pattern can handle basic types, collections, and parameterized types. The walkthrough emphasizes readable type declarations combined with reflective lookup to build flexible, reusable utilities for test data, mock objects, or factories. By following the example, developers learn how to compose and register generators for different types and how to leverage type references to simplify generic value creation at runtime.
Kotlin 反射:类型引用
通过类型引用示范如何在运行时识别类型,并以随机值生成器作为实作例子。
重點摘要
类型引用可在运行时传递并检查类型信息以配合反射使用。
示例将类型映射到不同的值生成器,以生成符合类型的随机值。
说明如何处理基本类型、集合与参数化类型以构建可复用的生成器模式。
本文介绍 Kotlin 的类型引用在反射中的使用,并通过一个随机值生成器作为实践示例。文章说明如何利用类型引用在运行时识别所需类型,将不同类型映射到特定的值生成器,从而使生成器返回符合类型的随机实例;并展示处理基本类型、集合与参数化类型的方式。将可读的类型声明与反射查找结合,可构建出灵活且可复用的工具,适用于测试数据、模拟对象或通用工厂等场景,帮助开发者简化基于类型生成值的工作流。
Kotlin 反射:型別參考
透過型別參考示範如何以反射在執行期識別型別,並以隨機值產生器作為實作範例。
重點摘要
型別參考可在執行期傳遞並檢查型別資訊以配合反射使用。
範例將型別對應到不同的值產生器,以產生符合型別的隨機值。
示範如何處理基本型別、集合與參數化型別以建立可重用的產生器模式。
本文介紹 Kotlin 的型別參考在反射中的運用,並透過一個隨機值產生器做實作示範。文章說明如何使用型別參考在執行期辨識所需型別,將不同型別對應到特定的值產生器,使產生器能回傳符合型別的隨機實例;同時示範處理基本型別、集合與參數化型別的做法。透過可讀的型別宣告與反射查找的結合,建立出可重用且靈活的工具,適用於測試資料、模擬物件或通用工廠等場景,幫助開發者簡化依型別生成資料的流程。
KT Academy
作者:
發布:11-06 00:00
Effective Kotlin Item 48: Consider using object declarations
Prefer object declarations when you need a single, reusable instance instead of a regular class.
重點摘要
Object declarations create a single, automatically instantiated singleton.
They reduce boilerplate and provide concise, self-contained definitions.
Use them for stateless utilities, managers, or any single-instance need.
This item argues that when a single, globally accessible instance is required, Kotlin's object declarations are preferable to regular classes. Object declarations define a singleton in one concise construct: there is no need to write factory code or manage instances manually. They produce a single object with properties and functions, initialized lazily and safely by the runtime, which reduces boilerplate and the risk of incorrect instantiation. Objects can implement interfaces and hold state or behavior like any class, but without explicit construction. For utilities, managers, or other components meant to exist only once, choosing an object declaration clarifies intent and simplifies code compared with creating a class plus a separate singleton instance or factory.
Effective Kotlin 第48条:考虑使用 object 声明
需要单一可重用实例时,应使用 object 声明而不是常规类。
重點摘要
object 声明会创建单一且自动管理的单例对象。
语法简洁,可减少样板代码与手动实例管理。
适合用于工具、管理器或任何只需单实例的场景。
当程序需要一个全局且可重用的实例时,Kotlin 的 object 声明比常规类更适合。object 在一处声明即为单例,无需编写工厂方法或手动管理实例;对象的属性和方法可以像类一样存在,但由运行时以延迟且线程安全的方式初始化,从而减少样板代码和错误。object 还能实现接口并保存状态或行为,因此对于工具类、管理器或其他设计为单一实体的组件,使用 object 声明可以更明确地表达意图并简化代码。
Effective Kotlin 第48條:考慮使用 object 宣告
需要單一可重用實例時,應以 object 宣告取代一般類別。
重點摘要
object 宣告會建立單一且自動管理的 singleton。
語法簡潔,能減少樣板程式碼與手動實例管理。
適用於工具函式、管理器或任何只需單一實例的情境。
當程式設計上只需要一個全域且可重用的實例時,Kotlin 的 object 宣告比一般類別更合適。object 在一處宣告即為 singleton,免除撰寫工廠或手動管理實例的負擔;物件的屬性與方法可以像類別一樣存在,但由執行階段以延遲且執行緒安全的方式初始化,減少樣板與錯誤。object 也能實作介面並保存狀態或行為,因此對於工具、管理器或其他設計為單一實體的元件,使用 object 宣告能更明確表達意圖並簡化程式碼。
KT Academy
作者:
發布:11-07 00:00
Get an ebook if you have a paperback!
Special promotion: post a photo of your paperback and we'll give you the ebook — valid until the end of this year.
重點摘要
Limited-time promotion through the end of the year
Paperback owners must post a photo of the book
Participants receive the ebook as a giveaway
A special, time-limited promotion runs until the end of this year: we will give away ebooks to readers who own a paperback and post a photo of that paperback. The announcement specifies that paperback owners must share a photograph showing the physical book; after posting the photo they will receive the ebook. The message highlights only the posting requirement and the year-end deadline, without listing additional eligibility conditions or detailed redemption steps. Interested participants should follow the original promotion post for any further instructions or verification details. This offer is temporary and intended to provide ebook copies to those who already own the paperback and submit a photo within the promotional period.
有平装书就领电子书!
限时促销:发布你和平装书的照片,我们将赠送电子书——活动截至今年年底。
重點摘要
活动截止至今年年底
需为平装书持有者并发布书籍照片
发布照片后可获得赠送的电子书
这是一项限时促销,活动截止至今年年底:我们向持有平装书并发布该平装书照片的读者赠送电子书。公告要求平装书持有者上传显示实物书的照片,符合条件者在发布后将收到电子书。公告仅说明了张贴照片的要求与时间限制,未提供其他资格细节或完整兑换步骤。建议有意参与者参考原始促销贴文以获取进一步指引或验证信息。此优惠为临时性赠送,旨在回馈在活动期间分享平装书照片的读者。
有平裝書就領電子書!
限時促銷:只要張貼你與平裝書的照片,即可免費獲得對應電子書,活動至今年底止。
重點摘要
活動限定至今年底
需為平裝書持有者並張貼書籍照片
張貼後可獲得免費電子書
本次為期限定的促銷活動公告指出,活動至今年底止,凡擁有平裝書並張貼該平裝書照片的讀者,即可獲贈電子書。公告僅說明參與者需張貼展示實體書的照片與活動期限,未列出其他附加條件或完整兌換流程。欲參加者應依原始促銷貼文說明操作或確認可能的驗證細節。此優惠為臨時性贈送,目的是回饋已持有平裝書且在活動期間張貼照片的讀者。
KT Academy
作者:
發布:11-13 00:01
Data classes in Kotlin
Data classes are Kotlin classes designed to hold data that the compiler augments with generated methods like equals(), hashCode(), toString(), copy(), and componentN().
重點摘要
Declared with the data keyword in the primary constructor
Compiler auto-generates equals, hashCode, toString, copy, componentN
Commonly used for DTOs, value objects, and simple data holders
Data classes in Kotlin are a concise way to define classes whose primary purpose is to hold data. By marking a class with the data keyword and declaring its properties in the primary constructor, the compiler automatically generates useful implementations such as equals(), hashCode(), toString(), copy(), and componentN() functions. These generated members reduce boilerplate and make instances easy to compare, print, duplicate with modifications, and destructure. In typical use, properties are declared as val for immutability, and copy() or destructuring declarations are used to produce modified or extracted values. Data classes are ideal for DTOs, value objects, and simple containers of state. The article focuses on what data classes are in Kotlin and how to use them, emphasizing their purpose and the convenience they provide when modeling data.
Kotlin 的数据类(Data class)
数据类用于保存数据,Kotlin 编译器会自动生成 equals、hashCode、toString、copy 和 componentN 等方法,减少样板代码。
重點摘要
在主构造函数前使用 data 关键字声明
自动生成 equals、hashCode、toString、copy、componentN 等成员
常用于 DTO、值对象和简单的数据容器
数据类(data class)是 Kotlin 中用于简洁定义以保存数据为主的类。只要在主构造函数前加上 data 关键字并声明属性,编译器会自动生成 equals、hashCode、toString、copy 与 componentN 等方法,减少样板代码,使对象比较、打印、复制与解构更方便。实践中通常将属性设为 val 以保持不可变,通过 copy() 进行修改或使用解构声明提取值。本文聚焦于什么是 data class 以及如何使用它们,强调它们在表示数据对象与简化代码方面的便利性。
Kotlin 的資料類別(Data class)
資料類別是用來保存資料的 Kotlin 類別,編譯器會自動產生如 equals、hashCode、toString、copy 與 componentN 等方法以減少樣板程式碼。
重點摘要
以 data 關鍵字加在主建構子前宣告
自動提供 equals、hashCode、toString、copy、componentN 等方法
適合用於 DTO、值物件與簡單資料容器
資料類別(data class)是 Kotlin 提供用來簡潔定義以保存資料為主的類別。只要在主建構子前加上 data 關鍵字並宣告屬性,編譯器會自動產生 equals、hashCode、toString、copy 與 componentN 等方法,減少樣板程式碼,使物件比較、列印、複製與解構更方便。實務上常將屬性設為 val 以維持不變性,透過 copy() 修改或使用解構宣告取得值。本文重點說明 data class 的用途與基本使用方式,強調它們在表示資料物件與簡化程式碼方面的好處。
KT Academy
作者:
發布:11-14 00:00
Kotlin Essentials Updated with Exercises
Kotlin Essentials was updated to include exercises that help readers practice and consolidate their knowledge.
重點摘要
Kotlin Essentials has been updated
Exercises were added to enable practice
Aims to help readers consolidate knowledge
Kotlin Essentials has been updated to include exercises intended to help readers practice and consolidate their knowledge. The addition provides opportunities for learners to apply concepts and test their understanding through direct practice, turning descriptive content into actionable tasks. By combining explanations with exercises, the update supports active learning and helps readers reinforce key topics and develop practical skills. The release retains the original instructional material while adding practice elements that encourage repetition, review, and hands-on engagement. Overall, the inclusion of exercises enhances Kotlin Essentials as a learning resource for developers and learners seeking to strengthen their Kotlin fundamentals.
Kotlin Essentials 现已新增练习题
Kotlin Essentials 已更新,现增添练习题,帮助读者练习并巩固所学知识。
重點摘要
Kotlin Essentials 已更新
新增练习题以便练习
旨在帮助读者巩固与应用知识
Kotlin Essentials 已更新,现加入了练习题,旨在帮助读者练习并巩固所学内容。新增的练习为学习者提供了将概念付诸实践、检验理解的机会,将说明性材料转化为可操作的练习。通过把讲解与练习结合,此次更新支持主动学习,帮助读者强化重点主题并提升实作能力。在保留原有教学内容的基础上添加练习项,方便读者反复练习与检视学习成果。总体来看,练习题的加入增强了 Kotlin Essentials 作为学习资源的实用性,适合希望稳固 Kotlin 基础的开发者与学习者。
Kotlin Essentials 現已新增練習題
Kotlin Essentials 已更新,現在新增了練習題,讓讀者能練習並鞏固所學知識。
重點摘要
Kotlin Essentials 已更新
新增練習題以便練習
幫助讀者鞏固與應用知識
Kotlin Essentials 已更新,現在新增了練習題,讓讀者能夠練習並鞏固所學知識。這些練習題提供學習者將概念付諸實作、檢驗理解的機會,能把說明性的內容轉化為可操作的練習。透過說明搭配練習,更新有助於主動學習、強化重點主題並提升實作能力。在保留原教學內容的基礎上加入練習項目,方便讀者反覆練習與檢視學習成效。總體而言,加入練習題提高了 Kotlin Essentials 作為學習資源的實用性,適合想穩固 Kotlin 基礎的開發者與學習者。
KT Academy
作者:
發布:11-20 00:00
Effective Kotlin — Item 49: Use caching when possible
Explains why caching is beneficial and outlines general approaches for applying it.
重點摘要
Caching reduces latency and repeated computation.
Use memoization, in-memory caches, TTLs, or persistent caches as appropriate.
Consider invalidation, capacity, thread-safety, and monitoring when implementing.
This item explains why developers should use caching when possible and outlines practical approaches for doing so. Caching stores frequently used or expensive-to-compute results to reduce latency, lower CPU and I/O load, and improve overall throughput. Common techniques include memoization, in-memory caches with eviction policies such as LRU, expiration/TTL settings, and persistent caches for longer-lived data. Key considerations include cache invalidation, capacity limits, thread-safety, consistency with the authoritative data source, and memory versus persistence trade-offs. Implementations should also include monitoring for cache hit rates and staleness, and strategies to warm or refresh caches when needed. The recommendation is to analyze read and update patterns, apply caching where it brings measurable benefit, and accompany it with clear invalidation, testing, and observability to avoid correctness issues or resource exhaustion.
Effective Kotlin 第49条:在可能时使用缓存
说明为何应使用缓存并概述可采用的实现方法。
重點摘要
缓存能降低延迟并减少重复计算。
常用策略有记忆化、内存缓存、过期/TTL 与持久化缓存。
实现时需考虑失效、容量、并发安全与监控。
本条说明为何在可行时应使用缓存:缓存经常访问或昂贵的计算结果,可减少延迟、降低 CPU 与 I/O 负荷、提升吞吐量。常见做法包括记忆化、带驱逐策略(如 LRU)的内存缓存、过期/TTL 设置以及用于长期数据的持久化缓存。关键注意事项有缓存失效机制、容量限制、与权威数据源的一致性、并发与线程安全,以及内存与持久化之间的权衡。建议根据读取与更新模式评估收益,在带有明确失效、刷新策略以及监控指标的前提下应用缓存,以避免正确性问题或资源耗尽。
Effective Kotlin 第49條:在可能時使用快取
說明為何應該使用快取以及如何在實作上採取常見做法。
重點摘要
快取可降低延遲並避免重複計算。
常見做法有記憶化、記憶體快取、TTL 與持久化快取。
實作時須考量失效策略、容量、併發與監控。
本條討論為何在可行時應使用快取:透過暫存常用或昂貴計算結果,可提升效能、降低延遲與資源消耗。文章介紹常見做法,例如記憶化、記憶體快取、配置過期與容量限制、以及持久化快取的應用。並提醒需考量一致性與失效策略、同步與併發存取、安全性與記憶體使用等權衡。總結為:在分析讀取頻率與更新成本後,合理設計快取可顯著改善系統效能,但須配套失效與監控措施以避免不一致或資源耗盡。
KT Academy
作者:
發布:11-27 00:15
Kotlin Symbol Processing (KSP)
A practical overview covering the essential aspects of Kotlin Symbol Processing for real-world use.
重點摘要
KSP provides a Kotlin-first API for annotation-based code generation.
Designed for performance and incremental processing compared with kapt.
Commonly used to implement code generators and compile-time analysis.
Kotlin Symbol Processing (KSP) is a Kotlin-native API for processing symbols and generating code at compile time. It focuses on practical, efficient handling of annotations and other Kotlin language constructs, enabling developers to write processors that inspect source symbols and produce generated code or diagnostics. In practice, KSP is valued for being lighter-weight and more directly integrated with the Kotlin compiler than Java-oriented tools such as kapt, offering better incremental build behavior and performance. Typical uses include generating boilerplate, implementing domain-specific compile-time checks, and integrating with libraries like KotlinPoet for code emission. When adopting KSP, developers consider processor design, testing strategies, build integration (Gradle), and migration paths from existing annotation processors to take advantage of Kotlin-centric features and improved build times.
Kotlin 符号处理 (KSP)
面向实务的概述,说明 Kotlin Symbol Processing 在项目中要点与应用场景。
重點摘要
为 Kotlin 提供原生的符号处理与注解驱动代码生成接口。
比 kapt 更轻量、对增量编译和构建性能更友好。
适用于生成样板代码、编译期分析与自定义代码生成器。
Kotlin Symbol Processing(KSP)是为 Kotlin 打造的编译期符号处理与代码生成接口,侧重于在实际开发中的可用性和效率。开发者可以在编译阶段读取 Kotlin 符号并生成代码或给出诊断信息,常见用途包括自动化生成样板代码、实现编译期检查以及与 KotlinPoet 等工具配合输出代码。相较于面向 Java 的 kapt,KSP 更贴合 Kotlin 编译器,通常能带来更好的增量编译表现和构建性能。在采用 KSP 时,应考虑处理器的设计与测试策略、Gradle 集成,以及从现有注解处理器迁移的具体做法。
Kotlin 符號處理 (KSP)
實務導向概述,涵蓋 Kotlin Symbol Processing 在真實專案中的核心要點。
重點摘要
提供以 Kotlin 為中心的符號處理與註解代碼生成 API。
相較於 kapt 更輕量且有利於增量編譯與效能優化。
常用於產生樣板碼、編譯期檢查與自訂代碼生成器。
Kotlin Symbol Processing(KSP)是一套為 Kotlin 設計的編譯期符號處理與代碼生成 API,強調在實務中的效率與可用性。它允許開發者檢視 Kotlin 原始碼符號並在編譯階段產生程式碼或提示訊息,常見用途包括自動產生樣板碼、實作領域特定的編譯期檢查,以及與 KotlinPoet 等工具整合來輸出程式碼。相較於以 Java 為主的 kapt,KSP 更貼近 Kotlin 編譯流程,通常帶來較好的增量編譯行為與效能。採用時需考量處理器設計、測試方法、Gradle 等建置整合,以及從既有註解處理器遷移的實務步驟。
KT Academy
作者:
發布:12-04 00:00
Effective Kotlin Item 60: Use appropriate collection types
Using non-standard collection types can improve performance in Kotlin.
重點摘要
Select collection implementations that match your use case
Non-standard or specialized collections can reduce runtime overhead
Balance readability and maintainability against measured performance gains
Item 60 of Effective Kotlin advises choosing collection types that fit the problem and performance requirements. The core idea is that the concrete collection implementation matters: different implementations and non-standard, specialized collection types can change memory use, allocation patterns, and runtime overhead. The guidance encourages developers to prefer clear, idiomatic collections by default, but to consider alternatives (for example, specialized or lower-level types) when profiling shows bottlenecks. It also reminds readers to measure real performance impacts and to weigh trade-offs such as API clarity, maintainability, and platform-specific behavior before replacing standard collections.
Effective Kotlin 第60条:使用适当的集合类型
使用非标准的集合类型可以提高 Kotlin 的性能。
重點摘要
选择符合使用场景的集合实现
非标准或专用集合能减少运行时开销
以测量结果为准,平衡可读性与性能取舍
第60条建议开发者根据具体需求选择合适的集合类型,因为不同的集合实现会影响内存使用、分配行为和运行开销。默认应使用清晰且符合惯例的集合,但在性能成为瓶颈时,可考虑采用非标准或专用集合以获得更好的效率。关键是通过基准或分析量化性能差异,并在替换前权衡对可维护性、API 明确性和平台特性的影响,确保优化确实带来实质收益。
Effective Kotlin 第60條:使用適當的集合類型
使用非標準的集合類型可以提升 Kotlin 的效能。
重點摘要
選擇與使用情境對應的集合實作
非標準或專用集合可降低執行時負擔
以度量為依據,權衡可讀性與效能增益
第60條建議開發者根據需求選擇合適的集合類型,因為具體的集合實作會影響記憶體、配置模式與執行效率。一般情況下應優先使用可讀且慣用的集合,但當效能成為瓶頸時,可考慮使用非標準或專用的集合類型來降低開銷。重點是以實際量測為依據,評估替換後對可維護性、API 清晰度與不同平台行為的影響,再決定是否採用替代方案。
KT Academy
作者:
發布:12-11 00:15
Annotation Processing
Implement your first annotation processor in Kotlin.
重點摘要
Implement your first annotation processor
Use Kotlin for the processor implementation
Processor runs at compile time to handle annotations
This article guides developers through implementing their first annotation processor using Kotlin. It outlines the core idea of annotation processing and presents a practical approach to create a processor that detects and handles annotations during compilation. The focus is on Kotlin-specific implementation and on integrating the processor into the build process so annotated elements are discovered at compile time. Aimed at readers new to annotation processing, the guide emphasizes minimal, practical setup and necessary boilerplate to get a working processor running. It also outlines common use cases such as generating auxiliary code and performing compile-time checks, illustrating why processors are useful in Kotlin projects.
注解处理
使用 Kotlin 实现你的第一个注解处理器。
重點摘要
实现你的第一个注解处理器
以 Kotlin 编写处理器
在编译阶段检测并处理注解
本文演示如何使用 Kotlin 实现第一个注解处理器。文章介绍了注解处理的基本概念,并以实践角度说明如何创建一个在编译时检测和处理注解的处理器。重点在于 Kotlin 特定的实现方式,以及如何将处理器集成到构建流程,使被注解的代码能在编译阶段被发现并处理。该指南面向注解处理新手,强调最小的实用配置与必要的样板代码,帮助读者快速搭建可运行的处理器并理解其在编译工具链中的作用,同时概述了常见用途如生成辅助代码与编译期校验。
註解處理
使用 Kotlin 實作你的第一個註解處理器。
重點摘要
實作你的第一個註解處理器
以 Kotlin 編寫處理器
在編譯階段偵測並處理註解
本文示範如何使用 Kotlin 實作第一個註解處理器。文章說明註解處理的核心概念,並以實務導向介紹如何建立一個在編譯時偵測與處理註解的處理器。重點放在 Kotlin 特有的實作方式,以及如何將處理器整合到建構流程,使被註解的程式碼能在編譯時期被發現並處理。此指南針對初學者,強調必要的設定與最小樣板,讓讀者能快速建立可運作的處理器並理解其在編譯工具鏈中的角色,同時說明常見應用如產生輔助程式碼與編譯期檢查。
KT Academy
作者:
發布:12-18 00:15
JavaScript interoperability
How to interoperate between Kotlin and JavaScript.
重點摘要
Concepts and goals of Kotlin–JavaScript interoperability
General approaches for connecting Kotlin and JS code
Considerations for types, runtimes, and build tooling
This article explains how to interoperate between Kotlin and JavaScript. It presents interoperability as the practice of enabling Kotlin and JS code to call and work with each other, describes the reasons teams might combine the two languages, and outlines general approaches and considerations for such integrations. The piece emphasizes key topics developers should be aware of—type representation across boundaries, runtime environments, and build and tooling implications—so they can evaluate trade-offs when sharing logic or integrating modules. Intended as a practical introduction rather than an exhaustive tutorial, the article gives readers a conceptual overview and guidance on what to investigate next when choosing techniques and tools to enable Kotlin–JavaScript collaboration in web or multiplatform projects.
JavaScript 互操作性
说明如何在 Kotlin 与 JavaScript 之间进行互操作。
重點摘要
阐述 Kotlin 与 JavaScript 互操作的概念与目的
概述将两种语言连接起来的一般方法
提示类型映射、运行时环境和构建工具的注意事项
本文说明如何在 Kotlin 与 JavaScript 之间实现互操作,将其定义为让两种语言的代码能够相互调用和协同工作的实践。文章介绍了为什么会需要将 Kotlin 与 JS 结合、常见的整合思路,以及在实施时需要考虑的要点,例如跨语言的类型表示、不同的运行时环境以及构建与工具链的影响。作为一篇实践导向的概述性文章,它旨在为开发者提供判断与选择合适技术路径的参考,并指引后续查找具体工具与示例以在网页或多平台项目中实现 Kotlin 与 JavaScript 的配合。
JavaScript 互操作性
說明如何在 Kotlin 與 JavaScript 之間進行互操作。
重點摘要
說明 Kotlin 與 JavaScript 互操作的概念與目的
概述連接兩種語言的一般方法
提醒型別對應、執行環境與建置工具的考量
本文說明如何在 Kotlin 與 JavaScript 之間進行互操作,將互操作性定義為讓兩種語言的程式能相互呼叫與協同工作。文章介紹為何會需要將 Kotlin 與 JS 結合、可採取的一般整合方式,以及在實作時應注意的重點,例如跨界的型別表示、執行時環境差異以及建置與工具鏈的影響。此文以實務導向的概念性說明為主,旨在幫助開發者評估利弊並指引後續選擇適合的技術與工具,以在網頁或多平台專案中實現 Kotlin 與 JavaScript 的協作。
KT Academy
作者:
發布:12-28 00:00
Big Kotlin Challenge
Do you want to learn Kotlin? Join our Big Kotlin Challenge!
重點摘要
Invitation to learn Kotlin
Direct call to join the Big Kotlin Challenge
Message contains no further details; follow the link for more
This brief announcement invites anyone who wants to learn Kotlin to join the Big Kotlin Challenge. Phrased as a direct question—"Do you want to learn Kotlin?"—it immediately follows with an explicit invitation to participate, making the message a concise call to action. The text itself contains no additional information about format, duration, prerequisites, or content; instead, it functions as a prompt directing interested readers to follow the linked resource for details. As such, the announcement is aimed at motivating prospective learners to take the next step toward studying Kotlin by joining the named challenge. Readers seeking specifics will need to consult the referenced page or contact the organizers, but the core fact communicated here is simple and clear: if you want to learn Kotlin, the Big Kotlin Challenge is being offered as an avenue to do so. It emphasizes accessibility and serves as an initial prompt to engage with the program.
Big Kotlin Challenge
你想学 Kotlin 吗?加入我们的 Big Kotlin Challenge!
重點摘要
邀请想学 Kotlin 的读者参与
以直接提问并呼吁加入挑战为核心
原文未提供更多细节,需点击链接了解
这则简短公告以直接提问的方式向想学 Kotlin 的读者发出邀请:「Do you want to learn Kotlin? Join our Big Kotlin Challenge!」。文字简洁,将学习动机与参与挑战连接,作为明确的行动号召。原文未提供详细的活动信息、课程内容或报名方式,读者若需进一步细节需点击链接或查询活动页面。总体而言,这是一则目标明确的招募或推广讯息,旨在吸引有意学习者的注意并鼓励他们参与 Big Kotlin Challenge,作为学习 Kotlin 的起点。
Big Kotlin Challenge
你想學 Kotlin 嗎?加入我們的 Big Kotlin Challenge!
重點摘要
邀請想學 Kotlin 的讀者參加
以直接提問並呼籲參與作為訊息核心
原文未提供更多細節,需點閱連結了解
這則簡短的公告以直接提問的方式向想學 Kotlin 的讀者發出邀請:「Do you want to learn Kotlin? Join our Big Kotlin Challenge!」。文字簡潔,將學習動機與參與挑戰連結,作為明確的行動呼籲。原文未提供詳細的活動資訊、課程內容或報名方式,讀者若需進一步細節需點閱連結或查詢活動頁面。整體而言,這是一則目標明確的招募或推廣訊息,旨在引起有意學習者的注意並鼓勵他們參與 Big Kotlin Challenge,作為學習 Kotlin 的起點。
KT Academy
作者:
發布:01-03 00:00
Simulating Dice Casting to Evaluate RISC Game Fairness
Use programming to simulate repeated dice-cast battles in RISC and measure whether outcomes are unbiased.
重點摘要
Model dice-based battles with code to observe outcome distributions
Run many simulated trials to estimate fairness statistically
Use results to inform game balance and rule adjustments
This article demonstrates how programming can be used to simulate dice-cast battles in the RISC board game to assess fairness. By encoding the game's battle mechanics and repeatedly simulating encounters, you can gather outcome frequencies and calculate statistical measures that indicate whether particular rules or dice configurations favor one side. The simulation approach lets you explore scenarios at scale, test variations of rules quickly, and visualize differences that would be impractical to observe through manual play alone. Such simulations provide quantitative evidence to support discussions about game balance and can guide adjustments to create a more equitable game experience.
模拟掷骰以评估 RISC 游戏的公平性
用编程模拟大量掷骰战斗,统计结果分布以判断是否存在偏向。
重點摘要
用代码重现 RISC 的掷骰战斗规则
通过大量模拟试验估计结果统计特性
以数据为依据评估并改进游戏平衡
本文介绍如何利用编程对 RISC(类似 Risk 的博弈)中的掷骰战斗进行模拟,以评估游戏公平性。将战斗机制编码后,重复执行大量模拟,可收集不同结果的出现频率并计算统计量,从而判断规则或骰子设定是否偏向某方。模拟方法能快速测试规则变体、扩大样本量并以可视化或数值形式呈现差异,弥补仅靠实际对局难以达到的统计深度。基于这些量化结果,可以更有依据地讨论和调整游戏平衡,提升玩法的公平性与体验。
模擬擲骰以評估 RISC 遊戲的公平性
用程式模擬大量擲骰戰鬥,量化結果分佈以判斷規則是否偏頗。
重點摘要
以程式重現 RISC 的擲骰戰鬥機制
透過大量試驗估計結果的統計分佈
用數據支持遊戲平衡與規則調整
本文示範如何透過程式模擬 RISC(Risk 類型)中的擲骰戰鬥,來檢驗遊戲的公平性。將戰鬥規則程式化後,重複執行大量模擬,可以蒐集各種結果的出現頻率並計算統計指標,判斷是否存在偏向某一方的情形。這種方法能以大樣本快速測試不同規則或數值設定,並將觀察到的差異以數據呈現,彌補僅靠手動實際對局難以達到的樣本量與精確度。透過模擬得到的量化結果,可作為調整遊戲平衡與制定合理規則的依據。
KT Academy
作者:
發布:01-08 00:00
Effective Kotlin — Item 19: Do Not Repeat Knowledge
Repeating domain knowledge across code leads to inconsistency and maintenance pain; centralize knowledge so changes affect one place only.
重點摘要
Duplicated knowledge causes divergence and bugs when requirements change.
Centralize rules into a single abstraction or API to reduce maintenance cost.
Aligns with the Single Responsibility Principle by assigning one owner to each piece of knowledge.
Item 19 explains why repeating knowledge — such as business rules, invariants, formats or assumptions — across multiple places in code is problematic: when requirements change, duplicated implementations diverge, producing bugs, increasing test and maintenance burden, and complicating refactoring. The guidance is to centralize knowledge into a single abstraction, module, or API so that clients depend on that policy rather than re-implementing it. Central ownership localizes changes, simplifies testing and documentation, and makes evolution safer. This practice also relates directly to the Single Responsibility Principle: give one module the responsibility for a specific piece of knowledge (the policy) and let other modules perform mechanics using it, thereby separating decision-making from execution and minimizing inconsistent behavior.
Effective Kotlin 第19条:不要重复知识
将相同知识散布在多个地方会导致不一致与维护困难,应将知识集中到单一拥有者以便变更时只需修改一处。
重點摘要
知识重复会在需求变更时引发实现分歧与错误。
将规则集中到单一抽象或模块可降低维护与测试成本。
与单一职责原则一致,让一个模块负责管理特定知识。
本条说明为何把相同知识(如业务规则、不变式、数据格式或假设)散布在代码多处是危险的:当需求或规则变化时,重复实现容易出现行为不一致、产生错误并增加测试与维护成本。建议将这些知识集中到单一抽象、模块或 API 中,让其他代码依赖该抽象而不是各自重复实现。集中所有权能使变更局部化、测试与文档更简单,也便于重构。这也契合单一职责原则:把特定知识的责任交给一个模块,分离决策与执行,从而减少不一致行为并提升系统可维护性。
Effective Kotlin 第19條:不要重複知識
將相同知識散布在多處會造成不一致與維護困難,應把知識集中到單一擁有者以便變更時只需修改一處。
重點摘要
知識重複會在需求變更時導致實作分歧與錯誤。
把規則集中到單一抽象或模組可以降低維護與測試成本。
與單一職責原則一致,讓一個模組負責管理特定知識。
本條說明為何把相同知識(如商業規則、不變式、資料格式或假設)散布在程式多處是有害的:當需求或規則改變時,重複的實作容易出現行為不一致、產生錯誤並提高測試與維護成本。建議將這些知識集中在單一抽象、模組或 API 中,讓其他程式依賴該抽象而非重複決策。集中擁有使變更可局部化、文件與測試更容易,也便於重構。這也呼應單一職責原則:將特定知識的責任交給一個模組,將決策與執行分離,以避免不一致行為並提高系統可維護性。
KT Academy
作者:
發布:01-15 00:00
Functional Kotlin now with exercises
Functional Kotlin has been updated to include exercises that let readers practice the concepts.
重點摘要
Functional Kotlin updated with exercises
Exercises enable readers to practice and apply concepts
Update pairs explanations with hands-on tasks
Functional Kotlin has been updated to include exercises that allow readers to practice the material presented in the resource. The addition of exercises provides practical tasks alongside conceptual explanations so learners can apply functional programming ideas in Kotlin, test their understanding, and consolidate skills. By working through problems, readers have a structured way to translate theory into code, check comprehension, and gain hands-on experience. The update links explanatory content with active practice, making it easier for developers and learners to internalize patterns and techniques. Overall, the change enhances the resource’s instructional value by providing opportunities to practice and reinforce the knowledge introduced in the original content.
Functional Kotlin 现已加入练习题
Functional Kotlin 已更新,现在新增练习题以便读者练习并应用所学概念。
重點摘要
Functional Kotlin 更新并新增练习题
练习题帮助读者实践并检验知识
将说明内容与实作任务结合以强化学习
《Functional Kotlin》已更新,现在新增练习题让读者可以实践并练习资源中介绍的知识。这些练习提供动手机会,使学习者将函数式 Kotlin 的概念从理论转为实践,检验理解并巩固技能。通过题目练习,读者能更主动地学习,将讲解与实际编码结合,提高在项目中应用的信心与熟练度。本次更新增强了教材的实用性,对想深入掌握函数式编程技术的 Kotlin 使用者尤为有帮助。
Functional Kotlin 現在新增練習題
Functional Kotlin 已更新,現在新增練習題讓讀者可以實作並練習所學知識。
重點摘要
Functional Kotlin 已更新並加入練習題
練習題讓讀者能實作並練習概念
說明內容現可搭配動手練習加強學習
《Functional Kotlin》已更新,現在新增練習題讓讀者可以實作並練習書中或資源所述的知識。這些練習提供動手的機會,讓學習者將函式式 Kotlin 的概念從理論轉為實作,檢驗理解程度並鞏固技能。透過題目練習,讀者能更主動地學習,將說明與實際編碼結合,提高應用於專案的信心與熟練度。此次更新強化了教材的實用性,對想深入掌握函式式編程技術的 Kotlin 使用者尤其有幫助。
KT Academy
作者:
發布:01-22 00:15
Static Code Analysers
Static analysers inspect source code without running it to find issues early — Detekt is one such tool for Kotlin.
重點摘要
Analyze source code without execution
Detect bugs, style violations and maintainability issues
Detekt is a Kotlin-focused static analyser
Static code analysers examine source code without executing programs to identify issues early in development. They look for bugs, potential runtime errors, style violations, code smells, and maintainability problems by applying syntactic and semantic rules, heuristics, and patterns. Integrating static analysis into the build or CI pipeline helps catch regressions, enforce coding standards, and reduce manual code review workload. Detekt is an example of a static analyser tailored to Kotlin: it provides configurable rulesets, reports, and can be extended to fit project conventions. While static analysis cannot replace testing or dynamic analysis, it complements them by surfacing structural problems and enforcing consistency. Choosing the right tool and configuring rules to match team practices maximizes signal-to-noise and developer adoption. Regular use of static analysers supports cleaner codebases, fewer defects, and more predictable maintenance.
静态代码分析器
静态分析在不运行程序的情况下检查源代码以早期发现问题——Detekt 是面向 Kotlin 的此类工具。
重點摘要
在不运行代码的情况下检查源代码
发现错误、风格与可维护性问题
Detekt 是针对 Kotlin 的静态分析工具
静态代码分析器在不运行程序的情况下检查源代码,通过语法与语义规则、启发式判断和既有模式来发现错误、潜在运行问题、风格违规与可维护性缺陷。将静态分析集成到构建或 CI 流程中可以及早拦截回归、强制团队规范并减少代码审查负担。Detekt 是一个面向 Kotlin 的静态分析工具示例,提供可配置的规则集与报告,并可扩展以符合项目惯例。虽然无法替代测试或动态分析,但静态分析能补足二者,提升代码结构一致性与可维护性;选择合适工具并调整规则以配合团队,可以提高准确性与采纳率,保持更干净且缺陷更少的代码库。
靜態程式碼分析器
靜態分析在不執行程式的情況下檢查原始碼以早期發現問題——Detekt 是針對 Kotlin 的此類工具。
重點摘要
在不執行程式下檢查原始碼
找出錯誤、風格與可維護性問題
Detekt 為專門支援 Kotlin 的靜態分析工具
靜態程式碼分析器在不執行程式的情況下檢查原始碼,透過語法與語意規則、啟發式判斷與既有模式來找出錯誤、潛在執行問題、風格違規與可維護性缺陷。將靜態分析整合到建置或 CI 流程中可以及早攔截回歸、強制團隊規範並減少代碼審查負擔。Detekt 是針對 Kotlin 的靜態分析工具範例,提供可配置的規則集與報告,並可擴充以符合專案慣例。雖然無法取代測試或動態分析,但靜態分析能補足兩者,提升程式結構一致性與可維護性;選好工具並調整規則以配合團隊,可提高準確性與採用率,維持更乾淨且較少缺陷的程式碼庫。
KT Academy
作者:
發布:01-29 00:00
Effective Kotlin Item 20: Do not repeat common algorithms
Why extracting utility functions is so important for our programs.
重點摘要
Avoid duplication by centralizing common algorithms
Improve readability, testability, and maintenance
Enable reuse and consistent behavior across codebase
Extracting utility functions for common algorithms prevents repetition and clarifies developer intent by giving a single, well-named place for shared behavior. When algorithms are centralized, code becomes easier to read because callers express intent instead of implementation details, and the implementation can be optimized or corrected in one location. Utility functions also improve testability: isolated functions are simpler to unit-test and to mock or replace. Reuse reduces the chance of subtle inconsistencies or bugs that come from multiple ad-hoc implementations of the same logic. Additionally, central utilities encourage consistent interfaces and make refactoring safer and faster. Overall, taking the time to extract common algorithms into well-documented utilities pays off in fewer defects, easier maintenance, and clearer, more expressive code across the project.
Effective Kotlin 第20条:不要重复常见算法
说明为何将常用算法抽取为工具函数对程序很重要。
重點摘要
通过集中管理避免代码重复
提高可读性、可测试性与维护性
促进复用并保证行为一致性
把常见算法抽取为工具函数可以防止在不同位置重复实现,并通过明确的命名表达开发意图,使调用方不需要关心实现细节。行为集中管理后,修复或优化只需在单一位置进行,降低错误扩散的可能;独立的工具函数也更利于编写单元测试或进行替换和模拟,从而提升整体质量。这种做法还能促进代码复用和接口一致性,使重构过程更安全、速度更快。总之,抽取共用算法能带来更少的缺陷、更便于维护以及更清晰的代码结构。
Effective Kotlin 第20條:不要重複常見的演算法
說明為何將常用演算法抽出成工具函式對程式很重要。
重點摘要
透過集中管理避免程式碼重複
提升可讀性、可測試性與維護性
促進重用並確保行為一致性
將常見演算法抽成工具函式能避免在不同位置重複實作,並以具體的名稱表達程式意圖,使呼叫端不必暴露實作細節。當行為集中管理時,修正或優化只需改在一處,降低錯誤散佈的風險;獨立的工具函式也更容易編寫單元測試或替換模擬物,進而提升整體品質。此做法還能促進程式碼重用與接口一致性,使重構更安全、更快速。總結來說,投入時間抽出共用演算法會換來更少的缺陷、更容易維護與更清晰的程式設計。
KT Academy
作者:
發布:02-05 00:00
Abstraction Design: Introduction
Abstraction hides implementation details and exposes essential behavior so programmers can manage complexity and build reusable components.
重點摘要
Separates interface from implementation
Reduces complexity by hiding details
Enables reuse, decoupling, and safer changes
Abstraction in programming is the practice of defining simplified, higher-level views of systems so developers can reason about behavior without needing all implementation details. By presenting a clear interface and concealing internal complexity, abstraction makes code easier to understand, test, and maintain. Common forms include functions, classes, modules, libraries, and APIs that encapsulate data and operations behind well-defined contracts. Proper abstraction reduces cognitive load, limits the scope of changes, encourages reuse, and helps teams evolve systems independently. It also improves correctness by restricting how components interact and enabling safer substitution or replacement. While over-abstraction can introduce indirection and unnecessary layers, thoughtfully designed abstractions are essential for building scalable, maintainable software and managing complexity across projects and teams.
抽象设计:导论
抽象通过隐藏实现细节并暴露必要行为,使程序员能够控制复杂性并构建可复用的组件。
重點摘要
接口与实现分离
隐藏细节以降低复杂性
促进复用、解耦与安全修改
在编程中,抽象是以更高层次的视角简化系统的做法,使开发者无需掌握所有实现细节即可理解其行为。通过定义明确接口并封装内部复杂性,抽象提高了代码的可读性、可测试性和可维护性。常见形式包括函数、类、模块、库和 API,它们以合同方式封装数据与操作。恰当的抽象能减轻认知负担、限制变更影响、鼓励复用,并允许团队独立演进系统;同时通过限定组件交互方式提升正确性。尽管过度抽象可能引入不必要的间接层,但经过深思熟虑的抽象设计对于构建可扩展和可维护的软件至关重要。
抽象設計:導論
抽象透過隱藏實作細節並暴露必要行為,讓程式設計師能夠控制複雜度並建構可重用的元件。
重點摘要
介面與實作分離
透過隱藏細節降低複雜度
促進重用、解耦與安全變更
在程式設計中,抽象是將系統以較高層次、簡化的視角呈現的做法,使開發者能在不需掌握所有實作細節下理解行為。透過定義清晰介面並封裝內部複雜度,抽象有助於提高可讀性、可測試性與可維護性。常見形式包括函式、類別、模組、函式庫與 API,它們以明確契約封裝資料與操作。良好的抽象能減輕認知負擔、限制變更範圍、鼓勵重用,並允許團隊獨立演化系統;同時藉由限制元件互動方式增進正確性。雖然過度抽象會造成不必要的間接層次,但經過思考的抽象設計對構建可擴展與可維護的軟體至關重要。
KT Academy
作者:
發布:02-19 00:00
Each Function Should Be Written at a Single Level of Abstraction
Write each function at one consistent level of abstraction so its body reads as a single coherent step rather than a mix of high-level intent and low-level detail.
重點摘要
Keep each function focused on one abstraction level.
Extract implementation details into well-named helper functions.
Refactor and name functions so code reads like clear, composable steps.
Item 25 argues that every function should be written at a single level of abstraction and describes how to achieve that. Mixing high-level intent and low-level implementation inside the same function makes code harder to read, test, and maintain. By keeping functions focused on one conceptual layer, high-level routines can orchestrate tasks by calling well-named helpers while low-level routines encapsulate details. The recommended techniques include extracting details into separate functions, giving those functions descriptive names, and refactoring until the statements inside a function operate at the same level. This approach yields clearer code, easier testing, and safer changes, because implementation details can be modified or replaced without altering higher-level logic. It also encourages short, well-named functions and clearer interfaces that communicate intent.
每个函数应以单一抽象层次编写
保持每个函数在一致的抽象层次,避免在同一函数中混合高层意图与低层实现细节。
重點摘要
函数应只表达一个抽象层次的意图。
将实现细节抽取为具描述性的辅助函数。
通过命名与重构使函数内部语句属于同一概念层级。
第25条说明了为什么每个函数应以单一抽象层次编写以及如何实现。当函数同时包含高层意图和低层实现细节时,代码会变得难以阅读、测试和维护。保持函数专注于一个概念层级,使高层函数通过调用命名清晰的辅助函数来编排任务,而低层函数封装具体实现。建议的做法包括将细节抽出为独立函数、使用描述性命名并持续重构,直到函数内部的语句处于相同的抽象层次。这能提升可读性、可测试性和维护性,并减少修改实现时对高层逻辑的影响。
每個函式應以單一抽象層次撰寫
讓每個函式維持一致的抽象層次,避免將高階意圖與低階實作細節混雜在同一函式中。
重點摘要
函式應專注於單一抽象層次。
將細節抽出為具描述性的輔助函式。
透過命名與重構讓函式語句屬於同一概念層級。
第25項說明為何每個函式應以單一抽象層次撰寫,並說明如何做到。當函式同時包含高階意圖與低階實作時,程式會變得難以閱讀、測試與維護。維持單一層次能讓高階函式像編排步驟般呼叫具描述性的輔助函式,而低階函式則封裝具體細節。建議作法包括把實作細節抽出為獨立函式、使用描述性命名,並持續重構直到函式內的敘述屬於同一概念層級。這有助於提升可讀性與可測試性,並在變更實作時降低對高階邏輯的影響。
KT Academy
作者:
發布:02-26 00:00
Item 26: Use Abstraction to Protect Code Against Changes
Abstract volatile parts behind stable interfaces so changes in implementation don't ripple through the codebase.
重點摘要
Isolate variability by defining clear interfaces
Hide implementation details to reduce coupling
Balance upfront abstraction cost against long-term stability
Abstraction is a deliberate technique to shield the rest of the codebase from change by introducing stable interfaces and encapsulating volatile details. By isolating the parts of a system that are likely to change—using interfaces, adapters, facades or other encapsulation mechanisms—you allow implementations to evolve without forcing widespread modifications. This reduces coupling, simplifies testing, and makes substitutions or refactorings safer. However, abstraction has consequences: it requires design effort, can introduce indirection and slight performance costs, and risks mismatched or leaky abstractions if boundaries are poorly chosen. The pragmatic approach is to abstract where volatility is expected or where a clean contract provides clear benefits, and to iterate the abstraction as usage reveals real needs.
第26条:使用抽象来保护代码免受变更影响
把易变的部分封装在稳定接口后面,使实现变化不会波及整个代码库。
重點摘要
通过接口或适配器隔离可变性
隐藏实现细节以降低耦合度
在抽象的前期成本与长期稳定性之间权衡
抽象是一种通过提供稳定契约并封装可能变化的实现来保护代码的做法。将系统中容易变更的部分用接口、适配器或外观模式隔离,可以使实现替换或演进时不必大范围修改依赖者,从而降低耦合、简化测试并提高可维护性。与此同时,抽象会带来设计成本、额外的间接层以及潜在的性能开销,若边界划分不当还可能导致抽象泄漏。实践上应在预期会发生变更或接口带来明显好处的地方引入抽象,并根据实际使用逐步调整抽象边界。
第 26 項:使用抽象以保護程式碼免受變動影響
將容易變動的部分封裝在穩定介面之後,讓實作變更不會波及整個程式碼庫。
重點摘要
以介面或適配器隔離易變元素
隱藏實作細節以降低耦合
在抽象成本與長期穩定性間取得平衡
抽象是一種將變動隔離開來的策略,透過提供穩定的介面並封裝可能變更的實作,避免變動向外擴散。常見做法包括定義介面、使用適配器或外觀(facade)等,把不穩定的部分包在明確契約之後,讓替換或重構能較安全地進行。這能降低耦合、簡化測試,並提高模組互換性。但抽象也有代價:需要前期設計、可能增加間接層與輕微效能損耗,若邊界設計不良還會導致抽象滲漏。實務上應在預期會變動或契約明顯帶來好處的地方施行抽象,並隨使用情境調整。
KT Academy
作者:
發布:03-04 00:00
What is CoroutineContext and how does it work?
CoroutineContext is an immutable collection of keyed elements (Dispatcher, Job, etc.) that defines how a coroutine is executed, cancelled and handled.
重點摘要
Immutable collection of context elements (Dispatcher, Job, Name, etc.)
Elements are keyed and combined with the + operator to form new contexts
Controls dispatching, lifecycle (cancellation) and exception handling
CoroutineContext is the data holder that accompanies a coroutine and determines its behavior. It is an immutable collection of keyed elements—typical examples are Dispatcher (which chooses the thread or thread pool for execution), Job (which manages parent–child relationships and cancellation), CoroutineName, and CoroutineExceptionHandler. Elements implement CoroutineContext.Element and are retrieved by their CoroutineContext.Key; contexts can be combined with the + operator to produce new contexts. The context is available inside coroutines via the coroutineContext property and is usually provided by CoroutineScope when launching coroutines. Specialized elements such as ThreadContextElement bridge thread-local state when coroutines move between threads. In short, CoroutineContext centralizes execution configuration, lifecycle control, and exception handling, enabling structured concurrency and predictable scheduling for coroutines.
什么是 CoroutineContext 以及它如何工作?
CoroutineContext 是一个不可变的元素集合(如 Dispatcher、Job),用于定义协程的执行、取消和异常处理行为。
重點摘要
不可变的元素集合:Dispatcher、Job、CoroutineName 等
元素以 Key 标识,可用 + 合并生成新 context
负责调度、生命周期(取消)与异常处理
CoroutineContext 是伴随协程的资料集合,用于定义协程的执行与管理行为。它是不可变的元素集合,常见元素包括 Dispatcher(决定执行的线程或线程池)、Job(建立父子关系并支持取消)、CoroutineName 与 CoroutineExceptionHandler。每个元素以 Key 标识、实现 CoroutineContext.Element,可通过 CoroutineContext.Key 取得;不同 context 可用 + 运算符合并成新的 context。在协程内可通过 coroutineContext 访问上下文,CoroutineScope 在启动协程时会提供上下文。像 ThreadContextElement 这样的特殊元素可以在协程切换线程时桥接线程本地状态。CoroutineContext 将调度、生命周期和异常处理集中管理,是实现结构化并发与可预测调度的关键。
什麼是 CoroutineContext 以及它如何運作?
CoroutineContext 是一個不可變的元素集合(例如 Dispatcher、Job),用以定義協程的執行、取消與例外處理行為。
重點摘要
不可變的元素集合:Dispatcher、Job、CoroutineName 等
元素以 Key 識別,可用 + 合併成新 context
負責調度、生命週期(取消)與例外處理
CoroutineContext 是伴隨協程的資料集合,用來定義協程的執行與管理行為。它是不可變的元素集合,常見元素有 Dispatcher(決定執行的執行緒或執行緒池)、Job(建立父子關係並可取消)、CoroutineName 與 CoroutineExceptionHandler。每個元素以 Key 識別,實作 CoroutineContext.Element,並可用 + 合併產生新 context;在協程內可透過 coroutineContext 取得。ThreadContextElement 等特殊元素可在協程切換執行緒時橋接執行緒本地狀態。CoroutineContext 集中處理調度、生命週期與例外等行為,是實作結構化並發與可預測排程的核心。
KT Academy
作者:
發布:03-05 00:00
KotlinConf 2024 — What Is This All About?
An exploration of the biggest Kotlin conference and what attendees can expect.
重點摘要
Overview of the conference's purpose and scope
Focus on technical talks, hands-on workshops, and community sessions
Practical guidance for prospective attendees
This article explores KotlinConf 2024, the largest event dedicated to the Kotlin language, summarizing its purpose, structure, and what attendees can expect. It outlines the conference’s focus on technical talks, hands-on workshops, and community-led sessions, and highlights opportunities for learning, networking, and staying current with ecosystem developments. The piece frames KotlinConf as a meeting point for developers, library authors, and teams interested in language features, tooling, and best practices, and notes that it often serves as a venue for official updates and community announcements. It also describes informal networking events, sponsor booths, and chances to meet contributors and maintainers, which can help attendees find collaborators and learn about ecosystem libraries and tools. Practical tips on choosing sessions, balancing deep dives with broader overviews, and making the most of meetups are offered to help prospective attendees maximize value from the event.
KotlinConf 2024 — 这是什么内容?
探索 KotlinConf 2024 —— 规模最大的 Kotlin 会议,以及参会者可以期待的内容。
重點摘要
概述会议宗旨与规模
聚焦技术演讲、实践工作坊与社区交流
为准参会者提供参与与准备建议
本文介绍 KotlinConf 2024——规模最大的 Kotlin 年会,说明会议宗旨、形式与参会者可以期待的内容。内容涵盖技术演讲、实践工作坊与社区主导议程,强调学习、交流与掌握生态系统发展机会;并指出会议常成为官方更新与社区公告的平台。文章还提到非正式交流活动、赞助商展位以及与贡献者、维护者交流的机会,有助于寻找合作伙伴并了解常用工具与库。最后提供挑选议程、平衡深度与广度以及利用活动社交时机扩大人脉的实务建议,帮助有意参会者规划并最大化参会收益。
KotlinConf 2024 — 這是關於什麼?
探索 KotlinConf 2024 —— 規模最大的 Kotlin 會議,以及參加者可期待的內容。
重點摘要
概述會議宗旨與規模
聚焦技術演講、實作工作坊與社群交流
為準參加者提供參與與準備建議
本文介紹 KotlinConf 2024——規模最大的 Kotlin 年會,說明會議宗旨、形式與參加者可期待的內容。內容涵蓋技術演講、實作工作坊與社群主導議程,強調學習、交流與掌握生態系發展的機會;並指出會議常成為官方更新與社群公告的平台。文章也提到非正式交流活動、贊助商攤位與與貢獻者、維護者面談的機會,有助於尋找合作夥伴並了解常用工具與函式庫。最後提供挑選議程、平衡深度與廣度以及利用晚間聚會擴展人脈的實務建議,幫助有意參加者規劃並最大化參會收益。
KT Academy
作者:
發布:03-06 00:00
flatMapMerge is... weird
How not to get surprised by flatMapMerge behavior.
重點摘要
Warnings about unexpected flatMapMerge behavior
Advice to form correct mental models when composing flows
Practical guidance to avoid surprises in asynchronous streams
This short piece, titled "flatMapMerge is... weird," focuses on preventing surprises when using flatMapMerge. It alerts developers to the possibility of unexpected behavior when composing asynchronous flows and emphasizes the importance of forming correct expectations. The article's goal is to help readers recognize common sources of confusion, reduce debugging time, and adopt safer patterns when working with reactive stream composition. Rather than being an exhaustive API reference, it aims to clarify characteristic behaviors and offer practical guidance so developers can more reliably predict outcomes and choose appropriate approaches when using flatMapMerge in real-world code.
flatMapMerge 有点奇怪
如何避免对 flatMapMerge 的行为感到意外。
重點摘要
提醒 flatMapMerge 可能出现的意外行为
强调建立正确心智模型以组合流
提供实务建议以降低惊讶和调试成本
本文以标题「flatMapMerge 有点奇怪」提醒读者如何不被 flatMapMerge 的行为所惊讶。文章指出在合成异步数据流时可能出现的预期落差,强调理解其特性并建立正确心智模型的重要性。内容旨在帮助开发者识别常见困惑来源、减少调试时间,并采用更稳健的写法或替代方案。本文并非详尽的 API 指南,而是提供实务导向的说明与建议,让使用者在实际开发中更准确地预测合成后数据流的行为,避免因行为差异而受困扰。
flatMapMerge 有點奇怪
如何避免對 flatMapMerge 的行為感到意外。
重點摘要
提醒 flatMapMerge 可能帶來的意外行為
強調建立正確的心智模型以組合資料流
提供實務導向的建議以降低驚訝與除錯成本
本文以標題「flatMapMerge 有點奇怪」提醒讀者避免被 flatMapMerge 的行為所驚訝。文章指出在合成非同步資料流時可能出現的預期落差,強調理解其特性與建立正確心智模型的重要性。重點在於協助開發者辨識常見的困惑來源、減少除錯時間,並採取更穩健的寫法或替代方案。此文並非完整的 API 手冊,而是提供實務導向的說明與建議,讓使用者在實際開發中能更準確預測合成後資料流的行為,避免被行為差異所困擾。
KT Academy
作者:
發布:03-18 00:01
Generics in Kotlin
A concise explanation of the core principles behind Kotlin's generics.
重點摘要
Parameterize types to create reusable, type-safe APIs
Use type parameters to reduce casts and prevent runtime errors
Control subtype relationships with bounds and variance annotations
This article distills the essence of how generics work in Kotlin. Generics let you parameterize types so classes, interfaces, and functions can operate on different data types while preserving compile-time type safety. By declaring type parameters you create reusable, type-safe APIs that reduce the need for casts and lower the chance of runtime type errors. Kotlin supports constraining type parameters (upper bounds) to restrict acceptable types and provides variance annotations (in/out) to manage subtyping relationships for generic types. Generics are commonly used across collections and APIs to express intent and enforce contracts between components. Understanding these concepts helps developers design safer, more modular code and improves interoperability with Java generics on the JVM; the article emphasizes conceptual behavior and practical benefits rather than low-level implementation details.
Kotlin 的泛型
扼要说明 Kotlin 泛型的核心原理与用途。
重點摘要
通过类型参数化类与函数以提升可复用性
在编译期保持类型安全并减少类型转换
使用上界与变异注解控制泛型的子类型关系
本文阐述 Kotlin 泛型的核心概念:通过类型参数对类、接口与函数进行参数化,使程序在编译期保持类型安全并提高可复用性,减少强转与运行时错误。Kotlin 支持为类型参数设定上界以限制可接受的类型,并提供变异注解(in/out)来控制泛型类型的子类型关系。泛型广泛用于集合与 API,有助于明确设计意图并强化组件间的契约。理解泛型有助于编写更安全、模块化的代码;本文侧重于概念与实务上的价值,而非底层实现细节。
Kotlin 的泛型
簡要說明 Kotlin 泛型的核心原則與用途。
重點摘要
以型別參數化類別與函式以提高可重用性
在編譯期維持型別安全並減少轉型需求
透過上界與變異註記控制泛型型別關係
本文說明 Kotlin 泛型的核心:以型別參數參數化類別、介面與函式,使程式在編譯期保持型別安全並提升可重用性,減少轉型與執行期錯誤。Kotlin 可對型別參數設定上界以限制可接受型別,並提供變異註記(in/out)來控制泛型的子型關係。泛型廣泛應用於集合與 API,有助於明確設計意圖並強化元件間的契約。理解泛型可幫助撰寫更安全且模組化的程式碼;本文聚焦概念與實務價值,而非深究底層實作細節。
KT Academy
作者:
發布:03-19 00:00
Book Promotion for 2024 Company Workshop Attendees
Our special promotion for company workshops organised in 2024.
重點摘要
Special promotion tied to company workshops in 2024
Promotion concerns books for workshop attendees
Readers should consult the linked article for details
This short announcement states that there is a special promotion of books for attendees of company workshops organized in 2024. The message is concise: it highlights the promotion's existence and directs interested parties to the linked article for complete details. The announcement does not provide further specifics about eligibility, duration, or redemption procedures; instead it functions as a notice to companies and workshop participants that a book-related promotion will be available during 2024 events. The announcement serves as an initial notice and invitation to consult the article or contact the organizers for specifics, scheduling, or to register interest.
2024 公司研讨会参与者书籍促销
我们为 2024 年举办的公司研讨会提供特别促销。
重點摘要
针对 2024 年公司研讨会的特别促销
促销与参与者的书籍相关
请查看文中链接以获取详细信息
本文简短宣布针对 2024 年举办的公司研讨会,提供一项面向参与者的书籍促销活动。内容非常简要,仅说明存在该促销并附上链接以查阅完整资讯。公告本身未列出具体资格、期限或兑换方式,仅作为初步通知;有意参加或欲了解详细条款的公司与参与者,应依文中链接或联系主办单位以获取完整说明。
2024 公司工作坊參與者書籍促銷
我們為 2024 年舉辦的公司工作坊提供特別促銷。
重點摘要
針對 2024 年公司工作坊的特別促銷
促銷內容與工作坊參與者的書籍相關
請參閱連結以取得完整說明
本文短文宣布針對 2024 年舉辦的公司工作坊,提供一項針對參與者的書籍促銷活動。內容非常簡要,只說明有此促銷,並提供連結以查閱完整資訊。公告本身未列出詳細資格、期間或兌換方式,僅作初步通知;有意參加或欲了解具體條件的公司與參與者,應依文中連結或聯絡主辦單位以取得完整說明。
KT Academy
作者:
發布:03-25 00:00
Why Non-Blocking?
From blocking to non-blocking with Kotlin, Coroutines and Spring Boot
重點摘要
Explains why non-blocking I/O matters for throughput and resource efficiency
Introduces Kotlin Coroutines as a way to write non-blocking code with sequential style
Describes integration and migration strategies for Spring Boot applications
This article examines the shift from traditional blocking I/O to non-blocking approaches using Kotlin, Coroutines, and Spring Boot. It outlines the motivations for non-blocking design—improved throughput, lower latency, and better resource utilization—then introduces Kotlin Coroutines as a lightweight concurrency primitive that lets developers write sequential-looking code without blocking threads. The piece discusses how coroutines integrate with Spring Boot, common strategies to move blocking endpoints and libraries to non-blocking equivalents, and the trade-offs involved such as API compatibility and increased debugging complexity. Practical guidance helps developers decide when to adopt non-blocking patterns and how they can improve scalability for I/O-bound workloads in Spring Boot applications.
为何采用非阻塞?
从阻塞到非阻塞:使用 Kotlin、Coroutine 和 Spring Boot
重點摘要
说明非阻塞设计对吞吐量与资源利用的好处
介绍 Kotlin Coroutine 如何在不阻塞线程下实现轻量并发
描述在 Spring Boot 中的整合与将阻塞代码迁移为非阻塞的策略
本文讨论从传统阻塞 I/O 向非阻塞方法的转变,以 Kotlin、Coroutine 和 Spring Boot 为例。文章概述了采用非阻塞设计的动机——提高吞吐量、降低延迟并优化资源利用率,介绍 Kotlin Coroutine 作为轻量并发原语,能在不阻塞线程的前提下让代码保持顺序风格。文中还说明了 Coroutine 与 Spring Boot 的整合方式、把阻塞端点与库改造为非阻塞替代的常见策略,以及此类迁移的权衡(如 API 兼容性与调试复杂度)。文章为在 I/O 密集型负载下提升可扩展性提供了实务考量。
為何採用非阻塞?
從阻塞到非阻塞:以 Kotlin、Coroutine 與 Spring Boot 為例
重點摘要
說明非阻塞設計對吞吐量與資源效率的影響
介紹 Kotlin Coroutine 如何在不阻塞執行緒下實現輕量並發
說明在 Spring Boot 中整合與將阻塞程式轉為非阻塞的策略
本文討論從傳統阻塞 I/O 轉向非阻塞設計,並以 Kotlin、Coroutine 與 Spring Boot 為主軸。文章說明採用非阻塞的動機(包含吞吐量、延遲與資源效率),介紹 Kotlin Coroutine 如何以輕量級並發原語在不阻塞執行緒的情況下讓程式碼看似同步。內容闡述 Coroutine 與 Spring Boot 的整合方式、將阻塞端點與函式庫轉為非阻塞的常見策略,以及此類轉換的取捨(例如 API 相容性與除錯複雜度)。文章並提供何時採用非阻塞設計的實務考量,說明在 I/O 密集型工作負載下,非阻塞模式可提升可擴展性。
KT Academy
作者:
發布:04-15 00:00
A Pattern for Composing Flow Operations
A pattern for composing flow operations shows how to extend and operate on top of your existing flows.
重點摘要
Describes a reusable composition pattern for flows
Focuses on extending and operating on existing flow sequences
Emphasizes reuse, separation of concerns, and safer layering
This article presents a pattern for composing flow operations that enables developers to extend and operate on top of existing flows. It outlines the motivation for layering additional behavior without altering original flow sources, aiming to improve reuse and separation of concerns. The pattern highlights how to add transformations, side effects, or orchestration steps by composing operations around existing streams, so behaviors can be shared and tested independently. The discussion covers expected benefits—such as clearer structure and easier testing—as well as practical considerations like complexity and potential performance trade-offs when adding layers. Overall, the piece offers a practical, high-level approach for safely composing and extending asynchronous data streams by operating above current flow implementations.
组合 Flow 操作的模式
该模式示范如何在现有的 flow 之上进行扩展和操作。
重點摘要
提出可复用的 flow 组合模式
侧重在不修改原始 flow 的扩展与操作
强调重用性、责任分离和更安全的分层
本文介绍了一种用于组合 Flow 操作的模式,核心在于在现有数据流之上新增或操作行为而不修改原始来源。该模式允许开发者通过在流外层添加转换、引入副作用或协调步骤来实现行为复用与独立测试,从而改善代码结构与可维护性。文章同时讨论了采用该模式的优点(如更容易测试与重用)以及实际考量(例如增加的复杂度或性能影响)。总体上,它提供了一种实用的高层方法,帮助在已有的异步数据流上安全地组合与扩展功能。
組合 Flow 操作的模式
這個模式示範如何在既有的 flow 之上擴充與操作。
重點摘要
提出可重複使用的 flow 組合模式
著重在不修改原始 flow 的擴充與操作
強調重用性、責任分離與更安全的分層
本文說明一種用以組合 Flow 操作的模式,重點在於在既有流(flows)之上新增或操作行為,而不需直接改動原始來源。此模式讓開發者能透過在流外層進行轉換、加入副作用或協調步驟來實現行為重用與獨立測試,藉此提升程式結構清晰度與維護性。文章亦指出採用該模式的好處(如更容易測試與重用)與實務考量(例如增加的複雜度或效能影響)。總體而言,它提供一種務實的高階方法,幫助在現有的非同步資料流上安全地組合與擴展功能。
KT Academy
作者:
發布:04-29 00:00
Item 28: Consider wrapping external APIs
Wrapping external APIs isolates your code from third-party changes, centralizes error handling, and simplifies testing.
重點摘要
Decouples application code from vendor-specific details
Centralizes error handling, retries, logging, and metrics
Makes unit testing easier via stable interfaces and mocks
Wrapping external APIs creates an abstraction layer between your application and third-party services. By encapsulating HTTP calls, authentication, serialization, error handling, and retries inside a small module, you decouple the rest of your code from vendor specifics and reduce the blast radius when external interfaces change. A wrapper clarifies intent, provides a single place for logging and metrics, and makes unit testing easier by allowing mocks or fakes. Implementing a wrapper should focus on a stable, domain-oriented interface, hide transport details, map errors to meaningful domain errors, and keep the surface minimal. Start simple, add tests and documentation, and evolve the wrapper as needs appear. The result is code that’s easier to maintain, safer when dependencies change, and simpler to test and observe.
第28项:考虑为外部 API 添加封装
为外部 API 添加封装可以将第三方变动隔离、集中处理错误,并使测试更简单。
重點摘要
将应用代码与供应商细节解耦
集中处理错误、重试、日志和指标
通过稳定接口与 mock/fake 简化单元测试
为何要为外部 API 添加封装以及如何开始:封装(wrapper)在应用与第三方服务之间建立抽象层,将 HTTP 调用、认证、序列化、错误处理与重试等细节封装在一个小模块中。这样可以把供应商特有的变动和故障范围限制在封装内部,简化其余代码、提升可测试性(可替换为 mock 或 fake)、统一日志与度量,并便于将错误映射为有意义的领域错误。实现时应提供稳定且以领域为导向的接口、隐藏传输细节、保持接口简洁,并从简单开始,补充测试与文档,随需求演进。结果是更易维护、更安全且更好测试的系统。
第28項:考慮為外部 API 加上封裝
為外部 API 加上封裝可將第三方變動隔離、集中處理錯誤,並讓測試更容易。
重點摘要
將應用程式與供應商細節解耦
集中處理錯誤、重試、日誌與指標
透過穩定介面與 mock/fake 簡化單元測試
為何要為外部 API 加上包裝以及如何著手:包裝(wrapper)在應用程式與第三方服務之間建立抽象層,將 HTTP 呼叫、認證、序列化、錯誤處理與重試等細節封裝在一個小模組中。這樣能將供應商特有的變化與錯誤半徑限制到包裝內部,簡化其他程式碼、提升可測試性(可替換為 mock 或 fake)、統一日誌與度量,並便於錯誤映射為具意義的領域錯誤。實作時應提供穩定且以領域為導向的介面、隱藏傳輸細節、保持介面簡潔,並從簡單開始、補上測試與文件,隨需求演進。結果是更易維護、更安全且更好測試的系統。
KT Academy
作者:
發布:05-06 00:00
Item 29: Minimize elements’ visibility
Minimizing visible UI elements reduces distraction and clarifies priorities — here’s why it matters and how to achieve it.
重點摘要
Reduce cognitive load for users
Prioritize and surface primary actions
Use progressive disclosure and context-aware display
This item explains why designers should minimize the visibility of interface elements and outlines practical approaches to do so. Keeping fewer elements visible helps users focus on primary tasks, lowers cognitive load, and reduces the chance of errors or accidental interactions. The guidance covers design strategies such as prioritizing content and controls, hiding or de-emphasizing secondary features, and revealing options progressively or only in relevant contexts. It also recommends balancing discoverability and simplicity so important functions remain accessible when needed. Overall, the goal is a clearer, less noisy interface that supports user goals while maintaining accessibility and usability through thoughtful, context-sensitive presentation and testing.
第29项:最小化元素可见性
最小化界面中可见的元素可以减少干扰并明确使用优先级:本文说明原因与做法。
重點摘要
降低用户的认知负担
突出并优先显示主要操作
通过渐进揭示和情境显示隐藏次要功能
本文解释了为什么应最小化界面元素的可见性以及如何实现。减少同时可见的元素有助于用户专注主要任务、降低认知负担并减少误触或混淆。实践上可以通过对内容和控件进行优先排序、隐藏或弱化次要功能、采用渐进揭示、折叠面板或根据情境显示来实现;同时需在简洁性与可发现性之间取得平衡,并通过用户测试与无障碍处理,确保关键功能在需要时仍可访问。
第29項:最小化元素可見性
最小化介面中可見的元素可以減少干擾並釐清使用優先順序:本文說明原因與做法。
重點摘要
降低使用者的認知負擔
突顯並優先顯示主要操作
以漸進揭露與情境顯示隱藏次要功能
本文說明為何應該最小化介面元素的可見性,以及如何實作。減少同時顯示的元素可讓使用者更專注於主要任務、降低認知負擔並減少誤觸或混淆。實務上可透過優先排序內容與控制項、將次要功能隱藏或弱化、採用漸進揭露、折疊面板或依情境顯示來達成;同時要在簡潔性與可被發現性之間取得平衡,並透過使用者測試與無障礙處理,確保重要功能在需要時仍可被存取。
KT Academy
作者:
發布:05-10 00:00
Kotlin bites on X/Twitter 3
A collection of concise Kotlin knowledge bites presented in tweet-sized posts.
重點摘要
Tweet-sized Kotlin tips
Concise, bite-sized explanations
Designed for quick reading and sharing
This short article compiles a set of concise Kotlin 'bites'—extremely brief tips or observations—formatted as tweets for quick consumption and sharing on X/Twitter. Each bite aims to convey a single idea, insight, or practical note about Kotlin, letting readers scan and absorb language features, idioms, or tooling pointers with minimal reading time. The format emphasizes brevity and clarity, making the collection suitable for developers who prefer short, focused reminders or for sharing on social media. The presentation encourages repeated exposure and sharing, helping readers accumulate knowledge over time. It works as a quick reference, a source of reminders during coding, and a prompt for deeper follow-up reading on topics that pique curiosity.
Kotlin 推文精选 3
以推文形式呈现的一系列 Kotlin 小知识。
重點摘要
推文大小的 Kotlin 技巧
简洁、易读的知识片段
适合快速浏览与分享
本文以推文形式汇整一系列简短的 Kotlin 知识片段,每则为一句话或短段落,便于快速阅读与分享。这些“小咬”强调单一概念或实用提醒,帮助开发者在短时间内吸收语言特性、常用写法或工具要点。格式重视简洁与明确,适合作为日常复习、编码时的速查或在社群上传播。通过反复浏览与分享,读者可逐步积累实务经验,并被激发深入研究某些主题的兴趣。
Kotlin 推文精選 3
以推文形式呈現的一系列 Kotlin 小知識。
重點摘要
推文大小的 Kotlin 技巧
簡潔、易讀的知識片段
適合快速瀏覽與分享
本文以推文形式彙整一系列簡短的 Kotlin 知識片段,每則皆為一句話或短段落,便於快速閱讀與分享。這些「小咬」強調單一概念或實用提醒,幫助開發者在短時間內吸收語言特性、慣用法或工具要點。格式重視簡潔與明確,適合用作日常複習、程式開發時的速查或在社群上傳播。透過反覆瀏覽與分享,讀者可逐步累積實務經驗,並被激發深入研究某些主題的動機。
KT Academy
作者:
發布:05-13 00:00
How many threads does your network client use?
Many popular network clients consume way more threads than you might expect.
重點摘要
Network clients often consume far more threads than developers expect.
Excess threads raise memory, scheduling overhead, and scalability concerns.
The article outlines the problem and points toward practical mitigation.
Many widely used network clients allocate far more operating-system threads than developers typically anticipate. This surprising thread consumption can arise from per-connection threads, background workers, blocking I/O, or library defaults; the resulting increase in memory use and scheduling overhead makes debugging harder and limits scalability under load. The article provides a concise overview of why clients end up with high thread counts, how to observe and measure thread usage in real deployments, and how to reason about the trade-offs involved. Its aim is practical: to help engineers recognize when thread growth is problematic and to guide them toward sensible remediation steps so networked applications run more efficiently and scale more predictably without assuming any specific implementation details.
你的网络客户端使用了多少线程?
许多流行的网络客户端消耗的线程数量,远比你想象的要多。
重點摘要
许多网络客户端实际上会使用大量线程。
线程过多会增加内存和调度负担,影响可扩展性。
文章概述问题并指引可行的缓解方向。
许多流行的网络客户端在不经意间会启动比预期更多的操作系统线程,可能来自每连接的线程、后台任务或阻塞式 I/O 及库的默认行为,这会带来更高的内存占用和调度开销,增加调试难度并限制在高负载下的扩展能力。文章简要说明了客户端为何产生高线程数、如何在实际部署中观察和衡量线程使用情况,并讨论在不同场景下的权衡和可行的缓解方向,旨在帮助工程师识别问题、降低不必要的资源消耗,从而使网络应用运行得更高效、更具可扩展性。
你的網路用戶端使用了多少執行緒?
許多常見的網路用戶端所消耗的執行緒數,遠比你預期的要多。
重點摘要
許多網路用戶端實際上會使用大量執行緒。
過多執行緒會增加記憶體與排程負擔,影響擴展性。
本文概述問題並指引實務上可行的緩解方向。
許多常見的網路用戶端在未預期的情況下會啟用大量作業系統執行緒,可能來自每連線的執行緒、背景工作或阻塞式 I/O 與函式庫預設,這會提升記憶體佔用與排程成本,使除錯更困難並限制在高負載下的擴展能力。本文簡要說明用戶端為何會出現高執行緒數、如何在真實部署中觀察與衡量執行緒使用情形,並說明在不同情境下評估取捨與可採取的緩解方向,目的是幫助工程師辨識問題、減少不必要的資源消耗,讓網路應用更有效率且更容易擴展。
KT Academy
作者:
發布:05-15 00:00
Updates in Kotlin for Developers series
We've made changes to the Kotlin for Developers series — here's what's new.
重點摘要
Announcement of updates to the Kotlin for Developers series
Readers are directed to the linked article for full "what's new" details
Encouragement to review the updates to stay current with the series
This brief announcement notifies readers that the "Kotlin for Developers" series has been updated. The notice itself does not enumerate the specific changes; instead it points readers to the linked article where the full "what's new" information is published. The message invites developers and learners who follow the series to consult the article to understand the scope and implications of the updates and to adjust their study or project plans if needed. It also signals that the series is actively maintained to remain current. For the precise list of changes, examples, or version notes, please see the article at the provided link and consider providing feedback to the maintainers if you have questions.
Kotlin for Developers 系列更新
我们已对 Kotlin for Developers 系列进行了更新——以下说明有哪些改动。
重點摘要
公告 Kotlin for Developers 系列已更新
请至链接文章查看完整的“What's new”说明
建议读者检查更新内容以保持学习或项目同步
该简短公告说明「Kotlin for Developers」系列已更新,但正文并未逐条列出具体变更,而是引导读者前往链接文章查看完整的“What's new”说明。公告提示关注该系列的开发者与学习者查看更新内容,以了解更新范围并据此调整学习或项目安排,也表明维护团队在持续保持资料的时效性。如需详细的修订清单或版本说明,请参阅文章并向维护团队反馈问题。
Kotlin for Developers 系列更新
我們已對 Kotlin for Developers 系列進行更新──以下說明有哪些改動。
重點摘要
公告 Kotlin for Developers 系列已更新
請至連結文章查看完整的「What's new」說明
建議讀者檢視更新內容以維持學習或專案的同步
這則簡短公告指出「Kotlin for Developers」系列已經更新,但本文未列出具體變更,並引導讀者前往連結文章查看「What's new」的完整說明。公告提醒追蹤此系列的開發者與學習者檢視新版內容,以了解更新範圍並調整學習或專案計畫,同時也顯示維護團隊持續保持教材時效。若需詳細修訂清單或版本說明,請參考文章內文並回饋意見。
KT Academy
作者:
發布:05-20 00:00
Kotlin Coroutines: Deep Dive — Third Edition Now Available
Learn about the new release of the famous book about Kotlin Coroutines.
重點摘要
The third edition of the Kotlin Coroutines: Deep Dive book is now ready.
The announcement invites readers to learn about the new release.
The article provides a link for readers to find further information.
This brief announcement reports that the third edition of the well-known 'Kotlin Coroutines: Deep Dive' book is now ready. The article's core message is an invitation to readers to learn about the new release; it points to the book's updated edition and provides a link for further information. For Kotlin developers and anyone interested in coroutine-based concurrency, the announcement signals a new edition to consult. The piece does not detail changes or chapter-level content in the announcement itself; instead, it serves as a pointer to the full article where readers can find release notes, availability, and other particulars. Readers are encouraged to follow the provided link to review the official release information and to consider the new edition for their study or reference on Kotlin coroutines.
Kotlin Coroutines: Deep Dive 第三版已发布
了解这本知名 Kotlin 协程书籍的第三版新发行。
重點摘要
《Kotlin Coroutines: Deep Dive》第三版已发布。
公告邀请读者了解此次新发行。
文章提供链接以获取更多发布细节。
本文简短宣布知名书籍《Kotlin Coroutines: Deep Dive》第三版已正式发布,并邀请读者了解此次新发行,文章附有链接以获取完整信息。公告本身未详细列出章节或具体修订内容;欲知新版的变动摘要、发布方式或示例更新,请参阅原文链接。对于 Kotlin 开发者和对协程技术感兴趣的读者而言,该第三版是值得参考的新版本资料。
Kotlin Coroutines: Deep Dive 第三版已推出
了解這本知名 Kotlin 協程書籍的第三版新發行。
重點摘要
《Kotlin Coroutines: Deep Dive》第三版已正式推出。
文章短篇公告並邀請讀者了解新版本。
公告附上連結供讀者取得更多發布資訊。
本文簡短宣布知名書籍《Kotlin Coroutines: Deep Dive》第三版已正式推出,並邀請讀者了解此新發行,文章附上連結以取得完整資訊。公告未在內文詳述章節或具體修訂內容;欲掌握新版的變動摘要、發行方式或範例更新,請參閱原文連結。對 Kotlin 開發者與學習協程技術者而言,該第三版為重要的參考來源。
KT Academy
作者:
發布:05-27 00:00
Learn Kotlin with Marcin Moskala
See what materials and options from Marcin Moskala you can have to learn Kotlin.
重點摘要
Overview of materials and options from Marcin Moskala
Guides readers to explore and choose resources
Serves as an entry point for learning Kotlin
This brief article directs readers to the materials and options offered by Marcin Moskala for learning Kotlin. It invites an exploration of available resources so learners can identify and select what best suits their background, goals, and preferred learning pace. The page serves as an entry point for those interested in Kotlin, highlighting that multiple materials and formats may be available and encouraging readers to compare choices rather than following a single prescribed path. By presenting the offerings in one place, the article aims to make it easier to begin or continue a Kotlin learning journey with guidance from Marcin Moskala. Ultimately, the piece is meant to help prospective learners discover the materials and options they can use to study Kotlin and to empower them to choose the resources that align with their needs.
与 Marcin Moskala 一起学 Kotlin
查看可以从 Marcin Moskala 获取的 Kotlin 学习材料与可选方案。
重點摘要
介绍 Marcin Moskala 的 Kotlin 学习材料与选项
引导读者检视并挑选合适的资源
作为学习 Kotlin 的入口与参考
本文简要说明可以从 Marcin Moskala 获取的 Kotlin 学习材料与选项,邀请读者浏览这些资源并挑选最符合个人背景、目标与学习节奏的方案。该页面作为想学 Kotlin 的人的入口,将可用的材料与选择集中呈现,鼓励比较不同方式而非走单一路径,帮助使用者更容易开始或持续 Kotlin 的学习历程,并根据需求与偏好决定合适的学习方向与资源。
與 Marcin Moskala 一起學 Kotlin
查看可從 Marcin Moskala 獲得的 Kotlin 學習材料與可選方案。
重點摘要
介紹 Marcin Moskala 的 Kotlin 學習材料與選項
引導讀者檢視並挑選適合的資源
作為學習 Kotlin 的入口與參考
本文簡短說明可以從 Marcin Moskala 取得的 Kotlin 學習材料與選項,邀請讀者瀏覽這些資源並挑選最符合個人背景、目標與學習步調的方案。該頁面作為想學 Kotlin 的人的入口,將可用的材料與選擇集中呈現,鼓勵比較不同方式而非採取單一路徑,幫助使用者更容易開始或持續 Kotlin 的學習歷程,並依需求與偏好決定適合的學習方向與資源。
KT Academy
作者:
發布:06-03 00:00
Mutable objects or properties?
Time to answer the question: var/readonly vs val/mutable — which one should you use?
重點摘要
Poses the central question: var/readonly vs val/mutable
Compares the mutability semantics and their implications
Aims to provide guidance for choosing based on intent and trade-offs
This short article sets out to answer a common design question: should you use var/readonly or val/mutable? It frames the comparison between two approaches to mutability, examines the semantics each keyword conveys (that is, whether values or references can change), and considers the practical effects on code clarity, safety, and maintainability. Rather than prescribing a one-size-fits-all rule, the piece aims to describe the trade-offs and typical usage scenarios so readers can choose based on intent: prefer immutability when possible for clearer, safer code, and allow mutability when necessary for performance or stateful behaviors. It targets developers weighing language constructs across projects.
可变的对象还是属性?
现在来回答:var/readonly 与 val/mutable,应该选择哪个?
重點摘要
提出关键问题:var/readonly 与 val/mutable 的选择
对比两者在可变性语义及其影响
说明如何根据意图和权衡来做出决定
本文旨在回答一个常见的设计问题:应该使用 var/readonly 还是 val/mutable?文章对比了这两种表示可变性的写法,说明它们各自传达的语义(例如值或引用是否可以改变),并讨论这对代码可读性、安全性与可维护性的实际影响。文章并不一味给出唯一答案,而是阐述不同方案的权衡与典型使用场景,帮助读者根据设计意图做出选择:在可能时优先采用不可变以提升安全与明确性;在需要性能或维护状态时使用可变。目的是让开发者更清楚地判断何时使用 var/readonly 或 val/mutable。
可變的物件還是屬性?
現在來回答:var/readonly 與 val/mutable,應該選哪一個?
重點摘要
提出核心問題:var/readonly 與 val/mutable 的選擇
比對兩者在可變性語義與實際影響
說明如何根據意圖與權衡來做出選擇
本文要回答一個常見的設計問題:應該使用 var/readonly 還是 val/mutable?文章比對這兩種表示可變性的寫法,說明各自傳達的語義(例如值或參考是否可變)以及對程式可讀性、安全性與可維護性的影響。文章並非片面下結論,而是闡述不同做法的權衡與典型使用情境,幫助讀者依據設計意圖做出選擇:在可能情況下優先不可變以提升安全與明確性;在需要效能或管理狀態時則採用可變。目的是讓開發者更清楚地判斷何時使用 var/readonly 或 val/mutable。
KT Academy
作者:
發布:06-10 00:00
Cancellation in Kotlin Coroutines
Everything you need to know about the cancellation mechanism in Kotlin Coroutines.
重點摘要
Comprehensive overview of coroutine cancellation
Explains how the cancellation mechanism affects running coroutines
Offers practical guidance for handling cancellation in code
This article provides a concise, comprehensive overview of the cancellation mechanism in Kotlin Coroutines. It aims to collect the essential information developers need to understand how cancellation is initiated, how it propagates through coroutine scopes, and what its observable effects are on running coroutines. The piece emphasizes practical knowledge useful for everyday development: recognizing when and why to cancel coroutines, how cancellation interacts with structured concurrency, and what developers should watch out for to avoid common pitfalls. Intended as a one-stop reference, the article helps readers grasp the conceptual model and apply best practices when writing cancellable coroutine-based code in Kotlin.
Kotlin 协程的取消机制
关于 Kotlin 协程的取消机制,您需要了解的全部内容。
重點摘要
对协程取消机制的全面概述
说明取消如何影响正在运行的协程
提供处理取消的实用建议
本文对 Kotlin 协程的取消机制做出简明而全面的介绍,汇总开发者需要掌握的关键点。文章说明取消如何被触发、如何在协程范围内传播以及对正在运行的协程的影响。内容侧重实用性:何时以及为何取消协程、取消与结构化并发的关系,以及避免常见问题的注意事项。作为一份一站式参考,本文帮助读者理解概念并在编写可取消的 Kotlin 协程代码时采用合适的实践。
Kotlin 協程的取消機制
關於 Kotlin 協程取消機制,你需要知道的一切。
重點摘要
完整概述協程的取消機制
說明取消如何影響正在執行的協程
提供實務上處理取消的建議
本文為 Kotlin 協程的取消機制提供一個簡明而完整的總覽,彙整開發者需要掌握的要點。文章說明取消是如何被觸發、如何在協程範圍中傳播,以及對正在執行協程的實際影響。內容強調實務面向:何時及為何需要取消協程、取消與結構化併發的互動,以及避免常見陷阱的注意事項。作為一個一站式參考,本文幫助讀者建立概念模型並在撰寫可取消的 Kotlin 協程程式時採取合適的做法。
KT Academy
作者:
發布:06-10 00:00
Key advantages of Kotlin Coroutines
Kotlin Coroutines simplify asynchronous programming by offering lightweight, structured concurrency with built-in cancellation and clearer, sequential-style code.
重點摘要
Lightweight, non-blocking concurrency
Structured concurrency with scope-based cancellation
Cleaner async code with less callbacks and boilerplate
Kotlin Coroutines excel at making asynchronous and concurrent programming more readable and efficient. They provide lightweight, cooperative concurrency through suspendable functions rather than OS threads, which lets you scale many concurrent tasks without the overhead of thread pools. Coroutines enforce structured concurrency and integrate cancellation and exception handling into scopes and builders, improving lifecycle management. The suspend/resume model leads to linear, sequential-looking code for complex asynchronous flows, reducing callbacks and boilerplate. Coroutines interoperate with existing Java APIs and platform dispatchers, and they support common patterns such as flow-based streams, parallelism, and resource-safe cancellation. They are supported by a mature standard library and tooling that help with debugging and testing asynchronous code, further reducing development friction and runtime surprises.
Kotlin 协程的主要优势
Kotlin 协程以轻量、结构化的并发和内建取消,简化非同步编程并提升可维护性。
重點摘要
轻量且非阻塞的并发方式
结构化并发与作用域级取消
让异步代码线性化,减少回调
Kotlin 协程在处理异步与并发时能提高代码可读性和执行效率。协程以可挂起函数替代 OS 线程,开销小,适合大量并发任务;结构化并发、作用域化的取消与异常处理加强生命周期与资源管理;挂起/恢复模型使复杂异步流程呈现线性代码,减少 callback 与样板代码。协程可与 Java API 和平台调度器互通,支持 Flow、并行执行与安全取消,并具备完善的标准库与调试/测试工具,有助于提升响应性并简化维护。
Kotlin 協程的主要優勢
Kotlin 協程以輕量、結構化的併發與內建取消機制,讓非同步程式碼更清晰且易於管理。
重點摘要
輕量且非阻塞的併發模型
結構化併發與作用域化取消
讓非同步程式碼呈現線性、減少 callback
Kotlin 協程在非同步與併發場景能顯著提升程式可讀性與執行效率。協程以可掛起函式取代 OS 執行緒,資源開銷小,適合大量並發任務;結構化併發、作用域化的取消與例外處理強化生命週期與資源管理;掛起/恢復模型讓複雜非同步流程寫成類似同步的線性程式碼,減少 callback 與樣板碼。協程與 Java API 與平台調度器互通,支援 Flow、並行執行與安全取消,並有標準函式庫與除錯/測試工具,能改善回應性並簡化維護。
KT Academy
作者:
發布:06-10 00:00
The problem of union types for type systems
Union types are not such a good idea for static type systems.
重點摘要
Argues that union types are problematic in static type systems
Highlights trade-offs between flexibility and static guarantees
Calls for careful evaluation by language and type system designers
This short article argues that union types are not well suited to static type systems. It presents a cautionary view: while unions can increase flexibility by allowing values of multiple alternative types, that flexibility can complicate type checking and inference, weaken static guarantees, and make programs harder to reason about and maintain. The piece frames union types as a trade-off between expressiveness and the costs imposed on implementation complexity, developer understanding, and soundness assumptions. Rather than an outright rejection, the article urges language designers and implementers to weigh these costs carefully and consider whether alternatives or constrained designs better serve the goals of a given statically typed language.
类型系统中的联合类型问题
联合类型对静态类型系统并非一个好主意。
重點摘要
认为联合类型不适合静态类型系统
强调灵活性与静态保证之间的权衡
建议语言设计者慎重评估引入联合类型的代价
本文论述了联合类型对静态类型系统的不利之处。作者提出谨慎观点:尽管联合类型能提升类型表达的灵活性,让值属于多种备选类型,但这会增加类型检查与类型推断的复杂度,削弱静态保证,并使程序更难以推理与维护。文章把重点放在灵活性带来的实现成本与可维护性风险上,并建议语言设计者在决定采用或扩展联合类型时,权衡其带来的收益与对实现复杂度、可靠性以及开发者体验的潜在影响。
型別系統中的聯合類型問題
聯合類型對於靜態型別系統來說並非那麼理想。
重點摘要
主張聯合類型不適合靜態型別系統
指出靈活性與靜態保證之間的取捨
提醒語言設計者謹慎評估引入聯合類型的代價
本文論述聯合類型不適合靜態型別系統的觀點。作者指出,雖然聯合類型可以提升型別表達的靈活性,使值可屬於多種備選型別,但這種靈活性會增加型別檢查與型別推論的複雜度,削弱靜態保證,並使程式更難以理解與維護。文章將重點放在設計與實作的折衷與風險上,並非完全否定聯合類型,而是提醒在不同語言目標與使用情境下,必須慎重評估其對實作複雜度、可靠性與開發者體驗的影響。
KT Academy
作者:
發布:06-17 00:00
Power Assert now in Kotlin!
Explains what Power Assert is, how to use it, and how it works in Kotlin.
重點摘要
Describes what Power Assert is
Shows how to use Power Assert
Explains how Power Assert works in Kotlin
This article introduces Power Assert and focuses on three aspects: what Power Assert is, how to use it, and how it operates within Kotlin. It defines the concept, outlines usage scenarios and examples, and describes the way Power Assert interacts with Kotlin code—highlighting how developers can enable and apply it in tests or debugging workflows. The piece aims to give readers a clear, practical understanding of integrating Power Assert into Kotlin projects, covering basic setup and the underlying behavior that makes its assertions informative. Overall, the article serves as a concise guide for Kotlin developers who want to learn what Power Assert does, how to apply it, and what to expect from its operation in the Kotlin environment.
Power Assert 现在可用于 Kotlin!
说明什么是 Power Assert、如何使用,以及它在 Kotlin 中的工作方式。
重點摘要
介绍 Power Assert 的定义
示范 Power Assert 的使用方法
说明 Power Assert 在 Kotlin 中如何工作
本文介绍 Power Assert,重点说明三方面内容:什么是 Power Assert、如何使用它以及它在 Kotlin 中的运行方式。文章阐述了概念,给出使用场景与示例,并描述了 Power Assert 与 Kotlin 代码的基本交互,帮助开发者在测试或调试时将其整合到项目中。总体而言,本文为希望了解 Power Assert 在 Kotlin 环境中用途与工作原理的开发者提供了简洁且实用的入门说明。
Power Assert 現在可用於 Kotlin!
說明什麼是 Power Assert、如何使用,以及它在 Kotlin 中的運作方式。
重點摘要
介紹 Power Assert 的定義
示範 Power Assert 的使用方式
說明 Power Assert 在 Kotlin 中如何運作
本文介紹 Power Assert,並聚焦三個面向:什麼是 Power Assert、如何使用它,以及它在 Kotlin 中的運作原理。文章說明概念並示範使用情境,說明如何在 Kotlin 專案中啟用與應用 Power Assert,並描述其與 Kotlin 程式碼互動的基本行為,讓開發者能在測試或除錯時使用。整體上,本篇為想了解 Power Assert 在 Kotlin 環境中用途與運作的開發者提供簡明且實用的入門說明。
KT Academy
作者:
發布:06-24 00:00
Item 27: Specify API stability
How to specify API stability and why it matters.
重點摘要
Define explicit versioning and compatibility guarantees
Publish deprecation policies and clear change notices
Use testing, monitoring, and communication to reduce breakage
The article examines how to specify API stability and why that specification matters for both providers and consumers. It outlines common practices for communicating stability, including explicit versioning schemes (such as semantic versioning), published compatibility promises and deprecation policies, and clear documentation and change notices so clients know what to expect. Specifying stability reduces integration risk, builds trust, lowers maintenance and support costs, and helps clients plan upgrades. The piece also highlights practical measures—compatibility testing, automated contract checks, and monitoring of client usage—to validate promises and detect regressions early, and recommends clear deprecation timelines and migration tooling to make breaking changes less painful. Making API stability explicit enables safer, more sustainable evolution of software ecosystems while minimizing disruption.
条目 27:指定 API 稳定性
如何指定 API 稳定性,以及为何如此重要。
重點摘要
明确版本与兼容性承诺
公开弃用策略与变更说明
通过测试、监控与沟通减少破坏性变更
本文讨论如何具体指定 API 的稳定性及其重要性。文章说明可以透过版本号(如语义化版本)、兼容性承诺、明确的弃用策略以及公开的变更说明与文件来传达稳定性;并强调采用兼容性测试、自动合约检查与客户端使用情况监控,有助于验证承诺并及早发现回归。清晰的弃用时程与迁移工具可降低破坏性变更的影响。总之,把 API 稳定性明文化可以减少整合风险、建立信任,使提供方与使用方在演进过程中更协调,从而维持生态系统的可持续发展。
項目 27:指定 API 穩定性
如何指定 API 穩定性,以及為何如此重要。
重點摘要
明確版本與相容性保證
公開棄用政策與變更說明
以測試、監控與溝通降低破壞性變更
本文討論如何具體指定 API 的穩定性及其重要性。文章說明可透過版本號(例如語義化版本)、相容性承諾、明確的棄用政策、公開的變更說明與文件來傳達穩定性;並強調使用相容性測試、自動合約檢查與用戶端使用情況監控,有助於驗證承諾並及早發現回歸。清晰的棄用時程與升級工具能降低破壞性變更的影響。總之,將 API 穩定性明文化可減少整合風險、建立信任,並讓供應方與使用方在演進過程中更協調,維持生態系可持續發展。
KT Academy
作者:
發布:06-27 00:00
SharedFlow vs StateFlow
When to use SharedFlow and when to use StateFlow.
重點摘要
Explains when to use SharedFlow
Explains when to use StateFlow
Compares the two to guide selection
This article explains when to use SharedFlow and when to use StateFlow. It presents a focused comparison that helps Kotlin developers decide which flow type fits a given situation, describing their intended roles and practical consequences for application design. The piece walks readers through common scenarios and decision points, emphasizes the distinction between broadcasting events and representing mutable state, and offers guidance on selecting the appropriate abstraction. Rather than deep technical reference, it serves as a practical guide with examples and patterns that clarify typical usage, trade-offs, and best practices. By the end, readers should understand the high-level criteria to prefer SharedFlow or StateFlow in their coroutines-based architectures and feel equipped to apply the right choice in real projects. It is written succinctly to be quickly actionable for engineers deciding on event propagation or state management patterns.
SharedFlow 与 StateFlow 的使用时机
何时使用 SharedFlow、何时使用 StateFlow。
重點摘要
说明何时使用 SharedFlow
说明何时使用 StateFlow
比较两者以便选择
本文说明何时应使用 SharedFlow、何时应使用 StateFlow,提供针对性的比较以帮助 Kotlin 开发者在实际场景中做出选择。文章描述两者的预期角色与使用情境,带领读者浏览常见案例与决策要点,强调事件广播与状态表示的不同,并给出可直接采用的建议与示例模式。整体风格实用且精简,旨在帮助工程师在协程架构中判断应选哪种 flow,并在真实项目中快速应用合适的方案。
SharedFlow 與 StateFlow 的使用時機
何時使用 SharedFlow、何時使用 StateFlow。
重點摘要
說明何時使用 SharedFlow
說明何時使用 StateFlow
比較兩者以協助選擇
本文說明何時應使用 SharedFlow、何時應使用 StateFlow,提供專注的比較以協助 Kotlin 開發者在實務上做出選擇。文章闡述兩者各自的角色與使用情境,帶讀者檢視常見案例與決策要點,強調事件廣播與狀態表示的不同,並提供可直接應用的建議與範例模式。整體風格實用精簡,旨在幫助工程師在協程架構中判斷應採用哪種 flow,並在真實專案中快速套用適當方案。
KT Academy
作者:
發布:07-01 00:00
Kotlin Coroutines dispatchers
Guidance on where to use each dispatcher from the Kotlin Coroutines library.
重點摘要
Describes the intended role of each dispatcher
Offers guidance for selecting dispatchers by workload
Notes trade-offs affecting performance and threading
This article surveys the dispatchers provided by the Kotlin Coroutines library and explains where each dispatcher is appropriate. It clarifies the role dispatchers play in defining coroutine execution context and threading behavior, and offers practical guidance for selecting dispatchers that fit different kinds of work. The piece highlights considerations such as CPU-bound versus I/O-bound tasks, UI/main-thread constraints, and the importance of avoiding blocking or inappropriate thread use. It emphasizes matching dispatcher choice to workload to improve responsiveness and correctness, and discusses trade-offs including concurrency, context-switch overhead, and thread confinement. The overall aim is to help developers pick the simplest, safest dispatcher that meets performance and lifecycle requirements in real applications.
Kotlin Coroutines 调度器(dispatchers)
说明 Kotlin Coroutines 中各个 dispatcher 在何种情境下使用。
重點摘要
说明各 dispatcher 的用途与定位
按工作类型给出选择 dispatcher 的建议
讨论影响性能与线程使用的权衡点
本文梳理了 Kotlin Coroutines 提供的各类 dispatchers,并说明每种 dispatcher 适用的场景。文章阐明 dispatcher 如何决定协程的执行上下文与线程行为,并根据任务性质(如 CPU 密集、I/O 密集或需要主线程的 UI 操作)提供选择建议。内容强调要避免阻塞或不当占用主线程,讨论与性能、并发、上下文切换以及线程封闭性相关的权衡。其目的在于帮助开发者在实际项目中选择符合响应性和正确性需求的最合适 dispatcher。
Kotlin Coroutines 調度器(dispatchers)
說明 Kotlin Coroutines 各種 dispatchers 應在何種情境下使用。
重點摘要
說明每種 dispatchers 的用途與定位
依工作類型提供選擇 dispatchers 的建議
討論效能與執行緒相關的取捨與風險
本文整理 Kotlin Coroutines 提供的各種 dispatchers,說明每種 dispatchers 適合使用的情境。文章說明 dispatchers 如何決定協程的執行背景與執行緒行為,並以工作性質(如 CPU 密集、I/O 密集或需要主執行緒的 UI 操作)為依據,提供選擇建議。內容強調避免阻塞或不當佔用主執行緒,並討論與效能、並發、上下文切換及執行緒封閉性相關的取捨。目標是協助開發者在實務中挑選最簡單且安全的 dispatcher,以兼顧響應性與正確性。
KT Academy
作者:
發布:07-08 00:00
Item 30: Define contracts with documentation
Explain how to express library or module contracts and why those contracts matter.
重點摘要
Document the expectations of components: interfaces, parameters, returns and side effects
Use examples, types, formal specs or tests to make contracts verifiable
Clear contracts prevent misuse, ease maintenance and support compatibility
This item explains why we should define library or module contracts in documentation and how to express them. Contracts capture expectations between a component and its callers: public interfaces, parameter semantics, return values, side effects, pre/postconditions, error handling, and compatibility or version guarantees. Documentation can be plain prose, formal interface descriptions, annotated types, or executable artifacts such as tests and contract checks; examples and migration notes help consumers adopt correct usage. Well-defined contracts reduce misuse, simplify maintenance and refactoring, make guarantees explicit for implementers and users, and serve as criteria for compatibility and testing. The appropriate level of formality depends on project complexity and risk, but recording and communicating responsibilities and guarantees clearly is essential.
第30项:用文档定义契约
说明如何通过文档表达库或模块的契约,以及这些契约为何重要。
重點摘要
记录接口、参数、返回值、副作用与前后条件等期待
可用示例、类型注解、规范或可执行测试来表达契约
清晰的契约能防止误用、简化维护并支持兼容性
本项说明为何要通过文档定义库或模块的“契约”,以及如何表达这些契约。契约用于记录组件与调用方之间的期待:公开接口、参数语义、返回值、副作用、前后条件、错误处理及兼容或版本保证。文档可以是自然语言说明、规范化的接口描述、类型注解或可执行的测试与契约检查,示例与迁移说明能帮助使用者正确采用。清晰的契约可减少误用、简化维护与重构、让实现者與使用者明确各自的保证,并作为兼容性与测试的依据。根据项目复杂度与风险选择合适的形式,但核心是清楚记录与传达组件的职责与保证。
第30項:以文件定義契約
說明如何以文件表述函式庫或模組的契約,以及為何這些契約很重要。
重點摘要
記錄介面、參數、回傳、副作用與前後條件等期待
可用範例、型別標註、規範或可執行測試來表述契約
清楚的契約可防止誤用、簡化維護並維持相容性
本項說明為何要以文件定義函式庫或模組的「契約」,以及如何表述這些契約。契約透過明確記載介面、參數與回傳值、前後條件、錯誤處理、相依與版本承諾,以及使用範例與測試,傳達元件對使用者與實作者的期待。表述方式可採自然語言說明、規範化的 API 描述、型別簽章或可執行的測試與契約檢查,視專案複雜度與風險選擇合適形式。良好的文件能降低誤用風險、簡化維護與重構、明確保證並作為相容性與測試的依據,將契約清楚記錄是溝通保證與降低成本的關鍵做法。
KT Academy
作者:
發布:07-10 00:00
How to Get Your Workshop Financed by Your Company
Practical steps to secure company funding for your workshop.
重點摘要
Prepare a clear business case tying the workshop to company goals
Provide a transparent budget, outcomes, and success metrics
Engage stakeholders early and offer scalable or cost-sharing options
This article explains how to get your workshop financed by your company. It outlines the essential steps: prepare a concise business case that links the workshop to company objectives, employee skill development, or solutions to a specific problem; provide a transparent budget and expected outcomes (such as increased productivity, reduced errors, or measurable learning gains); and propose a clear plan for delivery, timeline, and measures of success. It also advises engaging the right stakeholders—your manager, HR, or learning and development teams—early, addressing potential objections, and offering alternatives such as scaled formats or cost-sharing to increase approval chances. Emphasizing return on investment and aligning the request with organizational priorities are key to securing funding.
让公司资助你的工作坊
说明如何获得公司资金支持来举办工作坊。
重點摘要
准备能关联公司目标的商业理由
提供清晰预算、预期成果与衡量标准
提前与主管或培训部门沟通并提出替代方案
本文说明如何向公司争取工作坊经费,重点在于准备有力的商业理由:阐明工作坊如何支持组织目标、提升员工技能或解决具体问题;提交清晰预算与预期成果(例如提高生产力或学习成效),并拟定可执行的计划与时间表。建议尽早与直属主管、人力资源或培训部门沟通,回应可能的疑虑,必要时提出缩减规模或成本分担等替代方案,通过强调投资回报与与组织优先事项的一致性,提升经费获批的可能性。
讓公司資助你的工作坊
說明如何取得公司資金支持以舉辦工作坊。
重點摘要
準備能連結公司目標的商業理由
提出清晰預算、預期成效與衡量標準
提早與主管或培訓單位溝通並提供替代方案
本文說明如何向公司爭取工作坊經費,重點在於準備有力的商業理由:說明工作坊如何支持組織目標、提升員工技能或解決具體問題;提出清晰預算與預期成效(例如生產力或學習成果),並建議可行的執行方式與時間安排。作者建議與直屬主管、人資或培訓單位溝通,強調投資回報與成本效益,必要時提供縮小規模或成本共擔等替代方案,以提高核准機率。
KT Academy
作者:
發布:07-15 00:00
Job and children awaiting in Kotlin Coroutines
Job is the core coroutine context element that enables structured concurrency by tracking child coroutines and controlling their lifecycle.
重點摘要
Job is a coroutine context element representing a cancellable lifecycle.
Jobs form parent–child relationships and track children for structured concurrency.
Job coordinates cancellation and completion so parents can await or cancel descendants.
In Kotlin coroutines, Job is the central context element responsible for structured concurrency. A Job represents a cancellable unit of work and can have child Jobs, forming a parent–child hierarchy that ensures predictable lifecycle management. Through this relationship, a parent Job can wait for its children to complete, propagate cancellation to descendants, and observe their completion state. This mechanism enforces structured concurrency by keeping coroutine lifecycles tied to their scope and by making cancellation and joining explicit and composable. Understanding Job and how children are awaited is essential to reliably compose and manage concurrent coroutines without leaks or uncontrolled background work.
Kotlin 协程中的 Job 与子协程等待
Job 是协程上下文中的核心元素,通过跟踪子协程并管理其生命周期来实现结构化并发。
重點摘要
Job 表示可取消的工作及其生命周期。
Job 通过父子关系追踪子协程以实现结构化并发。
父 Job 可以等待或取消子协程,统一管理完成与取消流程。
在 Kotlin 协程中,Job 是负责结构化并发的核心上下文元素。Job 表示一个可取消的工作单元,并能形成父子 Job 层次,使父协程能够等待子协程完成、将取消传递给后代并观察完成状态。该机制使协程的生命周期与作用域绑定,避免后台工作失控或资源泄露,并使取消和 join 等操作变得显式且可组合。理解 Job 与子协程的等待方式是可靠构建与管理并发协程的关键。
Kotlin 協程中的 Job 與子協程等待
Job 是協程上下文中的核心元素,透過追蹤子協程並管理其生命週期來實現結構化並發。
重點摘要
Job 表示可取消的工作與其生命週期。
Job 透過父子關係追蹤子協程以維持結構化並發。
父 Job 可等待或取消子協程,統一管理完成與取消行為。
在 Kotlin 協程中,Job 是負責結構化並發的關鍵上下文元素。Job 代表一個可取消的工作單位,能與子 Job 建立父子階層,使得父協程能等待子協程完成、將取消向下傳播,並觀察子協程的完成狀態。這種父子結構可讓協程生命週期與其作用域綁定,避免背景工作失控或資源洩漏,並使取消與 join 等操作顯性且可組合。理解 Job 與子協程的等待機制是正確構造和管理並發協程的基礎。
KT Academy
作者:
發布:07-22 00:00
Item 31: Respect Abstraction Contracts
Just because we can do something doesn't mean we should — respect abstraction contracts and understand why it matters.
重點摘要
Capability ≠ appropriateness — avoid doing something just because it's possible
Honor public interfaces and documented contracts rather than relying on internals
Breaking abstractions creates fragile, hard-to-maintain systems
Abstraction contracts define the expectations between components: what callers may rely on and what implementations may change. Respecting those contracts means using only the public, documented surface of a component and not depending on internal details, even if doing so is technically possible. Violating abstractions can lead to subtle bugs, brittle code, and higher maintenance cost because implementations can change without notice. To keep systems robust, treat interfaces as promises: follow their guarantees, document behavior and invariants, and evolve implementations through sanctioned extension points or explicit contract changes. This discipline preserves modularity, makes code easier to reason about, and reduces the risk of cascading failures when internals change.
第31项:尊重抽象契约
能做并不意味着就该做——尊重抽象契约并理解其重要性。
重點摘要
能做不代表应该做,别因为可行就绕过契约
使用公开接口与已文档化的契约,不依赖内部实现
破坏抽象会导致代码脆弱且难以维护
抽象契约规定了组件之间的约定:调用方可以依赖的行为以及实现可以变化的范围。尊重契约意味着仅通过公开且有文档的接口交互,不依赖内部细节,即便技术上可行也不去利用。违反契约会带来隐蔽的错误、提高维护成本,并使系统在内部变更时脆弱。为保持模块化与可理解性,应把接口视为承诺:遵守其保证、清晰记录行为与不变条件,并通过正式的扩展点或明确的契约变更来演进实现。这样能减少故障蔓延并降低长期维护负担。
第31條:尊重抽象合約
能做不代表應該做——尊重抽象合約並理解其重要性。
重點摘要
能做不等於應該做,避免因可行就繞過合約
使用公開介面與文件化的契約,不依賴內部實作
違反抽象會造成脆弱且難維護的程式碼
抽象合約定義了元件間的期望:呼叫者可依賴的行為與實作可變動的範圍。尊重合約就是只透過公開且文件化的介面互動,不依賴內部細節,即便技術上可行也不去使用。違反合約可能引發微妙錯誤、增加維護成本,且使系統在內部變動時脆弱難以修正。為維持模組化與可理解性,應把介面當作承諾:遵守其保證、清楚記錄行為與不變條件,並透過正式的擴充點或合約變更來演進實作。此做法能降低故障傳播與長期維護負擔。
KT Academy
作者:
發布:09-18 00:00
Which Kotlin workshop to choose?
A short guide on how to choose the best Kotlin workshop for you.
重點摘要
Assess your current Kotlin and programming experience
Match workshop topics and format to your learning goals
Prefer hands‑on exercises and schedules that fit your time
This short guide helps you choose the best Kotlin workshop by focusing on a few practical decision points. Begin by assessing your existing Kotlin and general programming experience, then clarify what you want to achieve—whether fundamentals, advanced topics, or practical project work. Compare workshops by topic coverage, the balance between hands‑on practice and lectures, prerequisites, instructor experience, class size, format (in‑person, live online, or self‑paced), duration and scheduling. Consider tangible outcomes such as sample projects, assignments and instructor feedback, and weigh cost against expected value and available time. If unsure, prioritize workshops that align with your immediate goals and include practical exercises so you can apply what you learn quickly.
选择哪个 Kotlin 工作坊?
一份简短指南,说明如何选择最适合你的 Kotlin 工作坊。
重點摘要
评估你当前的 Kotlin 与编程经验
将课程主题与学习目标进行匹配
优先包含实作练习且时间安排合适的课程
这是一份简短指南,指导你如何挑选最适合自己的 Kotlin 工作坊。首先评估你现有的 Kotlin 和编程能力,明确学习目标(例如基础、进阶或实作项目),然后比较各工作坊的主题覆盖、实作比重、先修需求、师资与班级规模,以及授课形式(线下、线上直播或自学)、时长与时间安排。注意课程是否提供示例项目、作业与反馈,并在费用与期望收益之间做平衡。若难以抉择,可优先选择与当前目标匹配并包含实作练习的工作坊,以便尽快将学习转化为实际成果。
要選哪個 Kotlin 工作坊?
一份簡短的指南,說明如何選擇最適合你的 Kotlin 工作坊。
重點摘要
先評估你目前的 Kotlin 與程式經驗
比對課程主題與學習目標的對應度
優先實作練習與符合時間安排的授課方式
這是一份簡短指南,說明如何挑選最適合自己的 Kotlin 工作坊。先評估你目前的 Kotlin 與程式能力,釐清學習目標(如基礎、進階或實務專案),再比較各工作坊的主題範圍、實作與講授的比例、先備條件、師資與班級規模,以及授課形式(實體、線上直播或自學)、時長與時間安排。留意課程是否提供範例專案、作業與回饋,並在費用與預期收穫間做取捨。若不確定,可優先選擇與當前目標相符且包含實作練習的課程,以利將學習快速轉化為成果。
KT Academy
作者:
發布:10-09 00:03
Why Use Kotlin Coroutines?
This article explains why coroutines stand out and provide capabilities not previously offered by other technologies.
重點摘要
Explains why coroutines are distinctive among technologies
Describes what coroutines offer that earlier solutions did not
Helps readers decide when and why to adopt coroutines
The article explains why Kotlin coroutines stand out and offer capabilities that were not provided by other technologies. It lays out the rationale for adopting coroutines, comparing their approach and benefits with previous solutions and clarifying which needs they address. Rather than diving into low-level implementation details, the piece focuses on the distinct position coroutines occupy in concurrent and asynchronous programming, how they change developer workflows, and what unique value they bring to application design and maintenance. It is intended for developers and architects seeking clearer guidance; the explanations aim to demystify trade-offs and adoption considerations, giving practical context without prescribing a single solution. The article also frames coroutines in terms of developer productivity, code clarity, and maintainability, helping readers weigh their adoption in real projects.
为什么使用 Kotlin 协程?
本文解释协程为何能够脱颖而出,并提供以往其他技术未曾提供的能力。
重點摘要
说明协程在技术上的独特之处
指出协程提供其他方案所不具备的能力
帮助读者判断何时应采用协程
本文解释为何 Kotlin 的协程(coroutines)能够脱颖而出,并提供以往其他技术未曾提供的能力。文章陈述采用协程的理由,对比以前的方案,说明协程在实践中能满足哪些需求及带来的影响;内容重点并非实现细节,而是阐明协程在开发流程、程序设计与维护上的独特定位,以及在选择协程时应权衡的取舍与适用场景。总体目标是帮助开发者与架构师理解何时采用协程及其能为项目带来的价值,提供实务评估的参考。
為何使用 Kotlin 協程?
本文說明協程為何能突顯其重要性,並提供過去其他技術未曾提供的能力。
重點摘要
說明協程在技術上的獨特性
指出協程提供其他方案所沒有的能力
協助讀者判斷何時採用協程
本文說明為何 Kotlin 的協程(coroutines)能夠突顯其重要性並提供過去其他技術未曾提供的能力。文章闡述採用協程的理由,對比過去的方案,說明協程在實務上能解決哪些需求與帶來的影響;文中重點不在細節實作,而在於說明協程在開發流程、程式設計與維護上的獨特定位,以及選用協程時應考量的取捨與場景。整體目標是幫助開發者與架構師理解何時採用協程以及它能為專案帶來的價值,提供實務評估的參考。
KT Academy
作者:
發布:10-19 00:00
Books for 2025 Company Workshops Attendees Promotion
A special promotion offering books to attendees of company workshops organized in 2025.
重點摘要
Promotion targets company workshops held in 2025
Attendees of those workshops are eligible for books
Refer to the linked article for full details
This brief announcement describes a special promotion that provides books to attendees of company workshops organized in 2025. It clarifies that the offer applies specifically to company workshops scheduled during the 2025 calendar year and that attendees of those workshops can receive books as part of the promotion. The notice is concise and directs readers to the referenced article page for complete information about eligibility, redemption procedures, and any requirements or timelines. Organizations planning workshops in 2025 and employees who will attend are advised to consult the linked article for the full terms and instructions on how to claim the promotional books.
2025 年公司研讨会参与者赠书优惠
针对 2025 年组织的公司研讨会,为参与者提供赠书的特别优惠。
重點摘要
面向 2025 年举办的公司研讨会
参与这些研讨会的人员可获得书籍
详细信息请查看文章链接
本公告简要说明了一项针对 2025 年组织的公司研讨会的特别优惠,内容为向参与该类研讨会的人员提供书籍赠送。公告明确该优惠仅适用于在 2025 年日历年内举办的公司研讨会,并建议有兴趣的组织和参与者前往所示文章页面,查阅有关资格、领取方式及具体条款等完整说明。计划在 2025 年举办研讨会的单位或将参与的员工,应依文章内的说明确认适用性与后续领取流程。
2025 年公司工作坊參加者贈書優惠
針對 2025 年舉辦的公司工作坊,提供參加者贈書的特別優惠。
重點摘要
適用於 2025 年舉辦的公司工作坊
參加該類工作坊的與會者可獲贈書籍
詳情請參閱文章連結說明
這則簡短公告說明了一項針對 2025 年舉辦的公司工作坊的特別優惠,內容是為參加該類工作坊的與會者提供書籍贈送。公告指出優惠限定於 2025 年內舉辦的公司工作坊,並提醒讀者至提供的文章連結查閱完整條款、資格與領取方式等詳細資訊。計畫在 2025 年舉辦工作坊的單位與預定參加的員工,應依文章說明確認是否符合資格及後續申請或兌換流程。
KT Academy
作者:
發布:10-21 00:00
Win a Free Ticket to Droidcon Italy!
Upgrade your Kotlin skills and win a free ticket to Droidcon Italy!
重點摘要
Upgrade your Kotlin skills
Chance to win a free ticket to Droidcon Italy
See the linked article for full details
This announcement encourages Kotlin developers to upgrade their skills while offering a chance to win a free ticket to Droidcon Italy. The linked article provides the entry information and any terms or deadlines; readers should follow that link for full contest rules and instructions. Improving Kotlin competence can benefit developers' careers and make attendance at a major Android-focused event more valuable. By participating, readers may combine professional development with the opportunity to attend sessions, talks, and networking at Droidcon Italy. No specific eligibility, dates, or entry mechanics are stated here; consult the original article for authoritative details. The short message serves as both an invitation to deepen Kotlin knowledge and an incentive—enter or explore the article to learn how you might secure a free pass to Droidcon Italy.
赢取 Droidcon Italy 免费门票!
提升你的 Kotlin 技能,并有机会赢得前往 Droidcon Italy 的免费门票!
重點摘要
提升 Kotlin 技能
有机会赢得 Droidcon Italy 免费门票
请参阅原文链接以获取完整信息
本公告鼓励 Kotlin 开发者提升技术,同时提供赢得前往 Droidcon Italy 免费门票的机会。原文链接会说明参加方式、资格及注意事项,请点击链接查阅完整规则与截止时间。提升 Kotlin 能力可强化开发实力并促进职业发展;若能获得门票,也可前往参加演讲、工作坊与交流,扩展人脉与视野。本文仅为宣告与邀请,并未在此列出详细条件,欲获取正式信息请以原文为准。
贏取 Droidcon Italy 免費門票!
提升你的 Kotlin 技能,並有機會贏得前往 Droidcon Italy 的免費門票!
重點摘要
提升 Kotlin 技能
有機會贏得 Droidcon Italy 免費門票
請參閱原文連結以取得完整資訊
本公告鼓勵 Kotlin 開發者提升技術,同時提供贏得前往 Droidcon Italy 免費門票的機會。原文連結會說明參加方式、資格及注意事項,請點選連結查閱完整規則與截止時間。提升 Kotlin 能力可強化開發實力並促進職涯成長;如能獲得門票,也可赴會參加講座、工作坊與交流,擴展人脈與視野。本文僅為宣告與邀請,並未在此列出詳細條件,欲取得正式資訊請以原文為準。
KT Academy
作者:
發布:11-13 00:00
The best dispatcher for a backend framework
Exploring different dispatchers to determine the best choice for backend request handlers.
重點摘要
Compare dispatcher implementations
Evaluate trade-offs for backend handlers
Select the most suitable dispatcher for context
This article examines various dispatcher approaches for backend frameworks with the goal of identifying the best option for handling incoming requests. It surveys different dispatcher designs — including simple routing, pattern-based routers, and more advanced dispatchers — and outlines criteria for comparison such as performance, scalability, clarity of control flow, ease of integration with request handlers, and maintainability. Rather than prescribing a single universal solution, the piece emphasizes evaluating trade-offs in context: the best dispatcher depends on factors like expected load, routing complexity, developer ergonomics, and error-handling needs. It suggests a methodical comparison of candidates by benchmarking request throughput and latency, reviewing how they compose with middleware, and assessing operational characteristics. The article aims to help backend engineers choose a dispatcher that balances efficiency and simplicity for their specific use case.
适用于后端框架的最佳调度器
让我们探索不同的调度器,找出最适合后端请求处理的方案。
重點摘要
比较不同调度器实现
评估性能、可扩展性与维护性
根据使用情境选择最合适方案
本文围绕探索和比较各种调度器展开,目标是在后端请求处理场景中找出最合适的实现方案。文章介绍了不同调度器的设计取向和比较标准,包括性能、可扩展性、路由灵活性、与请求处理器的集成难易以及后续维护成本等方面,同时指出不存在放之四海皆准的单一答案;最优选择应基于实际负载、路由复杂度与开发者成本来判断。建议通过基准测试、审视与中间件的组合性以及错误处理和运行特性的评估,系统化对候选项进行比较,帮助工程团队在效率与简洁性之间做出权衡。
適用於後端框架的最佳調度器
我們探討不同的調度器,找出最適合用於後端請求處理的方案。
重點摘要
比較不同調度器實作
評估效能、可擴展性與維護性
依使用情境選擇最合適方案
本文以探索與比較各種調度器為主題,目標是在後端請求處理中找出最合適的實作方案。內容說明不同調度器的設計取向與比較基準,包含效能、可擴展性、路由靈活度、與請求處理器的整合性以及後續維護成本等面向,並強調沒有放諸四海皆準的單一解;最佳選擇需視實際負載、路由複雜度與開發者使用成本而定。文章建議透過基準測試、檢視與中介軟體的相容性,以及錯誤與運作行為的評估,系統化比較候選方案,協助工程團隊在效率與簡潔性之間取得平衡。
KT Academy
作者:
發布:11-18 00:00
Representing ViewModel events with StateFlow vs. SharedFlow vs. Channel
Which mechanism—StateFlow, SharedFlow, or Channel—best models ViewModel events in Kotlin?
重點摘要
Compares StateFlow, SharedFlow, and Channel
Focuses on representing ViewModel events in Kotlin
Weighs trade-offs for different event patterns
The article asks how best to represent events emitted by a ViewModel in Kotlin, comparing StateFlow, SharedFlow, and Channel. It examines the semantics and typical use cases of each primitive—StateFlow for held state with a single latest value, SharedFlow for multicasted streams with configurable replay and buffering, and Channel for one-time consumable messages—and highlights how those behaviors map to UI event patterns. Key considerations discussed include lifecycle and subscription timing, whether events should be replayed to new collectors, buffering and backpressure behavior, and how each primitive fits scenarios such as one-shot navigation events versus persistent UI state. Rather than prescribing a single winner, the piece aims to guide developers to choose the primitive whose semantics align with their event requirements.
在 ViewModel 中用 StateFlow、SharedFlow 或 Channel 表示事件
在 Kotlin 的 ViewModel 中,应该使用 StateFlow、SharedFlow 还是 Channel 来表示事件?
重點摘要
比较 StateFlow、SharedFlow 与 Channel
关注如何在 ViewModel 表示事件
评估不同模式的取舍
文章提出在 Kotlin 的 ViewModel 中如何表示事件的问题,比较 StateFlow、SharedFlow 与 Channel 的差异。内容说明各方案的语义与适用场景:StateFlow 适合保留最新状态,SharedFlow 可做多播并配置 replay 与缓冲,Channel 则适合一次性消费的消息。讨论要点包括生命周期与订阅时机、是否将事件重放给新加入的收集者、缓冲与背压,以及如何对应单次导航事件或持久 UI 状态等模式。目的是帮助开发者根据事件语义(状态、流或一次性消费)与需求选择最合适的工具,而非一刀切。
在 ViewModel 中以 StateFlow、SharedFlow 或 Channel 表示事件
在 Kotlin 的 ViewModel 中,應以 StateFlow、SharedFlow 還是 Channel 來表示事件?
重點摘要
比較 StateFlow、SharedFlow 與 Channel
聚焦如何在 ViewModel 表示事件
評估不同模式的取捨
文章提出在 Kotlin 的 ViewModel 中如何表示事件的問題,並比較 StateFlow、SharedFlow 與 Channel 的差異。內容說明各方案的語意與適用場景:StateFlow 適合保持最新狀態,SharedFlow 可做多播並設定 replay 與緩衝,Channel 則適合一次性消費的訊息。討論重點包括生命週期與訂閱時機、是否要將事件重新傳遞給新加入的收集者、緩衝與背壓,以及如何對應單次導航事件或持久 UI 狀態等模式。目的是協助開發者根據事件語意(狀態、流或一次消費)與需求選擇最合適的工具,而非套用單一方案。
KT Academy
作者:
發布:12-02 00:00
Using BlockHound to Track Blocking Calls in Non-Blocking Dispatchers
A practical guide to using BlockHound to detect blocking calls that undermine non-blocking dispatchers.
重點摘要
Explains why blocking calls harm non-blocking dispatchers
Describes enabling BlockHound to detect blocking operations
Recommends using detections in tests and CI to prevent regressions
This article explains how to use BlockHound to track blocking calls in non-blocking dispatchers. It describes the problem of blocking operations undermining non-blocking execution and outlines a practical approach for detecting them with BlockHound. Readers are guided to enable BlockHound instrumentation in the runtime, run or test workloads that exercise non-blocking dispatchers, and observe BlockHound's detection warnings and stack traces to identify offending code. The piece emphasizes that tracking and removing blocking calls improves responsiveness and thread utilization in reactive or coroutine-based systems. It also notes that developers can integrate BlockHound into tests and CI to catch regressions before deployment. Overall, the article offers a focused, actionable overview for developers who want to find and fix blocking calls in non-blocking dispatchers.
在非阻塞调度器中使用 BlockHound 追踪阻塞调用
说明如何使用 BlockHound 检测会破坏非阻塞调度器的阻塞调用。
重點摘要
解释阻塞操作如何影响非阻塞执行
说明启用 BlockHound 并查看检测与堆栈跟踪
建议将检测纳入测试与 CI 以防止回归
本文说明如何使用 BlockHound 来追踪在非阻塞调度器中出现的阻塞调用。文章先解释阻塞操作如何破坏非阻塞执行,然后说明启用 BlockHound 监测、在运行或测试负载时观察检测警告与堆栈跟踪以定位问题代码,并强调将检测纳入测试与 CI 可在部署前捕获回归。整体提供给开发者一个实用可操作的流程,帮助改善系统响应性与线程利用率,避免非阻塞系统被同步阻塞影响。
在非阻塞調度器中使用 BlockHound 追蹤阻塞呼叫
說明如何使用 BlockHound 偵測會破壞非阻塞調度器的阻塞呼叫。
重點摘要
說明阻塞操作如何影響非阻塞執行
示範啟用 BlockHound 並觀察偵測與堆疊追蹤
建議將偵測納入測試與 CI 以提前捕捉問題
本文說明如何使用 BlockHound 來追蹤在非阻塞調度器(non-blocking dispatchers)中出現的阻塞呼叫。文章先說明阻塞操作如何破壞非阻塞執行,接着說明啟用 BlockHound 的監測、在執行或測試工作負載時觀察檢測警告與堆疊追蹤以定位問題程式碼,並強調將偵測納入測試與 CI 可在部署前捕捉迴歸。整體上提供開發者一個實用且具操作性的流程,幫助改善系統響應性與執行緒使用率,避免非阻塞系統被同步阻塞所影響。
KT Academy
作者:
發布:12-09 00:00
Jetpack Compose Modifier Guessing Game!
A playful way to learn Jetpack Compose modifiers by guessing and recognizing their effects.
重點摘要
Teaches Jetpack Compose modifiers through a game format
Encourages hands-on recognition of modifier effects
Suitable as a learning tool for practice and reinforcement
This short piece presents a playful learning approach: a guessing game focused on Jetpack Compose modifiers. The game format is designed to help developers familiarize themselves with how modifiers affect component appearance and behavior by prompting players to identify or predict which modifiers produce given results. As a lightweight, practice-oriented activity, it encourages repeated exposure, experimentation, and faster recall of common modifier patterns. The article frames the game as an engaging supplement to traditional study—useful for beginners to build intuition and for experienced developers to sharpen familiarity with modifier behavior.
Jetpack Compose Modifier 猜谜游戏!
通过猜测的方式有趣地学习 Jetpack Compose 的 modifier,辨别它们对组件的影响。
重點摘要
以游戏形式学习 Jetpack Compose modifiers
侧重识别并练习 modifier 的效果
作为巩固概念与实作直觉的辅助工具
本文提出一种趣味学习法:通过猜谜游戏来认识 Jetpack Compose 的 modifiers。游戏让学习者观察界面或行为变化并猜测对应的 modifier,从而加深对 modifier 如何影响组件外观与行为的理解。作为一种轻量的实践活动,能通过重复练习提高熟悉度,既适合入门学习,也适合有经验的开发者用来巩固或检验对常用 modifier 的直觉。
Jetpack Compose Modifier 猜謎遊戲!
以猜測方式有趣地學習 Jetpack Compose 的 modifier,辨識它們對元件的影響。
重點摘要
透過遊戲學習 Jetpack Compose 的 modifiers
強調辨識與練習 modifier 的效果
作為鞏固概念與實作直覺的輔助工具
本文介紹一種有趣的學習方式:以猜謎遊戲來認識 Jetpack Compose 的 modifiers。透過讓玩家觀察結果並猜測是哪個 modifier 或是哪組 modifier 所造成的效果,遊戲能幫助開發者更快建立對 modifier 如何影響元件外觀與行為的直覺。此活動屬於輕量且實作導向的練習,適合用來反覆強化常見用法,對初學者與想要鞏固技能的開發者都具有實用價值。
KT Academy
作者:
發布:12-16 00:00
Is reflection slowing down your code?
Let's benchmark reflection and see how it affects the performance of your code.
重點摘要
Benchmarks reflection to measure its runtime cost
Encourages empirical testing rather than assumptions
Aims to help developers make trade-offs between convenience and speed
This article proposes benchmarking reflection to determine its runtime cost and to clarify whether it slows down code in practical situations. It stresses the importance of measuring performance rather than relying on intuition, and outlines a general approach for comparing reflective and non-reflective techniques under controlled conditions. The piece highlights that the impact of reflection varies with language, runtime, and usage patterns, so testing on representative workloads is necessary to obtain meaningful results. Readers are encouraged to use appropriate metrics, run repeated trials to account for variance, and integrate benchmarking into their development workflow so decisions about using reflection are grounded in empirical data rather than assumptions.
反射是否在拖慢你的代码?
通过基准测试来查看反射如何影响代码性能。
重點摘要
通过基准测试衡量反射的运行成本
主张用实测数据替代直觉判断
帮助开发者在便利性与性能之间做出权衡
本文建议使用基准测试来量化 reflection(反射)对代码运行性能的影响,强调应以实测数据而非直觉来评估反射可能带来的开销。文章指出需要在可比较的条件下对比反射与非反射实现,并建议在具有代表性的负载或接近生产环境的场景中运行测试以获得有意义的结果。反射的性能影响会因语言、运行时与使用模式等因素而异,因此反复测试、选择合适的指标并将基准测试纳入开发流程,有助于开发者以数据为依据,在便利性与性能之间做出合理决策。
反射是不是讓你的程式變慢?
透過基準測試來檢視反射對程式效能的影響。
重點摘要
以基準測試量化反射的執行成本
主張以實證測量取代直覺判斷
協助開發者在便利性與效能間做出抉擇
本文提出透過基準測試來量化 reflection(反射)對程式執行效能的影響,強調以實證資料而非直覺來評估反射帶來的成本。文章說明應在可比較的條件下比對反射與非反射的做法,並建議在具代表性的負載或近似生產環境中執行測試,以取得有意義的結果。作者指出反射的效能影響會受到語言、執行環境與使用模式等變因左右,因此重複測試與適當的衡量指標有助於判讀測量結果,讓開發者能以數據為基礎,在開發流程中持續監控並做出合理取捨。
KT Academy
作者:
發布:12-24 00:00
Kotlin Christmas Dream
A brief personal dream about the future of Kotlin.
重點摘要
Single-sentence reflection on Kotlin's future
No concrete details or predictions
Invites readers to imagine Kotlin’s evolution
“Kotlin Christmas Dream” is a very short piece presenting the author's dream about Kotlin's future. The entire text is a single declarative sentence expressing a forward-looking personal vision. Although it offers no concrete details or predictions, the line suggests a sense of curiosity and optimism about how Kotlin may develop. As written, the piece functions more as an open prompt than a technical forecast: it encourages readers to imagine possibilities for language design, tooling, ecosystem, and community direction rather than to convey specific plans. Its brevity highlights the subjective and aspirational nature of the statement, leaving the reader with an invitation to reflect on Kotlin’s trajectory and to consider what contributors and users might hope for in the language’s continued evolution.
Kotlin 圣诞梦
关于 Kotlin 未来的简短个人梦想。
重點摘要
以一句话表达对 Kotlin 未来的梦想
未提供具体细节或预测
鼓励读者想象语言与生态的可能走向
本文以《Kotlin Christmas Dream》为题,仅用一句话表达作者对 Kotlin 未来的梦想到想象。原文未给出具体细节或预测,而是以简短的前瞻性陈述留下开放意象,促使读者思考语言设计、开发工具、生态系统与社区可能的发展方向。其极简表述强调主观与期盼,像是一种邀请,鼓励开发者和贡献者共同想象 Kotlin 的未来,而非宣示确定路线或计划。
Kotlin 聖誕夢
關於 Kotlin 未來的簡短個人夢想。
重點摘要
以一句話表達對 Kotlin 未來的夢想
未提供具體細節或預測
鼓勵讀者想像語言與生態的可能走向
本文標題《Kotlin Christmas Dream》,僅以一句話表達作者對 Kotlin 未來的夢想與想像。原文沒有提供具體細節或預測,故內容更像是一個開放性的前瞻性表述,提醒讀者思考語言設計、開發工具、生態系統與社群可能的發展方向。這種極簡的表述強調主觀的期盼與好奇,並以短短一句話作為邀請,促使開發者與貢獻者一起想像 Kotlin 的未來樣貌,而非宣布任何確定的路徑或計畫。
KT Academy
作者:
發布:01-07 00:00
How modifiers order affects Compose UI appearance
A complete explanation of how the order of modifiers changes the visual result of your Jetpack Compose UI.
重點摘要
Modifier sequence changes how UI is measured, laid out, clipped and drawn
Different orders can produce different spacing, size and visual effects
Explains reasoning, patterns and practical guidance for predictable UI
This article provides a complete explanation of how the order of modifiers in Jetpack Compose affects UI appearance. It explains that the sequence in which modifiers are applied changes how components are measured, positioned, clipped and rendered, and that altering order can lead to different spacing, backgrounds, sizes and interaction areas. The piece outlines why those differences occur and emphasizes intentional ordering to achieve predictable results. Through explanation and illustrative examples, it offers guidance and patterns developers can use to reason about modifier combinations, debug unexpected visuals, and avoid subtle layout bugs. The target audience is Compose developers seeking a clear mental model for arranging modifiers so their layouts behave as intended under various modifier compositions.
Modifier 顺序如何影响 Compose UI 显示
完整解釋 Jetpack Compose 中 Modifier 的順序如何改變 UI 的視覺與佈局行為。
重點摘要
Modifier 顺序会影响测量、布局、裁剪与绘制
不同顺序会导致间距、尺寸、背景范围与交互目标差异
提供原理说明与实用建议,帮助实现可预测的 UI
本文完整解释了 Jetpack Compose 中 Modifier 的顺序如何影响 UI 的呈现。文章说明 Modifier 的应用顺序会改变组件的测量、布局、裁剪与绘制方式,从而影响间距、背景范围、尺寸和触控目标等可见结果;调整顺序可能产生不同的视觉效果。作者阐述这些差异的原因,并强调应有意识地安排 Modifier 顺序以获得可预测的结果。通过说明与示例,文章提供了用于推理 Modifier 组合、调试意外视觉问题以及避免隐性布局错误的实用建议,适合希望建立稳定心智模型的 Compose 开发者。
Modifier 順序如何影響 Compose UI 顯示
完整說明 Jetpack Compose 中 Modifier 的順序如何改變 UI 的視覺與佈局行為。
重點摘要
Modifier 的先後順序會影響測量、佈局、剪裁與繪製
不同排列會改變間距、尺寸、背景範圍與互動目標
提供原理解說與實務建議,協助達成可預測的 UI
本文完整說明了 Jetpack Compose 中 Modifier 的順序如何影響 UI 呈現。文章指出,Modifier 的應用順序會改變元件的測量、佈局、剪裁與繪製方式,進而影響間距、背景範圍、尺寸與觸控目標等視覺結果;而調整順序則可能產生不同的顯示效果。作者說明這些差異的成因,並強調有意識地安排 Modifier 次序以獲得可預測的結果。透過說明與示例,文章提供了可用於推理 Modifier 組合、除錯視覺問題與避免隱性佈局錯誤的實務建議,適合希望建立穩定心智模型的 Compose 開發者。
KT Academy
作者:
發布:01-13 00:00
Collection Processing Guessing Game!
A fun game that pushes your understanding of Kotlin collection processing.
重點摘要
A playful exercise centered on Kotlin collection processing
Invites you to predict results and test your intuition
Aims to deepen practical understanding through challenge
The article presents a compact, playful exercise called the "Collection Processing Guessing Game" that prompts readers to engage with Kotlin collection processing by predicting outcomes. Framed as a game rather than a formal tutorial, it is intended to stretch and sharpen intuition about how collections are transformed and handled in Kotlin. By offering short, focused challenges, the game helps learners confirm assumptions, surface misconceptions, and build a clearer mental model of collection behavior. It functions as a low-pressure practice tool for newcomers and a quick validation exercise for experienced developers. Overall, the piece positions the game as an enjoyable, practical way to strengthen understanding of Kotlin collection processing.
集合处理猜谜游戏!
一个通过游戏化练习来挑战你对 Kotlin 集合处理理解的有趣活动。
重點摘要
以游戏方式聚焦 Kotlin 的集合处理
通过预测结果来检验直觉与假设
旨在通过练习加深实践理解
本文介绍了一个名为“集合处理猜谜游戏”的趣味练习,透过游戏化题目让读者预测 Kotlin 处理集合时的结果,从而挑战并强化对集合运算与数据转换行为的直觉。以轻松的题型形式,有助于确认假设、揭示误解并建立更稳固的认知模型,既适合初学者在低压环境中练习核心概念,也可作为资深开发者快速自我检验的工具。总体而言,文章将该游戏定位为一种既有趣又实用的方法,帮助读者加深对 Kotlin 集合处理的理解。
集合處理猜謎遊戲!
一個透過遊戲化練習來挑戰你對 Kotlin 集合處理理解的有趣活動。
重點摘要
以遊戲方式聚焦 Kotlin 的集合處理
透過預測結果來檢驗直覺與假設
旨在透過練習加深實務理解
本文介紹一個名為「集合處理猜謎遊戲」的有趣練習,透過遊戲化題目讓讀者預測 Kotlin 處理集合時的結果,以此挑戰並強化對集合運算與資料轉換行為的直覺。採用輕鬆的題目形式,有助於確認假設、揭露誤解並建立更穩固的心智模型,既適合初學者在低壓環境中練習核心概念,也可當成資深開發者快速自我檢驗的工具。整體而言,文章把這個遊戲定位為一種既有趣又實用的方法,幫助讀者加深對 Kotlin 集合處理的理解。
KT Academy
作者:
發布:01-20 00:00
Problems I Faced Using Kotlin/Wasm While Making a Game
A short account of the challenges encountered when publishing a simple game built with Kotlin and WebAssembly.
重點摘要
Short, first-person account of publishing issues
Focus on a simple game implemented with Kotlin/Wasm
Practical reflections meant for other developers
This article is a concise first-person account of the problems the author encountered when publishing a simple game implemented with Kotlin and WebAssembly (Wasm). It does not aim to be an exhaustive technical manual; instead, it summarizes the obstacles met during development and release, the troubleshooting attempts, and the practical lessons learned. The narrative highlights the kinds of issues that arose when preparing a Kotlin/Wasm project for distribution and shares candid reflections about what required extra attention. The intent is to help other developers who are considering or working with Kotlin/Wasm by offering a clear, experience-based perspective on what can go wrong and what to consider when publishing a small game made with this toolchain.
我在用 Kotlin/Wasm 制作游戏时遇到的问题
一篇简短的记录,说明在发布用 Kotlin 与 WebAssembly 制作的简单游戏时所面临的挑战。
重點摘要
以第一人称简短记录发布过程中的问题
聚焦使用 Kotlin/Wasm 制作的简单游戏
分享实务心得与反思供其他开发者参考
这篇文章是作者以第一人称撰写的简短记录,记述在发布用 Kotlin 与 WebAssembly(Wasm)制作的一款简单游戏时遇到的问题。文章不是详尽的技术手册,而是概述了在开发与发布过程中遇到的阻碍、尝试的解决方法以及所得的实际经验与教训。作者诚实地回顾了哪些环节需要额外注意,并提供基于经验的观点,旨在为考虑或正在使用 Kotlin/Wasm 的开发者在准备项目发布时提供参考与借鉴。
我在用 Kotlin/Wasm 製作遊戲時遇到的問題
一篇簡短的紀錄,述說在發佈以 Kotlin 與 WebAssembly 製作的簡單遊戲時所面臨的挑戰。
重點摘要
以第一人稱簡短紀錄發佈過程中的問題
聚焦使用 Kotlin/Wasm 製作的簡單遊戲
分享實務上的心得與反思供他人參考
這篇文章是一段簡短的第一人稱敘述,記錄作者在發佈以 Kotlin 與 WebAssembly(Wasm)製作的簡單遊戲時所遇到的問題。文章並非詳細教學,而是概述開發與發佈過程中碰到的阻礙、嘗試的解決方式,以及從中獲得的實務經驗與教訓。作者以經驗為出發點,誠實描述哪些環節需要特別注意,以及在準備 Kotlin/Wasm 專案發佈時可能會遇到的情況,期望為考慮或正在使用 Kotlin/Wasm 的開發者提供參考。
KT Academy
作者:
發布:03-03 00:15
Kotlin Compiler Plugins
All you need to know about Kotlin Compiler plugins.
重點摘要
A concise, comprehensive overview of Kotlin compiler plugins
Explains why compiler plugins matter for Kotlin tooling and compilation
Serves as a practical reference for Kotlin developers exploring plugins
This article serves as a concise, comprehensive primer on Kotlin compiler plugins. It presents the core idea that compiler plugins extend and modify the Kotlin compilation process, enabling tasks such as custom analyses, transformations, or code generation directly during compilation. Aimed at Kotlin developers and tool authors, the piece situates plugins within the broader Kotlin ecosystem and explains their practical value compared with other extension mechanisms. Readers can expect an approachable explanation of what compiler plugins do, how they integrate with the compiler workflow, and why one might adopt them in real projects. The article functions as a starting point for teams evaluating compiler-level extensions and for engineers seeking to understand where compiler plugins fit among Kotlin’s tooling and automation options.
Kotlin 编译器插件
关于 Kotlin 编译器插件你需要知道的所有事。
重點摘要
概述 Kotlin 编译器插件的核心概念与作用
说明插件如何与编译流程集成并扩展功能
为 Kotlin 开发者提供实用的入门参考
本文为 Kotlin 编译器插件提供了简明的总览,阐述了插件如何在编译阶段扩展或修改编译器行为,从而实现自定义分析、代码转换或在编译期生成代码等功能。文章针对希望理解编译器级别扩展的开发者与工具作者,说明插件在 Kotlin 生态中的定位、与其他扩展手段的差异,以及在实际项目中的潜在价值。读者可以借此了解何时考虑使用编译器插件、它们如何嵌入编译流程,并作为后续深入学习或评估的参考起点。
Kotlin 編譯器插件
有關 Kotlin 編譯器插件你需要知道的所有事。
重點摘要
全面介紹 Kotlin 編譯器插件的概念與用途
說明插件如何與編譯流程整合並擴充功能
為 Kotlin 開發者提供實務導向的參考起點
本文為 Kotlin 編譯器插件的簡潔總覽,說明插件如何在編譯階段擴充與修改編譯器行為,以達成自訂分析、程式碼轉換或編譯時產生程式碼等用途。文章定位於想了解編譯器層級擴充的開發者與工具作者,說明插件在 Kotlin 生態中的角色、與其他擴充方式的差異,以及在實務專案中可能帶來的價值。讀者可從中獲得對於何時採用編譯器插件、它們如何整合到編譯流程,以及作為進一步學習或評估的參考方向。
KT Academy
作者:
發布:03-11 00:00
Benefit: Open Workshop Recording
Attendees of open workshops will receive session recordings as a new benefit.
重點摘要
Recordings provided to open workshop attendees
Enables review and catch-up after sessions
Introduced to improve accessibility and learning flexibility
This brief announcement introduces a new benefit for attendees of the open workshops: session recordings will be made available to participants. The change is intended to help attendees review presented material, catch up on sessions they could not attend live, and reinforce learning after the event. The notice is concise and focuses on the single improvement—adding recordings to the attendee offering—to increase accessibility and flexibility for different schedules and learning paces. The announcement does not include technical details such as how recordings will be delivered, how long they will be retained, or access procedures; those logistics are expected to be provided separately by the organizers. Overall, the message communicates that recordings are now part of the workshop benefits, supporting continued learning and convenience for participants.
福利:公开工作坊录音/录像
公开工作坊的参与者将作为新增福利获得会话录影。
重點摘要
为参与者提供工作坊录影
便于复习课程或补看未能参加的场次
旨在提升可及性和学习弹性
本文宣布为公开工作坊的参与者新增一项福利:将提供会话录影。此举旨在帮助参与者重温所授内容、补看错过的场次,并加强会后学习效果,对时程受限或跨时区的学员尤其有利。公告内容简短明确,强调将录影纳入参与者福利,以提升工作坊的可及性与弹性。原文未具体说明录影的提供方式、保存期限或取用流程,相关细节预计由主办方另行说明或提供查询渠道。总体而言,公告传达的是录影福利的导入及其对参与者学习便利性的积极影响。
福利:開放式工作坊錄影
開放式工作坊的參加者將獲得會議錄影作為新增福利。
重點摘要
為參加者提供工作坊錄影
方便重溫課程或補看缺席場次
旨在提升可及性與學習彈性
本文宣布為開放式工作坊參加者新增一項福利:將提供會議錄影。此變更旨在讓與會者能重溫教學內容、補看無法參與的場次,並延伸學習效果,對不同時區或行程受限的學員尤其有幫助。訊息簡潔明確,強調錄影將成為參加者權益的一部分,以提升工作坊的可及性與彈性。原文未說明錄影的提供方式、保存期限或取用流程,參加者可留意後續說明或向主辦單位查詢詳細存取資訊。整體而言,公告主要傳達錄影福利的導入及其對學習便利性的正面影響。
KT Academy
作者:
發布:05-23 00:00
Coroutines Mastery
A five-week cohort workshop to master Kotlin Coroutines.
重點摘要
Five-week cohort workshop
Hands-on practice and peer support
Focused on mastering Kotlin Coroutines
Coroutines Mastery is a five-week cohort workshop designed to help developers learn and apply Kotlin Coroutines. The program centers on hands-on, guided learning in a cohort format, combining focused lessons, practical exercises, and collaborative problem-solving to build an understanding of asynchronous programming with coroutines. Participants work through coroutine concepts, patterns, and use cases to gain practical skills for real-world Kotlin applications. The workshop emphasizes progressive skill development across the five-week timeline, allowing learners to practice and integrate coroutine techniques into existing projects. Suitable for developers who want a structured, time-bound learning experience, the cohort aims to move attendees from foundational knowledge to confident application of coroutines in production code. The concise format supports steady progress, peer support, and measurable improvement in coroutine mastery.
Kotlin 协程精通
为期五周的 kohort 研习营,旨在掌握 Kotlin 协程技术。
重點摘要
五周 kohort 研习营
强调实作与同伴支持
目标是精通 Kotlin 协程
Coroutines Mastery 是为期五周的 kohort 研习营,专注于掌握 Kotlin 的 Coroutine 技术。课程以 cohort 小组制进行,通过循序渐进的教学、实务练习与同伴互助,使学员理解异步编程的核心概念、常见使用模式与设计思路。学习重点包括实作范例、调试与性能考量,以及如何将协程技巧整合到现有项目流程中。五周的密集安排强调动手操作与重复练习,并提供结构化的学习节奏,适合希望在限定时间内系统化学习并提升实务能力的开发者。本研习营旨在将参与者从基础概念提升到能在生产环境中自信运用协程的程度,同时在学习过程中获得同伴支持与可衡量的进步。
Kotlin 協程精通
為期五週的 kohort 工作坊,旨在掌握 Kotlin 協程技術。
重點摘要
五週 kohort 工作坊
強調實作與同儕支援
目標是掌握 Kotlin 協程
Coroutines Mastery 是為期五週的 kohort 工作坊,專注於掌握 Kotlin 的 Coroutine 技術。課程以 cohort 小組制進行,透過循序漸進的教學、實務練習與同儕互助,讓學員理解非同步程式設計的核心概念、常見使用模式與設計思維。學習重點包括實作範例、除錯與效能考量、以及如何將協程技巧整合入現有專案流程。五週的密集安排強調動手操作與反覆練習,並提供結構化的學習節奏,適合想在限定時間內系統化學習並提升實務能力的開發者。此工作坊旨在讓參與者從基礎概念進階到能於生產環境自信運用協程,並在學習過程中獲得同儕支援與可衡量的進步。
KT Academy
作者:
發布:06-03 00:00
KotlinConf 2025 Announcements
A concise compilation of the greatest announcements from KotlinConf 2025.
重點摘要
Compilation of KotlinConf 2025's top announcements
Concise overview for quick catch‑up
Designed for developers and community members who missed the event
This article collects the greatest announcements from KotlinConf 2025, offering a concise, single-place overview of the conference’s most notable news. It serves as a quick reference for developers, team leads, and Kotlin community members who want to catch up without watching full sessions. Rather than deep technical analysis, the piece highlights the headline items and main themes so readers can identify which topics merit deeper follow-up. The format helps readers decide which talks, release notes, or additional resources to consult next. By focusing on key announcements, the article saves time while keeping readers informed about the most important developments presented at KotlinConf 2025.
KotlinConf 2025 公告
精选并整理 KotlinConf 2025 的重要宣布,提供清晰的会议信息概览。
重點摘要
汇总 KotlinConf 2025 的重要宣布
以简洁概览快速了解会中要点
方便未能参会的开发者与社区成员回顾
本文汇总 KotlinConf 2025 的重要宣布,提供一个简洁的概览,帮助读者快速掌握会议中最关键的消息。内容以摘要形式呈现,重点列出值得关注的公告与主题,适合想快速回顾或未能出席会议的开发者与社区成员。文章旨在节省阅读时间,协助读者判断哪些议题需要进一步跟进,并在有官方资料或后续报导时作为参考,整体以实用的会议快览为主,而非深入的技术分析。
KotlinConf 2025 公告
精選並整理 KotlinConf 2025 的重要宣布,提供一目了然的會議重點總覽。
重點摘要
彙整 KotlinConf 2025 的重要宣布
以簡潔總覽快速掌握會議重點
適合未能參加者與開發者快速回顧
本文彙整 KotlinConf 2025 的重要宣布,提供一個簡潔的總覽,讓讀者迅速掌握會中最關鍵的消息。內容以標題式摘要呈現,側重於列出最值得關注的公告與主題,適合想快速回顧或未能參加會議的開發者與社群成員閱讀。文章旨在節省時間、指引讀者判斷哪些議題需要深入追蹤,並在有相關官方資料或後續報導時作為導引;整體重點為提供實用的會議快覽,而非詳盡的技術分析。
KT Academy
作者:
發布:06-24 00:00
Coroutines Races Guessing Game!
A fun game that pushes your understanding of Kotlin coroutines.
重點摘要
Playful exercise that challenges coroutine intuition
Centers on races and non-deterministic coroutine outcomes
Encourages prediction and reflection rather than formal theory
This short piece presents a playful guessing game designed to push your understanding of Kotlin coroutines. The activity frames situations in which multiple coroutines run concurrently — a race — and asks you to predict which outcome will occur. By drawing attention to timing, scheduling and nondeterminism, the game highlights how subtle differences in coroutine behavior can lead to different results. Rather than providing exhaustive theory, it offers a hands-on mental exercise to sharpen intuition about concurrency and coroutine interactions. Suitable as a quick self-check or a classroom prompt, the game aims to make learners more aware of the unpredictability inherent in concurrent execution and to encourage experimentation and careful observation.
协程竞赛猜测游戏!
一个有趣的游戏,旨在提高你对 Kotlin 协程的理解。
重點摘要
以游戏形式挑战协程直觉
关注协程竞赛与非确定性结果
鼓励预测、实验与反思
本文介绍了一个有趣的猜测游戏,目的是推动你对 Kotlin 协程的理解。游戏将多个协程并发执行的场景视为“竞赛”,要求参与者预测可能的结果。通过关注执行时序、调度与非确定性行为,该活动展示了细微差别如何改变最终输出。它侧重于动手练习以增强对并发与协程交互的直觉,而非提供详尽理论,适合作为快速自测或课堂引导,促使学习者在实验与观察中提升对并发行为的认识。
協程競賽猜測遊戲!
一個有趣的遊戲,旨在提升你對 Kotlin 協程的理解。
重點摘要
以遊戲方式挑戰協程直覺
聚焦協程競賽與非決定性結果
鼓勵預測、實驗與反思
本文介紹一個有趣的猜測遊戲,目的是推進你對 Kotlin 協程的理解。遊戲把多個協程同時執行的情境視為「競賽」,要求玩家預測可能的結果。透過關注執行時序、排程與非決定性行為,遊戲展示了細微變化如何影響最終結果。它不是以繁複理論為主,而是提供一種實作與思考的練習,適合用作自我檢測或教學引導,幫助學習者在實驗與觀察中建立對併發行為的直覺。
KT Academy
作者:
發布:07-01 00:00
KotlinConf 2025 Recordings
A personal selection of must-watch KotlinConf 2025 recordings.
重點摘要
Personal selection of must-watch KotlinConf 2025 recordings
Curated to highlight practical insights, new features, tooling, and architecture
Helps prioritize which conference videos to watch among all recordings
This article lists the author's recommended 'must-watch' recordings from KotlinConf 2025. It compiles selected conference sessions judged especially valuable for Kotlin developers and enthusiasts, emphasizing talks that deliver practical techniques, explanations of new language features, tooling tips, and architectural guidance. The curated lineup is intended to help readers prioritize which videos to view amid the full set of conference recordings, saving time by highlighting sessions that offer clear learning value. Entries typically include the session title and a brief note explaining its inclusion, so readers can quickly decide which talks match their interests and goals. Whether you seek concise technical takeaways or broader perspective on Kotlin's ecosystem and tooling, this selection provides a focused starting point for further exploration of KotlinConf 2025 content.
KotlinConf 2025 录影
作者挑选出 KotlinConf 2025 的必看录影推荐。
重點摘要
作者整理的 KotlinConf 2025 必看录影清单
聚焦实用技术、语言新特性、工具与架构议题
帮助读者优先选择要观看的会议录影
本文整理作者认为必看(must-watch)的 KotlinConf 2025 会议录影,为 Kotlin 开发者与爱好者提供一份优先观看清单。清单挑出具有实用技术洞见、语言新特性、工具使用与架构实现价值的场次,并说明每个录影的入选理由,方便读者在众多录影中快速判断哪些议程最值得观看与学习。此推荐列表适合想有效吸收会议重点、针对特定主题深入学习或作为日后复习参考的读者,能作为进一步探索 KotlinConf 2025 内容的起点。
KotlinConf 2025 錄影
作者挑選出 KotlinConf 2025 的必看錄影推薦。
重點摘要
作者整理的 KotlinConf 2025 必看錄影清單
聚焦實用技術、語言新特性、工具與架構議題
幫助讀者優先選擇要觀看的會議錄影
本文整理作者認為必看(must-watch)的 KotlinConf 2025 會議錄影,提供給 Kotlin 開發者與愛好者一份優先觀看清單。清單挑出具實用技術洞見、語言新特性、工具使用與架構實作價值的場次,並說明每個錄影的入選理由,方便讀者在眾多錄影中快速判斷哪些議程最值得觀看與學習。此推薦列表適合想有效吸收會議重點、針對特定主題深入學習或作為日後複習參考的讀者,能作為進一步探索 KotlinConf 2025 內容的起點。
KT Academy
作者:
發布:07-14 00:00
How to Turn Callback Functions into suspend Functions or Flow
Convert callback-based APIs into suspending functions or Flows safely and correctly using Kotlin Coroutines.
重點摘要
Wrap single-shot callbacks with suspendCoroutine or suspendCancellableCoroutine.
Use callbackFlow or channelFlow for listener-style or multi-emission callbacks.
Always handle cancellation, cleanup (unregister listeners), and exceptions to avoid leaks.
This guide explains how to interoperate callback-based APIs with Kotlin Coroutines by converting them into suspend functions or Flow. For single-response callbacks, wrap the API in suspendCoroutine or suspendCancellableCoroutine so the coroutine can suspend until a callback resumes or cancels it. For continuous or listener-style callbacks that emit multiple values, use callbackFlow or channelFlow to produce a Flow and ensure proper emission and backpressure handling. Key concerns include proper cancellation handling (unregistering listeners or stopping callbacks on coroutine cancellation), propagating errors as exceptions, and respecting coroutine contexts and timeouts. Following these patterns preserves resource safety, integrates with structured concurrency, and makes callback-based code easier to compose and test in coroutine-based applications.
将 Callback 函数转换为 suspend 函数或 Flow 的方法
通过 suspendCoroutine/suspendCancellableCoroutine 或 callbackFlow/channelFlow 将回调 API 正确转换为协程形式。
重點摘要
一次性回调用 suspendCoroutine 或 suspendCancellableCoroutine 包装。
多次事件或监听式回调使用 callbackFlow 或 channelFlow 生成 Flow。
必须处理取消、异常与资源释放(注销监听)以防止泄漏。
本指南介绍如何将基于回调的 API 转换为 Kotlin 协程可用的 suspend 函数或 Flow:对单次响应场景,使用 suspendCoroutine 或 suspendCancellableCoroutine 包装,使协程在回调完成时恢复或在取消时正确处理;对会发出多次事件或监听器模式,使用 callbackFlow 或 channelFlow 生成 Flow,同时处理发送、背压与取消。关键在于在协程取消时注销监听器以释放资源、将错误作为异常传播,并遵守协程上下文和超时策略。遵循这些模式可以保证资源安全、与结构化协程集成,并提高代码的可组合性与可测性。
將 Callback 函式轉為 suspend 函式或 Flow 的做法
使用 suspendCoroutine/suspendCancellableCoroutine 或 callbackFlow/channelFlow 將 callback API 正確轉為協程型式。
重點摘要
單次回呼用 suspendCoroutine 或 suspendCancellableCoroutine 包裝。
多次或監聽型回呼使用 callbackFlow 或 channelFlow 產生 Flow。
處理取消、例外與釋放資源(解除註冊)以避免記憶體或資源外洩。
本指南說明如何將基於 callback 的 API 正確轉換為 Kotlin Coroutines 可使用的 suspend 函式或 Flow:對於單次回應(one-shot)場景,應以 suspendCoroutine 或 suspendCancellableCoroutine 包裝,使協程能在回呼完成時恢復或在取消時正確處理;對於會多次發出事件或監聽器模式,則以 callbackFlow 或 channelFlow 建構 Flow 並處理發送、背壓與取消。重點在於於取消時解除註冊監聽器、將錯誤以例外傳遞,以及尊重協程的執行上下文與逾時行為。採用這些模式可確保資源安全、與結構化協程整合並提升可組合性與測試性。
KT Academy
作者:
發布:07-21 00:00
Calling blocking functions from suspending functions
Run blocking work on an appropriate dispatcher or wrap blocking APIs in suspension primitives so suspending functions don't block coroutines or the main thread.
重點摘要
Use withContext(Dispatchers.IO) or a dedicated dispatcher for blocking I/O
Wrap callback or blocking APIs with suspendCoroutine/suspendCancellableCoroutine
Ensure cancellation and resource cleanup to avoid leaks when bridging blocking code
This guide explains how to safely convert blocking functions into suspending functions in Kotlin Coroutines. The key idea is to avoid blocking coroutine threads (especially the main thread) by offloading blocking I/O or long-running work to an appropriate dispatcher such as Dispatchers.IO or a dedicated thread pool using withContext. For callback-based or legacy blocking APIs, wrap them with suspendCoroutine or suspendCancellableCoroutine so they integrate with coroutine suspension and cancellation semantics. Pay attention to cancellation, timeouts, and resource cleanup when bridging blocking code, and prefer CPU-bound work on Dispatcher.Default. Following these patterns preserves responsiveness, enables cooperative cancellation, and keeps coroutine-based code interoperable with existing blocking libraries.
在挂起函数中调用阻塞函数
将阻塞工作转移到合适的 dispatcher 或用 suspendCoroutine/suspendCancellableCoroutine 包装阻塞/回调 API,避免阻塞协程或主线程。
重點摘要
使用 withContext(Dispatchers.IO) 或专用 dispatcher 执行阻塞 I/O
用 suspendCoroutine 或 suspendCancellableCoroutine 包裹回调或阻塞 API
处理取消与资源清理以防止泄漏并支持协程取消语义
本指南介绍如何将阻塞函数正确转换为 Kotlin 协程的挂起函数。要点是不要在协程(尤其是主线程)上直接阻塞,而应使用 withContext 将阻塞 I/O 或耗时任务切换到 Dispatchers.IO 或专用线程池;对于回调式或旧阻塞接口,使用 suspendCoroutine 或 suspendCancellableCoroutine 封装,使其支持协程的挂起与取消。同时需关注取消、超时和资源释放等细节,CPU 密集型任务应使用 Dispatchers.Default。遵循这些做法可保持响应性并实现与现有阻塞库的安全互操作。
在掛起函數中呼叫阻塞函數
將阻塞工作移到適當的 dispatcher 或以 suspendCoroutine/suspendCancellableCoroutine 包裹阻塞/回呼 API,避免阻塞協程或主線程。
重點摘要
使用 withContext(Dispatchers.IO) 或專用 dispatcher 執行阻塞 I/O
以 suspendCoroutine 或 suspendCancellableCoroutine 包裝回呼或阻塞 API
處理取消與資源清理以避免記憶體或執行緒洩漏
本文說明如何正確將既有阻塞函數轉換為 Kotlin 協程的掛起函數。核心做法是不要在協程或主線程上直接阻塞,而是利用 withContext 將阻塞 I/O 或長時間工作派到 Dispatchers.IO 或專用執行緒池;對於回呼式或舊有阻塞 API,應以 suspendCoroutine 或 suspendCancellableCoroutine 包裝,讓它們支援協程的暫停與取消行為。並注意取消、逾時與資源釋放,對於 CPU 密集型工作則應使用 Dispatchers.Default。遵循這些模式可維持應用回應性並與現有阻塞程式庫良性互通。
KT Academy
作者:
發布:07-28 00:00
Building Your First Kotlin Multiplatform App: From Setup to iOS App Store with Compose Multiplatform (2025 Guide)
A practical walkthrough to create a Kotlin Multiplatform app with Compose Multiplatform, covering setup, cross‑platform development, and iOS App Store deployment.
重點摘要
Guides environment and project setup for Kotlin Multiplatform
Demonstrates building shared UI and logic using Compose Multiplatform
Covers testing, packaging, signing, and submitting to the iOS App Store
This comprehensive 2025 guide walks you through building your first Kotlin Multiplatform app with Compose Multiplatform, from initial setup to publishing on the iOS App Store. It explains how to configure the development environment and project structure for shared Kotlin code, and how to use Compose Multiplatform to create a single UI layer that targets multiple platforms. The guide also addresses platform-specific integration points for Android and iOS, practical considerations for testing and debugging shared and platform code, and the steps required to package, sign, and submit an iOS build to the App Store. Aimed at developers new to KMP and Compose Multiplatform, the article provides a clear sequence of tasks to move from a working prototype to a distributable iOS application.
从设置到上架:使用 Compose Multiplatform 构建你的第一个 Kotlin Multiplatform 应用(2025 指南)
一步步介绍如何使用 Compose Multiplatform 构建 Kotlin Multiplatform 应用,涵盖环境设置、跨平台开发与 iOS App Store 上架流程。
重點摘要
介绍 Kotlin Multiplatform 的开发环境与项目配置
演示使用 Compose Multiplatform 构建共享 UI 与业务逻辑
说明测试、打包、签名及提交到 iOS App Store 的步骤
本指南全面介绍如何使用 Compose Multiplatform 构建首个 Kotlin Multiplatform 应用,从初始环境与项目设置开始,讲解如何组织可跨平台复用的 Kotlin 代码并用 Compose Multiplatform 实现统一的用户界面。文章还涉及 Android 与 iOS 的平台集成要点、共享与平台代码的测试与调试实践,以及将应用打包、签名并提交到 iOS App Store 所需的流程与注意事项。目标读者为初学 KMP 与 Compose Multiplatform 的开发者,旨在提供从开发原型到 iOS 上架的清晰步骤。
從設定到上架:使用 Compose Multiplatform 建置你的第一個 Kotlin Multiplatform 應用(2025 指南)
逐步說明如何用 Compose Multiplatform 建構 Kotlin Multiplatform 應用,從環境設定、跨平台開發到 iOS App Store 上架。
重點摘要
說明 Kotlin Multiplatform 的環境與專案設定
示範以 Compose Multiplatform 建立共用介面與商業邏輯
涵蓋測試、打包、簽名與 iOS App Store 上架流程
本指南示範如何以 Compose Multiplatform 建置第一個 Kotlin Multiplatform 應用,內容從開發環境與專案結構設定開始,說明如何撰寫可在多平台重用的 Kotlin 共用程式碼,並以 Compose Multiplatform 建構統一的 UI。文章同時觸及 Android 與 iOS 的整合要點、共用與平台程式碼的測試與偵錯實務,以及將應用打包、簽名並提交至 iOS App Store 的必要步驟。此篇適合剛接觸 KMP 與 Compose Multiplatform 的開發者,提供從原型到可發佈 iOS 應用的實作流程。
KT Academy
作者:
發布:08-11 00:00
Converting Suspending Functions or Flows into Callback-Based APIs
How to correctly bridge Kotlin Coroutines suspending functions and flows to callback-style APIs while preserving cancellation, error handling, and resource cleanup.
重點摘要
Use coroutine primitives (e.g., suspendCancellableCoroutine, callbackFlow) to adapt suspend functions and flows.
Propagate cancellation and exceptions correctly and ensure resources are released on callback completion.
Preserve coroutine context and threading expectations when invoking callbacks from coroutine code.
This guide explains how to convert Kotlin Coroutines suspending functions and flows into callback-based functions safely and predictably. It covers the appropriate coroutine primitives to use—such as suspendCancellableCoroutine for single-shot suspend functions and callbackFlow for stream-like flows—so you can expose coroutine-based logic to callback-style APIs. The guide emphasizes propagating cancellation and exceptions back to the original coroutine, cleaning up resources when callbacks complete or are cancelled, and ensuring callbacks are invoked on the expected thread or context. Following these patterns helps avoid leaks, race conditions, and mismatched lifecycle behavior when interoperating between coroutines and traditional callback APIs.
将 suspend 函数或 Flow 转为回调(callback)接口
正确地将 Kotlin Coroutines 的 suspend 函数与 Flow 转换为回调风格 API,同时保留取消、错误处理与资源清理行为。
重點摘要
使用 suspendCancellableCoroutine、callbackFlow 等协程原语进行适配。
保证取消和异常正确传播,并在回调完成或取消时释放资源。
调用回调时保持协程上下文与线程的预期行为。
本指南介绍如何将 Kotlin Coroutines 的 suspend 函数与 Flow 安全地转换为基于回调的函数。内容建议使用合适的协程原语,例如对单次结果使用 suspendCancellableCoroutine、对流式数据使用 callbackFlow,并强调在适配过程中正确传播取消与异常,确保回调完成或取消时进行资源清理。还提醒在调用回调时保持原有的协程上下文与线程预期,从而避免内存泄漏、竞态条件以及生命周期不一致等问题。
將 suspend 函式或 Flow 轉為回呼(callback)介面
正確將 Kotlin Coroutines 的 suspend 函式與 Flow 轉換成 callback 風格 API,同時保留取消、錯誤處理與資源清理行為。
重點摘要
以 suspendCancellableCoroutine、callbackFlow 等協程原語作為橋接工具。
確保取消與例外能正確傳遞並在回呼結束或取消時釋放資源。
呼叫回呼時維持協程上下文與執行緒的期望行為。
本指南說明如何將 Kotlin Coroutines 的 suspend 函式與 Flow 安全地轉換為基於回呼的函式。說明會建議使用適當的協程原語,例如針對單次結果使用 suspendCancellableCoroutine、針對串流使用 callbackFlow,並示範如何在轉接時正確處理取消與例外,確保在回呼完成或被取消時釋放資源。此外也強調呼叫回呼時要維持原本的協程上下文與執行緒期望,以避免記憶體洩漏、競態條件或生命週期不一致等問題。
KT Academy
作者:
發布:08-18 00:00
Flow from suspending functions and vice versa
A guide on converting suspending functions to Flow and converting Flow back to suspending functions within Kotlin Coroutines.
重點摘要
Convert suspending functions to Flow
Convert Flow to suspending functions
Interoperate within Kotlin Coroutines
This article is a focused guide for Kotlin developers on converting suspending functions to Flow and converting Flow back to suspending functions within the Kotlin Coroutines framework. It describes why such conversions are useful — for example, adapting single-shot suspending APIs to reactive streams, or extracting a single result from an ongoing stream — and presents practical patterns for performing these translations. The guide covers decision points when to prefer a suspending function versus a Flow, explains how to bridge between the two while preserving coroutine semantics such as cancellation and context propagation, and highlights common pitfalls and best practices. Through step‑by‑step explanations and example code, readers learn how to implement conversions safely, manage lifecycle and error handling, and design interoperable coroutine-based APIs suited to different runtime needs.
从 suspending function 到 Flow 及反向互转
一篇说明如何在 Kotlin Coroutines 中将 suspending function 转为 Flow,或将 Flow 转回 suspending function 的指南。
重點摘要
将 suspending function 转为 Flow
将 Flow 转回 suspending function
在 Kotlin Coroutines 中实现互通
本文为 Kotlin Coroutines 的实作指南,说明如何将 suspending function 转为 Flow,以及如何将 Flow 转回 suspending function。文章阐述这类互转的用途与适用场景,例如在需要把单次挂起操作封装为数据流或从流中获取单一结果时的处理方式,并提出实务转换模式与要点。内容强调在互通时保持 coroutine 的语义(如取消、上下文传递)与错误处理,提示常见陷阱与最佳实践,并以步骤化说明与示例帮助开发者在真实项目中安全地调整 API 设计与使用方式。
從 suspending function 轉為 Flow 以及反向互轉
一篇說明如何在 Kotlin Coroutines 中將 suspending function 轉為 Flow,或將 Flow 轉回 suspending function 的指南。
重點摘要
將 suspending function 轉為 Flow
將 Flow 轉回 suspending function
在 Kotlin Coroutines 中保持互通性
本文為 Kotlin Coroutines 的實作指南,說明如何將 suspending function 轉為 Flow,以及如何將 Flow 轉回 suspending function。文章說明這類互轉的用途與適用情境,例如在需要把單次掛起操作封裝為資料流或從流中取得單一結果時的做法,並提出實務轉換模式與要點。內容強調在互通時保持 coroutine 的語意(如取消、上下文傳遞)與錯誤處理,提示常見陷阱與最佳實踐,並以步驟化說明與範例協助開發者在真實專案中安全地調整 API 設計與使用方式。
KT Academy
作者:
發布:08-25 00:00
New Cohort of Kotlin Coroutines Experts
The grand goal of the Coroutines Mastery course is to cultivate deep expertise in Kotlin coroutines.
重點摘要
A new cohort is focused on mastering Kotlin coroutines.
The Coroutines Mastery course sets a grand goal of producing experts.
Emphasis is on deep conceptual understanding and practical application.
The announcement highlights a new cohort connected to the Coroutines Mastery course and emphasizes the course's overarching objective: to cultivate true expertise in Kotlin coroutines. Rather than promising superficial familiarity, the course aims to develop deep conceptual models of how coroutines work, solid practical skills, and reliable patterns for applying them in real projects. The grand goal is to move learners from basic usage to expert-level understanding, equipping them to reason about concurrency and asynchronous flows clearly and to implement robust solutions. In short, the program is positioned as a structured path for developers who want to master both the theory and practice of Kotlin coroutines and become recognized experts in the topic.
新一届 Kotlin 协程专家班
Coroutines Mastery 课程的宏大目标是培养对 Kotlin 协程具有深入能力的专家。
重點摘要
一批新的学员加入以精通 Kotlin 协程为导向的课程。
课程设定了培养专家的宏大目标。
侧重建立概念性理解与实际应用能力。
文章提到与 Coroutines Mastery 课程相关的新一届学员,并强调该课程的宏大目标:培养在 Kotlin 协程领域达到专家水准的人才。课程目标超越基础使用,旨在帮助学习者建立对协程模型和运行机制的深刻理解,结合实践示例与设计策略,使其能够在真实项目中可靠且高效地处理并发与异步工作。总体上,课程通过系统化教学与练习,支持学员从原理到高阶应用逐步成长,最终具备在团队与产品中实际应用协程的专业能力。
新一屆 Kotlin 協程專家培訓班
Coroutines Mastery 課程的宏大目標是培養對 Kotlin 協程具備深刻專業能力的人才。
重點摘要
有新一批學員加入以精通 Kotlin 協程為目標的課程。
課程核心在於達成培養專家的宏大目標。
強調建立概念性理解與實務應用能力。
文章指出有新一屆學員(cohort)與 Coroutines Mastery 課程相關,並強調該課程的宏大目標:培養在 Kotlin 協程領域具有專家級能力的人才。課程不只著重操作技巧,而是要建立對協程模型與運作方式的深刻理解,配合實務範例與設計策略,幫助學員在實際專案中可靠且有效地處理併發與非同步問題。整體宗旨是從基礎理論到高階應用,透過系統化的學習與練習,讓學員達到能在團隊與產品中實際應用協程、具備專業判斷的程度。
KT Academy
作者:
發布:09-01 00:00
runBlocking in practice: Where it should be used and where not
A comprehensive guide to using runBlocking in Kotlin Coroutines, covering best practices and common pitfalls.
重點摘要
Comprehensive guidance on runBlocking usage
Explains appropriate contexts and when to avoid it
Summarizes best practices and common pitfalls
This article is a comprehensive guide to using runBlocking in Kotlin Coroutines. It explains when runBlocking is appropriate and when it should be avoided, summarizes best practices, and calls out common pitfalls that developers encounter. The guide helps readers reason about the blocking nature of runBlocking, its interactions with coroutines and dispatchers, and practical considerations when integrating it into applications or tests. Rather than prescribing one-size-fits-all rules, the article focuses on practical trade-offs and clear guidance to help decide whether runBlocking belongs in a given code path. It aims to give Kotlin developers a concise, practical reference for using runBlocking safely and effectively.
runBlocking 的实践应用:何时该用、何时不该用
一份关于在 Kotlin 协程中使用 runBlocking 的完整指南,涵盖最佳做法与常见陷阱。
重點摘要
全面说明 runBlocking 的使用情境
指出何时应避免使用 runBlocking
整理实务上的最佳做法与常见陷阱
本文为 runBlocking 在 Kotlin 协程中的实务指南,说明何时适合使用及何时应避免,并整理实务上的最佳做法与常见陷阱。文章探讨 runBlocking 的阻塞特性、与协程与调度器的互动,以及在应用或测试情境引入时的注意事项,重点在于提供可操作的建议与取舍方向,帮助开发者在不同代码路径中评估是否采用 runBlocking,以兼顾稳定性与设计清晰度。
runBlocking 的實務應用:何時該用、何時不該用
一份關於在 Kotlin 協程中使用 runBlocking 的完整指南,涵蓋最佳做法與常見陷阱。
重點摘要
全面說明 runBlocking 的使用情境
指出何時應避免使用 runBlocking
整理實務上的最佳做法與常見陷阱
本文為 runBlocking 在 Kotlin 協程中的實務指南,說明何時適合使用及何時應避免,並整理實務上的最佳做法與常見陷阱。文章探討 runBlocking 的阻塞性質、與協程與調度器的互動,以及在應用或測試情境導入時的注意事項,重點在於提供可操作的建議與取捨方向,幫助開發者在不同程式碼路徑中評估是否採用 runBlocking,以兼顧穩定性與設計清晰度。
KT Academy
作者:
發布:09-08 00:00
Kotlin Coroutines and JavaScript
Explains how to use Kotlin Coroutines in JavaScript projects and how to call JavaScript libraries from Kotlin Coroutines.
重點摘要
Use Kotlin Coroutines within JavaScript projects
Invoke JavaScript libraries from Kotlin Coroutines
Covers interoperability patterns, bridging, and runtime considerations
This article describes interoperability between Kotlin Coroutines and JavaScript. It explains two primary directions: embedding Kotlin Coroutines into JavaScript projects so coroutine-based code can participate in JS applications, and calling existing JavaScript libraries from within Kotlin coroutines. The text outlines general patterns for bridging asynchronous models (for example, mapping suspending functions to JavaScript promises), handling type conversions and runtime integration, and the typical setup concerns when combining the two ecosystems. It also highlights practical considerations such as preserving asynchronous semantics, managing execution contexts, and being aware of platform-specific limitations. Overall, the piece aims to guide developers on integrating coroutine-based Kotlin code with JavaScript-based codebases while minimizing interop pitfalls.
Kotlin 协程与 JavaScript
说明如何在 JavaScript 项目中使用 Kotlin 协程,以及如何从 Kotlin 协程调用 JavaScript 库。
重點摘要
在 JavaScript 项目中使用 Kotlin 协程
从 Kotlin 协程调用 JavaScript 库
介绍互操作模式、桥接方法与运行时注意事项
本文介绍了 Kotlin 协程与 JavaScript 之间的互操作方式,涵盖两种主要用例:在 JavaScript 项目中引入 Kotlin 协程,使基于协程的代码能参与 JS 应用;以及在 Kotlin 协程内调用已有的 JavaScript 库。文章从高层说明常见桥接模式,如把可挂起函数与 JavaScript Promise 对应、类型转换与运行时集成,以及整合时的配置与注意点。并提醒开发者关注异步语义的保持、执行上下文的管理以及平台特性限制,旨在帮助开发者在两个生态间安全且高效地进行代码互通。
Kotlin 協程與 JavaScript
說明如何在 JavaScript 專案中使用 Kotlin 協程,以及如何從 Kotlin 協程呼叫 JavaScript 函式庫。
重點摘要
在 JavaScript 專案中使用 Kotlin 協程
從 Kotlin 協程呼叫 JavaScript 函式庫
介紹互操作模式、橋接方法與執行時注意事項
本文說明 Kotlin 協程與 JavaScript 的互操作方式,涵蓋兩種主要方向:在 JavaScript 專案中嵌入 Kotlin 協程,讓以協程為基礎的程式能與 JS 應用整合;以及在 Kotlin 協程內呼叫既有的 JavaScript 函式庫。文章以高階角度描述常見的橋接模式,例如如何將可掛起函數與 JavaScript 的 Promise 對應、型別轉換與執行時整合,以及整合時的設定與注意事項。內容並提醒開發者注意保持非同步語意、管理執行上下文與平台差異,協助在兩個生態間安全且有效地整合程式碼。
KT Academy
作者:
發布:09-15 00:00
Kotlin Coroutines and Swift
How to use Kotlin Coroutines in Swift projects, or Swift libraries from Kotlin Coroutines.
重點摘要
Use Kotlin coroutines from Swift-based projects
Call Swift libraries and APIs from Kotlin coroutines
Guidance on interoperability strategies and practical considerations
This article explains how to integrate Kotlin Coroutines with Swift codebases in both directions: invoking coroutines from Swift projects and calling Swift libraries from Kotlin coroutine contexts. It focuses on interoperability strategies and practical considerations developers face when bridging the two ecosystems, such as mapping asynchronous models, handling threading and callbacks, adapting APIs, and dealing with error propagation between languages. Intended for teams sharing logic across Android and iOS (including Kotlin Multiplatform scenarios), the piece outlines conceptual approaches and recommends patterns for wrapping, adapting, and testing asynchronous interactions so that coroutine-based code and Swift consumers can interoperate reliably.
Kotlin 协程与 Swift
如何在 Swift 项目中使用 Kotlin 协程,或从 Kotlin 协程调用 Swift 库。
重點摘要
在 Swift 项目中使用 Kotlin 协程
从 Kotlin 协程调用 Swift 库
介绍互操作策略与实务注意点
本文介绍了在两种方向上整合 Kotlin 协程与 Swift 的方法:一是如何在 Swift 项目中使用 Kotlin 协程,二是如何从 Kotlin 协程中调用 Swift 的库。内容着重于互操作的策略与开发时需要注意的问题,包括异步模型的映射、线程与回调的处理、API 的包装与适配,以及跨语言错误传递等方面。面向需要在 Android 与 iOS 之间共享逻辑或使用 Kotlin Multiplatform 的开发者,文章提供了概念性建议与模式,帮助实现和测试跨语言的异步交互,确保协程与 Swift 端能可靠协作。
Kotlin 協程與 Swift
如何在 Swift 專案中使用 Kotlin 協程,或從 Kotlin 協程呼叫 Swift 函式庫。
重點摘要
在 Swift 專案中使用 Kotlin 協程
從 Kotlin 協程呼叫 Swift 函式庫
說明互通策略與實務注意事項
本文說明了如何在兩個方向上整合 Kotlin 協程與 Swift:一是從 Swift 專案呼叫並使用 Kotlin 協程,二是從 Kotlin 協程中呼叫 Swift 的函式庫。文章聚焦於互通策略與開發時常見的實務考量,包括非同步模型的對應、執行緒與回呼的處理、API 的包裝與適配,以及跨語言錯誤傳遞等議題。對於在 Android 與 iOS 間共享邏輯或使用 Kotlin Multiplatform 的團隊,本文提供概念性方法與建議模式,幫助實作與測試跨語言的非同步互動,以確保協程與 Swift 端能穩定協作。
KT Academy
作者:
發布:09-22 00:00
Kotlin Flow to RxJava or Reactor and vice versa
A guide for converting Kotlin Flow to RxJava or Reactor streams and converting those streams back to Flow.
重點摘要
Convert Kotlin Flow to RxJava streams
Convert Kotlin Flow to Reactor streams
Convert RxJava or Reactor streams back to Flow
This article is a focused guide on converting between Kotlin Flow and popular reactive stream libraries—RxJava and Reactor—in both directions. It is intended to help developers bridge reactive ecosystems when integrating libraries or migrating code, by showing how Flow instances can be adapted into RxJava or Reactor stream types and how those stream types can be turned back into Flow. The guide emphasizes interoperability concerns and the practical need to interoperate cleanly across different reactive APIs, enabling teams to mix implementations without rewriting entire codebases. Readers can expect clear explanations of the conversion intent and considerations relevant to using Flow alongside RxJava or Reactor in Kotlin projects.
Kotlin Flow 与 RxJava / Reactor 相互转换指南
介绍如何将 Kotlin Flow 转换为 RxJava 或 Reactor 的流,并将这些流再转换回 Flow。
重點摘要
将 Kotlin Flow 转为 RxJava 流
将 Kotlin Flow 转为 Reactor 流
将 RxJava / Reactor 流转回 Flow
本文是一篇面向实践的指南,讲解在 Kotlin 中如何在 Kotlin Flow 与 RxJava、Reactor 之间进行双向转换:既包括将 Flow 适配为 RxJava 或 Reactor 的流类型,也包括将这些流再转换回 Flow。该指南旨在帮助开发者在整合不同反应式库或迁移代码时实现互操作,强调跨生态系统协作的必要性和相关考量,使团队能够在不大幅重写代码的前提下混合使用多种反应式实现。
Kotlin Flow 與 RxJava / Reactor 互轉指南
說明如何將 Kotlin Flow 轉成 RxJava 或 Reactor 的串流,並將這些串流再轉回 Flow。
重點摘要
將 Kotlin Flow 轉換為 RxJava 串流
將 Kotlin Flow 轉換為 Reactor 串流
將 RxJava / Reactor 串流轉回 Flow
本文為一篇實用指南,說明如何在 Kotlin 中於 Kotlin Flow 與 RxJava、Reactor 之間互相轉換,包含從 Flow 轉為其他反應式串流型別,以及將這些串流再轉回 Flow。此指南旨在協助開發者在整合不同反應式函式庫或逐步遷移程式碼時,建立跨生態系的互通方式,並提醒在混用不同反應式 API 時需注意的互操作性議題,幫助團隊在不重寫整個程式碼庫的情況下協同使用多種反應式技術。
KT Academy
作者:
發布:09-29 00:00
Converting suspending functions to blocking functions or CompletableFuture
A guide on how to correctly convert suspending functions into blocking functions or CompletableFuture in Kotlin Coroutines.
重點摘要
Use coroutine-to-blocking interop utilities (e.g., runBlocking, kotlinx-coroutines-jdk8 future) rather than ad-hoc thread blocking.
Preserve coroutine semantics: propagate exceptions, respect cancellation, and run blocking work on appropriate dispatchers.
Consider timeouts, resource cleanup, and testing to avoid deadlocks, leaks, and unexpected behavior across boundaries.
This guide explains how to convert Kotlin suspending functions into blocking functions or CompletableFuture for Java interop. It describes using runBlocking to bridge suspending calls from synchronous code and using the kotlinx-coroutines-jdk8 future builder to obtain CompletableFuture results. Key concerns are preserving coroutine semantics—propagating exceptions, honoring cancellation, and avoiding blocking the default coroutine dispatcher—so blocking tasks should run on a dedicated dispatcher or thread pool. The article also highlights mapping timeouts and resource cleanup across the boundary, avoiding ad-hoc thread manipulation that can deadlock or leak resources, and preferring structured concurrency and existing interop helpers. Practical advice includes explicit error handling and testing strategies to ensure safe, predictable interoperability between coroutine-based APIs and blocking or Java-future-based callers.
将 suspending 函数转换为阻塞函数或 CompletableFuture
本指南介绍如何在 Kotlin 协程中正确地将 suspending 函数转换为阻塞函数或 CompletableFuture。
重點摘要
使用现有互通工具(如 runBlocking 与 kotlinx-coroutines-jdk8 的 future),避免随意阻塞线程。
保持协程语义:异常传播、取消支持及在合适的调度器上执行阻塞工作。
关注超时与资源清理,优先结构化并发与测试以防止死锁或资源泄露。
本指南介绍在 Kotlin Coroutines 中将 suspending 函数正确转换为同步阻塞函数或用于 Java 的 CompletableFuture 的做法。内容说明何时使用 runBlocking 从同步代码桥接协程调用,以及如何通过 kotlinx-coroutines-jdk8 的 future 生成 CompletableFuture。核心要点包括保持协程语义(异常和取消的传递)、避免在默认协程调度器上阻塞并将阻塞工作放在专用调度器或线程池中执行。文中还强调处理超时与资源释放、避免手动线程操作带来的死锁或泄露,并建议采用结构化并发与内置互通工具,同时通过错误处理和测试确保跨界互操作的安全与可预测性。
將 suspending 函式轉為阻塞函式或 CompletableFuture
本指南說明如何在 Kotlin Coroutines 中正確地把 suspending 函式轉換為阻塞函式或 CompletableFuture。
重點摘要
使用既有互通工具(如 runBlocking 與 kotlinx-coroutines-jdk8 的 future)而非任意阻塞執行緒。
保留協程語意:例外傳播、取消機制與執行緒/調度器的正確使用。
注意逾時與資源清理,並以結構化並發與測試避免死鎖或資源外洩。
本指南說明在 Kotlin Coroutines 中,如何將 suspending 函式正確轉換為同步阻塞函式或供 Java 使用的 CompletableFuture。內容涵蓋何時使用 runBlocking 在同步程式碼中呼叫協程,以及如何透過 kotlinx-coroutines-jdk8 的 future 建構器產生 CompletableFuture。重點在於保留協程的語意,包括例外與取消的傳遞,並避免在預設協程調度器上直接阻塞;有阻塞需求時應使用專用調度器或執行緒池。文章亦提醒處理逾時、資源釋放,以及以結構化方式與現有互通工具整合,並強調測試與錯誤處理以確保跨界呼叫的安全與可預期性。
KT Academy
作者:
發布:10-06 00:00
Coroutines vs Reactor: When Elegance and Simplicity Crush Complexity
The article contrasts Kotlin Coroutines' elegant, simple model with Reactor's comparatively greater complexity.
重點摘要
Direct comparison of Kotlin Coroutines and Reactor
Emphasizes Coroutines' elegance and simplicity
Frames Reactor as more complex by design
This short article compares Kotlin Coroutines with Reactor and highlights a central theme: Coroutines deliver an elegant and simple programming model, while Reactor introduces more complexity. Rather than providing exhaustive benchmarks or implementation details, the piece focuses on conceptual differences—how Coroutines aim for straightforward, readable concurrency and asynchronous code, whereas Reactor embodies a more involved, explicit reactive approach that can be harder to adopt and reason about. The write-up advocates for the clarity and developer ergonomics of Coroutines without denying that Reactor is a capable, feature-rich toolkit. Its purpose is to draw attention to how simplicity and elegance in language-level constructs can reduce mental overhead and implementation complexity when choosing a concurrency paradigm for Kotlin projects.
Coroutines 与 Reactor:当优雅与简洁击败复杂性
文章对比了 Kotlin Coroutines 的优雅与简洁,相较之下 Reactor 更显复杂。
重點摘要
比较 Kotlin Coroutines 与 Reactor
强调 Coroutines 的优雅与简洁
指出 Reactor 在设计上更为复杂
本文对比了 Kotlin Coroutines 和 Reactor,核心观点是 Coroutines 提供了更为优雅和简洁的编程模型,而 Reactor 则具有更高的复杂性。文章侧重于概念层面的比较,强调 Coroutines 如何让异步与并发代码更直观、更易阅读,而不是给出详细基准或实现细节。尽管并未否认 Reactor 的功能性与能力,作者还是指出语言层面的简洁性与可用性能够降低开发者的心智负担,并建议在为 Kotlin 项目选择并发范式时,应把可读性和开发效率作为重要考量。
Coroutines 與 Reactor:當優雅與簡潔壓倒複雜性
文章對比指出 Kotlin Coroutines 的優雅與簡潔,相較之下 Reactor 顯得更為複雜。
重點摘要
比較 Kotlin Coroutines 與 Reactor
強調 Coroutines 的優雅與簡潔
指出 Reactor 具有較高的複雜性
本文以比較為主題,強調 Kotlin Coroutines 在設計上呈現出較高的優雅性與簡潔性,而 Reactor 則被描繪為更為複雜的反應式框架。文章並未深入技術細節或列出量測數據,而是聚焦在觀念層面的差異:Coroutines 傾向讓非同步與並發程式碼更直觀、易讀;Reactor 則採用更顯式、功能豐富但學習與推理成本較高的方式。作者藉此提出,語言層級的簡潔與優雅能降低心智負擔,當在 Kotlin 專案中選擇併發範式時,這類可讀性與易用性的考量值得重視。
KT Academy
作者:
發布:10-17 00:00
Discussing Kotlin Coroutines on Talking Kotlin Podcast
An insightful discussion about Kotlin Coroutines on the Talking Kotlin podcast.
重點摘要
Episode covers Kotlin Coroutines
Described as an insightful discussion
Published by the Talking Kotlin podcast
This brief article points readers to an episode of the Talking Kotlin podcast that features an insightful discussion about Kotlin Coroutines. It presents the podcast episode as a resource for developers and listeners interested in the topic, highlighting the episode’s focus on coroutines without going into detailed technical specifics. The piece functions as a pointer to the podcast, encouraging those curious about Kotlin concurrency primitives to listen to the conversation for broader perspectives and conceptual insight. Since the article itself is short, it serves primarily to direct readers to the full podcast episode for deeper engagement with the subject.
在 Talking Kotlin 播客讨论 Kotlin 协程
在 Talking Kotlin 播客上对 Kotlin 协程进行了一场有见地的讨论。
重點摘要
节目聚焦 Kotlin 协程
被描述为有见地的讨论
来源为 Talking Kotlin 播客
本文简要介绍了 Talking Kotlin 播客的一期节目,该期对 Kotlin 协程(Coroutines)进行了有见地的讨论。文章内容简短,未展开具体技术细节,主要作为指引,提示对协程感兴趣的读者收听该集以获取更全面的观点与理解。对于希望从对话中获得概念性洞见或寻找不同视角的开发者和学习者,这篇介绍会将他们引导至完整的播客内容以便更深入地聆听与學習。
在 Talking Kotlin 播客上討論 Kotlin 協程
在 Talking Kotlin 播客上對 Kotlin 協程進行了一場具見地的討論。
重點摘要
節目主題為 Kotlin 協程
內容被描述為具見地的討論
來源為 Talking Kotlin 播客
本文簡短介紹了 Talking Kotlin 播客的一集,該集對 Kotlin 協程(Coroutines)進行了深入且具見地的討論。文章本身沒有提供技術細節,主要作為一個導引,提醒對協程主題有興趣的讀者或開發者可收聽該集以獲取更多觀點與理解。對於想要了解協程概念或尋求不同視角的聽眾,這篇介紹起到指向完整節目並鼓勵深入收聽的作用。
KT Academy
作者:
發布:10-20 00:00
How to implement a random coroutines challenge generator
A behind-the-scenes look at implementing a generator of engaging challenges to teach Kotlin Coroutines.
重點摘要
Designs a generator to produce varied, engaging Kotlin Coroutines exercises
Uses randomness while ensuring tasks remain meaningful and solvable
Covers problem modeling, difficulty control, testing, and feedback integration
This article gives a behind-the-scenes look at designing and implementing a random challenge generator aimed at teaching Kotlin Coroutines. It outlines goals such as producing varied, engaging tasks, balancing difficulty, and exposing coroutine concepts through practical exercises. The generator uses randomness to assemble scenarios and parameters while ensuring exercises remain meaningful and solvable; it also emphasizes clear specification, automated validation, and feedback for learners. Implementation considerations include modeling problems, selecting randomized elements, controlling difficulty progression, and integrating test harnesses to check coroutine behavior. The piece highlights trade-offs between novelty and pedagogical clarity and suggests iterating on examples based on learner results. Overall, the article demonstrates how a focused generator can produce a steady stream of targeted, hands-on challenges that help developers practice coroutine patterns, concurrency primitives, and structured concurrency in Kotlin.
如何实现一个随机 Kotlin 协程挑战生成器
从幕后解析如何实现一个为学习 Kotlin 协程而设计的有趣随机挑战生成器。
重點摘要
为 Kotlin 协程设计随机化练习题
注重题目多样性、难度与可解性
涵盖题目建模、难度控制与自动化验证
本文从幕后角度讲述如何设计与实现一个用于学习 Kotlin 协程的随机挑战生成器。文章阐明目标,包括生成多样且有趣的练习、平衡难度,以及通过具体场景让学习者练习协程语义与结构化并发。实现讨论涉及题目建模、随机元素的选择与组合、难度分级与进阶控制,并强调整合测试与自动化验证以确保解答正确性与提供学习反馈。同时指出在新颖性与教学清晰度之间的权衡,并建议根据学习者反馈持续优化题库与示例设计。
如何實作一個隨機 Kotlin 協程挑戰產生器
從幕後揭示如何實作一個為學習 Kotlin 協程而設的有趣挑戰題產生器。
重點摘要
為 Kotlin 協程設計隨機化練習題
注重題目多樣性、難度與可解性
涵蓋題目建模、難度控制與自動驗證設計
本文從幕後角度說明如何設計與實作一個用於學習 Kotlin 協程的隨機挑戰題產生器。文章說明產生器的目標:產出多樣且具趣味的練習、平衡難度、以及透過具體情境讓學習者練習協程語意與結構化並發。討論的實作面向包含題目建模、隨機元素的選取與組合、難度分級與進階控制,並強調整合測試與自動驗證以確認解答正確性與提供回饋。最後指出在新穎性與教學清晰度間的權衡,並建議根據學習者回饋持續調整題庫與範例設計。
KT Academy
作者:
發布:10-28 00:00
Suspending functions vs. Flow: When to use which?
Use suspending functions for single, immediate results and Flow for streams and reactive sequences.
重點摘要
Suspending functions are best for one-off or immediate results
Flow handles multi-value, time-based or streaming data
Flow provides operators, cancellation, and backpressure control
Suspending functions and Flow are two coroutine-based abstractions in Kotlin for asynchronous work with different purposes. Suspending functions are ideal for single values or straightforward sequential operations (one-shot I/O, simple computations), integrating naturally with structured concurrency and easy error handling. Flow is designed for multi-value streams and reactive-style scenarios: cold, cancellable sequences that emit values over time and offer operators (map, filter, debounce), composition, and strategies for sharing and backpressure. Choose suspending functions when you need a single computed result or simpler lifecycle semantics; choose Flow when you need to produce or combine multiple emissions, react to changing data, or apply stream operators. Understanding these trade-offs helps you write clearer, more maintainable, and performant coroutine code.
Suspending functions 与 Flow:什么时候用哪个?
需要一次性或即时结果时用 suspending function;需要处理多次或时间序列数据时用 Flow。
重點摘要
suspending function 适合一次性或即时结果
Flow 适合多值、持续或时间序列的数据流
Flow 支持运算子、取消和背压等流式控制
Kotlin Coroutines 中的 suspending function 与 Flow 都用于异步编程,但用途不同。suspending function 适合单次或即时返回的结果,逻辑直观、易于错误处理并与结构化并发配合良好;Flow 则用于多次或持续发射的流,支持冷序列、可取消、通过 map、filter、debounce 等运算子进行组合与转换,并能处理共享与背压。选择原则是:仅需一次计算或简单 I/O 用 suspending function;需要时间序列、多事件合流或响应式处理时用 Flow。理解这些权衡有助于提高代码的清晰度、性能和可维护性。
Suspending functions 與 Flow:何時使用哪個?
當只需單一次或立即的結果時使用 suspending function;當要處理多次或時間序列資料時使用 Flow。
重點摘要
suspending function 適合單次或立即的結果
Flow 適合多值、持續或時間序列的資料流
Flow 支援運算子、取消與背壓等流式控制
Kotlin Coroutines 的 suspending function 與 Flow 都用於非同步處理,但適用情境不同。suspending function 適合一次性或立即需要的結果,語意簡單、與結構化併發整合良好且易於錯誤處理;Flow 則針對多次或持續輸出的資料流,支援冷序列、可取消、透過 map、filter、debounce 等運算子做串接與轉換,並可處理共享與背壓。選擇上若只需單一計算或簡易 I/O,使用 suspending function;若需時間序列、多重事件或反應式合流,則採用 Flow。了解這些差異能提升程式的可讀性、效能與可維護性。
Medium Kotlin
作者:Siddharth
發布:12-03 10:48
How Kotlin Coroutines Actually Work Under the Hood — A Simple, Deep-Dive Explanation
Kotlin coroutines feel lightweight, readable, and ideal for modern concurrency; this article explains what happens under the hood.
重點摘要
Demystifies why coroutines feel lightweight and readable
Provides a clear deep-dive into underlying implementation ideas
Converts the apparent "magic" of coroutines into practical concepts
The article demystifies how Kotlin coroutines work beneath their concise syntax. It starts from the user experience — coroutines feel lightweight, readable, and well-suited to concurrent programming — and then walks through the underlying mechanisms that make that possible. The author offers a clear, approachable deep-dive aimed at readers who want to understand what actually happens when suspend functions yield control, how execution is resumed, and what runtime pieces collaborate to deliver non-blocking concurrency. Rather than only showing API usage, the piece explains core ideas and trade-offs so developers can reason about performance, scheduling, and portability. It is suitable for engineers familiar with Kotlin who want deeper conceptual grounding.
Kotlin 协程在底层究竟如何工作 — 一篇简单的深度解析
协程在使用时看起来轻量、可读且适合现代并发;本文解释了其底层发生了什么。
重點摘要
解释协程为何显得轻量且可读
用易懂方式剖析底层实现要点
将表面的“魔法”转化为可理解的实现概念
本文从使用体验切入,指出 Kotlin 协程看起来轻量、可读且适合并发,但其背后依赖一套让这些特性成立的机制。作者以清晰易懂的方式做深度解析,阐述协程在程序执行中如何暂停与恢复、运行时部件如何协作以实现非阻塞并发,以及这些设计上的考量。文章目的在于把表面的便利性还原为具体的实现概念,帮助熟悉 Kotlin 的开发者建立更扎实的概念性认识,而不只是停留在 API 使用上。
Kotlin 協程實際上如何在底層運作 — 一篇簡單深度解析
協程在使用時感覺輕量、可讀且適合現代並發;本文解析其底層機制,說明這些特性如何實現。
重點摘要
釐清協程看起來像「魔法」的原因
以淺顯方式解析底層實作概念
幫助開發者從概念上理解設計與取捨
本文從使用者的直觀感受出發,說明為何 Kotlin 協程會顯得輕量與可讀,並進一步以簡單且具體的深度解析揭示其底層機制。作者著重把表面的語法便利轉化為可理解的實作概念,說明協程在程式執行中暫停與恢復的基本想法,以及執行環境與調度如何配合,並討論這些設計帶來的實務考量。文章旨在讓熟悉 Kotlin 的工程師建立更穩固的概念理解,而非僅停留於 API 使用層次。
Medium Kotlin
作者:Tailorviren
發布:12-03 11:50
Jetpack Compose derivedStateOf Explained with Real UI Example | Performance Optimization Guide
A practical walkthrough showing how derivedStateOf affects recomposition and UI performance, with a side-by-side example (with vs without).
重點摘要
Explains purpose and use of derivedStateOf in Jetpack Compose
Provides a real UI example comparing implementations with vs without derivedStateOf
Focuses on reducing unnecessary recompositions to improve performance
Tailorviren’s article explains Jetpack Compose’s derivedStateOf using a practical UI example and a direct comparison of implementations with and without it. It describes how derivedStateOf lets you derive state values from other state while avoiding unnecessary recompositions, and shows the observable effect on UI updates in a real scenario. The guide highlights when to apply derivedStateOf to improve performance, outlines the typical causes of redundant recompositions, and summarizes best-practice patterns to keep Compose UIs efficient. Rather than deep API reference, the piece focuses on concrete, example-driven reasoning that helps developers decide whether derivedStateOf is appropriate for a specific case and how it impacts responsiveness and CPU usage. The article serves as a concise performance-optimization primer for Compose users seeking practical ways to reduce wasteful UI work.
Jetpack Compose derivedStateOf 解释与真实 UI 示例 | 性能优化指南
通过真实 UI 示例展示 derivedStateOf 如何影响重组与性能,并对比有无使用时的差异。
重點摘要
讲解 derivedStateOf 在 Jetpack Compose 中的作用与使用场景
提供真实 UI 示例,比较有无 derivedStateOf 的实现差异
聚焦减少多余重组以提升 UI 性能
本文由 Tailorviren 以实际 UI 示例说明 Jetpack Compose 的 derivedStateOf,并对比有无使用时的行为差异。文章解释 derivedStateOf 如何从其他 state 推导出衍生值,减少不必要的重组(recomposition),并在真实场景中观察到 UI 更新与性能的不同。内容聚焦于何时应用 derivedStateOf、常见导致多余重组的情形,以及实践上的最佳做法,帮助开发者判断在特定案例是否采用此工具以提升响应性与降低 CPU 开销。该指南以示例驱动的方式提供简洁的性能优化建议,适合想优化 Compose UI 的工程师阅读。
Jetpack Compose derivedStateOf 實作解析與實際 UI 範例 | 效能優化指南
以實際 UI 範例示範 derivedStateOf 如何影響重組與效能,並比較有無使用時的差異。
重點摘要
說明 derivedStateOf 在 Jetpack Compose 中的用途與效果
以實際 UI 範例比較有無 derivedStateOf 的行為差異
著重減少不必要的重組以提升 UI 效能
本文由 Tailorviren 以實際 UI 範例說明 Jetpack Compose 的 derivedStateOf,並對比有無使用時的行為差異。文章解釋 derivedStateOf 如何從其他 state 推導出衍生值,減少不必要的重組(recomposition),並在真實場景中觀察到 UI 更新與效能的不同。內容聚焦於何時應用 derivedStateOf、常見導致多餘重組的情形,以及實務上的最佳做法,幫助開發者判斷在特定案例是否採用此工具以提升響應性與降低 CPU 開銷。該指南以範例導向的方式提供簡潔的效能優化建議,適合想優化 Compose UI 的工程師閱讀。
Medium Kotlin
作者:Dobri Kostadinov
發布:12-03 00:27
Navigation Compose 3 Is Finally Stable — Here’s Why It Matters for Android Developers
Why Google rebuilt navigation for Compose — and why Nav3 finally gets it right.
重點摘要
Explains why Google rebuilt navigation for Jetpack Compose
Argues that Nav3's stability removes uncertainty for Compose-based projects
Discusses implications of Nav3 stability for Android development workflows
This article examines Google's decision to rebuild navigation for Jetpack Compose and explains why Navigation Compose 3 (Nav3) reaching stable status matters to Android developers. It outlines the motivations behind the redesign and argues that Nav3's stability reduces uncertainty for projects that rely on Compose-based navigation by providing more predictable behavior and official support. The piece highlights how a stable Nav3 can affect development workflows, dependency management, and migration planning, helping teams decide whether to adopt or upgrade. For developers evaluating navigation options for Compose apps, the article provides context on why Nav3 represents a noteworthy milestone that clarifies the recommended navigation path and eases the work of building modern Android user interfaces.
Navigation Compose 3 终于稳定了 — 这对 Android 开发者为何重要
为什么 Google 重新构建 Compose 的导航,以及 Nav3 为什么终于做对了。
重點摘要
解释 Google 为什么重建 Jetpack Compose 的导航
强调 Nav3 稳定版能降低项目不确定性
讨论 Nav3 稳定对开发流程与升级决策的影响
文章探讨了 Google 为何重建 Jetpack Compose 的导航组件,以及 Navigation Compose 3(Nav3)达到稳定版对 Android 开发者的意义。文中说明了重构的动机,并指出 Nav3 的稳定为依赖 Compose 导航的项目带来更可预期的行为与官方支持,从而减少不确定性。作者讨论了稳定版可能如何影响开发流程、依赖管理与迁移规划,为考虑采用或升级到 Nav3 的开发者提供背景与评估要点,并将 Nav3 的稳定视为明确的里程碑,有助于简化使用 Compose 构建现代 Android 界面的工作。
Navigation Compose 3 終於穩定了 — 為何這對 Android 開發者很重要
為何 Google 重新打造 Compose 的導覽系統,以及 Nav3 為何終於做對了。
重點摘要
說明 Google 為何重建 Jetpack Compose 的導覽
指出 Nav3 穩定版能降低專案不確定性
探討 Nav3 穩定對開發流程與升級規劃的影響
本文探討 Google 為何重建 Jetpack Compose 的導覽系統,以及 Navigation Compose 3(Nav3)達到穩定版對 Android 開發者的意義。文章說明重構的動機,並指出 Nav3 的穩定可為依賴 Compose 導覽的專案帶來可預期的行為與官方支援,從而減少不確定性。作者討論穩定版如何影響開發流程、相依管理與升級規劃,並為考慮採用或升級到 Nav3 的開發者提供背景與評估重點,將 Nav3 的穩定視為一個明確的里程碑,有助於簡化使用 Compose 建構現代 Android 介面的工作。
Medium Kotlin
作者:Andres Sandoval
發布:12-03 01:42
Network Monitoring in Android
In today's mobile-first world, users expect apps to work seamlessly regardless of network conditions.
重點摘要
Users expect apps to work regardless of network conditions
WiFi drops and connectivity changes cause UX issues
Network monitoring is essential for resilient Android apps
In a mobile-first world users expect apps to continue working regardless of network conditions. The excerpt highlights that despite these expectations, real-world Wi‑Fi drops and fluctuating connectivity can break user experiences. That problem motivates the need for network monitoring in Android: developers should detect connectivity status, respond to changes, and design apps that remain responsive, synchronize data when possible, or degrade gracefully when offline. Effective monitoring supports decisions like retrying or queuing requests, presenting appropriate offline UI, and conserving battery and bandwidth. Overall, network monitoring is presented as an essential practice for building resilient mobile apps that maintain functionality and preserve user trust across variable network environments.
Android 中的网络监控
在以移动为先的时代,用户期待应用在各种网络条件下仍能顺畅运行。
重點摘要
用户期待应用在不同网络状况下顺畅运行
WiFi 中断和网络波动会影响使用体验
在 Android 上进行网络监控以提升应用稳定性
在以移动为先的时代,用户期待应用在各种网络条件下仍能顺畅运行。摘录指出,现实中的 Wi‑Fi 中断与网络波动会破坏使用体验,因此需要在 Android 中实施网络监控。开发者应检测连通性并应对变化,设计能在弱网或离线时仍保持响应、同步数据或优雅降级的应用。有效的网络监控有助于决定重试或排队请求、呈现离线界面以及节省电量和流量,从而在多变的网络环境中维护功能性与用户信任。
Android 中的網路監控
在以行動為先的時代,使用者期待應用在各種網路狀況下仍能順暢運作。
重點摘要
使用者期待應用在各種網路下順暢運作
WiFi 中斷與網路波動會破壞使用體驗
在 Android 中監控網路以維持應用韌性
在以行動為先的時代,使用者期待應用在各種網路狀況下仍能順暢運作。本文摘錄指出,實際上 Wi‑Fi 中斷或網路波動常導致使用體驗中斷,因此在 Android 中進行網路監控十分重要。開發人員需偵測連線狀態與變化,並據此處理重試、排程同步或採取離線回退策略,讓應用在離線或弱網時仍保持回應能力與資料一致性。良好的網路監控可協助節省資源並維護使用者信任,是打造穩健行動應用的關鍵作法。
Medium Kotlin
作者:Jimly Asshiddiqy
發布:12-03 03:36
Let's Make Modularization Fun Again
A lightweight, simple, and useful Gradle Plugin to boost your productivity!
重點摘要
Introduces a lightweight Gradle plugin for modularization
Emphasizes simplicity and productivity benefits
Invites readers to continue on Level Up Coding for details
This short piece introduces a lightweight, simple, and useful Gradle plugin intended to boost developer productivity by making modularization less cumbersome. The excerpt frames the plugin as a practical aid for projects that want to organize code into modules without added complexity, focusing on straightforward usage and time savings. While the preview does not provide in-depth technical details, it highlights the plugin's core intentions—simplicity, utility, and improved workflow—and suggests that the full article contains installation steps, examples, and guidance. Readers are encouraged to follow the link to Level Up Coding to see the complete write-up, try the plugin in their own builds, and learn how it can help streamline modular structure and repetitive configuration tasks in real projects.
让模块化再次变得有趣
一个轻量、简单且实用的 Gradle 插件,可提升你的生产力!
重點摘要
介绍一个轻量的 Gradle 插件以辅助模块化
强调简洁性与提高生产力的优势
邀请读者前往 Level Up Coding 阅读完整文章
本文简要介绍了一款轻量、简单且实用的 Gradle 插件,旨在让模块化工作更高效、降低繁琐度。摘录将该插件视为一个务实的工具,适合希望在不增加复杂性的前提下整理模块结构的项目使用,侧重于简洁性与节省时间的效果。预览并未展开深度技术细节,但点出插件的核心目标──简单、实用并改善工作流程,并鼓励读者访问 Level Up Coding 查看完整内容,包括安装说明、示例与使用指导,以便在实际项目中尝试、简化重复配置与模块维护。
讓模組化再次變得有趣
一個輕量、簡單且實用的 Gradle 外掛,可提升你的生產力!
重點摘要
介紹一個輕量的 Gradle 外掛以協助模組化
強調簡單性與提升生產力的好處
引導讀者至 Level Up Coding 閱讀完整內容
本文簡短介紹了一款輕量、簡單且實用的 Gradle 外掛,目的是讓模組化工作更省時、不那麼繁瑣。文中將這個外掛定位為實用工具,適合希望在不增加複雜度下整理模組結構的專案使用,重點放在提升工作流程與節省時間的效果。摘錄未提供完整技術細節,但說明了外掛的核心訴求──簡潔與實用,並建議讀者前往 Level Up Coding 查看完整文章,其中包含安裝說明、範例與應用指引,方便在實際專案中嘗試並簡化重複設定與模組邊界管理。
Medium Kotlin
作者:Sivavishnu
發布:12-03 04:08
Mastering UI State in Jetpack Compose: Sealed Interfaces vs. Data Classes
Choose exclusive sealed types for mutually exclusive UI states, and use data classes when state is composable and made of multiple independent properties.
重點摘要
Use sealed interfaces for mutually exclusive states.
Use data classes for composite, independently changing properties.
Picking the right model improves clarity and prevents invalid state combinations.
This article explains how to choose between exclusive state models (sealed interfaces) and composite state models (data classes) when designing UI state for Jetpack Compose. It recommends sealed types for mutually exclusive states — for example loading, success, and error — because they make control flow and rendering decisions explicit and prevent impossible combinations. By contrast, data classes are recommended when UI state is composable and consists of multiple independent properties (such as form fields, toggles, or visibility flags), allowing parts of the UI to update independently. The author emphasizes that selecting the appropriate representation improves code clarity, reduces bugs related to invalid state combinations, and aligns with Compose’s state-driven UI updates. The guidance is pragmatic: choose sealed for exclusivity, data for composability, and favor immutable, well-structured models to keep Compose UIs clean and predictable.
掌握 Jetpack Compose 的 UI 状态:Sealed 接口 vs. Data 类
状态互斥时选 sealed,状态由多个独立属性组成时选 data class,以保持清晰且可预测的 Compose 界面。
重點摘要
互斥状态使用 sealed 接口。
复合且可组合的状态使用 data class。
正确选择能提升可读性并避免无效状态组合。
本文介绍在 Jetpack Compose 中何时在封闭型别(sealed interfaces)與資料類別(data classes)之間做選擇。建議當狀態互斥(例如 loading、success、error)時使用 sealed,使渲染與流程判斷更明確並避免不可能的狀態組合;當狀態由多個獨立屬性構成(如表單欄位、開關或可見性標記)時,使用 data class 能讓各部分獨立更新。作者強調,根據狀態是否互斥或可組合來選擇模型,有助於提高程式可讀性、降低錯誤,並符合 Compose 的狀態驅動更新理念。
在 Jetpack Compose 中掌握 UI 狀態:Sealed 介面 vs. Data 類別
當狀態互斥時選 sealed,當狀態由多個獨立屬性組成時選 data class,以維持乾淨且可預期的 Compose UI。
重點摘要
互斥狀態採用 sealed 介面。
複合且可組合的狀態採用 data class。
正確選擇可提高可讀性並避免無效狀態錯誤。
本文說明在 Jetpack Compose 中,何時使用封閉型別(sealed interfaces)作為獨占狀態,何時用資料類別(data classes)表達可組合的複合狀態。作者建議:當狀態互斥(例如 loading、success、error)時,採用 sealed 可使渲染與流程判斷明確並避免不可能的組合;當狀態由多個獨立屬性構成(如表單欄位、開關、可見性旗標)時,data class 讓各部分獨立更新更合適。選對表示方式可提升程式可讀性、降低無效狀態錯誤,並與 Compose 的狀態驅動更新模式相容。
Medium Kotlin
作者:Sivavishnu
發布:12-03 04:38
Unlocking Ultra-Smooth UIs: Your Android 16 Performance Playbook
Master Adaptive Refresh Rate (ARR), RecyclerView 1.4, and Timeless Kotlin Hacks for 120 FPS Fluidity.
重點摘要
Master Adaptive Refresh Rate (ARR) to align refresh timing with content.
Leverage RecyclerView 1.4 improvements to optimize scrolling and view recycling.
Apply concise Kotlin techniques to reduce jank and maintain 120 FPS fluidity.
This article serves as a concise performance playbook for Android 16 developers aiming for ultra-smooth, 120 FPS user interfaces. It focuses on mastering Adaptive Refresh Rate (ARR) to align display refresh with content needs, leveraging RecyclerView 1.4 improvements to optimize scrolling and view recycling, and applying "timeless" Kotlin techniques to reduce jank and lower overhead. The author frames these topics as practical levers—architecture choices, API usage, and lightweight language patterns—that together help maintain consistent frame pacing on modern devices. Rather than exhaustive API references, the piece highlights high-impact areas where small changes yield noticeable fluidity gains, and aims to give engineers pragmatic guidance for diagnosing frame drops and implementing responsive UI behaviors on Android 16. It includes examples, trade-offs, and tips for prioritizing smoothness over feature complexity.
解锁极致流畅界面:你的 Android 16 性能攻略
掌握 Adaptive Refresh Rate(ARR)、RecyclerView 1.4 与实用的 Kotlin 技巧,实现 120 FPS 流畅度。
重點摘要
通过 ARR 动态调整刷新率以减少画面不稳定。
利用 RecyclerView 1.4 的改进优化滚动与视图复用。
采用精简的 Kotlin 技巧以降低卡顿并维持高帧率。
本文为希望在 Android 16 上实现极致流畅 120 FPS 界面的开发者提供实用的性能攻略。文章集中讨论掌握 Adaptive Refresh Rate(ARR)以动态匹配刷新频率、利用 RecyclerView 1.4 的改进来优化滚动与视图复用,以及采用简洁有效的 Kotlin 技巧来降低卡顿与开销。作者以务实的角度指出能显著提升流畅度的关键领域,并给出诊断掉帧与优化响应行为的建议,帮助开发者在现代设备上维持稳定的帧率与良好体验。
解鎖極致流暢介面:你的 Android 16 性能攻略
掌握 Adaptive Refresh Rate(ARR)、RecyclerView 1.4 與實用的 Kotlin 技巧,達成 120 FPS 的流暢體驗。
重點摘要
透過 ARR 動態調整刷新率以降低畫面不穩定。
利用 RecyclerView 1.4 的改進優化滾動與視圖重用。
採用簡潔 Kotlin 做法以減少卡頓並維持高幀率。
本文為想在 Android 16 上達成極致流暢 120 FPS 介面的工程師提供實用的性能攻略。重點在掌握 Adaptive Refresh Rate(ARR)以動態調整更新率、運用 RecyclerView 1.4 的改進優化滾動與重用,以及採用簡潔有效的 Kotlin 技巧降低卡頓與開銷。作者以可操作的重點與取捨為導向,指出能顯著提升畫面順暢度的高影響區域,並提供診斷掉幀與優化響應行為的實務建議,協助開發者在現代裝置上維持穩定的幀率與良好的使用體驗。