基础篇 | Kotlin 学习笔记-编码规范(一)

“Willpower is for people who are still uncertain about what they want to do.” — Helia

Kotlin 官方文档

推荐几篇 Medium 上关于 Kotlin 的文章,可以让你更加的坚信,学习Kotlin 是没错滴。

需科学上网

Why you should totally switch to Kotlin

A Complete Guide To Learn Kotlin For Android Development

Why Kotlin is my next programming language

How we made Basecamp 3’s Android app 100% Kotlin

编码规范 - Coding Conventions

官方文档

命名风格 - Naming Style

部分命名规范与 Java 类似,不确定的时候可以默认使用 Java 的编码规范 ,e.g.

— 使用驼峰法命名(并避免命名含有下划线)

use of camelCase for names (and avoid underscore in names)

e.g. studentName ; onlineHomeWork

— 类型名以大写字母开头

types start with upper case

e.g. Student ; Question

— 方法和属性以小写字母开头

methods and properties start with lower case

1
2
3
//fun 是函数方法的关键字
fun getOnlineHomework(id: Long, token: String){
}

— 使用 4 个空格缩进

use 4 space indentation

— 公有函数应撰写函数文档,这样这些文档才会出现在 Kotlin Doc 中

public functions should have documentation such that it appears in Kotlin Doc