Skip to content

Commit b55ccc5

Browse files
committed
a
1 parent 26809c2 commit b55ccc5

File tree

7 files changed

+433
-64
lines changed

7 files changed

+433
-64
lines changed

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
title: Ari's page
2-
description: C coder learing golang
2+
description: C coder learing golang. C C++ python to golang.
33
show_downloads: true
44
google_analytics:
55
theme: jekyll-theme-time-machine

_site/404.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
<script type="text/javascript" src="/assets/js/script.js"></script>
1212

1313
<!-- Begin Jekyll SEO tag v2.4.0 -->
14-
<title>Ari’s page | C coder learing golang</title>
14+
<title>Ari’s page | C coder learing golang. C C++ python to golang.</title>
1515
<meta name="generator" content="Jekyll v3.7.2" />
1616
<meta property="og:title" content="Ari’s page" />
1717
<meta property="og:locale" content="en_US" />
18-
<meta name="description" content="C coder learing golang" />
19-
<meta property="og:description" content="C coder learing golang" />
18+
<meta name="description" content="C coder learing golang. C C++ python to golang." />
19+
<meta property="og:description" content="C coder learing golang. C C++ python to golang." />
2020
<link rel="canonical" href="http://localhost:4000/404.html" />
2121
<meta property="og:url" content="http://localhost:4000/404.html" />
2222
<meta property="og:site_name" content="Ari’s page" />
2323
<script type="application/ld+json">
24-
{"url":"http://localhost:4000/404.html","description":"C coder learing golang","@type":"WebPage","headline":"Ari’s page","@context":"http://schema.org"}</script>
24+
{"url":"http://localhost:4000/404.html","description":"C coder learing golang. C C++ python to golang.","@type":"WebPage","headline":"Ari’s page","@context":"http://schema.org"}</script>
2525
<!-- End Jekyll SEO tag -->
2626

27-
<meta name="description" content="C coder learing golang">
27+
<meta name="description" content="C coder learing golang. C C++ python to golang.">
2828

2929
<meta name="viewport" content="width=device-width,initial-scale=1">
3030

@@ -37,7 +37,7 @@
3737
<h1 class="title">Ari's page</h1>
3838
</header>
3939
<div id="container">
40-
<p class="tagline">C coder learing golang</p>
40+
<p class="tagline">C coder learing golang. C C++ python to golang.</p>
4141
<div id="main" role="main">
4242
<div class="download-bar">
4343
<div class="inner">

_site/another-page.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
<script type="text/javascript" src="/assets/js/script.js"></script>
1212

1313
<!-- Begin Jekyll SEO tag v2.4.0 -->
14-
<title>Ari’s page | C coder learing golang</title>
14+
<title>Ari’s page | C coder learing golang. C C++ python to golang.</title>
1515
<meta name="generator" content="Jekyll v3.7.2" />
1616
<meta property="og:title" content="Ari’s page" />
1717
<meta property="og:locale" content="en_US" />
18-
<meta name="description" content="C coder learing golang" />
19-
<meta property="og:description" content="C coder learing golang" />
18+
<meta name="description" content="C coder learing golang. C C++ python to golang." />
19+
<meta property="og:description" content="C coder learing golang. C C++ python to golang." />
2020
<link rel="canonical" href="http://localhost:4000/another-page.html" />
2121
<meta property="og:url" content="http://localhost:4000/another-page.html" />
2222
<meta property="og:site_name" content="Ari’s page" />
2323
<script type="application/ld+json">
24-
{"url":"http://localhost:4000/another-page.html","description":"C coder learing golang","@type":"WebPage","headline":"Ari’s page","@context":"http://schema.org"}</script>
24+
{"url":"http://localhost:4000/another-page.html","description":"C coder learing golang. C C++ python to golang.","@type":"WebPage","headline":"Ari’s page","@context":"http://schema.org"}</script>
2525
<!-- End Jekyll SEO tag -->
2626

