{"id":532,"date":"2022-08-29T22:00:51","date_gmt":"2022-08-29T22:00:51","guid":{"rendered":"https:\/\/melfaeforest.xhere.eu.org\/?p=532"},"modified":"2022-09-02T21:38:57","modified_gmt":"2022-09-02T21:38:57","slug":"learning-go-language-day-1","status":"publish","type":"post","link":"https:\/\/melfaeforest.xhere.eu.org\/?p=532","title":{"rendered":"Learning Go Language &#8211; Day 1"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">Key features of the Go language:\n- Simplicity\n- Strong and statically typed\n- Fast compile times\n- Garbage collected, AKA you do not need to manage your own memory\n- Built-in concurrency\n- Compile to standalone binaries\n- Used for servers and web-applications\n- Excellent community (golangbridge.org)<\/pre>\n\n\n\n<p><strong>Variable Declaration<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/\/\/ The 3 ways of declaring variables\n\n\/\/ #1: Blank declaration\nvar i int\ni = 42\n\n\/\/ #2: Compacted declaration\nvar i int = 42\n\n\/\/ #3: Shorthand declaration\ni := 42<\/pre>\n\n\n\n<p>NOTE: You cannot use the colon-equal syntax at the package level, you have to use the full syntax<\/p>\n\n\n\n<pre id=\"block-50f768bb-1294-409a-a2bf-8622443a43ee\" class=\"wp-block-preformatted\">\/\/ NOPE\nshowSeason := 20\n\n\/\/ YES\nvar showSeason int = 20\n\n\/*\nTIP: declare variables like how you would read it. \"You declare a variable named i with the type of integer\".\n*\/<\/pre>\n\n\n\n<p>If you have a bunch of variables of the same datatype at the package level, you can group them up in a block and declare them at once. This makes the code look cleaner.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ Dirty code without block declaration\nvar ygoName string = \"Xie\"\nvar deckName string = \"Manipulstring\"\nvar charAge string = \"???\"\n\n\/\/ Cleaner code with block declaration\nvar (\n  ygoName string = \"Xie\"\n  deckName string = \"Manipulstring\"\n  charAge string = \"???\"\n)<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-default\"\/>\n\n\n\n<p><strong>Variable Re-declaration &amp; Shadowing<\/strong><\/p>\n\n\n\n<p>You cant re-declare variables, but you can shadow them.<\/p>\n\n\n\n<p>You have to use variables you declared, otherwise you get yelled at.<\/p>\n\n\n\n<p><strong>Three Different Levels of Visibility:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1. Variables declared with a lowercase first-letter, which are visible to the package\n2. Variables declared that are capitalized, which is visible globally\n3. Variables declared inside blocks are block-scoped, and they can only be visible in that block of code\n\nNOTE: Use single-letters for the names of short-lived variables; longer names for long-lived variables (using camelCase).<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Type Conversion:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">- destinationType(variable)\n- Use strconv package for converting things to strings\n- You have to be explicit in your conversion. Go will not assume type conversion for the fear of losing valuable data<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>aeae<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Key features of the Go language: &#8211; Simplicity &#8211; Strong and statically typed &#8211; Fast compile times &#8211; Garbage collected, AKA you do not need to manage your own memory &#8211; Built-in concurrency &#8211; Compile to standalone binaries &#8211; Used for servers and web-applications &#8211; Excellent community (golangbridge.org) Variable Declaration \/\/\/\/ The 3 ways of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-532","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/melfaeforest.xhere.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/melfaeforest.xhere.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/melfaeforest.xhere.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/melfaeforest.xhere.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/melfaeforest.xhere.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=532"}],"version-history":[{"count":17,"href":"https:\/\/melfaeforest.xhere.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/532\/revisions"}],"predecessor-version":[{"id":626,"href":"https:\/\/melfaeforest.xhere.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/532\/revisions\/626"}],"wp:attachment":[{"href":"https:\/\/melfaeforest.xhere.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/melfaeforest.xhere.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/melfaeforest.xhere.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}