GOLang basic syntax

A typical hello world program

Well if you’re not new to programming, the code is almost self explanatory. But for others I’m going to explain this abstractly.

I said abstract because I don’t want to explain what are functions and packages this early.

So what is that above code? For starters, this code will print hello world in console.

One thing that I always like to do is just play around the code. Even try to break your own code. Because it always teach you something new.

Get excited whenever you get an error. Because it always teach you something new.

-ME (before getting fired from my job. lol)

First try to change “hello world part” in line 6.

See? now you have the power to print anything into the console with GO.(without even learning GO).

Wonderful. But if you’re really unlucky. You might do something that I did.

But rather than getting afraid. Think logically. I don’t want you to solve this error. But Just see what happened wrong here.

Take a minute to think about it.

Got anything?

Well if you tried few other examples, you might have realized whatever you type between "" gets printed. But in this example, He said, "hi" already contain a "

So Go thought that maybe I should print “He said, “, because for go " is the end to the string. But after that it saw something like hi"." which even I don’ty know the meaning of.

So obviously GO don’t know either. lol.

So the main takeaway here is

Go can do anything. But not on its own. You have to be super clear about what you want it to do.

Just as what we have “GRAMMAR” for english. we have “SYNTAX” for programming languages.


wait! how can I make the above code work?

well copy-paste the following code

package main

import "fmt"

func main() {
	fmt.Println("He said, \"hi\".")

Obviously, I wont tell you why this works. This might even looks cryptic to you. But believe everything in this code will make sense within the upcoming few articles.

About the author


Add comment

Leave a Reply

By vigneshwar

Most common tags

%d bloggers like this: