Skip to content

Commit

Permalink
added tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
PradeepKavachSec committed Apr 9, 2024
1 parent c986c21 commit c43f859
Show file tree
Hide file tree
Showing 42 changed files with 1,925 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ layout: default

Gomotw is Golang Module Of The Week Codex

## Tutorials

- [Computing](./tutorials/1_Computing/1_Computing/README.html)
- [Programming](./tutorials/1_Computing/2_Programming/README.html)
- [Debugging](./tutorials/1_Computing/3_Debugging/README.html)
- [Procedural Programming](./tutorials/2_Procedural_Programming/1_Procedural_Programming/README.html)
- [Variables](./tutorials/2_Procedural_Programming/2_Variables/README.html)
- [Logical Operators](./tutorials/2_Procedural_Programming/3_Logical_Operators/README.html)



## Text Formatting

- [String Functions](./1_Strings/README.html)
Expand Down
81 changes: 81 additions & 0 deletions tutorials/1_Computing/1_Computing/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
layout: default
---

# Computing

At its broadest level, computing is defined as anything
that involves computers in some way, from designing the physical components that
make up a single device to designing massive systems like the Internet that use
computing principles.

### Programming Is Everywhere

No matter where in computing you end up going, you’ll likely be dealing with
programming in some way. Even if you’re not writing code yourself, you might be
designing programs for someone else to code, or designing the hardware which will
run code. Being able to program is like being able to speak a language. Just as you
need to speak Spanish to communicate in Spain, you need to speak “code” to com-
municate in computing.

# Programming Vocabulary

In order to talk about programming, there are some basic terms we need to know.

### Programs and Code

A **line of code** is generally a single command. Very often, we’ll talk in terms of
individual lines of code and what each line does. In practice, we’ll find a single line
could actually set off a sequence of lots of other commands, but generally a single
line of code is the smallest unit we’re interested in dealing with at this stage.

A **program**, for our purposes, is a collection of lines of code that serves one
or more overall functions. This could be anything from calculating the average of
some numbers to running a self-driving automobile. Programs are often what we’re
interested in building. A program is like a house and lines of code are like individual
bricks.

### Input and Output

Nearly every program we write is also largely defined by its relationship with its
input and its output. **Input** is anything that we put into a program for it to work
on, and output is what the program gives us in return. Usually we’re not going to
write programs that do the exact same thing every time they’re used—usually we’re
going to write programs that process input in some way, providing **output** that
corresponds to the input.

### Compiling and Executing

**Compiling** is like reading over code and looking for errors in the way we’ve
written it. It’s kind of like the proofreading you would do on an essay.
Code has more strict syntax than an essay, though, so we rely on other computer programs, called compilers, to do this for us. They read in the code
and let us know what problems they find.

**Executing** is then when the program is actually run. Just because some code
compiled into a program doesn’t mean it will actually do what we want it to do—it
just means that what we told it to do makes sense. For example, imagine we wrote a program that would add two numbers, but instead we accidentally put a subtraction
sign instead of an addition sign. The code still makes perfect sense during compila-
tion, it just does the wrong thing

## Programming Languages

In order to write an essay, you must have a language in which to write it. You could
write an essay in English, Japanese, Spanish, or Mandarin, but there must be a language. The same is true for programming: you must have a language in which to write. Just as different written languages have different syntax, different vocabular-
ies, different structures, so also do different programming languages have different syntax, different vocabulary, and different structures.

## Console vs. GUI

**Console**
An output medium for a program to show exclusively text-based output.

**Graphical User Interface**
An output medium that uses more than just text, like forms, buttons,tabs, and more. More programs are graphical user interfaces.

## Computing vs. Programming

**Programming** is indeed the foundation of computing. Learning to program is like learning to speak the language of the computer. However, learning to speak the language of the computer is only a small part of actual computing. **Computing** is about what you use that language to say. It’s oftentimes easy to focus too strongly on the programming and miss the underlying concepts and principles of computing as a whole.

### Code Segments

To demonstrate the Foundations and the Language and to apply them to the Domain, you’re going to see a lot of code segments.

8 changes: 8 additions & 0 deletions tutorials/1_Computing/2_Programming/1_hello_world.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// #1_hello_world.go
package main

import "fmt"

func main() {
fmt.Println("Hello World")
}
12 changes: 12 additions & 0 deletions tutorials/1_Computing/2_Programming/2_PrintingOtherValues.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 2_PrintingOtherValues.go
package main

import "fmt"

func main() {
fmt.Println("Hello World")
fmt.Println(5)
fmt.Println(5.1)
fmt.Println(true)
fmt.Println(false)
}
12 changes: 12 additions & 0 deletions tutorials/1_Computing/2_Programming/3_executing_code.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 3_ExecutingCode.go
package main

import "fmt"

func main() {
fmt.Println("This is Line1")
fmt.Println("This is Line2")
fmt.Println("This is Line3")
fmt.Println("This is Line4")
fmt.Prinln("This is Line5")
}
126 changes: 126 additions & 0 deletions tutorials/1_Computing/2_Programming/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
layout: default
---

# Programming

## What Is Programming?

Programming is the foundation of computing. Programming is effectively being
able to speak the computer’s language, to give it directions in a way that it under-
stands. Like any language, computers have vocabulary words and syntax that they
understand.

## Writing Code: Lines

the most basic atom of development is the line of code. Lines of code are individual commands to give to the computer. Chains of these lines form complex behaviors or instructions for the computer to carry out.

### Chaining Together Instructions