27-
<meta name="description" content="C coder learing golang">
27+
<meta name="description" content="C coder learing golang. C C++ python to golang.">
2828

2929
<meta name="viewport" content="width=device-width,initial-scale=1">
3030

@@ -37,7 +37,7 @@
3737
<h1 class="title">Ari's page</h1>
3838
</header>
3939
<div id="container">
40-
<p class="tagline">C coder learing golang</p>
40+
<p class="tagline">C coder learing golang. C C++ python to golang.</p>
4141
<div id="main" role="main">
4242
<div class="download-bar">
4343
<div class="inner">

_site/index.html

Lines changed: 136 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
<script type="text/javascript" src="/assets/js/script.js"></script>
1212

1313
<!-- Begin Jekyll SEO tag v2.4.0 -->
14-
<title>Ari’s page | C coder learing golang</title>
14+
<title>Ari’s page | C coder learing golang. C C++ python to golang.</title>
1515
<meta name="generator" content="Jekyll v3.7.2" />
1616
<meta property="og:title" content="Ari’s page" />
1717
<meta property="og:locale" content="en_US" />
18-
<meta name="description" content="C coder learing golang" />
19-
<meta property="og:description" content="C coder learing golang" />
18+
<meta name="description" content="C coder learing golang. C C++ python to golang." />
19+
<meta property="og:description" content="C coder learing golang. C C++ python to golang." />
2020
<link rel="canonical" href="http://localhost:4000/" />
2121
<meta property="og:url" content="http://localhost:4000/" />
2222
<meta property="og:site_name" content="Ari’s page" />
2323
<script type="application/ld+json">
24-
{"url":"http://localhost:4000/","description":"C coder learing golang","name":"Ari’s page","@type":"WebSite","headline":"Ari’s page","@context":"http://schema.org"}</script>
24+
{"url":"http://localhost:4000/","description":"C coder learing golang. C C++ python to golang.","name":"Ari’s page","@type":"WebSite","headline":"Ari’s page","@context":"http://schema.org"}</script>
2525
<!-- End Jekyll SEO tag -->
2626

27-
<meta name="description" content="C coder learing golang">
27+
<meta name="description" content="C coder learing golang. C C++ python to golang.">
2828

2929
<meta name="viewport" content="width=device-width,initial-scale=1">
3030

@@ -37,7 +37,7 @@
3737
<h1 class="title">Ari's page</h1>
3838
</header>
3939
<div id="container">
40-
<p class="tagline">C coder learing golang</p>
40+
<p class="tagline">C coder learing golang. C C++ python to golang.</p>
4141
<div id="main" role="main">
4242
<div class="download-bar">
4343
<div class="inner">
@@ -66,7 +66,19 @@ <h1 class="title">Ari's page</h1>
6666

6767
<p>Of course I made some assosations in my mind with C/C++/python. I know golang tutorials let you know that you should not make such assumptions.. but you will anyway.</p>
6868

69-
<p>So here is what I learned this far.</p>
69+
<p>So here is what I learned this far :</p>
70+
71+
<h1 id="-standalone-binaryexecutable"><a href="#header-1"></a> standalone binary/executable</h1>
72+
73+
<p>The thing why I really like golang (so far) is that it makes standalone executable.</p>
74+
75+
<p>Of course this means that everything is staticly linked to the executable/binary and the size grows compared e.g C.. but compared to benefit of having executable standalone, I could not care less.</p>
76+
77+
<p>No different path settings/exports/registry entries, install programs etc.. just run or compile+run the binary ;)</p>
78+
79+
<p>have you ever seen python or ruby script to fail due imported library incombability ;)</p>
80+
81+
<p>And so far what I have tried, the same code compiles to windows and runs the same way.. standalone. (You can even copile it at linux for windows).</p>
7082

