From 7788807d29b1c0c0303486dd99a2a76ec3f824d6 Mon Sep 17 00:00:00 2001 From: SonOfAnton Date: Mon, 30 Jan 2023 17:47:34 -0800 Subject: [PATCH 1/6] Adding guielines for writing platform agnostic code --- CONTRIBUTING.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 50fb803ba6568..377cd7db05999 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,6 +59,22 @@ During the collector release process, all `./.chloggen/*.yaml` files are transcr Alternately, copy `./.chloggen/TEMPLATE.yaml`, or just create your file from scratch. +## Platform Agnostic Code + +In order to ensure compatibility with different operating systems, it is advised to write a code that is platform-agnostic. Below are some guidelines to follow when writing platform-agnostic code: + +* Avoid using platform-specific libraries, features etc. Please opt for cross-platform solutions. + +* Avoid hard-coding platform specific values. Use environment variables or configuration files for storing platform specific values. + +* Be mindful of + - Standard file systems and file paths such as forward slashes (/) instead of backward slashes (\) in Windows. + - Consistent line ending formats such as Unix (LF) or Windows (CRLF). + +* Test your implementation thoroughly on different platforms 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 From b35e52ff29d100c41fec9fa50e58ecb4be49e416 Mon Sep 17 00:00:00 2001 From: SonOfAnton Date: Mon, 30 Jan 2023 18:11:10 -0800 Subject: [PATCH 2/6] Reformat opening sentence --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 377cd7db05999..2b6bbdd25994c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -61,7 +61,7 @@ Alternately, copy `./.chloggen/TEMPLATE.yaml`, or just create your file from scr ## Platform Agnostic Code -In order to ensure compatibility with different operating systems, it is advised to write a code that is platform-agnostic. Below are some guidelines to follow when writing platform-agnostic code: +In order to ensure compatibility with different operating systems, code should be platform-agnostic. Below are some guidelines to follow when writing platform-agnostic code: * Avoid using platform-specific libraries, features etc. Please opt for cross-platform solutions. From 48b863570e090e805f1f3f1244e56e5bcebce2b7 Mon Sep 17 00:00:00 2001 From: SonOfAnton Date: Tue, 31 Jan 2023 21:17:31 -0800 Subject: [PATCH 3/6] Review comments --- CONTRIBUTING.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2b6bbdd25994c..5187aff10803a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,16 +59,30 @@ During the collector release process, all `./.chloggen/*.yaml` files are transcr Alternately, copy `./.chloggen/TEMPLATE.yaml`, or just create your file from scratch. -## Platform Agnostic Code +## Portable Code -In order to ensure compatibility with different operating systems, code should be platform-agnostic. Below are some guidelines to follow when writing platform-agnostic 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 cross-platform solutions. +* 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. +* 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. + - Standard file systems and file paths such as forward slashes (/) instead of backward slashes (\) in Windows. Refer to [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 and fix any issues. From 0ac1400ce6e2757dc1b7c48a2925e17ec1ef6b9c Mon Sep 17 00:00:00 2001 From: SonOfAnton Date: Tue, 31 Jan 2023 21:19:17 -0800 Subject: [PATCH 4/6] Backslashes typo --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5187aff10803a..e063e3fc4496b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -82,7 +82,7 @@ In order to ensure compatibility with different operating systems, code should b ``` * Be mindful of - - Standard file systems and file paths such as forward slashes (/) instead of backward slashes (\) in Windows. Refer to [path/filepath package](https://pkg.go.dev/path/filepath) when working with filepaths. + - Standard file systems and file paths such as forward slashes (/) instead of backward slashes (\\) in Windows. Refer to [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 and fix any issues. From f7c5cd98c84fea2b4cf373f97886b60a46db50c8 Mon Sep 17 00:00:00 2001 From: SonOfAnton Date: Thu, 2 Feb 2023 00:02:04 -0800 Subject: [PATCH 5/6] Additional changes according to comments --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e063e3fc4496b..1ce4027cd9675 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -69,7 +69,7 @@ In order to ensure compatibility with different operating systems, code should b For example, avoid using hard-coded file path ``` - filePath := "C:/Users/Bob/Documents/sampleData.csv" + filePath := "C:\Users\Bob\Documents\sampleData.csv" ``` Instead environment variable or configuration file can be used. @@ -82,7 +82,7 @@ In order to ensure compatibility with different operating systems, code should b ``` * Be mindful of - - Standard file systems and file paths such as forward slashes (/) instead of backward slashes (\\) in Windows. Refer to [path/filepath package](https://pkg.go.dev/path/filepath) when working with filepaths. + - 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 and fix any issues. From 7c57b35377c6d8ea73f9c7c26889833c34448012 Mon Sep 17 00:00:00 2001 From: SonOfAnton Date: Thu, 2 Feb 2023 18:58:26 -0800 Subject: [PATCH 6/6] Best effort testing change --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1ce4027cd9675..cd112b7b8435b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -85,7 +85,7 @@ In order to ensure compatibility with different operating systems, code should b - 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 and fix any issues. +* 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.