progress
This commit is contained in:
parent
612124d1e3
commit
2f89a70005
3 changed files with 141 additions and 2 deletions
|
@ -21,6 +21,11 @@
|
||||||
<li><a href="#mongodb-the-destroyer">MongoDB the Destroyer!</a></li>
|
<li><a href="#mongodb-the-destroyer">MongoDB the Destroyer!</a></li>
|
||||||
<li><a href="#months-of-gestation">9 months of gestation</a></li>
|
<li><a href="#months-of-gestation">9 months of gestation</a></li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
|
<li><a href="#long-live-the-new-flesh">Long live the new flesh</a><ul>
|
||||||
|
<li><a href="#deep-access">Deep access</a></li>
|
||||||
|
<li><a href="#merges">Merges</a></li>
|
||||||
|
<li><a href="#syntax">Syntax</a></li>
|
||||||
|
</ul></li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -131,12 +136,63 @@
|
||||||
<p>Each choice was balanced. In the end some of those choices were changed.</p>
|
<p>Each choice was balanced. In the end some of those choices were changed.</p>
|
||||||
<p>For example, we don’t use Storm at all now. The power of core.async was far from enough to deal with taking all resources of our machines.</p>
|
<p>For example, we don’t use Storm at all now. The power of core.async was far from enough to deal with taking all resources of our machines.</p>
|
||||||
<p>Today you could see a result here:</p>
|
<p>Today you could see a result here:</p>
|
||||||
<iframe src="https://dev.pulse.vigiglo.be/#/vgteam/TV_Shows/dashboard" style="width:100%; border:solid 2px #DDD; padding: none; margin: 20px 0; height: 500px;">
|
<div class="wrap" style="height: 630px; width: 100%;">
|
||||||
|
<iframe src="https://dev.pulse.vigiglo.be/#/vgteam/TV_Shows/dashboard" style="width:200%; border:solid 2px #DDD; padding: none; margin: 20px 0; height: 1200px; -ms-zoom:0.5; -moz-transform: scale(0.5); -moz-transform-origin: 0 0; -o-transform: scale(0.5); -o-transform-origin: 0 0; -webkit-transform: scale(0.5); -webkit-transform-origin: 0 0">
|
||||||
</iframe>
|
</iframe>
|
||||||
|
</div>
|
||||||
|
<h2 id="long-live-the-new-flesh">Long live the new flesh</h2>
|
||||||
|
<figure>
|
||||||
|
<img src="img/videodrome.jpg" alt="Long Live the new Flesh" /><figcaption>Long Live the new Flesh</figcaption>
|
||||||
|
</figure>
|
||||||
|
<p>Difficulties with the new mindset. As everything new, there is a period of adaptation. Typically the most difficult part was to deal with reversed arrays.</p>
|
||||||
|
<p>In javascript one would write</p>
|
||||||
|
<pre class="sourceCode javascript"><code class="sourceCode javascript">foo[<span class="st">"a"</span>]=<span class="st">"value-for-a"</span>
|
||||||
|
foo[<span class="st">"b"</span>]=<span class="st">"value-for-b"</span>
|
||||||
|
foo[<span class="st">"c"</span>]=<span class="st">"value-for-c"</span>
|
||||||
|
|
||||||
|
<span class="fu">foreach</span> (i <span class="kw">in</span> foo) {v[foo[i]]=i;}</code></pre>
|
||||||
|
<ul>
|
||||||
|
<li>Java null pointer exception!</li>
|
||||||
|
<li>Unreadable stacktrace</li>
|
||||||
|
</ul>
|
||||||
|
<p>What were the immediate wins!</p>
|
||||||
|
<h3 id="deep-access">Deep access</h3>
|
||||||
|
<p>For the brave an true there is the lenses Haskell library. But for clojurist, the basic access function should be good enough.</p>
|
||||||
|
<p>Let’s compare Javascript with Clojure:</p>
|
||||||
|
<pre class="sourceCode javascript"><code class="sourceCode javascript">foo={<span class="st">"db"</span>: [{<span class="st">"name"</span>:<span class="st">"John Doe"</span>,<span class="st">"age"</span>:<span class="dv">30</span>},{<span class="st">"name"</span>:<span class="st">"Rich"</span>,<span class="st">"age"</span>:<span class="dv">40</span>},{<span class="st">"age"</span>:<span class="dv">20</span>}]
|
||||||
|
<span class="co">// other stuff , ....</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
<span class="kw">var</span> val = <span class="kw">function</span>() {
|
||||||
|
x = foo[db];
|
||||||
|
<span class="kw">if</span> (x) {
|
||||||
|
<span class="kw">let</span> y = x[<span class="dv">1</span>];
|
||||||
|
<span class="kw">if</span> (y) {
|
||||||
|
<span class="kw">return</span> <span class="ot">y</span>.<span class="fu">age</span>;
|
||||||
|
} <span class="kw">else</span> <span class="kw">return</span> nil;
|
||||||
|
} <span class="kw">else</span> <span class="kw">return</span> nil;
|
||||||
|
}();</code></pre>
|
||||||
|
<p>Yes, you have to manually check at each level if the value is null or not. Without this manual check, your code is going to crash at runtime!</p>
|
||||||
|
<p>Now lets compare the situation with clojure:</p>
|
||||||
|
<pre class="sourceCode clojure"><code class="sourceCode clojure">(<span class="kw">-></span> foo <span class="kw">:db</span> <span class="kw">second</span> <span class="kw">:age</span>)</code></pre>
|
||||||
|
<p>Yes, that’s all. The default value in case of problem is <code>nil</code>.</p>
|
||||||
|
<h3 id="merges">Merges</h3>
|
||||||
|
<p><strong>Seriously!!!!!</strong></p>
|
||||||
|
<pre class="sourceCode clojure"><code class="sourceCode clojure">(<span class="kw">into</span> map1 map2)</code></pre>
|
||||||
|
<p>I don’t even want to compare to javascript as it would be ridiculous. Mainly, you can’t<a href="#fn2" class="footnoteRef" id="fnref2"><sup>2</sup></a>, or you need jQuery and its ugly.</p>
|
||||||
|
<h3 id="syntax">Syntax</h3>
|
||||||
|
<p>Learning Clojure syntax take about 3 minutes. It is clean, no <em>fucking</em> comma, semicolons, etc…</p>
|
||||||
|
<ul>
|
||||||
|
<li>Arrays: <code>[a b c]</code> in javascript <code>[a,b,c]</code> (why the commas?)</li>
|
||||||
|
<li>Hash Map (Associative arrays): <code>{:key1 value1 :key2 value2}</code> in javascript you need to define an Object and keys are generally strings: <code>{"key1":value1, "key2":value2}</code>. Multiline object declaration always have bad number of commas.</li>
|
||||||
|
<li>Set: <code>#{:a :b :c}</code> in javascript sets doesn’t even exists you have to simulate them with Objects: <code>{"a":true, "b":true, "c":true}</code></li>
|
||||||
|
<li>inline function declaration; compare <code>#(* % 2)</code> in clojure with <code>function(x){return x * 2;}</code> in javascript</li>
|
||||||
|
</ul>
|
||||||
<section class="footnotes">
|
<section class="footnotes">
|
||||||
<hr />
|
<hr />
|
||||||
<ol>
|
<ol>
|
||||||
<li id="fn1"><p>Just a great thank you to FPComplete and in particular Michael Snoyman!<a href="#fnref1">↩</a></p></li>
|
<li id="fn1"><p>Just a great thank you to FPComplete and in particular Michael Snoyman!<a href="#fnref1">↩</a></p></li>
|
||||||
|
<li id="fn2"><p><a href="http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically" class="uri">http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically</a><a href="#fnref2">↩</a></p></li>
|
||||||
</ol>
|
</ol>
|
||||||
</section>
|
</section>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
|
@ -199,4 +199,87 @@ resources of our machines.
|
||||||
|
|
||||||
Today you could see a result here:
|
Today you could see a result here:
|
||||||
|
|
||||||
<iframe src="https://dev.pulse.vigiglo.be/#/vgteam/TV_Shows/dashboard" style="width:100%; border:solid 2px #DDD; padding: none; margin: 20px 0; height: 500px;"></iframe>
|
<div class="wrap" style="height: 630px; width: 100%;">
|
||||||
|
<iframe src="https://dev.pulse.vigiglo.be/#/vgteam/TV_Shows/dashboard" style="width:200%; border:solid 2px #DDD; padding: none; margin: 20px 0; height: 1200px; -ms-zoom:0.5; -moz-transform: scale(0.5); -moz-transform-origin: 0 0; -o-transform: scale(0.5); -o-transform-origin: 0 0; -webkit-transform: scale(0.5); -webkit-transform-origin: 0 0"></iframe>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
## Long live the new flesh
|
||||||
|
|
||||||
|
![Long Live the new Flesh](img/videodrome.jpg)
|
||||||
|
|
||||||
|
Difficulties with the new mindset.
|
||||||
|
As everything new, there is a period of adaptation.
|
||||||
|
Typically the most difficult part was to deal with reversed arrays.
|
||||||
|
|
||||||
|
In javascript one would write
|
||||||
|
|
||||||
|
~~~ {.javascript}
|
||||||
|
foo["a"]="value-for-a"
|
||||||
|
foo["b"]="value-for-b"
|
||||||
|
foo["c"]="value-for-c"
|
||||||
|
|
||||||
|
foreach (i in foo) {v[foo[i]]=i;}
|
||||||
|
~~~
|
||||||
|
|
||||||
|
- Java null pointer exception!
|
||||||
|
- Unreadable stacktrace
|
||||||
|
|
||||||
|
What were the immediate wins!
|
||||||
|
|
||||||
|
### Deep access
|
||||||
|
|
||||||
|
For the brave an true there is the lenses Haskell library.
|
||||||
|
But for clojurist, the basic access function should be good enough.
|
||||||
|
|
||||||
|
Let's compare Javascript with Clojure:
|
||||||
|
|
||||||
|
~~~ {.javascript}
|
||||||
|
foo={"db": [{"name":"John Doe","age":30},{"name":"Rich","age":40},{"age":20}]
|
||||||
|
// other stuff , ....
|
||||||
|
}
|
||||||
|
|
||||||
|
var val = function() {
|
||||||
|
x = foo[db];
|
||||||
|
if (x) {
|
||||||
|
let y = x[1];
|
||||||
|
if (y) {
|
||||||
|
return y.age;
|
||||||
|
} else return nil;
|
||||||
|
} else return nil;
|
||||||
|
}();
|
||||||
|
~~~
|
||||||
|
|
||||||
|
Yes, you have to manually check at each level if the value is null
|
||||||
|
or not. Without this manual check, your code is going to crash at runtime!
|
||||||
|
|
||||||
|
Now lets compare the situation with clojure:
|
||||||
|
|
||||||
|
~~~ {.clojure}
|
||||||
|
(-> foo :db second :age)
|
||||||
|
~~~
|
||||||
|
|
||||||
|
Yes, that's all. The default value in case of problem is `nil`.
|
||||||
|
|
||||||
|
### Merges
|
||||||
|
|
||||||
|
**Seriously!!!!!**
|
||||||
|
|
||||||
|
~~~ {.clojure}
|
||||||
|
(into map1 map2)
|
||||||
|
~~~
|
||||||
|
|
||||||
|
I don't even want to compare to javascript as it would be ridiculous.
|
||||||
|
Mainly, you can't[^2], or you need jQuery and its ugly.
|
||||||
|
|
||||||
|
[^2]: <http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically>
|
||||||
|
|
||||||
|
### Syntax
|
||||||
|
|
||||||
|
Learning Clojure syntax take about 3 minutes.
|
||||||
|
It is clean, no _fucking_ comma, semicolons, etc...
|
||||||
|
|
||||||
|
- Arrays: `[a b c]` in javascript `[a,b,c]` (why the commas?)
|
||||||
|
- Hash Map (Associative arrays): `{:key1 value1 :key2 value2}` in javascript you need to define an Object and keys are generally strings: `{"key1":value1, "key2":value2}`. Multiline object declaration always have bad number of commas.
|
||||||
|
- Set: `#{:a :b :c}` in javascript sets doesn't even exists you have to simulate them with Objects: `{"a":true, "b":true, "c":true}`
|
||||||
|
- inline function declaration; compare `#(* % 2)` in clojure with `function(x){return x * 2;}` in javascript
|
||||||
|
|
BIN
articles/img/videodrome.jpg
Normal file
BIN
articles/img/videodrome.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Loading…
Reference in a new issue