Skip to content

Latest commit

 

History

History
123 lines (82 loc) · 1.9 KB

CONTRIBUTING.md

File metadata and controls

123 lines (82 loc) · 1.9 KB

Welcome to husi contributing guide

Welcome and thank you for contributing! 🎉

Overview

Readable > Useful > High performance but poorly readable

Coding detail

Common

  • All comments use English.

  • Reduce Confusing abbreviations.

Bad

dl := &net.Dialer{}

Good

dialer := &net.Dialer{}
  • If a comment is meaningless, it is meaningless like this sentence, which is redundant.

  • Readable code from naming, not comments.

  • Use constant as much as possible.

Bad

import (
    "net"

    N "github.com/sagernet/sing/common/network"
)

func defaultDNS() (net.Conn, error) {
    return net.Dial(N.NetworkUDP, "8.8.8.8:53") // Google DNS
}

Good

import (
    "net"

    N "github.com/sagernet/sing/common/network"
)


func defaultDNS() (net.Conn, error) {
    const googleDNS = "8.8.8.8:53"
    return net.Dial(N.NetworkUDP, googleDNS)
}

Our style use name to tell reader what's this mean.

Go

  • Use make fmt_go and make test_go before committing.

  • Create unit test as much as possible.

  • Make writing documentions a habbit.

Java / Kotlin

  • Reduce forEach.

Bad

val numberList = listOf(1, 2, 3)
numberList.forEach(::println)

Good

val numberList = listOf(1, 2, 3)
for (number in numberList) {
    println(number)
}
  • also sometimes better than apply.

Bad

lateinit var textView: TextView
val isVisible = true

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    textView = findViewByID(R.id.textView).apply {
        this@apply.isVisible = isVisible
    }
}

Good

lateinit var textView: TextView
val isVisible = true

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    textView = findViewByID(R.id.textView).also {
        it.isVisible = isVisible
    }
}