- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 144字
- 2021-06-24 19:15:29
Low coupling
The code dependency between threads is referred to as coupling. We should try to keep coupling as low as possible, to avoid complexity and make the code base easy to read and maintain. Now, what does that actually mean? Refer to the program with threading where we accessed and modified the someData value from two threads simultaneously. That can be called coupling, as both the threads were dependent on each other. For your reference, we copied the following code-snippet:
async(CommonPool) { for(i in 11..20) { myData.someData+=i println("someData from 1st async ${myData.someData}") delay(500) } } async(CommonPool) { for(i in 1..10) { myData.someData++ println("someData from 2nd async ${myData.someData}") delay(300) } }
In the next program, where we introduced immutability, the coupling is reduced. Here, both the threads were reading the same element, but one thread's operations and changes didn't affect the other one.
推薦閱讀
- JavaScript從入門到精通(微視頻精編版)
- 軟件項目管理(第2版)
- 動手玩轉Scratch3.0編程:人工智能科創教育指南
- Raspberry Pi for Secret Agents(Third Edition)
- 編譯系統透視:圖解編譯原理
- Mastering openFrameworks:Creative Coding Demystified
- R語言數據可視化:科技圖表繪制
- Python青少年趣味編程
- 零基礎輕松學C++:青少年趣味編程(全彩版)
- NGUI for Unity
- SSH框架企業級應用實戰
- Scrapy網絡爬蟲實戰
- 數字媒體技術概論
- 算法訓練營:海量圖解+競賽刷題(入門篇)
- HTML5 Game Development by Example:Beginner's Guide(Second Edition)