Skip to content

Commit 42091ff

Browse files
committed
a
1 parent 17da646 commit 42091ff

File tree

4 files changed

+92
-69
lines changed

4 files changed

+92
-69
lines changed

_site/index.html

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ <h1 class="title">Ari's page</h1>
6464

6565
<p>So I needed to learn golang.. I tought I’ll share my experiences.</p>
6666

67-
<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>
67+
<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 I could not help my self but to make them anyway.</p>
6868

6969
<p>So here is what I learned this far :</p>
7070

@@ -136,6 +136,8 @@ <h1 id="-go-routines"><a href="#header-1"></a> go routines</h1>
136136

137137
<p>I think them as threads, fork etc.</p>
138138

139+
<p>Here main() waits for childs to exit and first foo() finnishes last.</p>
140+
139141
<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">
140142

141143
</span><span class="k">import</span><span class="x"> </span><span class="s">"fmt"</span><span class="x">
@@ -159,8 +161,10 @@ <h1 id="-go-routines"><a href="#header-1"></a> go routines</h1>
159161
</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">
160162
</span><span class="p">}</span><span class="x">
161163
</span></code></pre></div></div>
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+
<p>For some really good reason there ++really is no++ official api/function to get the go routine id (thread id).
165+
So I just use some id for now. I did try to use uuid but those make log line too long.</p>
166+
167+
<p>Perhaps in future I’ll use the ‘context’ stuff they included quite resently.
164168
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>
165169

166170
<h1 id="-struct"><a href="#header-1"></a> struct</h1>
@@ -200,15 +204,6 @@ <h1 id="-imported-packages"><a href="#header-2"></a> imported packages</h1>
200204
<p>Public funtions you can overwrite, like virtual function in C++.
201205
Now the real mess starts when you include/import some package that uses private structs and/or constants.</p>
202206

203-
<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">
204-
</span><span class="k">import</span><span class="x"> </span><span class="s">"my_utils"</span><span class="x">
205-
206-
</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">
207-
</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">
208-
</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">
209-
</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">
210-
</span><span class="p">}</span><span class="x">
211-
</span></code></pre></div></div>
212207
<p>in file my_utils.go, I added private my_server</p>
213208

214209
<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">
@@ -223,9 +218,21 @@ <h1 id="-imported-packages"><a href="#header-2"></a> imported packages</h1>
223218
</span><span class="p">}</span><span class="x">
224219
</span></code></pre></div></div>
225220

226-
<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>
221+
<p>At main I try to use it.</p>
222+
223+
<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">
224+
</span><span class="k">import</span><span class="x"> </span><span class="s">"my_utils"</span><span class="x">
225+
226+
</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">
227+
</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">
228+
</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">
229+
</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">
230+
</span><span class="p">}</span><span class="x">
231+
</span></code></pre></div></div>
227232

228-
<p>Now because the my_server is private I can not overwrite the Foo() anymore in my main().</p>
233+
<p>Because my_server is private I can not use public funtion Foo().
234+
I can not even access/set the bar variable if I change the my_server to public My_server !!
235+
Same apply if the private is the this-pointer instance I mentioned at function paragraph.</p>
229236

230237
<p>In C++ you could inherit the whole class (my_utils), and then overwrite the Foo().</p>
231238

@@ -245,10 +252,8 @@ <h2 id="-some-whining-about-this-issue"><a href="#header-3"></a> some whining ab
245252
<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.
246253
If I think it is any use to anybody other than just cut and paste code.</p>
247254

248-
<blockquote>
249-
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>The end so far.
250-
</code></pre></div> </div>
251-
</blockquote>
255+
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>The end so far.
256+
</code></pre></div></div>
252257

253258
<p><a href="http://hits.dwyl.io/apmattil/apmattil.github.io"><img src="http://hits.dwyl.io/apmattil/apmattil.github.io.svg" alt="HitCount" /></a></p>
254259

_site/pages.html

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ <h1 class="title">Ari's page</h1>
6464

6565
<p>So I needed to learn golang.. I tought I’ll share my experiences.</p>
6666

67-
<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>
67+
<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 I could not help my self but to make them anyway.</p>
6868

6969
<p>So here is what I learned this far :</p>
7070

@@ -136,6 +136,8 @@ <h1 id="-go-routines"><a href="#header-1"></a> go routines</h1>
136136

137137
<p>I think them as threads, fork etc.</p>
138138

139+
<p>Here main() waits for childs to exit and first foo() finnishes last.</p>
140+
139141
<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">
140142

141143
</span><span class="k">import</span><span class="x"> </span><span class="s">"fmt"</span><span class="x">
@@ -159,8 +161,10 @@ <h1 id="-go-routines"><a href="#header-1"></a> go routines</h1>
159161
</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">
160162
</span><span class="p">}</span><span class="x">
161163
</span></code></pre></div></div>
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+
<p>For some really good reason there ++really is no++ official api/function to get the go routine id (thread id).
165+
So I just use some id for now. I did try to use uuid but those make log line too long.</p>
166+
167+
<p>Perhaps in future I’ll use the ‘context’ stuff they included quite resently.
164168
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>
165169

166170
<h1 id="-struct"><a href="#header-1"></a> struct</h1>
@@ -200,15 +204,6 @@ <h1 id="-imported-packages"><a href="#header-2"></a> imported packages</h1>
200204
<p>Public funtions you can overwrite, like virtual function in C++.
201205
Now the real mess starts when you include/import some package that uses private structs and/or constants.</p>
202206

203-
<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">
204-
</span><span class="k">import</span><span class="x"> </span><span class="s">"my_utils"</span><span class="x">
205-
206-
</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">
207-
</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">
208-
</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">
209-
</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">
210-
</span><span class="p">}</span><span class="x">
211-
</span></code></pre></div></div>
212207
<p>in file my_utils.go, I added private my_server</p>
213208

214209
<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">
@@ -223,9 +218,21 @@ <h1 id="-imported-packages"><a href="#header-2"></a> imported packages</h1>
223218
</span><span class="p">}</span><span class="x">
224219
</span></code></pre></div></div>
225220

226-
<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>
221+
<p>At main I try to use it.</p>
222+
223+
<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">
224+
</span><span class="k">import</span><span class="x"> </span><span class="s">"my_utils"</span><span class="x">
225+
226+
</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">
227+
</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">
228+
</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">
229+
</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">
230+
</span><span class="p">}</span><span class="x">
231+
</span></code></pre></div></div>
227232

228-
<p>Now because the my_server is private I can not overwrite the Foo() anymore in my main().</p>
233+
<p>Because my_server is private I can not use public funtion Foo().
234+
I can not even access/set the bar variable if I change the my_server to public My_server !!
235+
Same apply if the private is the this-pointer instance I mentioned at function paragraph.</p>
229236

230237
<p>In C++ you could inherit the whole class (my_utils), and then overwrite the Foo().</p>
231238

@@ -245,10 +252,8 @@ <h2 id="-some-whining-about-this-issue"><a href="#header-3"></a> some whining ab
245252
<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.
246253
If I think it is any use to anybody other than just cut and paste code.</p>
247254

248-
<blockquote>
249-
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>The end so far.
250-
</code></pre></div> </div>
251-
</blockquote>
255+
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>The end so far.
256+
</code></pre></div></div>
252257

253258
<p><a href="http://hits.dwyl.io/apmattil/apmattil.github.io"><img src="http://hits.dwyl.io/apmattil/apmattil.github.io.svg" alt="HitCount" /></a></p>
254259

0 commit comments

Comments
 (0)