Skip to content

Commit

Permalink
Addressed reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
grgprarup committed Nov 3, 2023
1 parent ae40d16 commit f62335f
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/assets/JourneyWithGo-ABlogSeries/goFundamentals.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ episode: 3
**[गो](https://go.dev "Go in Nepali")** **"Journey With Go - A Blog Series"** about the basics of Go `Go Basic`,
advanced concepts in Go `Go Beyond Basics`, testing with go `Godog as Test Framework` and many more.

This is the third installment of the series. You are here which means you have already read the first and second blog of
This is the third installment of the series. You are here which means you have most likely read the first and second blog of
the series. If you haven't, please read them
first [Go Basics](https://blog.jankaritech.com/#/blog/Journey%20With%20Go%20-%20A%20Blog%20Series/Go%20Basics%20-%20The%20Starting%20Point "Go Basics"), [Control Statements](https://blog.jankaritech.com/#/blog/Journey%20With%20Go%20-%20A%20Blog%20Series/Control%20Statements%20-%20Control%20Your%20Go "Control Statements").

Expand Down Expand Up @@ -59,6 +59,8 @@ In Go, a string is a sequence of bytes (not characters) that is used to represen
means once created, their values cannot be changed. However, you can assign a new value to a string variable, which will
create a new string.

_Note: The rune is encoded with single quotes, whereas the string is encoded with double quotes._

```go
package main

Expand All @@ -83,6 +85,8 @@ func main() {
Slicing is a mechanism to extract a portion of a string. It is done by specifying the start and end indices of the part
of the string that you want to extract. The syntax for slicing a string is `string[start:end]`.

Taking the above `greeting` variable as example:

| slice | output | description |
|------------------|---------------|------------------------------------------------------------------------------------------------|
| `greeting[7:]` | World! | It gives the sub-string from index 7 to the end |
Expand Down Expand Up @@ -125,7 +129,7 @@ Index: 11, Value: d
Index: 12, Value: !
```

### **2.3. Rune Count Vs Len**
### **2.3. `len` Vs `RuneCountInString`**

The `len` function returns the number of bytes in a string, whereas the `utf8.RuneCountInString` function returns the number of runes in a string.

Expand Down Expand Up @@ -156,7 +160,7 @@ However, for the Thai language, the value returned by the `len` function is diff

## **3. Array**

In Go, an array is a fixed-length sequence of elements of a single type. Arrays are useful when you know the number of elements that you want to store in advance.
In Go, an array is a fixed-length sequence of elements of the same type. Arrays are useful when you know the number of elements that you want to store in advance.

### **3.1. Declaration of Array**

Expand Down Expand Up @@ -592,11 +596,6 @@ type Triangle struct {
func (t Triangle) area() float64 {
return 0.5 * t.base * t.height
}

func area() float64 {
t := Triangle{base: 10, height: 5}
return 0.5 * t.base * t.height
}
```

In the above example we have defined a method associated with a struct named `Triangle` by adding a receiver to the function definition. The receiver is the name of the struct that the method is associated with. The receiver is enclosed in parentheses before the method name.
Expand Down Expand Up @@ -761,7 +760,7 @@ func (r Rectangle) perimeter() float64 {
}

func main() {
triangle := Triangle{base: 10, height: 5}
var triangle Shape = Triangle{base: 10, height: 5}
fmt.Println(triangle) // {10 5}

area := triangle.area()
Expand All @@ -770,7 +769,7 @@ func main() {
perimeter := triangle.perimeter()
fmt.Println("Perimeter of triangle is " + fmt.Sprintf("%.2f", perimeter)) // 25

rectangle := Rectangle{length: 10, width: 5}
var rectangle Shape = Rectangle{length: 10, width: 5}
fmt.Println(rectangle) // {10 5}

area = rectangle.area()
Expand All @@ -793,19 +792,12 @@ Perimeter of rectangle is 30.00

## What we have learned so far

In this blog, we have learned how to declare, define, manipulate, and use the following terms in Go language:
- Rune and String
- Array
- Function and Method
- Struct and Interface

## Conclusion

In this blog, we have learned how to declare, define, manipulate, and use the following terms in Go language:
- rune and string
- array
- function and method
- struct and interface

In the next blog, we will learn about some advanced topics like Errors, Goroutines, and Channels in Go language.

*Keep learning and keep practicing*.
Expand Down

0 comments on commit f62335f

Please sign in to comment.