Skip to content

Commit

Permalink
Adding guidelines for writing platform agnostic code (#18188)
Browse files Browse the repository at this point in the history
* Adding guielines for writing platform agnostic code

* Reformat opening sentence

* Review comments

* Backslashes typo

* Additional changes according to comments

* Best effort testing change
  • Loading branch information
swapnilashtekar authored Feb 14, 2023
1 parent 4747138 commit 4e57f9c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@ During the collector release process, all `./.chloggen/*.yaml` files are transcr

Alternately, copy `./.chloggen/TEMPLATE.yaml`, or just create your file from scratch.

## Portable Code

In order to ensure compatibility with different operating systems, code should be portable. Below are some guidelines to follow when writing portable code:

* Avoid using platform-specific libraries, features etc. Please opt for portable multi-platform solutions.

* Avoid hard-coding platform-specific values. Use environment variables or configuration files for storing platform-specific values.

For example, avoid using hard-coded file path
```
filePath := "C:\Users\Bob\Documents\sampleData.csv"
```

Instead environment variable or configuration file can be used.
```
filePath := os.Getenv("DATA_FILE_PATH")
```
or
```
filePath := Configuration.Get("data_file_path")
```

* Be mindful of
- Standard file systems and file paths such as forward slashes (/) instead of backward slashes (\\) in Windows. Use the [`path/filepath` package](https://pkg.go.dev/path/filepath) when working with filepaths.
- Consistent line ending formats such as Unix (LF) or Windows (CRLF).

* Test your implementation thoroughly on different platforms if possible and fix any issues.

With above guidelines, you can write code that is more portable and easier to maintain across different platforms.

## Adding New Components

**Before** any code is written, [open an
Expand Down

0 comments on commit 4e57f9c

Please sign in to comment.