# Functional Programming in Go ![rw-book-cover](https://blog.logrocket.com/wp-content/uploads/2020/02/functional-programming-in-go.png) ## Metadata - Author: [[LogRocket Blog]] - Full Title: Functional Programming in Go - Category: #articles - Document Tags: [[dev]] [[dev/design-patterns]] - URL: https://blog.logrocket.com/functional-programming-in-go/ - Archive: https://web-archive.alecodes.page/bookmarks?bf=1&search=&title=Functional%20Programming%20in%20Go > [!tldr] > Functional programming in Go improves code readability and testing by using pure functions that avoid shared state and side effects. Key concepts include pure functions, function composition, and immutable data, which help isolate functions and simplify debugging. Although Go isn't primarily designed for functional programming, embracing its principles can enhance code quality. ## Highlights Functional programming is the process of building software by composing pure functions, avoiding shared state, mutable data, and side-effects. Functional programming is declarative rather than imperative, and application state flows through pure functions. Contrast with object-oriented programming, where application state is usually shared and colocated with methods in objects. [View Highlight](https://read.readwise.io/read/01jabdy8qw3m23ajpv5za0fjzw)) A pure function always returns the same output if you give it the same input. This property is also referenced as idempotence. Idempotence means that a function should always return the same output, independent of the number of calls. [View Highlight](https://read.readwise.io/read/01jabdzwffdbxj7ytv2a0j3qa5)) A pure function can’t have any side effects. In other words, your function cannot interact with external environments. [View Highlight](https://read.readwise.io/read/01jabe0bb4tdcvj81vw8j4138c)) The basic idea of function composition is straightforward: you combine two pure functions to create a new function. This means the concept of producing the same output for the same input still applies here. Therefore, it’s important to create more advanced functionality starting with simple, pure functions. [View Highlight](https://read.readwise.io/read/01jabe21zz515334qxqr6yt50z)) The goal of functional programming is to make the state visible and explicit to eliminate any side effects. A program uses immutable data structures to derive new data from using pure functions. [View Highlight](https://read.readwise.io/read/01jabe3pmzrd7kw27340367da6)) to follow the functional programming paradigm as closely as possible, I suggest sticking to the following guidelines. • No mutable data to avoid side effects • No state (or implicit state, such as a loop counter) • Do not modify variables once they are assigned a value • Avoid side effects, such as an API call [View Highlight](https://read.readwise.io/read/01jabe5qev8y668kb3z1f9qtf9))