# Arts Week 18 | leetcode 384 scrambling array | 12 elements of application development

Time：2021-6-4

## ARTS

Arts is an activity launched by Chen Hao in the geek time column. The purpose is to keep learning through sharing.

Each person writes an arts every week: algorithm is an algorithm problem, review is to read an English article, technology / tips is to share a small technology, share is to share a viewpoint.

### Content of this week

This week’s arts you’ll see:

1. An interview question that is not suitable for an interview
2. 12 elements of application service development12-Factor.
3. (question) what is the purpose of k8s related development?

### Algorithm

This week’s algorithm problem isLeetCode 384 Shuffle An ArrayScramble the array

See the specific explanationhereThis problem is to investigate the realization of shuffle algorithm, but more importantly, it can prove the correctness of the algorithm. The above two problems are explained in great detail

``````type Solution struct {

original []int

}

func Constructor(nums []int) Solution {

return Solution{original: nums}

}

/** Resets the array to its original configuration and return it. */

func (this *Solution) Reset() []int {

return this.original

}

/** Returns a random shuffling of the array. */

func (this *Solution) Shuffle() []int {

l := len(this.original)

ret := make([]int, l)

copy(ret, this.original)

//Shuffle algorithm

for i := l - 1; i >= 0; i-- {

//Generating random numbers in the range of [0, I]

r := rand.Intn(i + 1)

ret[i], ret[r] = ret[r], ret[i]

}

return ret

}``````

I don’t think this question is suitable for interview because I don’t think it’s a common algorithm or a general idea

### Review article recommendation

What is the recommended English article for this week12-Factor.

This is an article that introduces the key elements of software development and delivery process. As the title says, the author thinks that a good application should follow 12 features

PS: the app in this paper refers to a service or a process. If it corresponds to a distributed system, it is one of the services in the whole system

Here are the so-called “12 elements”:

1. Each application uses its own code repository (repo)
2. The code dependency of each application should be specifiedExplicit declarationAnd the dependence of different applications should be differentIsolated from each other.
3. Save the configuration in the runtime rather than in the code

Interestingly, the author lists a test standard: even if the project is completely open source, it will not cause information leakage

1. Manage the application’s backing service as a resource

Similar to the idea of policy mode, the application can replace the MySQL service it relies on with other similar services, such as Amazon RDS, without modifying any code except for configuration changes

1. Use build, release and run to strictly distinguish different stages of application

Build compiles code to the specified running environment, including the specified code version and dependent version

Release refers to the combination of build output and configuration files, which can run directly in the target environment

Run is to select the output version of a release phase and run it

1. Every application should be a stateless process

Any data that needs to be saved (so called state) should be stored by the dependent service in 4

1. Provide services through port binding
2. Depending on the process model to achieve service expansion (scaling)
3. Use quick start and graceful close to maximize robustness
4. The development environment, pre release environment and online environment should be consistent as far as possible

The specific measures are to use integration tools to reduce release time, and to use Devops to avoid cognitive differences in development and operation

1. Think of the log as an event stream
2. Run the background management task as a one-time process

Background management task is a kind of non business logic, which is similar to database migration

### Tip programming skills

This week’s programming has no skill

### Share flash

This week, I chatted with several friends who are engaged in or want to engage in k8s related development

I have always thought that I am a solution engineer in this field, and I still have a rational understanding of the work related to k8s development. Because the first reason given by these people for why to do k8s is: “because k8s is the future.”