Skip to content

Instantly share code, notes, and snippets.

@PeterRK
PeterRK / package level generics.md
Last active Oct 16, 2018
package level generics
View package level generics.md

Package level generics may look less confusing.

package abc(Key,Value)

contract CompileCheck(a1 Key, a2 Value) {
	//...
}

type Pair struct {
	K Key
@PeterRK
PeterRK / Simple Error Handling for Go 2.md
Last active Dec 8, 2020
Simple Error Handling for Go 2
View Simple Error Handling for Go 2.md

Key Parts of Error Handling

val, err := function()
if err != nil {
	//handler codes...
}

Error handling consists of 3 key parts, trigger, handler and binding rule. In Go 1, trigger is if err != nil, handler is a piece of code in {}, and binding rule is obvious. Handler holds the control flow switch.

Actually, I donot think error handling in Go 1 has any functional problem. The only problem is repetition, especially repetition of triggers. Go 1 allows us to place trigger and assignment in one line, but that does not really solve the problem.