7183
<h1 id="-first-look"><a href="#header-1"></a> first look</h1>
7284
<p>e.g edited https://tour.golang.org/basics/4</p>
@@ -82,15 +94,47 @@ <h1 id="-first-look"><a href="#header-1"></a> first look</h1>
8294
</span><span class="n">fmt</span><span class="o">.</span><span class="n">Println</span><span class="p">(</span><span class="n">add</span><span class="p">(</span><span class="m">42</span><span class="p">,</span><span class="x"> </span><span class="m">13</span><span class="p">))</span><span class="x">
8395
</span><span class="p">}</span><span class="x">
8496
</span></code></pre></div></div>
85-
<p>nothing too complicated.. they(=golang developers) just switched variable first and type after that.
86-
Fixed type if initialized… fine.
87-
Return value is at the end of function defination.. makes sence.
88-
You need brackes if you have more than one return value (btw really nice feature).</p>
97+
<p>nothing too complicated.. they(=golang developers) just switched variable first and type after that.</p>
98+
99+
<p>variable type fixed to the type of initialized… fine.
100+
Return value is at the end of function defination.. makes sence.</p>
101+
102+
<p>You need brackes if you have more than one return value (btw really nice feature).</p>
103+
104+
<p>I think it is stated somewhere but I missed first that if function name starts with CAPITAL e.f Foo() it is public when in package.</p>
105+
106+
<h1 id="-funtions"><a href="#header-1"></a> funtions</h1>
107+
108+
<p>Basic function is simple as above.
109+
But then there is sometimes stuff just after the ‘func’ keyword, tutorials somehow seem to skip this .. I leared this by googling the very similar question.</p>
110+
111+
<p>But then function can be also ‘class/struct’ function.</p>
112+
113+
<p>That is the stuff in brackets after ‘func’ is like automaticly made class/struct instance.. and used like this-pointer in C++.</p>
114+
115+
<div class="language-golang highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">package</span><span class="x"> </span><span class="n">main</span><span class="x">
116+
</span><span class="k">import</span><span class="x"> </span><span class="s">"fmt"</span><span class="x">
117+
118+
</span><span class="k">type</span><span class="x"> </span><span class="n">zoo</span><span class="x"> </span><span class="k">struct</span><span class="x"> </span><span class="p">{</span><span class="x">
119+
</span><span class="n">i</span><span class="x"> </span><span class="kt">string</span><span class="x">
120+
</span><span class="p">}</span><span class="x">
121+
122+
</span><span class="k">func</span><span class="x"> </span><span class="p">(</span><span class="n">y</span><span class="x"> </span><span class="n">zoo</span><span class="p">)</span><span class="x"> </span><span class="n">Foo</span><span class="p">(</span><span class="n">x</span><span class="x"> </span><span class="kt">int</span><span class="p">)</span><span class="x"> </span><span class="p">{</span><span class="x">
123+
</span><span class="n">fmt</span><span class="o">.</span><span class="n">Printf</span><span class="p">(</span><span class="s">"something %d %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="x"> </span><span class="n">x</span><span class="p">,</span><span class="x"> </span><span class="n">y</span><span class="o">.</span><span class="n">i</span><span class="p">)</span><span class="x">
124+
</span><span class="p">}</span><span class="x">
125+
126+
</span><span class="k">func</span><span class="x"> </span><span class="n">main</span><span class="p">()</span><span class="x"> </span><span class="p">{</span><span class="x">
127+
</span><span class="n">y</span><span class="x"> </span><span class="o">:=</span><span class="x"> </span><span class="n">zoo</span><span class="p">{}</span><span class="x">
128+
</span><span class="n">y</span><span class="o">.</span><span class="n">i</span><span class="x"> </span><span class="o">=</span><span class="x"> </span><span class="s">"hello"</span><span class="x">
129+
</span><span class="n">y</span><span class="o">.</span><span class="n">Foo</span><span class="p">(</span><span class="m">5</span><span class="p">)</span><span class="x">
130+
</span><span class="p">}</span><span class="x">
131+
</span></code></pre></div></div>
132+
<p>output of this is :
133+
something 5 hello</p>
89134

90135
<h1 id="-go-routines"><a href="#header-1"></a> go routines</h1>
91136

92-
<p>I think them as threads, fork etc.
93-
(I don’t know how to add neat golang play area here yet, but if you run this first foo funtion exits last.)</p>
137+
<p>I think them as threads, fork etc.</p>
94138

95139
<div class="language-golang highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">package</span><span class="x"> </span><span class="n">main</span><span class="x">
96140

@@ -115,10 +159,87 @@ <h1 id="-go-routines"><a href="#header-1"></a> go routines</h1>
115159
</span><span class="n">time</span><span class="o">.</span><span class="n">Sleep</span><span class="p">(</span><span class="m">500</span><span class="o">*</span><span class="n">time</span><span class="o">.</span><span class="n">Millisecond</span><span class="p">)</span><span class="x">
116160
</span><span class="p">}</span><span class="x">
117161
</span></code></pre></div></div>
118-
<p>For some really good reason there ++really is no++ api/function to get the go routine id (thread id), so I just use some id for now. Perhaps in future I’ll use the ‘context’ stuff they included quite resently.</p>
162+
<p>For some really good reason there ++really is no++ official api/function to get the go routine id (thread id), so I just use some id for now. I did try to use uuid but those make log line too long.
163+
Perhaps in future I’ll use the ‘context’ stuff they included quite resently.
164+
I also heard that golang has inbuilt thread/go routine/function engine.. so you should be able to run more than real threads.. never needed that much yet.</p>
119165