Imagine we are developing a program to print out the roster of students in this class.
One command would instruct the program to grab a student’s profile from some file
or database. Another would instruct the program to grab the student’s name from
that profile. Another would instruct the program to print that name. Another would
instruct the program to repeat those three commands for every student in the class.
By chaining these instructions together, the computer can print out the entire class
roster

### The Print Statement

the Println() command is the first fundamental thing to understand. This is how you print output for you to see while running.

### Work in Small Chunks

We want to develop programs in small chunks. You don’t write an entire essay from start to end without reading over the paragraphs as you write them. You likely wouldn’t paint a picture from start to finish without pausing to
get feedback. So also, we want to develop our programs in small chunks, testing
throughout to make sure we’re on the right track

## Writing Code: Lines in Go

### Your First Program: Hello, World

```
// #1_hello_world.go
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
```
you would get output like this if you run it
```
$ go run 1_hello_world.go
Hello World
```
### Printing Other Values

In addition to printing strings of characters like “Hello, world,” . Go also lets us
directly print a couple other things. First, we can print numbers like 5 or 5.1 directly
using the print statement without quotation marks. Second, we can also print what
are called “boolean” values.

```
// 2_PrintingOtherValues.go
package main
import "fmt"
func main() {
fmt.Println("Hello World")
fmt.Println(5)
fmt.Println(5.1)
fmt.Println(true)
fmt.Println(false)
}
```
if you run this go code you would get output like this
```
$ go run 2_PrintingOtherValues.go
Hello World
5
5.1
true
false
$
```
## Executing Code in Go

### Encountering Errors
Let’s try an example of this.Below are five lines of code. You might notice
that the fifth line has an error: I’ve misspelled the word “Println.”
```
// 3_ExecutingCode.go
package main
import "fmt"
func main() {
fmt.Println("This is Line1")
fmt.Println("This is Line2")
fmt.Println("This is Line3")
fmt.Println("This is Line4")
fmt.Prinln("This is Line5")
}
```
What happens when
I run this code? it prints the error message
```
$ go run 3_executing_code.go
# command-line-arguments
./3_executing_code.go:11:2: undefined: fmt.Prinln
$
```
### Compiling in Go

when we compile this code we get
```
$ go build 3_executing_code.go
# command-line-arguments
./3_executing_code.go:11:2: undefined: fmt.Prinln
$
```
54 changes: 54 additions & 0 deletions tutorials/1_Computing/3_Debugging/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
layout: default
---

# Debugging

Debugging is trying to find
why your code doesn’t behave the way you want it to. Maybe it’s generating some
errors. Maybe it’s not generating errors, but the output isn’t what you want it to be.
Either way, there’s a bug in the code: a bug is a mistake or problem that is causing
the code to fail at its goal. Debugging is the process of finding and removing those
bugs.

### Types of Error

- **Compilation Errors**
compilation errors are those that occur when compiling our code in the first
place. Not every language has compilation, and so, not every language has com-
pilation errors. Those languages that don’t require compilation, like Python and
JavaScript, can sometimes have tools that simulate this process, letting us know
before we execute our code if there are errors present within it.

Errors can differ significantly from language to language, but there are some
common ones. For compilation errors, some things you might often encounter are:
_Syntax errors_. You’ve written code that just doesn’t make sense in the current
programming language. This is akin to a grammatical error in an essay.
_Name errors_. You’ve written code that tries to use something that doesn’t exist.
Imagine, for example, I asked you, “Give her the book,” but never specified who
“her” is. The command doesn’t make sense because I’m including a person that
doesn’t exist.
_Type errors_. You’ve written code that tries to do something that doesn’t make
sense, like requesting the smell of True or the color of the number 5.

- **Runtime Errors**
Runtime errors are errors that we encounter only when actually running the code.
Languages that don’t have compilation will only have runtime errors, and even
languages that do require compilation can have runtime errors because we can’t
anticipate every error just by looking at the code.

Runtime errors most often occur because of something specific to the results
that code generates when it runs. Some of the common runtime errors you will
encounter are:
_Divide by zero errors_. Your code contains a number being divided by another,
but when those numbers actually have values, it turns out you’re trying to divide
by zero!
_Null errors_. Null errors are like name errors: you’re referring to something that
doesn’t exist. Here, though, the variable would exist, but it wouldn’t have any
value. Imagine your code said, “Grab the twelfth book on the shelf,” but the
shelf only has six books. The request makes sense in the directions until you
see the shelf: then you realize you’re trying to use something that doesn’t exist,
but you only “see” that at runtime.
_Memory errors_. Your computer can only remember a certain amount of stuff at
a time. If you try to require it to remember more than that, you’ll hit a memory
error.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 10_code_block_comments.go
package main

import "fmt"

//Count function
//Prints the number from 1 to i
//On a single line
func countdown(i int) {
for j := 1; j < i+1; j++ {
fmt.Printf("%d ", j)
}
fmt.Println()
}

func main() {
countdown(10)
countdown(5)
countdown(2)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import "fmt"

func main() {
numberOfTimesToPrint := 5
for i := 0; i < numberOfTimesToPrint; i++ {
fmt.Println("Hello World")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 1_hello_world.go
package main

import "fmt"

func main() {
fmt.Println("Hello world")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 2_hello_world_2.go
package main

import "fmt"

func main() {
fmt.Println("Hello world")
fmt.Println("Hello world")
fmt.Println("Hello world")
fmt.Println("Hello world")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 3_datatypes_and_variables.go
package main

import (
"fmt"
"time"
)

func main() {
fmt.Println(5)
fmt.Println(5.1)
fmt.Println(time.Now())
}
Loading

0 comments on commit c43f859

Please sign in to comment.