November 2018
Intermediate to advanced
346 pages
8h 12m
English
As programmers, we should always strive to keep things simple, and resort to complexity when there is no other way. Let's see this principle in action. Try to determine what this next example does in three seconds or less:
func NotSoSimple(ID int64, name string, age int, registered bool) string { out := &bytes.Buffer{} out.WriteString(strconv.FormatInt(ID, 10)) out.WriteString("-") out.WriteString(strings.Replace(name, " ", "_", -1)) out.WriteString("-") out.WriteString(strconv.Itoa(age)) out.WriteString("-") out.WriteString(strconv.FormatBool(registered)) return out.String()}
How about this one:
func Simpler(ID int64, name string, age int, registered bool) string { nameWithNoSpaces ...Read now
Unlock full access