120166
<h1 id="-packages"><a href="#header-1"></a> packages</h1>
121-
<p>coming soo..</p>
167+
168+
<p>package imports are like the one’s in python, and acts like class in C++.
169+
Each package file can even have init() function.. like class constructor in C++.</p>
170+
171+
<p>As I wrote earlier funtion names with starting capitals are public with small letter private to the file (or in C++ to the class).</p>
172+
173+
<p>This does not only apply to the functions but also to the e.g constans, structs etc.</p>
174+
175+
<p>Again nothing really compilated.</p>
176+
177+
<p>in file src/my_utils.go</p>
178+
<div class="language-golang highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span><span class="x"> </span><span class="s">"fmt"</span><span class="x">
179+
180+
</span><span class="k">func</span><span class="x"> </span><span class="n">Foo</span><span class="p">(</span><span class="n">x</span><span class="x"> </span><span class="kt">int</span><span class="p">)</span><span class="x"> </span><span class="p">{</span><span class="x">
181+
</span><span class="n">fmt</span><span class="o">.</span><span class="n">Printf</span><span class="p">(</span><span class="s">"foo %d"</span><span class="p">,</span><span class="x"> </span><span class="n">x</span><span class="p">)</span><span class="x">
182+
</span><span class="p">}</span><span class="x">
183+
</span></code></pre></div></div>
184+
<p>so in my_prog.go I can call it.</p>
185+
186+
<div class="language-golang highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">package</span><span class="x"> </span><span class="n">main</span><span class="x">
187+
</span><span class="k">import</span><span class="x"> </span><span class="n">my_utils</span><span class="x">
188+
189+
</span><span class="k">func</span><span class="x"> </span><span class="n">main</span><span class="p">()</span><span class="x"> </span><span class="p">{</span><span class="x">
190+
</span><span class="n">Foo</span><span class="p">(</span><span class="m">5</span><span class="p">)</span><span class="x">
191+
</span><span class="p">}</span><span class="x">
192+
</span></code></pre></div></div>
193+
194+
<h1 id="-imported-packages"><a href="#header-2"></a> imported packages</h1>
195+
196+
<p>Public funtions you can overwrite, like virtual function in C++.
197+
Now the real mess starts when you include/import some package that uses private structs and/or constants.</p>
198+
199+
<div class="language-golang highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">package</span><span class="x"> </span><span class="n">main</span><span class="x">
200+
</span><span class="k">import</span><span class="x"> </span><span class="s">"my_utils"</span><span class="x">
201+
202+
</span><span class="k">func</span><span class="x"> </span><span class="n">main</span><span class="p">()</span><span class="x"> </span><span class="p">{</span><span class="x">
203+
</span><span class="k">var</span><span class="x"> </span><span class="n">y</span><span class="x"> </span><span class="n">my_utils</span><span class="o">.</span><span class="n">my_server</span><span class="x">
204+
</span><span class="n">y</span><span class="o">.</span><span class="n">bar</span><span class="x"> </span><span class="o">=</span><span class="x"> </span><span class="s">"not bar"</span><span class="x">
205+
</span><span class="n">my_utils</span><span class="o">.</span><span class="n">Foo</span><span class="p">(</span><span class="m">5</span><span class="p">,</span><span class="x"> </span><span class="n">y</span><span class="p">)</span><span class="x">
206+
</span><span class="p">}</span><span class="x">
207+
</span></code></pre></div></div>
208+
<p>in file my_utils.go, I added private my_server</p>
209+
210+
<div class="language-golang highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">package</span><span class="x"> </span><span class="n">my_utils</span><span class="x">
211+
</span><span class="k">import</span><span class="x"> </span><span class="s">"fmt"</span><span class="x">
212+
213+
</span><span class="k">type</span><span class="x"> </span><span class="n">my_server</span><span class="x"> </span><span class="k">struct</span><span class="x"> </span><span class="p">{</span><span class="x">
214+
</span><span class="n">bar</span><span class="x"> </span><span class="kt">string</span><span class="x">
215+
</span><span class="p">}</span><span class="x">
216+
217+
</span><span class="k">func</span><span class="x"> </span><span class="n">Foo</span><span class="p">(</span><span class="n">x</span><span class="x"> </span><span class="kt">int</span><span class="p">,</span><span class="x"> </span><span class="n">y</span><span class="x"> </span><span class="n">my_server</span><span class="p">)</span><span class="x"> </span><span class="p">{</span><span class="x">
218+
</span><span class="n">fmt</span><span class="o">.</span><span class="n">Printf</span><span class="p">(</span><span class="s">"foo %d, %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="x"> </span><span class="n">x</span><span class="p">,</span><span class="x"> </span><span class="n">y</span><span class="p">)</span><span class="x">
219+
</span><span class="p">}</span><span class="x">
220+
</span></code></pre></div></div>
221+
222+
<p>Because my_server is private I can not use Foo(), I can not even access/set the bar variable if I change the my_server to public My_server !!</p>
223+
224+
<p>Now because the my_server is private I can not overwrite the Foo() anymore in my main().</p>
225+
226+
<p>In C++ you could inherit the whole class (my_utils), and then overwrite the Foo().</p>
227+
228+
<p>As far I know ,you can not do this in golang with out tricks ;(</p>
229+
230+
<h1 id="-some-whining-about-this-issue"><a href="#header-3"></a> some whining about this issue</h1>
231+
232+
<p>“They are privat for a reason”.. bollocks, my personal quess is that I would do it.. because as said in C++ you can just inherit and do what ever you want with members.</p>
233+
234+
<p>Yeah, I know this is what the golang interface stuff is for but you see this all the time.. and end up ripping others code.</p>
235+
236+
<p>A lot of code/project what I have seen are not writen to be extended or used anywhere else than specific case, even the projects intention was to create interface !</p>
237+
238+
<p>In general I have started to be little sceptical of projects started 2/3 years ago.. A lot of them seem to be playing with golang and just dumped to github.
239+
I hope standard library has sceptical members what to put there or were are in the mess as some many other languages.</p>
240+
241+
<p>So I learned <strong>my lesson</strong>, I have to think what members really need be private or use interface in an github project.
242+
If I think it is any use to anybody other than just cut and paste code.</p>
122243

123244
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>The end so far.
124245
</code></pre></div></div>

0 commit comments

Comments
 (0)