본문 바로가기

전체 글343

SOLID Principle of OOP Design SOLID principle is a recommendation for good object-oriented design. SRP (Single Responsibility Principle) OCP (Open-Closed Principle) LSP (Liskov Substitution Principle) ISP (Interface Segregation Principle) DIP (Dependency Inversion Principle) For a good design, decrease coupling among modules and increase the cohesion of code. SOLID principle helps it. SRP (Single Responsibility Principle) A .. 2021. 10. 24.
[Go] goroutine and channel A goroutine is a lightweight thread in Go. Goroutine We usually use goroutine in those cases. When one task can be split into different segments to perform better. When making multiple requests to different API endpoints. Any work that can utilize multi-core CPUs should be well optimized using goroutines Running background operations in a program might be a use case for a goroutine. We simply ad.. 2021. 10. 23.
[Go] Error Handling Error Type error type is an interface including Error() method. type error interface { Error() string } In other words, we can use any type that has Error() method as error type. defer A defer statement defers the execution of a function until the surrounding function returns. Therefore, we can use it for error handling. func test() { defer fmt.Println("Apple") fmt.Println("Banana") fmt.Println(.. 2021. 10. 22.
[Go] Map Map is a collection that accesses a value through a key. In addition, map is a mutable, duplicable, and unordered data structure. Map Declaration var numMap1 map[string]int = make(map[string]int) numMap1["one"] = 1 numMap1["two"] = 2 fmt.Println(numMap1) // map[one:1 two:2] numMap2 := make(map[int]string) numMap2[1] = "one" numMap2[2] = "two" fmt.Println(numMap2) // map[1:one 2:two In Array and .. 2021. 10. 21.
[Go] Linked List Go provide some useful data structure. Usage package main import ( "container/list" "fmt" ) func main() { v := list.New() testList1 := v.PushBack(1) testList2 := v.PushFront(2) v.InsertBefore(3, testList1) v.InsertAfter(4, testList2) for e := v.Front(); e != nil; e = e.Next() { fmt.Print(e.Value, " ") } fmt.Println() // 2 4 3 1 for e := v.Back(); e != nil; e = e.Prev() { fmt.Print(e.Value, " ") .. 2021. 10. 20.
[Go] Functions Go also has functions. A function is a group of codes that perform a single action. In such a way, a function increases the reusability of code. A function has its own scope. So the variables inside a function are only used in the function. Syntax func FUNCTION_NAME(PARAMETER_NAME PARAMETER_TYPE, ...) [RETURN_NAME] RETURN_TYPE { FUNCTION_BODY } Here are some examples. func sayHi() { fmt.Println(.. 2021. 10. 19.
[Python] Docstring Docstring is a powerful tool to document in Python. Docstring becomes a __doc__ property for the object. You can find the official Docstring Conventions in the below link. https://www.python.org/dev/peps/pep-0257/ Docstring Syntax Python recommends using """triple double quotes""" for Docstring. You can start with r for raw string and u for Unicode string. Docstring Specification One-line Docstr.. 2021. 10. 18.
[Go] Interface An interface is an abstract concept which enables polymorphism in Go. An interface type is defined as a set of method signatures. A value of interface type can hold any value that implements those methods. An interface increases decoupling so helps you write clean code. Interface Declaration An interface is declared as a type. type INTERFACE_NAME interface{ METHOD_PROTOTYPES } The zero value of .. 2021. 10. 17.
[Go] Method A Method is a kind of function. But a method belongs to the receiver. In contrast, function belongs nowhere. Therefore, a method increases the cohesion of code. Method Definition func (RECEIVER) METHOD_NAME() RETURN_TYPE { STATEMENTS } A receiver can be all local types, and local type is defined as type keyword within the package. If a receiver exists, it is a method, and if not, it is a functio.. 2021. 10. 17.