From cb8df8f89953a8649f321563aa7bf3cf134d5072 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Tue, 14 Nov 2023 17:50:52 +0100 Subject: [PATCH] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- docs/effective-gno.md | 169 ---------------------------- docs/how-to-guides/effective-gno.md | 25 ++++ misc/docusaurus/sidebars.js | 1 + 3 files changed, 26 insertions(+), 169 deletions(-) delete mode 100644 docs/effective-gno.md create mode 100644 docs/how-to-guides/effective-gno.md diff --git a/docs/effective-gno.md b/docs/effective-gno.md deleted file mode 100644 index 4b83e8dcc4e..00000000000 --- a/docs/effective-gno.md +++ /dev/null @@ -1,169 +0,0 @@ -# Effective Gno - -This document provides advice and guidelines for writing effective Gno code. - -## Formatting - -### Indentation - -Use 4 spaces for each level of indentation. Avoid using tabs. - -```gno -func main() { - fmt.Println("Hello, World!") -} -``` - -### Braces - -The opening brace should be on the same line as the function declaration. - -```gno -func hello() { - // code here -} -``` - -## Comments - -### Inline Comments - -Use `//` for inline comments. - -```gno -var a = 1 // This is an inline comment -``` - -### Block Comments - -For longer descriptions, use `/* ... */`. - -```gno -/* -This is a longer comment that -spans multiple lines. -*/ -``` - -## Variables - -### Declaration - -Declare variables using the `var` keyword. - -```gno -var x int = 10 -``` - -You can also declare multiple variables at once: - -```gno -var ( - a = 1 - b = 2 -) -``` - -### Naming - -Use camelCase for variable names. - -```gno -var myVariable = "hello" -``` - -## Functions - -### Declaration - -Declare functions using the `func` keyword. - -```gno -func myFunction() { - // code here -} -``` - -### Parameters - -Function parameters should be declared in the function signature. - -```gno -func add(a int, b int) int { - return a + b -} -``` - -### Return Values - -Functions can return multiple values. - -```gno -func divmod(a int, b int) (int, int) { - return a / b, a % b -} -``` - -### Error Handling - -Use errors for exception handling. - -```gno -func doSomething() error { - // if something goes wrong - return errors.New("Something went wrong") -} -``` - -## Control Structures - -### If Statements - -If statements do not need parentheses around the condition. - -```gno -if condition { - // code here -} -``` - -### For Loops - -Gno uses the `for` keyword for loops. - -```gno -for i := 0; i < 10; i++ { - // code here -} -``` - -For each loops are also supported. - -```gno -for index, value := range array { - // code here -} -``` - -## Structs - -Structs are used to group related data together. - -```gno -type Person struct { - Name string - Age int -} -``` - -## Interfaces - -Interfaces are defined using the `interface` keyword. - -```gno -type Reader interface { - Read(p []byte) (n int, err error) -} -``` - -Remember, the key to effective Gno programming is practice. Write code, read code, and don't be afraid to ask for help. Happy coding! diff --git a/docs/how-to-guides/effective-gno.md b/docs/how-to-guides/effective-gno.md new file mode 100644 index 00000000000..dcc88764dcf --- /dev/null +++ b/docs/how-to-guides/effective-gno.md @@ -0,0 +1,25 @@ +--- +id: effective-gno +--- + +# Effective Gno + +This document provides advice and guidelines for writing effective Gno code. + +First, Gno shares many similarities with Go. Therefore, please read ["Effective Go"](https://go.dev/doc/effective_go) first. + +## Where effective Gno is not like Go + +... + +## Good Gno Patterns + +... + +## Bad Gno Patterns + +... + +## General Mantra + +... diff --git a/misc/docusaurus/sidebars.js b/misc/docusaurus/sidebars.js index 265bfb49f9c..3b50c1ab79e 100644 --- a/misc/docusaurus/sidebars.js +++ b/misc/docusaurus/sidebars.js @@ -26,6 +26,7 @@ const sidebars = { type: 'category', label: 'How-to Guides', items: [ + 'how-to-guides/effective-gno', 'how-to-guides/simple-contract', 'how-to-guides/simple-library', 'how-to-guides/testing-gno',