tag:blogger.com,1999:blog-27696320480267143402024-03-14T10:27:08.612+02:00Programming, Architecture, NoSQL.בלוג על נושאים חמים בתכנות -
Blog about hot matters in programmingRoi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-2769632048026714340.post-70996543809965151122016-06-20T16:01:00.005+03:002016-06-20T16:10:28.747+03:00Advanced query and indexing an array inside an array in Couchbase(or... arrays part 2)<div>
Hi All,</div>
<div>
<br />
<b>TL;DR- Using indexes is a must, especially when you index an array!</b><br />
<br /></div>
<div>
This is a following post to <a href="http://roikatz.blogspot.co.il/2016/03/index-arrays-in-couchbase-45.html">that post</a> about array indexing in <a href="http://www.couchbase.com/">Couchbase</a>.</div>
<div>
In the previous post I only showed the simple case of an array without any property, or an array without any nested array,</div>
<div>
Today we will take it to the next level, Array inside an array (nested array) and properties inside the JSON array.</div>
<div>
<br /></div>
<div>
So take in instance this kind of document:</div>
<div>
<br /></div>
<div style="background: #f8f8f8; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">{
<span style="color: green; font-weight: bold;">"name"</span>: <span style="color: #ba2121;">"Roi"</span>,
<span style="color: green; font-weight: bold;">"lastName"</span>: <span style="color: #ba2121;">"Katz"</span>,
<span style="color: green; font-weight: bold;">"note2"</span>: <span style="color: #ba2121;">"blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah blah"</span>,
<span style="color: green; font-weight: bold;">"city"</span>: <span style="color: #ba2121;">"Tel Aviv"</span>,
<span style="color: green; font-weight: bold;">"note1"</span>: <span style="color: #ba2121;">"blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah blah"</span>,
<span style="color: green; font-weight: bold;">"age"</span>: <span style="color: #666666;">50</span>,
<span style="color: green; font-weight: bold;">"visited"</span>: [
{
<span style="color: green; font-weight: bold;">"country"</span>: <span style="color: #ba2121;">"UK"</span>,
<span style="color: green; font-weight: bold;">"cities"</span>: [
<span style="color: #ba2121;">"London"</span>,
<span style="color: #ba2121;">"Manchester"</span>,
<span style="color: #ba2121;">"Coventry"</span>
]
},
{
<span style="color: green; font-weight: bold;">"country"</span>: <span style="color: #ba2121;">"Israel"</span>,
<span style="color: green; font-weight: bold;">"cities"</span>: [
<span style="color: #ba2121;">"Kfar-Saba"</span>,
<span style="color: #ba2121;">"Tel-Aviv"</span>,
<span style="color: #ba2121;">"Jerusalem"</span>
]
}
]
}
</pre>
</div>
<br />
<div>
We want to query the countries inside the "visited" property first, and later a city inside the inner JSON array.<br />
<br />
So how do we query the Countries inside the array?<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #f8f8f8; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: green; font-weight: bold;">select</span> <span style="color: #666666;">*</span> <span style="color: green; font-weight: bold;">from</span> people p
<span style="color: green; font-weight: bold;">where</span> visited <span style="color: green; font-weight: bold;">is</span> <span style="color: green; font-weight: bold;">not</span> missing
<span style="color: green; font-weight: bold;">and</span> <span style="color: green; font-weight: bold;">any</span> visit <span style="color: green; font-weight: bold;">in</span> p.visited satisfies vi<span style="line-height: 125%;">sit.country</span><span style="color: #666666; line-height: 125%;">=</span><span style="color: #19177c; line-height: 125%;">"Israel"</span><span style="line-height: 125%;"> </span><span style="color: green; font-weight: bold; line-height: 125%;">end</span><span style="line-height: 125%;">;</span></pre>
</div>
<br />
Where p is actually the people bucket alias, and visit is a sort of a function on top of the people.<br />
But - while it works we are doing it without an index (except for PrimaryScan), and it going to take a long time to get the results even on a fairly small dataset.<br />
With a dataset of over 100K documents, but only 2 are really relevant it took the query about 2 seconds to run - as it was running on the primary scan.<br />
<br />
However, When I do introduce the index, the timings are cut down to <b>4ms</b>!<br />
<br />
The index I used here to speed things up was "countries_indx"<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #f8f8f8; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: green; font-weight: bold;">CREATE</span> <span style="color: green; font-weight: bold;">INDEX</span> countries_indx <span style="color: green; font-weight: bold;">ON</span></pre>
<pre style="line-height: 125%; margin: 0;"><span style="line-height: 125%;">people(</span><span style="color: green; font-weight: bold; line-height: 125%;">distinct</span><span style="line-height: 125%;"> </span><span style="color: green; line-height: 125%;">array</span><span style="line-height: 125%;"> visit.country </span><span style="color: green; font-weight: bold; line-height: 125%;">for</span><span style="line-height: 125%;"> visit </span><span style="color: green; font-weight: bold; line-height: 125%;">in</span><span style="line-height: 125%;"> visited </span><span style="color: green; font-weight: bold; line-height: 125%;">end</span><span style="line-height: 125%;">)</span></pre>
</div>
<br />
Please note again, as it was in my previous post - that "visit" which comes after the for keyword must be the exact same phrase as after the any keyword in the select query.<br />
If they are not - you won't be able to use the index.<br />
<br /></div>
<div>
Here is a taste of the proper explain plan - from which you can understand the usage of the correct index (countries_indx with IndexScan).<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #f8f8f8; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">[
{
<span style="color: green; font-weight: bold;">"plan"</span>: {
<span style="color: green; font-weight: bold;">"#operator"</span>: <span style="color: #ba2121;">"Sequence"</span>,
<span style="color: green; font-weight: bold;">"~children"</span>: [
{
<span style="color: green; font-weight: bold;">"#operator"</span>: <span style="color: #ba2121;">"DistinctScan"</span>,
<span style="color: green; font-weight: bold;">"scan"</span>: {
<span style="color: green; font-weight: bold;">"#operator"</span>: <span style="color: #ba2121;">"IndexScan"</span>,
<span style="color: green; font-weight: bold;">"index"</span>: <span style="color: #ba2121;">"countries_indx"</span>,
<span style="color: green; font-weight: bold;">"index_id"</span>: <span style="color: #ba2121;">"f0dd08732dd1b9a2"</span>,
<span style="color: green; font-weight: bold;">"keyspace"</span>: <span style="color: #ba2121;">"people"</span>,
<span style="color: green; font-weight: bold;">"namespace"</span>: <span style="color: #ba2121;">"default"</span>,
<span style="color: green; font-weight: bold;">"spans"</span>: [
{
<span style="color: green; font-weight: bold;">"Range"</span>: {
<span style="color: green; font-weight: bold;">"High"</span>: [
<span style="color: #ba2121;">"\"Israel\""</span>
],
<span style="color: green; font-weight: bold;">"Inclusion"</span>: <span style="color: #666666;">3</span>,
<span style="color: green; font-weight: bold;">"Low"</span>: [
<span style="color: #ba2121;">"\"Israel\""</span>
]
}
}
],
<span style="color: green; font-weight: bold;">"using"</span>: <span style="color: #ba2121;">"gsi"</span>
}
},
{
<span style="color: green; font-weight: bold;">"#operator"</span>: <span style="color: #ba2121;">"Parallel"</span>,
<span style="color: green; font-weight: bold;">"~child"</span>: {
<span style="color: green; font-weight: bold;">"#operator"</span>: <span style="color: #ba2121;">"Sequence"</span>,
<span style="color: green; font-weight: bold;">"~children"</span>: [
{
<span style="color: green; font-weight: bold;">"#operator"</span>: <span style="color: #ba2121;">"Fetch"</span>,
<span style="color: green; font-weight: bold;">"as"</span>: <span style="color: #ba2121;">"p"</span>,
<span style="color: green; font-weight: bold;">"keyspace"</span>: <span style="color: #ba2121;">"people"</span>,
<span style="color: green; font-weight: bold;">"namespace"</span>: <span style="color: #ba2121;">"default"</span>
},
{
<span style="color: green; font-weight: bold;">"#operator"</span>: <span style="color: #ba2121;">"Filter"</span>,
<span style="color: green; font-weight: bold;">"condition"</span>: <span style="color: #ba2121;">"(((`p`.`visited`) is not missing) and any `visit` in (`p`.`visited`) satisfies ((`visit`.`country`) = \"Israel\") end)"</span>
},
{
<span style="color: green; font-weight: bold;">"#operator"</span>: <span style="color: #ba2121;">"InitialProject"</span>,
<span style="color: green; font-weight: bold;">"result_terms"</span>: [
{
<span style="color: green; font-weight: bold;">"expr"</span>: <span style="color: #ba2121;">"self"</span>,
<span style="color: green; font-weight: bold;">"star"</span>: <span style="color: green; font-weight: bold;">true</span>
}
]
},
{
<span style="color: green; font-weight: bold;">"#operator"</span>: <span style="color: #ba2121;">"FinalProject"</span>
}
]
}
}
]
},
<span style="color: green; font-weight: bold;">"text"</span>: <span style="color: #ba2121;">"select * from people p\nwhere visited is not missing\nand any visit in p.visited satisfies visit.country=\"Israel\" end;"</span>
}
]
</pre>
</div>
</div>
<div>
<br /></div>
<div>
<br />
Now let's continue to the more interesting query,<br />
We want to query for a documents which contains the city of London in their visited property,<br />
how would we do it? by nesting array queries!<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #f8f8f8; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: green; font-weight: bold;">select</span> <span style="color: #666666;">*</span> <span style="color: green; font-weight: bold;">from</span> people p
<span style="color: green; font-weight: bold;">where</span> visited <span style="color: green; font-weight: bold;">is</span> <span style="color: green; font-weight: bold;">not</span> missing
<span style="color: green; font-weight: bold;">and</span> <span style="color: green; font-weight: bold;">any</span> visit <span style="color: green; font-weight: bold;">in</span> p.visited satisfies
<span style="color: green; font-weight: bold;">any</span> city <span style="color: green; font-weight: bold;">in</span> visit.cities satisfies city <span style="color: #666666;">= </span><span style="color: #19177c;">"London"</span> <span style="color: green; font-weight: bold;">end</span> </pre>
<pre style="line-height: 125%; margin: 0;"><span style="color: green; font-weight: bold;">end</span>;
</pre>
</div>
</div>
<div>
<br />
That query needs a bit more of an explanation.<br />
First we should add the visited is not missing expression in order to filter out every document which doesn't have that property.<br />
<br />
Second, we would like to search an array of arrays basically, because of it we would like to do something similar a a nested for loop.<br />
first we looking in the visited property, and afterwards for each part of the outer array we are looking for a property cities and in the cities array for a city named "London".<br />
The visit variable in the outer loop is the same one as in the inner loop for visit.cities.<br />
<br />
But as before we still don't have an index for that, which yields a very slow performance roughly 1.8s -2s to execute that query.<br />
<br />
When we add the index we are going back to the golden time of ±4ms for the exact same query.<br />
The index is<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #f8f8f8; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: green; font-weight: bold;">CREATE</span> <span style="color: green; font-weight: bold;">INDEX</span> <span style="color: #666666;">`</span>cities_indx<span style="color: #666666;">`</span> <span style="color: green; font-weight: bold;">ON</span>
people( <span style="color: green; font-weight: bold;">distinct</span> <span style="color: green;">array</span>
( <span style="color: green; font-weight: bold;">distinct</span> <span style="color: green;">array</span> city <span style="color: green; font-weight: bold;">for</span> city <span style="color: green; font-weight: bold;">in</span> visit.cities <span style="color: green; font-weight: bold;">end</span>)
<span style="color: green; font-weight: bold;">for</span> <span style="color: #666666;">`</span>visit<span style="color: #666666;">`</span> <span style="color: green; font-weight: bold;">in</span> <span style="color: #666666;">`</span>visited<span style="color: #666666;">`</span> <span style="color: green; font-weight: bold;">end</span>)
</pre>
</div>
<br />
Just make sure that city in the index corresponds to the city in the query, and so on for the visit.<br />
<br />
if you have a JSON property in each of the cities, you just add in the query "city.yourProperty".<br />
<br />
<br />
That's all!<br />
Hope you've enjoyed.<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
<div>
<br /></div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-76305053880232736722016-05-31T17:34:00.001+03:002016-05-31T17:40:58.936+03:00Shrinking your Couchbase memory footprint with compression Hi,<br />
<br />
<b>TL;DR: Compression will decrease your memory footprint and increase your memory residency.</b><br />
<br />
<div class="separator" style="clear: both; text-align: left;">
An important and integral part of Couchbase server many people forget is that Couchbase is not only a fast general use document database with advanced querying of N1QL, it's also is Key/Value store altogether.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
If it is the kind of operations you might need, and you can "pay" in terms of be able to get the data by only the key and not be able to index things than you might consider of compressing your JSON or object and save it into binary document in the database instead of just a JSON.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
For instance, each bucket contains exactly 1 million documents which looks similar to this one:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBu7SY_6AcNKyo11HM_1umHmMnu1uP0Ks1ljZWaPMMBBQ6cTwuAkS9J5GL7HbHDXmke6be1Sh8MBhsNCU_HLUxrv1XPdhrt25VV-48259_sYEfIjljirscDlejYYr7mVIS1ERfOMPdxcMe/s1600/Screen+Shot+2016-05-30+at+17.04.50.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="135" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBu7SY_6AcNKyo11HM_1umHmMnu1uP0Ks1ljZWaPMMBBQ6cTwuAkS9J5GL7HbHDXmke6be1Sh8MBhsNCU_HLUxrv1XPdhrt25VV-48259_sYEfIjljirscDlejYYr7mVIS1ERfOMPdxcMe/s400/Screen+Shot+2016-05-30+at+17.04.50.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Underscores are there in order to guaranty the size of 278 bytes</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Each document contains 56 bytes of metadata, about 15 bytes of key size and 278 bytes of value in JSON format. (349bytes per document) - about 349,000,000 bytes of RAM which are 332.8Mb.</div>
<div class="separator" style="clear: both; text-align: left;">
We can check the amount of bytes in the memory, of active vbuckets by using the following cbstats command:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">./cbstats localhost:11210 -b compressed all | grep active_itm_memory
vb_active_itm_memory: 349000000
</pre>
</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<br />
<div class="separator" style="clear: both; text-align: left;">
Compressed document takes about 107-108bytes, so 178,000,000 appx. or 169Mb.</div>
<div class="separator" style="clear: both; text-align: left;">
in cbstats:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">./cbstats localhost:11210 -b compressed all | grep active_itm_memory
vb_active_itm_memory: 178139161
</pre>
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Figures in the following screenshot are slightly different as there is some extra overhead or the Couchbase engine. </div>
<div class="separator" style="clear: both; text-align: left;">
The figures here are the actual volume that the bucket takes in the memory, not only data.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7DXOO2nrsxuWU9hg4HhDai-57v12c4-0z7LDWooyQ09ZPRvbxDO2LGP8TS6mgQqAedMeWCJuH0FMUFD_Jcbq3132VpbfieiO9zaj_8rHXIze54BRFhZEhIDmOjuwGaMgpFwgBauFyDXsR/s1600/Screen+Shot+2016-05-30+at+16.44.21.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="41" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7DXOO2nrsxuWU9hg4HhDai-57v12c4-0z7LDWooyQ09ZPRvbxDO2LGP8TS6mgQqAedMeWCJuH0FMUFD_Jcbq3132VpbfieiO9zaj_8rHXIze54BRFhZEhIDmOjuwGaMgpFwgBauFyDXsR/s400/Screen+Shot+2016-05-30+at+16.44.21.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span id="goog_447123798"></span><span id="goog_447123799"></span><br /></div>
<br />
We can see here that the data compressed almost by the factor of 2! (349 vs 178).<br />
meaning - reducing the amount of machines/memory needed by almost 50%.<br />
And if you are not on 100% residence ratio - that method will surely increase it.<br />
<br />
So wait! If I need half of the machines (on that use case), where is the catch?<br />
<br />
<u>Three things you must note here:</u><br />
1) As described before, you cannot index compressed documents.<br />
2) Creating the document you want to insert takes more time.<br />
3) Reading the document takes longer as you need to decompress.<br />
<br />
Creating the documents time is varying in a factor of 6.<br />
I've used the best compression setting for worst case scenario.<br />
From the tests I've run, the compression factor in gzip lib for Java doesn't really change much for the data in terms of time and footprint.<br />
That machine is my laptop so not a server grade machine.<br />
<br />
<b>Uncompressed</b><br />
Generating 1M documents took: <b>5002ms</b><br />
<br />
<b>Compressed</b><br />
Generating 1M documents took: <b>31731ms</b><br />
<br />
So how do you insert compressed documents?<br />
<br />
<ol>
<li>Create the stream</li>
<li>Wrap it with BinaryDocument</li>
<li>Insert it to Couchbase (observable)</li>
</ol>
<div>
Here is a snip of creating a compressed binary document and adding it to a collection:</div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #f0f0f0; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">ByteArrayOutputStream baos <span style="color: #666666;">=</span> <span style="color: #007020; font-weight: bold;">new</span> ByteArrayOutputStream<span style="color: #666666;">();</span>
OutputStream gzipOut <span style="color: #666666;">=</span> <span style="color: #007020; font-weight: bold;">new</span> GZIPOutputStream<span style="color: #666666;">(</span>baos<span style="color: #666666;">){{</span>def<span style="color: #666666;">.</span><span style="color: #4070a0;">setLevel</span><span style="color: #666666;">(</span>Deflater<span style="color: #666666;">.</span><span style="color: #4070a0;">BEST_SPEED</span><span style="color: #666666;">);}};</span>
ObjectOutputStream objectOut <span style="color: #666666;">=</span> <span style="color: #007020; font-weight: bold;">new</span> ObjectOutputStream<span style="color: #666666;">(</span>gzipOut<span style="color: #666666;">);</span>
objectOut<span style="color: #666666;">.</span><span style="color: #4070a0;">writeObject</span><span style="color: #666666;">(</span>doc<span style="color: #666666;">.</span><span style="color: #4070a0;">content</span><span style="color: #666666;">().</span><span style="color: #4070a0;">toString</span><span style="color: #666666;">());</span>
objectOut<span style="color: #666666;">.</span><span style="color: #4070a0;">close</span><span style="color: #666666;">();</span>
<span style="color: #902000;">byte</span><span style="color: #666666;">[]</span> bytes <span style="color: #666666;">=</span> baos<span style="color: #666666;">.</span><span style="color: #4070a0;">toByteArray</span><span style="color: #666666;">();</span>
ByteBuf toWrite <span style="color: #666666;">=</span> Unpooled<span style="color: #666666;">.</span><span style="color: #4070a0;">copiedBuffer</span><span style="color: #666666;">(</span>bytes<span style="color: #666666;">);</span>
BinaryDocument binDoc <span style="color: #666666;">=</span> BinaryDocument<span style="color: #666666;">.</span><span style="color: #4070a0;">create</span><span style="color: #666666;">(</span>key<span style="color: #666666;">,</span> toWrite<span style="color: #666666;">);</span>
docsToInsertZipped<span style="color: #666666;">.</span><span style="color: #4070a0;">add</span><span style="color: #666666;">(</span>binDoc<span style="color: #666666;">);</span></pre>
<pre style="line-height: 125%; margin: 0;"><pre style="color: #333333;"></pre>
<pre style="color: #333333;">Observable<span style="color: #666666;">.</span><span style="color: #4070a0;">from</span><span style="color: #666666;">(</span>docsToInsertZipped<span style="color: #666666;">).</span><span style="color: #4070a0;">flatMap</span><span style="color: #666666;">(</span>docBinary<span style="color: #666666;">-></span>compressedBucket<span style="color: #666666;">.</span><span style="color: #4070a0;">async</span><span style="color: #666666;">().</span><span style="color: #4070a0;">upsert</span><span style="color: #666666;">(</span>docBinary<span style="color: #666666;">)).</span><span style="color: #4070a0;">toBlocking</span><span style="color: #666666;">().</span><span style="color: #4070a0;">subscribe</span><span style="color: #666666;">();</span></pre>
</pre>
</div>
<div>
<br />
In order to read the data:<br />
<ol>
<li>Read (get) the document</li>
<li>Uncompress the content</li>
<li>Convert the byte buffer to string</li>
</ol>
<div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #f0f0f0; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">BinaryDocument binaryDocument <span style="color: #666666;">=</span> compressedBucket<span style="color: #666666;">.</span><span style="color: #4070a0;">get</span><span style="color: #666666;">(</span><span style="color: #4070a0;">"person::0000001"</span><span style="color: #666666;">,</span>BinaryDocument<span style="color: #666666;">.</span><span style="color: #4070a0;">clas</span>
<span style="color: #902000;">byte</span><span style="color: #666666;">[]</span> data <span style="color: #666666;">=</span> <span style="color: #007020; font-weight: bold;">new</span> <span style="color: #902000;">byte</span><span style="color: #666666;">[</span>binaryDocument<span style="color: #666666;">.</span><span style="color: #4070a0;">content</span><span style="color: #666666;">().</span><span style="color: #4070a0;">readableBytes</span><span style="color: #666666;">()];</span>
binaryDocument<span style="color: #666666;">.</span><span style="color: #4070a0;">content</span><span style="color: #666666;">().</span><span style="color: #4070a0;">readBytes</span><span style="color: #666666;">(</span>data<span style="color: #666666;">);</span>
GZIPInputStream gis <span style="color: #666666;">=</span> <span style="color: #007020; font-weight: bold;">new</span> GZIPInputStream<span style="color: #666666;">(</span><span style="color: #007020; font-weight: bold;">new</span> ByteArrayInputStream<span style="color: #666666;">(</span>data<span style="color: #666666;">));</span>
InputStreamReader reader <span style="color: #666666;">=</span> <span style="color: #007020; font-weight: bold;">new</span> InputStreamReader<span style="color: #666666;">(</span>gis<span style="color: #666666;">);</span>
BufferedReader buffered <span style="color: #666666;">=</span> <span style="color: #007020; font-weight: bold;">new</span> BufferedReader<span style="color: #666666;">(</span>reader<span style="color: #666666;">);</span>
String read<span style="color: #666666;">;</span>
<span style="color: #007020; font-weight: bold;">while</span> <span style="color: #666666;">((</span>read <span style="color: #666666;">=</span> buffered<span style="color: #666666;">.</span><span style="color: #4070a0;">readLine</span><span style="color: #666666;">())</span> <span style="color: #666666;">!=</span> <span style="color: #007020; font-weight: bold;">null</span><span style="color: #666666;">)</span> <span style="color: #666666;">{</span>
System<span style="color: #666666;">.</span><span style="color: #4070a0;">out</span><span style="color: #666666;">.</span><span style="color: #4070a0;">println</span><span style="color: #666666;">(</span>read<span style="color: #666666;">);</span>
<span style="color: #666666;">}</span>
</pre>
</div>
<br />
<br />
A much more complicated process than just get the document,<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #f0f0f0; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">JsonDocument document <span style="color: #666666;">=</span> uncompressedBucket<span style="color: #666666;">.</span><span style="color: #4070a0;">get</span><span style="color: #666666;">(</span><span style="color: #4070a0;">"person::0000001"</span><span style="color: #666666;">);</span>
System<span style="color: #666666;">.</span><span style="color: #4070a0;">out</span><span style="color: #666666;">.</span><span style="color: #4070a0;">println</span><span style="color: #666666;">(</span>document<span style="color: #666666;">.</span><span style="color: #4070a0;">content</span><span style="color: #666666;">().</span><span style="color: #4070a0;">toString</span><span style="color: #666666;">());</span>
</pre>
</div>
<br />
but it is faster, as in that code you don't need to serialize the bytes into JsonDocument.<br />
Take into account that you might have to serialize it anyway, or put it behind wrappers.<br />
<br />
That's it.<br />
Now you have another tool you might use in your toolbox.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
</div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-63777042139416571052016-03-08T09:31:00.000+02:002016-03-08T09:39:18.709+02:00How to index arrays in Couchbase 4.5Hi,<br />
<br />
So you've installed your new shiny Couchbase 4.5 (currently in dev preview stage) and found out that you now can index your favorite array in you JSON document.<br />
<br />
But how can you do it?<br />
I am going to demonstrate in the easiest and the quickest way how to achieve that extra crank of speed for you array entries.<br />
<br />
I'm going to insert some documents in the following format to the default bucket<br />
<blockquote class="tr_bq">
{ "name": "Some Name", "cities_traveled":["city1", "city2" ... , "cityN"] }</blockquote>
Next, we going to need to create a simple index for that array of cities,<br />
and Primary index for convenience.<br />
<br />
Primary:<br />
<blockquote class="tr_bq">
create primary index `idx_prime` on `default` using GSI;</blockquote>
Array Index:<br />
<blockquote class="tr_bq">
create index `idx_traveled` on `default` (distinct array city for city in cities_traveled end) using GSI;</blockquote>
and try to select our data out using explain to verify we are using our index:<br />
<blockquote class="tr_bq">
<blockquote class="tr_bq">
explain select * from `default` d</blockquote>
<blockquote class="tr_bq">
where any city in d.cities_traveled satisfies city="London" end;</blockquote>
</blockquote>
Let's break it up a little:<br />
<ul>
<li>We create our index named idx_traveled on the bucket default, and specifying that we want to iterate on every property inside an array in the property "cities_traveled" distinctly.</li>
<li>The first part of the select it's simple, select everything from our bucket, naming it d</li>
<li>In the where clause we have stated that we want at least on of our elements in the cities_traveled property to have London string in it.</li>
<li>We need to be careful, the "any city" must much to the city definition string of the index - or it won't work.</li>
</ul>
<div>
<u><b>Good Query</b></u><br />
<br />
<b>Query</b><br />
<blockquote class="tr_bq">
select * from `default` d</blockquote>
<blockquote class="tr_bq">
where any <b>city</b> in d.cities_traveled satisfies <b>city</b> = "London" end</blockquote>
The "<b>city</b>" after any and in the expression are exactly the same as in the index definition.<br />
<br />
<b>Explain</b><br />
<br />
Notice the index that being used is our "idx_traveled" and the operator is IndexScan<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "UnionScan",
"scans": [
{
"#operator": "IndexScan",
"index": "idx_traveled",
"keyspace": "default",
"namespace": "default",
"spans": [
{
"Range": {
"High": [
"\"London\""
],
"Inclusion": 3,
"Low": [
"\"London\""
]
}
}
],
"using": "gsi"
}
]
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Fetch",
"as": "d",
"keyspace": "default",
"namespace": "default"
},
{
"#operator": "Filter",
"condition": "any `city` in (`d`.`cities_traveled`) satisfies (`city` = \"London\") end"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "self",
"star": true
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
}
]
</code></pre>
<br /></div>
<div>
<b><u>Bad Query</u></b><br />
<br />
<b>Query</b><br />
<blockquote class="tr_bq">
select * from `default` d</blockquote>
<blockquote class="tr_bq">
where any <b>someCity</b> in d.cities_traveled satisfies <b>someCity</b> = "London" end</blockquote>
The "<b>someCity</b>" after any and in the expression are not the same as in the index definition.<br />
<br />
<b>Explain</b><br />
<b><br /></b>
Notice the index used is idx_prime and the operator is PrimaryScan<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "PrimaryScan",
"index": "idx_prime",
"keyspace": "default",
"namespace": "default",
"using": "gsi"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Fetch",
"as": "d",
"keyspace": "default",
"namespace": "default"
},
{
"#operator": "Filter",
"condition": "any `a` in (`d`.`cities_traveled`) satisfies (`a` = \"London\") end"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "self",
"star": true
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
}
]
</code></pre>
<br /></div>
<div>
Query result:</div>
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> &lt;pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; [
{
"d": {
"cities_traveled": [
"Tel-Aviv",
"London",
"New-York",
"San Francisco",
"Los-Angeles"
],
"name": "Roi"
}
},
{
"d": {
"cities_traveled": [
"Kilmarnock",
"London",
"New-York",
"San Francisco",
"Los-Angeles"
],
"name": "Jonny Walker"
}
}
]
&lt;/code&gt;&lt;/pre&gt;
</code></pre>
</code></pre>
<br />
So that was a brief how-to of array indexes in Couchbase 4.5!<br />
for more information and memory optimized indexes - check the <a href="http://developer.couchbase.com/documentation/server/4.5-dp/indexing-arrays.html">documentation</a>.<br />
<br />
Thanks all!<br />
Roi.<br />
<blockquote class="tr_bq">
</blockquote>
<blockquote class="tr_bq">
</blockquote>
<blockquote class="tr_bq">
</blockquote>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-4151724345517105942016-02-04T17:04:00.000+02:002016-02-04T17:12:47.285+02:00Getting started with Kafka and Couchbase as an endpointHi all,<br />
<a href="http://www.couchbase.com/">Couchbase</a> is great as a source for <a href="http://kafka.apache.org/">Apache Kafka </a>using the <a href="https://github.com/couchbase/couchbase-kafka-connector">DCP connector</a>.<br />
However it is also great as an endpoint for digesting data, as it is fast, memory first and reliable storage.<br />
<br />
In this blog post I will show you how to build simple Java application for a producer and a consumer which save the published messages from Kafka into Couchbase.<br />
<br />
I assume here, that you already have a Kafka cluster (even if it's single node cluster).<br />
If not, try to follow <a href="https://www.digitalocean.com/community/tutorials/how-to-install-apache-kafka-on-ubuntu-14-04">that installation guide</a>.<br />
<br />
This blog environment have 4 parts:<br />
1. Kafka producer<br />
2. Apache Kafka queue<br />
3. Kafka consumer<br />
4. Couchbase server<br />
<br />
<h2>
Producer</h2>
We need the producer in order to submit messages to our queue.<br />
In the queue, those messages are being digested and every application which subscribed to the topic - can read those messages.<br />
The source of our messages will be a dummy JSON file I've created using <a href="https://www.mockaroo.com/">Mockaroo</a>, which we will split and sent to the queue.<br />
<br />
our sample JSON data looks something similar to:<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> {
"id":1,
"gender":"Female",
"first_name":"Jane",
"last_name":"Holmes",
"email":"jholmes0@myspace.com",
"ip_address":"230.49.112.20",
"city":"Houston"
}
</code></pre>
<br />
The producer code:<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
public class KafkaSimpleProducer {
public static void main(String[] args) throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
config.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
config.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
KafkaProducer<String, String> producer = new KafkaProducer<String, String>(config);
File input = new File("sampleJsonData.json");
byte[] encoded = Files.readAllBytes(Paths.get(input.getPath() ));
String jsons = new String(encoded, Charset.defaultCharset());
System.out.println("Splitting file to jsons....");
List<String> splittedJsons = split(jsons);
System.out.println("Converting to JsonDocuments....");
int docCount = splittedJsons.size();
System.out.println("Number of documents is: " + docCount );
System.out.println("Starting sending msg to kafka....");
int count = 0;
for ( String doc : splittedJsons) {
System.out.println("sending msg...." + count);
ProducerRecord<String,String> record = new ProducerRecord<>( "couchbaseTopic", doc );
Future<RecordMetadata> meta = producer.send(record);
System.out.println("msg sent...." + count);
count++;
}
System.out.println("Total of " + count + " messages sent");
producer.close();
}
public static List<String> split(String jsonArray) throws Exception {
List<String> splittedJsonElements = new ArrayList<String>();
ObjectMapper jsonMapper = new ObjectMapper();
JsonNode jsonNode = jsonMapper.readTree(jsonArray);
if (jsonNode.isArray()) {
ArrayNode arrayNode = (ArrayNode) jsonNode;
for (int i = 0; i < arrayNode.size(); i++) {
JsonNode individualElement = arrayNode.get(i);
splittedJsonElements.add(individualElement.toString());
}
}
return splittedJsonElements;
}
}
</code></pre>
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO_t81D2R_RS-SzG0ARCucqZOcqUUVk0ReqUUgYEyFzP5-cqrdJSpwvsirKF67axOXWmTI1Sr8lBTw2-NwCmaS3Dp6Zj90dqOQzkZcHz2Utj-45YKpIL4R1A5_WvGwsTOVd_xTaQgeYHx-/s1600/Screen+Shot+2016-02-04+at+14.53.04.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="251" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO_t81D2R_RS-SzG0ARCucqZOcqUUVk0ReqUUgYEyFzP5-cqrdJSpwvsirKF67axOXWmTI1Sr8lBTw2-NwCmaS3Dp6Zj90dqOQzkZcHz2Utj-45YKpIL4R1A5_WvGwsTOVd_xTaQgeYHx-/s400/Screen+Shot+2016-02-04+at+14.53.04.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Output from the Producer App</td></tr>
</tbody></table>
<br />
<h2>
Consumer </h2>
This is a simple one, very straight forward, just get the messages from the queue, and use the Couchbase Java SDK in order to insert documents into Couchbase. For simplicity, I'll be using the sync java SDK, but using the async is totally possible and even recommended.<br />
<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
import kafka.consumer.Consumer;
import kafka.consumer.ConsumerConfig;
import kafka.consumer.KafkaStream;
import kafka.javaapi.consumer.ConsumerConnector;
import kafka.message.MessageAndMetadata;
import java.util.*;
public class KafkaSimpleConsumer {
public static void main(String[] args) {
Properties config = new Properties();
config.put("zookeeper.connect", "localhost:2181");
config.put("zookeeper.connectiontimeout.ms", "10000");
config.put("group.id", "default");
ConsumerConfig consumerConfig = new kafka.consumer.ConsumerConfig(config);
ConsumerConnector consumerConnector = Consumer.createJavaConsumerConnector(consumerConfig);
Map<String, Integer> topicCountMap = new HashMap<>();
topicCountMap.put("couchbaseTopic", 1);
Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumerConnector.createMessageStreams(topicCountMap);
List<KafkaStream<byte[], byte[]>> streams = consumerMap.get("couchbaseTopic");
List<String> nodes = new ArrayList<>();
nodes.add("localhost");
Cluster cluster = CouchbaseCluster.create(nodes);
final Bucket bucket = cluster.openBucket("kafkaExample");
try {
for (final KafkaStream<byte[], byte[]> stream : streams) {
for (MessageAndMetadata<byte[], byte[]> msgAndMetaData : stream) {
String msg = convertPayloadToString(msgAndMetaData.message());
System.out.println(msgAndMetaData.topic() + ": " + msg);
try {
JsonObject doc = JsonObject.fromJson(msg);
String id = UUID.randomUUID().toString();
bucket.upsert(JsonDocument.create(id, doc));
} catch (Exception ex) {
System.out.println("Not a json object: " + ex.getMessage());
}
}
}
} catch (Exception ex) {
System.out.println("EXCEPTION!!!!" + ex.getMessage());
cluster.disconnect();
}
cluster.disconnect();
}
private static String convertPayloadToString(final byte[] message) {
String string = new String(message);
return string;
}
}
</code></pre>
<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNxsmnq9sI5J-W3sbraSnpr15TTc0qpf7VmKurn-WSe0PixapmRimzyBlD_Ommn-j8kJ0OgV-NDQkC4WFM6eelGenT-HZkGyCf69sFLKqTGYKWLGnihlomcoZPqZG1zofy3jTgXWxXeuxd/s1600/Screen+Shot+2016-02-04+at+14.53.14.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNxsmnq9sI5J-W3sbraSnpr15TTc0qpf7VmKurn-WSe0PixapmRimzyBlD_Ommn-j8kJ0OgV-NDQkC4WFM6eelGenT-HZkGyCf69sFLKqTGYKWLGnihlomcoZPqZG1zofy3jTgXWxXeuxd/s400/Screen+Shot+2016-02-04+at+14.53.14.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Output from the Consumer app</td></tr>
</tbody></table>
<br />
<h2>
Couchbase Server </h2>
Now we can look on the result in Couchbase server.<br />
Look at kafkaExample bucket - Filled with 1000 documents.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsUVyAZQbsjix9LkVjYdhJNykviVpc14xqEEAT66zaqiwjz_HSHDE74oaBU67aj7q6P5J4MrDsDlBvv4vVhQAzzzY5l5WqoHZrGnH_BamxUK1Xo1YISDbRUwG-mQL2GpVOEYGkorMHUuas/s1600/Screen+Shot+2016-02-04+at+14.51.40.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="139" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsUVyAZQbsjix9LkVjYdhJNykviVpc14xqEEAT66zaqiwjz_HSHDE74oaBU67aj7q6P5J4MrDsDlBvv4vVhQAzzzY5l5WqoHZrGnH_BamxUK1Xo1YISDbRUwG-mQL2GpVOEYGkorMHUuas/s640/Screen+Shot+2016-02-04+at+14.51.40.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
Each document looks something like that:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDDaW5tW4-WAZAXqNm0IoQeME6yNdFiGSgitPlsreMW_hh4m5onUxYtjEMprbaJsUxdEe59zlfygJMk13HN3VfBQ4UACTJWNo0-BkRo54_HMBTB06vO494jYdcIU2jL1zOlBZ4lFJpdORt/s1600/Screen+Shot+2016-02-04+at+14.52.04.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="137" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDDaW5tW4-WAZAXqNm0IoQeME6yNdFiGSgitPlsreMW_hh4m5onUxYtjEMprbaJsUxdEe59zlfygJMk13HN3VfBQ4UACTJWNo0-BkRo54_HMBTB06vO494jYdcIU2jL1zOlBZ4lFJpdORt/s640/Screen+Shot+2016-02-04+at+14.52.04.png" width="640" /></a></div>
<br />
Simple 3 part solution.<br />
Note, that on a Production environment, Producer, Consumer, Kafka or Couchbase will be on or more machines each.<br />
<br />
Full (including Maven dependencies) code in <a href="https://github.com/roikatz/kafka-consumer-couchbase">GitHub</a>.<br />
<br />
Roi.Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com3tag:blogger.com,1999:blog-2769632048026714340.post-81154307565820858522016-01-03T18:48:00.001+02:002016-01-07T09:39:52.909+02:00Couchbase Mobile - Part 2 - Couchbase lite views (Indexes!)Hi,<br />
<br />
In the <a href="http://roikatz.blogspot.co.il/2015/12/couchbase-mobile-part-1-couchbase-lite.html">part 1</a> we've built our tiny yet cool application, we've even replicated it to another Couchbase Lite.<br />
<br />
But what now? We want to actually use it!<br />
So how do we use a database? well at least with "getting" the data you have couple of options:<br />
1) Get by primary key<br />
2) Get by an index (or "selecting" it where x)<br />
<br />
Up until now, in our simple sample app we could only use the "primary key" to access our data and retrieve it.<br />
<br />
But it's not the only way to get you data from Couchbase Lite,<br />
In this part we will learn the basics of Couchbase lite indexing. AKA Views.<br />
<div>
<br /></div>
On the the views, we run our Queries.<br />
So we need to:<br />
<br />
1. Create View<br />
2. Run Queries on the view<br />
3. Get the results<br />
<br />
We will built our use case - of how using "views" in Couchbase Lite.<br />
<br />
1. start a new WPF project.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCeHrY6IAoNoJiKe8uKAxrxXOGM76N9nPYWAIRABWlp4CiRqcSlDljHWCwYTuPnwyr8_JQWgoagK4lWjF01LvXWxzeiaTtqu1FYS9AhgHnZQHoLnXC8o2ZLKKGbcpXMCzNUy2QekqQzujh/s1600/Screen+Shot+2015-12-29+at+14.55.37.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="221" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCeHrY6IAoNoJiKe8uKAxrxXOGM76N9nPYWAIRABWlp4CiRqcSlDljHWCwYTuPnwyr8_JQWgoagK4lWjF01LvXWxzeiaTtqu1FYS9AhgHnZQHoLnXC8o2ZLKKGbcpXMCzNUy2QekqQzujh/s320/Screen+Shot+2015-12-29+at+14.55.37.png" width="320" /></a></div>
<br />
<br />
2. Add Nuget Couchbase.Lite package<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijNjQM6C6BYA0V1poPBS5dnrnoH8bKrIeC7lQsxSuUlclKnA0yoQOLzXr1yjsIOuUyQFYa3PFeT0ulPDeF1FNIZNBMQTmklLCTjmOJ_8czIgvH7KbFiOxB9wBVQy3ymRTVywT6L9a101pg/s1600/Screen+Shot+2015-12-29+at+13.17.15.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="158" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijNjQM6C6BYA0V1poPBS5dnrnoH8bKrIeC7lQsxSuUlclKnA0yoQOLzXr1yjsIOuUyQFYa3PFeT0ulPDeF1FNIZNBMQTmklLCTjmOJ_8czIgvH7KbFiOxB9wBVQy3ymRTVywT6L9a101pg/s320/Screen+Shot+2015-12-29+at+13.17.15.png" width="320" /></a></div>
<br />
3. Copy that XAML<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <Window x:Class="CouchbaseLiteViews_Blog.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CouchbaseLiteViews_Blog"
mc:Ignorable="d"
Title="CouchbaseLite Working with views" Height="285.808" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="0" Grid.Row="0" Margin="0 10 0 0">
<Button Content="Insert" Click="InsertDocumentClick" />
<Button Content="Read" Click="GetDocumentClick" />
<Button Content="InsertSomeData!" Click="InsertSomeDataClick" />
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" Margin="0 10 0 0">
<TextBox Text="{Binding DocumentId}" Margin="1"/>
<TextBox Text="{Binding DocumentText}" TextWrapping="Wrap" AcceptsReturn="True" Height="190" VerticalScrollBarVisibility="Visible"/>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Margin="0 10 0 0" Orientation="Horizontal">
<Button Content="GetDocument" Width="100" Margin="1" Click="GetByCityClick"/>
<TextBox Text="{Binding City}" Width="100"/>
</StackPanel>
</Grid>
</Window>
</code></pre>
<br />
Which translates to<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXNsKe1I3laYFqYu8vF2kR_5MUiTwwP-5uZ8K2maqk4Ec30e5IY9-X49FYK_vGE0sodSIKtrbeNrrkE5Y7u3t8nZfWWPVO_UqLk71TiXqeVLPZxb6ms9GpW3Bb20CrRYhsgx_GXCsvUcVX/s1600/Screen+Shot+2016-01-03+at+14.47.11.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXNsKe1I3laYFqYu8vF2kR_5MUiTwwP-5uZ8K2maqk4Ec30e5IY9-X49FYK_vGE0sodSIKtrbeNrrkE5Y7u3t8nZfWWPVO_UqLk71TiXqeVLPZxb6ms9GpW3Bb20CrRYhsgx_GXCsvUcVX/s400/Screen+Shot+2016-01-03+at+14.47.11.png" title="GUI generates form the XAML above" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">GUI generates form the XAML above</td></tr>
</tbody></table>
<br />
4. After you got the basic UI, which you can explore later (nothing much here really), lets go the the actual code.<br />
<br />
After we started all up, and Initialized the Database let us define our views.<br />
In this case I've defined 1 view - just to show how to set things up.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> private void GenerateViews()
{
var docsByCity = _database.GetView("docs_by_city");
docsByCity.SetMap((doc, emit) =>
{
if (doc.ContainsKey("City"))
{
emit(doc["City"], doc);
}
}, "1");
}
</code></pre>
<br />
What you can see here, that once I retrieve a name from the _database I can define a map on it,<br />
a map is basically a projection and filtering.<br />
<br />
In the example above, I've created a view named "docs_by_city",<br />
assigned a delegate, checked if some key ("City") exist and then emitted it to the index.<br />
simple as that.<br />
We've just created our index which for every document contains a property named City - it emits the whole document, you can choose to emit whatever you want, depends on app's requirements.<br />
It can be adjusted for better performance and smaller index size.<br />
Also you can put as your key about any string you would like or compose your index from several properties to target special needs.<br />
<blockquote class="tr_bq">
<b>It's never good to store the entire document in the index as it basically make a copy of the document inside the index. Try to keep your index as small as possible. But if you happen to need some kind of index which has the entire document as a result, for performance it's better to keep the document in the index instead of accessing the result.Document property - to same some round tripping to the database.</b></blockquote>
The number "1" here, it the version of the index, During development if you change the map function you also need to increment that number (in case you haven't deleted the whole database), in order to rebuild the index.<br />
<blockquote class="tr_bq">
There are 2 special queries.<br />
1. Get all documents count. (with _database.DocumentCount)<br />
2. Get all documents. (with _database.CreateAllDocumentsQuery())<br />
</blockquote>
After we defined our view (<b>*index</b>) we can start writing the code and use it.<br />
<br />
The usage, is fairly simple only 5 steps.<br />
<ol>
<li>Get the view</li>
<li>Create a query on the view</li>
<li>Define your criteria on the index</li>
<li>Run it</li>
<li>Read it</li>
</ol>
<div>
In code it's look even simpler</div>
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> private void GetByCityClick(object sender, RoutedEventArgs e)
{
var docsByCity = _database.GetView("docs_by_city");
var query = docsByCity.CreateQuery();
query.StartKey = City;
query.EndKey = City;
var queryResults = query.Run();
MessageBox.Show(string.Format("{0} documents has been retrieved for that query", queryResults.Count));
if (queryResults.Count == 0) return;
var documents = queryResults.Select(result => JsonConvert.SerializeObject(result.Value, Formatting.Indented)).ToArray();
var commaSeperaterdDocs = "[" + string.Join(",", documents) + "]";
DocumentText = commaSeperaterdDocs;
}
</code></pre>
<br />
I want the exact "City" so i've written on start and end key the same value.<br />
I run the query and check if there is any results.<br />
Then I "beautify" the result (for every value) and return that as a JSON array.<br />
<blockquote class="tr_bq">
<b>Please pay attention here that I'm not using result.Document but <u>result.Value</u>, as using the result.Document will not use the index and will go and query the database for each result.<br />so for performance, please use result.key, result.value or result.DocumentId.</b></blockquote>
Now just add that part to generate some data...<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> private void InsertSomeDataClick(object sender, RoutedEventArgs e)
{
var result = MessageBox.Show("Press Yes to insert some data (10 docs)!", "Confirm", MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
var count = _database.DocumentCount;
string[] cities = { "London", "New York", "Tel Aviv" };
var rnd = new Random();
for (int i = 0; i < 10; i++)
{
var id = "document" + (i + count);
var cityIndex = rnd.Next(0, 3);
var properties = new Dictionary<string, string>();
properties.Add("name", "Roi Katz");
properties.Add("City", cities[cityIndex]);
var doc = JsonConvert.SerializeObject(properties);
InsertDocument(id, doc);
}
MessageBox.Show("10 Records inserted");
}
}
</code></pre>
<br />
And we are good to go!<br />
This is how we do a simple view!<br />
Of course we have more to come on Couchbase lite views, it's just the start.<br />
<br />
Of course we do need to create the proper properties,<br />
So for full project, please check my <a href="https://github.com/roikatz/CouchbaseLite_Views/tree/master/CouchbaseLiteViews_Blog">GitHub page</a>.<br />
<br />
Roi.<br />
<br />
<br />
<br />
<br />
<br />Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com1tag:blogger.com,1999:blog-2769632048026714340.post-1455955151560785272015-12-31T16:01:00.004+02:002015-12-31T16:01:58.678+02:00Setting up Couchbase Server to work with Microsoft Active Directory LDAPHi all!<br />
<br />
So you want to authenticate users access to <a href="http://www.couchbase.com/">Couchbase</a> through your <a href="https://msdn.microsoft.com/en-us/library/bb742424.aspx">Active Directory</a> LDAP service.<br />
<br />
Couchbase has that ability.<br />
You can actually map every user to one of three access permissions levels (as for v4.1)<br />
1. Full Admin<br />
2. Read Only<br />
3. No access<br />
<br />
I assume the following:<br />
1.You already have an Active Directory up and running<br />
<i>If not, please refer to <a href="http://www.rackspace.com/knowledge_center/article/installing-active-directory-on-windows-server-2012" target="_blank">here</a> or <a href="http://sharepointgeorge.com/2012/configuring-active-directory-ad-ds-in-windows-server-2012/" target="_blank">here</a> for setup instructions.</i><br />
2. You already have Couchbase already installed (on a Linux Distro)<br />
<i>If not, please refer to those guides: <a href="http://docs.couchbase.com/admin/admin/Install/RHEL-install-intro.html" target="_blank">RHEL</a> or <a href="http://docs.couchbase.com/admin/admin/Install/Ubuntu-install.html" target="_blank">Debian</a></i><br />
<br />
As for v4.1 of Couchbase, only the Linux distros support the LDAP, it's not available on Windows nor MacOS.<br />
<br />
<blockquote class="tr_bq">
My setup here is an Azure Windows server 2012 R2 VM with Active Directory and a local Ubuntu 14.04.3 LTS VM with Couchbase v4.1 installed.</blockquote>
<br />
<br />
In the setting of your Linux Couchbase you will find a tab called LDAP Auth Setup<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSrcqubGEL4hx_G0FRR2Q7q3wfbXZsPMR-QlgZ6KKzndg9Rwa_BAWczXdm3JbjyjkC15t_y8VQrpwwL_FugbAqlRi3xpG5J28pcYVh7pIsdl5YYTvvexfmcmJmG-zcRrfn8deV0pIZBJTr/s1600/Screen+Shot+2015-12-31+at+11.36.17.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="252" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSrcqubGEL4hx_G0FRR2Q7q3wfbXZsPMR-QlgZ6KKzndg9Rwa_BAWczXdm3JbjyjkC15t_y8VQrpwwL_FugbAqlRi3xpG5J28pcYVh7pIsdl5YYTvvexfmcmJmG-zcRrfn8deV0pIZBJTr/s400/Screen+Shot+2015-12-31+at+11.36.17.png" width="400" /></a></div>
<br />
<blockquote class="tr_bq">
To fully understand how the LDAP authentication works with Couchbase,<br />please read Couchbase's <a href="http://developer.couchbase.com/documentation/server/4.0/security/security-ldap-new.html" target="_blank">documentation</a>.</blockquote>
<br />
So first thing first, install the <a href="http://developer.couchbase.com/documentation/server/4.0/security/security-saslauthd-new.html" target="_blank">saslauthd</a><br />
Pay attention if you are using RHEL or Ubutntu, paths and instructions are a bit different.<br />
<br />
TL;DR version in Ubuntu<br />
1. sudo apt-get update<br />
2. sudo apt-get install sasl2-bin<br />
3. sudo nano /etc/default/saslauthd<br />
4. Change START=yes, MECHANISMS="ldap"<br />
5. Save and quit (ctrl+x)<br />
6. switch to sudo (sudo -u)<br />
7. change permission for /var/run/saslauthd and /var/run/saslauthd/mux to 755 so couchbase user can access them.<br />
8. cd to /etc folder<br />
9. if saslauthd.conf does not exist - touch it and add 755 permissions.<br />
10. configure the file as follows:<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> ldap_servers: ldap://yourmachineaddress:389
ldap_search_base: dc=couchbase,dc=org
ldap_filter: (sAMAccountName=%u)
ldap_bind_dn: CN=[admin user],CN=Users,DC=couchbase,DC=org
ldap_password: [admin password]
ldap_auth_method: bind
ldap_version: 3
ldap_use_sasl: no
ldap_restart: yes
ldap_deref: no
ldap_start_tls: no
</code></pre>
<br />
<b>ldap_servers</b> is your AD server<br />
<b>ldap_search_base</b> is on what domain you would like to search users (here it's couchbase.org on AD)<br />
<b>ldap_filter </b>is what you want to return<br />
<b>ldap_bind_dn</b> is a user with admin privileges permissions who can search the AD user tree.<br />
<b>ldap_password</b> the admin user password<br />
<br />
11. Open <a href="https://technet.microsoft.com/en-us/library/dd772723(v=ws.10).aspx" target="_blank">Active Directory ports</a> for LDAP, 389 (TCP+UDP), 3268,3269, 636 (UDP)<br />
12. You can test your active directory connection with <a href="http://jxplorer.org/" target="_blank">JXplorer</a><br />
13. Restart your salsauthd service - sudo service saslauthd restart<br />
14. Test it! - sudo -u couchbase /usr/sbin/testsaslauthd -u <username> -p mypassword -f /var/run/saslauthd/mux</username><br />
15. if you have permissions and set it all up as above you should get a success message.<br />
the username and the password here are the ones you want to check, not the ldap admin.<br />
<br />
now let's use it on the Couchbase console!<br />
1. Login to your cluster management console and hit settings -> LDAP Auth setup.<br />
2. Enable LDAP<br />
3. Choose your default behavior - if you don't specify the username anywhere<br />
4. Write down some users or groups in each box<br />
5. Hit save<br />
6. Test it (on the right)<br />
7. If everything is ok - you should get something like "user 'x' has 'Full Admin' access<br />
because I've listed that user under the Full Admin.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT3i0oTkYfkT6UbZvcuuOCDWIeS_OTPnEtZoFph9u6VRHOdG8nAsODOdG_mtGktO0KZL_QU3btyp3mvBJDU3E6HlAlqYm-LDXiZWf4MJW4JolgFGU3AZYJW0H2RblA-vv7rjCxJGeg-TK9/s1600/Screen+Shot+2015-12-31+at+12.54.11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="266" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT3i0oTkYfkT6UbZvcuuOCDWIeS_OTPnEtZoFph9u6VRHOdG8nAsODOdG_mtGktO0KZL_QU3btyp3mvBJDU3E6HlAlqYm-LDXiZWf4MJW4JolgFGU3AZYJW0H2RblA-vv7rjCxJGeg-TK9/s400/Screen+Shot+2015-12-31+at+12.54.11.png" width="400" /></a></div>
<br />
8. now sign out and try logging in with the Active Directory Credentials.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjijVxlAbE8tG3b22P5V5VRo1nN14mZtds3oQvDkqhR-1xULTDlITdr6u_PhVuBRu4JMTK-MOVQnJGO_deZQuLrdykZ52p5l_PZHlltzndkd10xKE-m4KSqW5RXc20BmFEBz5PRLf83vGtC/s1600/Screen+Shot+2015-12-31+at+16.00.18.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="152" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjijVxlAbE8tG3b22P5V5VRo1nN14mZtds3oQvDkqhR-1xULTDlITdr6u_PhVuBRu4JMTK-MOVQnJGO_deZQuLrdykZ52p5l_PZHlltzndkd10xKE-m4KSqW5RXc20BmFEBz5PRLf83vGtC/s320/Screen+Shot+2015-12-31+at+16.00.18.png" width="320" /></a></div>
<br />
If I will get the password wrong - I won't be able to access, as expected.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihBjS5rjHJyNrcV6MGufVNNH5XjK9gHQ5u2sM2EHhBOflE-M8_bmLSpy7TxZvN0TTLiCvSRi5mGHk4E3iQrbIYori0tSBpHSDbWTrjwAo4ZUQYl0YEiXiZgNhzkgoSeAiylhaFbW7FGzwt/s1600/Screen+Shot+2015-12-31+at+16.00.27.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="168" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihBjS5rjHJyNrcV6MGufVNNH5XjK9gHQ5u2sM2EHhBOflE-M8_bmLSpy7TxZvN0TTLiCvSRi5mGHk4E3iQrbIYori0tSBpHSDbWTrjwAo4ZUQYl0YEiXiZgNhzkgoSeAiylhaFbW7FGzwt/s320/Screen+Shot+2015-12-31+at+16.00.27.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
In case you AD server is unreachable, you would still be able to log in through your regular Couchbase accounts.<br />
<br />
<br />
<br />
Thats all!<br />
Hope you enjoyed.<br />
<br />
Roi.<br />
<br />
<br />
<br />
<br />Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-38711176405094819562015-12-24T15:09:00.001+02:002015-12-24T15:21:18.765+02:00Couchbase Mobile - Part 1 - Couchbase lite & P2PHi all<br />
Couchbase Mobile solution is thrilling innovative and yet fairly simple - it just works!<br />
<br />
In this blog we will cover the Couchbase Lite peer-to-peer capabilities, how<br />
you can very easily, to connect two Couchbase Lite databases from two different<br />
devices together using the built in replication.<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCVSpA48ageKu7wJQF13Zjvb1KR5YFz7yeRAmwQa3DoBLmuFVYUPb0mE8Cj451yHLdkCZ244HWUQxmw4a512N-CcfLs5CwPtjZO3SXTtsy-MtwqcBCxUzF-kEfoYuuiwDo34QstL8jHmRk/s1600/Screen+Shot+2015-12-24+at+08.01.57.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCVSpA48ageKu7wJQF13Zjvb1KR5YFz7yeRAmwQa3DoBLmuFVYUPb0mE8Cj451yHLdkCZ244HWUQxmw4a512N-CcfLs5CwPtjZO3SXTtsy-MtwqcBCxUzF-kEfoYuuiwDo34QstL8jHmRk/s320/Screen+Shot+2015-12-24+at+08.01.57.png" width="163" /></a>In general the <a href="http://developer.couchbase.com/mobile/" target="_blank">Couchbase's Mobile </a>solution consists of 3 parts,<br />
1) <a href="http://www.couchbase.com/nosql-databases/couchbase-server" target="_blank">Couchbase Server</a><br />
2) <a href="http://developer.couchbase.com/documentation/mobile/1.1.0/get-started/sync-gateway-overview/index.html" target="_blank">Sync Gateway</a><br />
3) <a href="http://developer.couchbase.com/documentation/mobile/1.1.0/get-started/couchbase-lite-overview/index.html" target="_blank">Couchbase Lite</a><br />
<br />
Couchbase server holding all the data and can be synced through Sync Gateway to the Embedded Couchbase lite and vice versa.<br />
<br />
On this part I will focus on the Couchbase Lite and how to set up P2P replication on .Net platform (but it's pretty much the same on every other platform)<br />
<br />
So before we get into some coding, what is Couchbase Lite?<br />
Couchbase lite is an <a href="https://github.com/search?utf8=%E2%9C%93&q=couchbase+lite&type=Repositories&ref=searchresults" target="_blank">opened-source</a>, embedded document database with built-in abilities of Key/Values store, Indexing (aka Views), and above all - Replication.<br />
Replication is what making that little Database so special.<br />
I can replicate itself to the sync gateway or to any other Couchbase Lite database,<br />
It features security through authentication and segregation of data from one device to another via concept that called channels.<br />
<br />
What is replication? as it sounds - duplicate\copy data from one local database to another target, which can be either another local database or the sync gateway.<br />
The API which the replication is using is basically a REST API, which every Couchbase lite is implementing.<br />
<br />
So let's build a simple App that replicates data between two peers!<br />
as I said, I've used C# .Net here (don't run away :) ), but the code is actually pretty much the same in Java.<br />
To properly test that project, you might have to use two computers in a network.<br />
but, because we will create the database locally in the folder of the app, a copy to a different location and using separate ports will be ok as well.<br />
<br />
First of all, Open Visual Studio 2015 (can be community) as an administrator, In a simple WPF form.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj49wgG78BeTI0siiXKPX8JulY47V6ZpcqlnrX5cs6G7rO3yKqSJQArWWCAXCfBJvh5Ao5gX7jm7_Dk3xKFBkWxI2zrWCsKggtVcmOMVVmQ8fVVTW48XSY4t52JX7TTwKaNVjdr14JqG9UJ/s1600/Screen+Shot+2015-12-24+at+11.27.04.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj49wgG78BeTI0siiXKPX8JulY47V6ZpcqlnrX5cs6G7rO3yKqSJQArWWCAXCfBJvh5Ao5gX7jm7_Dk3xKFBkWxI2zrWCsKggtVcmOMVVmQ8fVVTW48XSY4t52JX7TTwKaNVjdr14JqG9UJ/s320/Screen+Shot+2015-12-24+at+11.27.04.png" width="320" /></a></div>
<br />
right click on References -> Manage Nuget Packages...<br />
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfYmkB11cC6K40cZM3AXNhwycF-dnFPrqR-MiNRU2W21Z9b_Y2YCsP7nLYKq7SynYtP6uOBzoHKYjaDDtPk2Bc9Lp_sep7bI1B9TI_eT7zAHNMARxosVk-uQQq_sgEAHzd8E5kG7BRaHni/s1600/Screen+Shot+2015-12-24+at+11.29.38.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="304" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfYmkB11cC6K40cZM3AXNhwycF-dnFPrqR-MiNRU2W21Z9b_Y2YCsP7nLYKq7SynYtP6uOBzoHKYjaDDtPk2Bc9Lp_sep7bI1B9TI_eT7zAHNMARxosVk-uQQq_sgEAHzd8E5kG7BRaHni/s320/Screen+Shot+2015-12-24+at+11.29.38.png" width="320" /></a></div>
Next, add the Couchbase Lite which is available via nuget package.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZkAMnvboDMDaRZtsVLHZtAoIIaRjoeJFQOAjqM3EOuKATo95Yqhc5ut6ncU5i4tS_sy4hy2gutOJOgOPQXAw_Wtygd__g6vN6lmHZUFV0890rCd85NgE4YedauTISu8r2FXku8YcP-BA4/s1600/Screen+Shot+2015-12-24+at+11.30.23.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="127" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZkAMnvboDMDaRZtsVLHZtAoIIaRjoeJFQOAjqM3EOuKATo95Yqhc5ut6ncU5i4tS_sy4hy2gutOJOgOPQXAw_Wtygd__g6vN6lmHZUFV0890rCd85NgE4YedauTISu8r2FXku8YcP-BA4/s320/Screen+Shot+2015-12-24+at+11.30.23.png" width="320" /></a></div>
<br />
<br />
<br />
Search for Couchbase Lite and install the latest Couchbase.Lite and Couchbase.Lite.Listener.<br />
at the time of the writing of this blog, the latest is 1.1.2.<br />
<br />
Once installed, Copy and paste the following code to your MainWindow XAML page.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <Window x:Class="CouchbaseP2P_Blog.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CouchbaseP2P_Blog"
mc:Ignorable="d"
Title="Couchbase Lite P2P Example" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0">
<TextBlock Text="Replicate to (address): " Margin="1"/>
<TextBlock Text="Replicate to (port): " Margin="1"/>
<TextBlock Text="Listen On Port" Margin="1"/>
<Button Content="Start Replicating" Click="StartReplcatingClick"/>
<Button Content="Start P2P Listener" Click="StartListenerClick"/>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1">
<TextBox Text="{Binding ReplicateToAddress}" />
<TextBox Text="{Binding ReplicateToPort}"/>
<TextBox Text="{Binding ListenOnPort}"/>
<TextBlock Text="{Binding IsReplicating}" Margin="1"/>
<TextBlock Text="{Binding IsListening}" Margin="1"/>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="1" Margin="0 10 0 0">
<Button Content="Insert" Click="InsertDocumentClick" />
<Button Content="Read" Click="GetDocumentClick" />
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" Margin="0 10 0 0">
<TextBox Text="{Binding DocumentId}" Margin="1"/>
<TextBox Text="{Binding DocumentText}" TextWrapping="Wrap" AcceptsReturn="True" MinHeight="100"/>
</StackPanel>
</Grid>
</Window>
</code></pre>
<br />
That code above, should look similar to the following output<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG4kfLeOZQAyH3camPBcVAAs2ekycDTEBTEet940Kh8uHwExIZpFgSdbRgqmE8MX1OebTk2v383eGFhFGV29DC5pgm5zROhyphenhyphenzSbTejUxTtE5EfYNr1anvfuBxTF7l3L0STRMDdDv7ZGItc/s1600/Screen+Shot+2015-12-24+at+14.37.01.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG4kfLeOZQAyH3camPBcVAAs2ekycDTEBTEet940Kh8uHwExIZpFgSdbRgqmE8MX1OebTk2v383eGFhFGV29DC5pgm5zROhyphenhyphenzSbTejUxTtE5EfYNr1anvfuBxTF7l3L0STRMDdDv7ZGItc/s400/Screen+Shot+2015-12-24+at+14.37.01.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<br />
Next we need to connect the XAML doc to the CodeBehind.<br />
That sample is not MVVM for simplicity - but I did used binding.<br />
<br />
First lets initialize the Database and set it to be created locally in our working folder,<br />
We will call that method from the constructor.<br />
Steps are,<br />
<ol>
<li> Get the path where you want your database to be created</li>
<li>Create manager with that path</li>
<li>Initialize Database with the manager.</li>
</ol>
<div>
<i style="background-color: yellow;">Note: the const DB_NAME in our case will be "sampledb" and it must have all lowercase letter.</i></div>
<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> private void InitializeDatabase()
{
_dbPath = new DirectoryInfo(Environment.CurrentDirectory);
_manager = new Manager(_dbPath, ManagerOptions.Default);
_database = _manager.GetDatabase(DB_NAME);
}
</code></pre>
<br />
Add code to start Couchbase Lite Listener<br />
Just create a new listener with the wanted port and the desired database name.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> private void StartListenerClick(object sender, RoutedEventArgs e)
{
_listener = new CouchbaseLiteTcpListener(_manager, ushort.Parse(ListenOnPort), DB_NAME);
_listener.Start();
IsListening = "Listening";
}
</code></pre>
<br />
And lastly - the code for our replication<br />
Steps are:<br />
<br />
<ol>
<li>Create pull/push replication to address and port</li>
<li>Decide whether you want continuous replication of one time</li>
<li>Start the replication.</li>
</ol>
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> private void StartReplcatingClick(object sender, RoutedEventArgs e)
{
try
{
if (_pulls == null) _pulls = new List<replication>();
if (_pushes == null) _pushes = new List<replication>();
var pull = _database.CreatePullReplication(CreateSyncUri(ReplicateToAddress, int.Parse(ReplicateToPort), DB_NAME));
var push = _database.CreatePushReplication(CreateSyncUri(ReplicateToAddress, int.Parse(ReplicateToPort), DB_NAME));
pull.Continuous = true;
push.Continuous = true;
pull.Start();
push.Start();
_pulls.Add(pull);
_pushes.Add(push);
IsReplicating = "Replicaing!";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private Uri CreateSyncUri(string hostname, int port, string dbName)
{
Uri syncUri = null;
string scheme = "http";
try
{
var uriBuilder = new UriBuilder(scheme, hostname, port, dbName);
syncUri = uriBuilder.Uri;
}
catch (UriFormatException e)
{
Debug.WriteLine(string.Format("{0}: Cannot create sync uri = {1}", dbName, e.Message));
}
return syncUri;
}
</replication></replication></code></pre>
<br />
Lets add a bit of code for Insert and Get<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> private void InsertDocumentClick(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(DocumentId))
{
MessageBox.Show("Please specify ID");
return;
}
var document = _database.GetDocument(DocumentId);
var properties = JsonConvert.DeserializeObject<Dictionary<string, object>>(DocumentText);
var revision = document.PutProperties(properties);
}
private void GetDocumentClick(object sender, RoutedEventArgs e)
{
var doc = _database.GetDocument(DocumentId);
DocumentText = JsonConvert.SerializeObject(doc.Properties, Formatting.Indented);
}
</code></pre>
<br />
All we have to do now is to connect all the bindings you see in the XAML page and to implement INotifyPropertyChanged<br />
<br />
Here is the <a href="https://github.com/roikatz/CouchbaseLiteP2P/blob/master/CouchbaseP2P_Blog/MainWindow.xaml.cs" target="_blank">full Code Behind</a><br />
The full project can be found on <a href="https://github.com/roikatz/CouchbaseLiteP2P" target="_blank">Github</a><br />
<br />
Now, in order to use it and test your replication, follow the following steps:<br />
<br />
<ol>
<li>Copy your executable folder to 2 different folders (i.e. Client1 and Client2)</li>
<li>Start both clients under Administrator privileges</li>
<li>Configure Client1 listening Port as 49840</li>
<li>Configure Client2 listening Port as 49841</li>
<li>Configure Client1 replication address to localhost and port 49841</li>
<li>Configure Client2 replication address to localhost and port 49840</li>
<li>Once it started replicating, Add a sample JSON with an ID on Client1 and test it on Client2<br />and vice versa.</li>
</ol>
<br />
<br />
That's all!<br />
We've built our first Couchbase lite replication in c# without all the fuss and hard work of the replication logic!<br />
<br />
Next time - A bit more of Coucbase lite replications and deep dive into views.<br />
<br />
Please check API, and quickstarts <a href="http://developer.couchbase.com/documentation/mobile/1.1.0/get-started/couchbase-mobile-overview/index.html" target="_blank">here</a><br />
<br />
Merry xmas!<br />
Roi.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://images.clipartpanda.com/xmas-clip-art-biyE6LyiL.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://images.clipartpanda.com/xmas-clip-art-biyE6LyiL.png" height="200" width="141" /></a></div>
<br />
<br />
<br />Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com1tag:blogger.com,1999:blog-2769632048026714340.post-14187502901580013592015-11-26T12:07:00.000+02:002015-11-26T12:33:13.422+02:00Using the Spark Connector for Couchbase - Part 1<div class="MsoNormal">
Hi all!</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">This is the first post
from a series of how using <a href="http://www.couchbase.com/" target="_blank">Couchbase</a> with <a href="https://spark.apache.org/" target="_blank">Apache Spark</a>.<br />
In this post I will explain how to set up the environment, and how to use Spark
with Couchbase in the simplest form.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">In the next posts we
will continue on to the <a href="http://spark.apache.org/sql/" target="_blank">SparkSQL</a> with <a href="http://www.couchbase.com/n1ql" target="_blank">N1QL</a> world, and the exciting Spark
Streaming with <a href="http://docs.couchbase.com/admin/admin/Concepts/dcp.html" target="_blank">DCP</a> and more.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">Our world, "Big Data", is divided.</span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">As obscure as Big Data may
sound – and is, there are 2 major parts on every data analysis.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">The first is the
operational side, That is what you need in order to get the work done – in real
time those are Databases such as Couchbase.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">The Second part is the heavy
lifting of aggregation large amount of data,<br />
those are platforms such as Apache Hadoop or Spark.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">Couchbase integrates with
both in order to achieve the full solution, In that post and in others to follow –
I will work you through how to do you first steps and more, integrating
your Couchbase server – with Spark – with ease.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">I'm assuming that you
already know at least a little bit on Spark,<br />
But if not – in one sentence<span style="mso-spacerun: yes;"> </span>Apache
Spark is an open source cluster computing framework.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">It’s main Data structure
call RDD and I’m encouraging you to read the Spark developer guide.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">The demo we are going to
build will be in Spark “Native” language, which is Scala, <br />
Don’t panic, that is fairly simple! <br style="mso-special-character: line-break;" />
<!--[if !supportLineBreakNewLine]--><br style="mso-special-character: line-break;" />
<!--[endif]--><o:p></o:p></span></div>
<div class="MsoNormal">
<u><span style="mso-bidi-language: HE;">Software needed:<o:p></o:p></span></u></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;"><a href="https://www.jetbrains.com/idea/download/" target="_blank">IDE: IntelliJ Idea 15 with SBT Plugin</a><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;"><a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html" target="_blank">Java</a>: 1.8<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;"><a href="http://www.scala-lang.org/download/" target="_blank">Scala</a>: 2.10.4
(important!)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;"><a href="http://www.couchbase.com/nosql-databases/downloads?gtmRefId=FixedCTA-Download" target="_blank">Couchbase: 4.0 </a>with travel-sample
bucket installed<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;"><a href="http://spark.apache.org/" target="_blank">Spark</a>: 1.5.x or greater<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;"><a href="https://github.com/couchbase/couchbase-spark-connector/" target="_blank">Couchbase Sparkconnector</a>: 1.0 <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">So first thing first.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="mso-bidi-language: HE;">If you already know Spark
or Scala you can skip the set up phase.<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<u>Setting up the Project<o:p></o:p></u></div>
<div class="MsoNormal">
Let's open the IDE and
start a new project of type Scala with SBT<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiU2XYISCALp83Opa_TBq5WiyrxUCIHcsS82xE1RBFWJkkmRVYi7rH-oymMBSuxchhvGKb00At2ZZwt8Dq1HFDX1pa0sBiQEvj_wc9mwXpqaB791vls0nPcb-sdF-C95HRDKbCp0LQ02Tsz/s1600/Screen+Shot+2015-11-12+at+12.07.44.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="275" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiU2XYISCALp83Opa_TBq5WiyrxUCIHcsS82xE1RBFWJkkmRVYi7rH-oymMBSuxchhvGKb00At2ZZwt8Dq1HFDX1pa0sBiQEvj_wc9mwXpqaB791vls0nPcb-sdF-C95HRDKbCp0LQ02Tsz/s400/Screen+Shot+2015-11-12+at+12.07.44.png" width="400" /></a></div>
<div>
<br /></div>
<br />
<div class="MsoNormal">
Hit next and choose the
name of the project, Project SDK (at least 1.7) SBT version (whatever you have
it’s fine, here I’ve used 0.13.8) and the Scala Version as 2.10.4 (any 2.10
will be fine).<br />
<br />
Check the auto-import and click finish.<br />
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4EYwbK8nXJ8uyF_hDsfi3A_dp119QsaZc1-PYNxOWyUaQIlvdliSr6zpCfXWQhhHWyV0SE1WO7B7zsmleO8gxIdMb0VxisQdOgvVQtqCyjc0p2aDiwU90yaqhB_9HWXZmn82jyNalvs59/s1600/Screen+Shot+2015-11-11+at+11.19.17.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="275" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4EYwbK8nXJ8uyF_hDsfi3A_dp119QsaZc1-PYNxOWyUaQIlvdliSr6zpCfXWQhhHWyV0SE1WO7B7zsmleO8gxIdMb0VxisQdOgvVQtqCyjc0p2aDiwU90yaqhB_9HWXZmn82jyNalvs59/s400/Screen+Shot+2015-11-11+at+11.19.17.png" width="400" /></a></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Next, set up the build.sbt
file under the module root.<br />
SBT stands for Scala Build Tool, and function also as a dependencies resolver,
A bit like Maven. It also connects to the same repository as Maven.<br />
After you define the properties on this file, the SBT plugin will download the
required dependencies.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The simple structure or
the SBT is as follows:<br />
1) name of the project “name := someProjectName”<o:p></o:p></div>
<div class="MsoNormal">
2) version of your
project “version := 1.0”<o:p></o:p></div>
<div class="MsoNormal">
3) Scala version which
you’ll be using “scalaVersion := “2.10.4”<o:p></o:p></div>
<div class="MsoNormal">
4) list of dependencies (from
maven repository) <o:p></o:p></div>
<div class="MsoNormal">
“libraryDependencies ++= Seq( “groupId” % “artifactId” % “revision”)”<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
our sbt file will look
like that:<o:p></o:p></div>
<div class="MsoNormal" style="background: white; margin-bottom: 12.0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<i><span style="color: #660e7a; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">name </span></i><span style="font-family: "menlo"; font-size: 8pt;">:= </span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"SparkCouchbase"<br />
<br />
</span></b><i><span style="color: #660e7a; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">version </span></i><span style="font-family: "menlo"; font-size: 8pt;">:= </span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"1.0"<br />
<br />
</span></b><i><span style="color: #660e7a; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">scalaVersion </span></i><span style="font-family: "menlo"; font-size: 8pt;">:=
</span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"2.10.4"<br />
<br />
</span></b><i><span style="color: #660e7a; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">libraryDependencies </span></i><span style="font-family: "menlo"; font-size: 8pt;">++=
</span><i><span style="color: #660e7a; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">Seq </span></i><span style="font-family: "menlo"; font-size: 8pt;">(</span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"org.apache.spark"
</span></b><span style="font-family: "menlo"; font-size: 8pt;">% </span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"spark-core_2.10" </span></b><span style="font-family: "menlo"; font-size: 8pt;">%
</span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"1.5.1"</span></b><span style="font-family: "menlo"; font-size: 8pt;">,<br />
</span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"org.apache.spark"
</span></b><span style="font-family: "menlo"; font-size: 8pt;">% </span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"spark-sql_2.10" </span></b><span style="font-family: "menlo"; font-size: 8pt;">%
</span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"1.5.1"</span></b><span style="font-family: "menlo"; font-size: 8pt;">,<br />
</span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"org.apache.spark"
</span></b><span style="font-family: "menlo"; font-size: 8pt;">% </span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"spark-streaming_2.10" </span></b><span style="font-family: "menlo"; font-size: 8pt;">%
</span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"1.5.1"</span></b><span style="font-family: "menlo"; font-size: 8pt;">,<br />
</span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"com.couchbase.client"
</span></b><span style="font-family: "menlo"; font-size: 8pt;">%% </span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"spark-connector" </span></b><span style="font-family: "menlo"; font-size: 8pt;">%
</span><b><span style="color: green; font-family: "menlo"; font-size: 8.0pt; mso-bidi-font-size: 12.0pt;">"1.0.0"</span></b><span style="font-family: "menlo"; font-size: 8pt;">)<o:p></o:p></span></div>
<div class="MsoNormal">
<u>note:</u> the double
%% means that the Scala version will be taken from the variable defined in
scalaVersion<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
the dependencies are as
follows:<o:p></o:p></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
</div>
<ol>
<li><span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; text-indent: -0.25in;"> </span><span style="text-indent: -0.25in;">The Spark
code dependency compiled for Scala 2.10 in version 1.5.1</span></li>
<li><span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; text-indent: -0.25in;"> </span><span style="text-indent: -0.25in;">The Spark SQL dependency compiled for Scala 2.10 in version 1.5.1</span></li>
<li><span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; text-indent: -0.25in;"> </span><span style="text-indent: -0.25in;">The streaming
for Spark compiled for Scala 2.10 in version 1.5.1</span></li>
<li><span style="text-indent: -0.25in;">The great Couchbase
connector to Spark, compiled for Scala 2.10 (from the scalaVersion) in version
1.0.0</span></li>
</ol>
<span style="background-color: lime;">for more about dependencies look <a href="http://mvnrepository.com/artifact/org.apache.spark/spark-core_2.10">here</a></span><br />
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Next, we need to take
care on the directory structure.<br />
If we don’t set the correct structure, the SBT plugin won’t be able to compile
our project.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
So create new Directory
under the module named src/main/scala,<o:p></o:p></div>
<div class="MsoNormal">
and mark the Scala folder
as sources (bluish colored).<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Your project structure
should look more or less as follows:</div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3ryPY1i919LiWl1mtOGXq9H2wmlRkK02mgjcrcR2tSGEeX9CaERnDzEjxmF2k5-N5H5cGzzjt73i7Z5bazgkgN85MK4pLzisxqKER2Z4x64kMql8tCwhdP89nO3So7DvH1XBhJwn65seN/s1600/Screen+Shot+2015-11-12+at+12.46.21.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="305" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3ryPY1i919LiWl1mtOGXq9H2wmlRkK02mgjcrcR2tSGEeX9CaERnDzEjxmF2k5-N5H5cGzzjt73i7Z5bazgkgN85MK4pLzisxqKER2Z4x64kMql8tCwhdP89nO3So7DvH1XBhJwn65seN/s320/Screen+Shot+2015-11-12+at+12.46.21.png" width="320" /></a></div>
<div class="MsoNormal">
</div>
<div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now after we set
everything up it’s time for some coding!<o:p></o:p></div>
<span style="font-family: "calibri"; font-size: 12.0pt; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-language: HE; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><br clear="all" style="mso-special-character: line-break; page-break-before: always;" />
</span>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<u>Coding</u><o:p></o:p></div>
<div class="MsoNormal">
Finally, some coding.<o:p></o:p></div>
<div class="MsoNormal">
After you see that the little
bar of the sbt has finished downloading the dependencies package you can start
writing your program.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
First make sure that you already
have the Couchbase server installed with the travel-sample bucket.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now, create a new Scala
Object in the Scala source folder with the name of your liking,<o:p></o:p></div>
<div class="MsoNormal">
I chose
SparkCouchbase.scala<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Next, create a main
function so your code will look like that<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> object SparkCouchbase {
def main(args: Array[String]): Unit ={
}
}
</code></pre>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
So far, what we’ve
created here is an Object (think of is as a singleton class), and a method main
which gets an array of String and return Unit (which is basically nothing)<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now we need to add the
sparky flavor.<o:p></o:p></div>
<div class="MsoNormal">
In order to do so, we
need to add some imports that were downloaded earlier by the SBT auto import.<br />
We need the basic spark package<o:p></o:p></div>
<pre style="background: white;"><b><span style="color: navy; font-family: "menlo"; font-size: 10.5pt; mso-bidi-font-size: 12.0pt;">import </span></b><span style="font-family: "menlo"; font-size: 10.5pt;">org.apache.spark._<o:p></o:p></span></pre>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
we need the basic Couchbase
to spark connector package<o:p></o:p></div>
<pre style="background: white;"><b><span style="color: navy; font-family: "menlo"; font-size: 10.5pt; mso-bidi-font-size: 12.0pt;">import </span></b><span style="font-family: "menlo"; font-size: 10.5pt;">com.couchbase.spark._<o:p></o:p></span></pre>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
and Json document and
object extension packages<o:p></o:p></div>
<pre style="background: white;"><b><span style="color: navy; font-family: "menlo"; font-size: 10.5pt; mso-bidi-font-size: 12.0pt;">import </span></b><span style="font-family: "menlo"; font-size: 10.5pt;">com.couchbase.client.java.document.JsonDocument
</span><b><span style="color: navy; font-family: "menlo"; font-size: 10.5pt; mso-bidi-font-size: 12.0pt;">import </span></b><span style="font-family: "menlo"; font-size: 10.5pt;">com.couchbase.client.java.document.json.JsonObject<o:p></o:p></span></pre>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
4 imports in total, plus
we need the spark init and configuration, which defining the application name,
spark cluster location, what bucket we want to connect to in Couchabse, or the
node addresses.<o:p></o:p></div>
<div class="MsoNormal">
Finally, we must have the
SparkContext, in order to use spark framework<o:p></o:p></div>
<div class="MsoNormal">
so our code will look
like that,<o:p></o:p></div>
<div class="MsoNormal">
please not, if you don’t
specify a bucket – the connector will go to the default bucket, and if you don’t
specify an address for the nodes, it will try to find Couchbase in the
localhost (127.0.0.1).<o:p></o:p><br />
<br /></div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> import org.apache.spark._
import com.couchbase.spark._
import com.couchbase.client.java.document.JsonDocument
import com.couchbase.client.java.document.json.JsonObject
object SparkCouchbase {
def main(args: Array[String]): Unit ={
val sparkConf = new SparkConf().setAppName("CouchbaseTricks")
.setMaster("local[*]")
.set("com.couchbase.bucket.travel-sample","")
.set("com.couchbase.bucket.default","")
.set("com.couchbase.nodes","127.0.0.1")
val sc = new SparkContext(sparkConf)
}
}
</code></pre>
<br />
So we set the app name,
CouchbaseTricks, the cluster (local cluster-testing with x number of nodes as
the number of cores), which buckets we want to connect to (travel-sample,
default) and the nodes in the cluster.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now we need to do
something with it. Like Getting some documents.<o:p></o:p></div>
<div class="MsoNormal">
We will do it using the
couchbaseGet from the context.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Let’s get some major
airports: Heathrow, SF international and Los Angeles international and others,
and print their code and name with country.<o:p></o:p></div>
<div class="MsoNormal">
Then save it back to Couchbase,
default bucket, as our major airports.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We will use two methods
from the Couchbase connector, the couchbaseGet and saveToCouchbase.<o:p></o:p></div>
<div class="MsoNormal">
The first get a scala
sequence of documents from Couchbase and parallelize them (making them an RDD),
this method under your spark context.<br />
The Latter saves an RDD to Couchbase.<span dir="RTL" lang="HE" style="font-family: "times new roman"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-language: HE; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Let’s look at the code
and break it down a bit<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jutZy5ae9XOcdQRH4FL-qzq4CK-R6OXA5JylhxXx02qa_BB5c1yR1Bkyou_XDzUiQJWUvpJc4HKO0yMPUdaO8CYo3PfSZZ1kVpMpIFht4zqrvwPbcEfiNr1qZAsowiFo1j1hQ8noG92w/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> val airportsSeq = Seq("airport_507", "airport_3469", "airport_3484", "airport_3797", "airport_3576", "airport_502", "airport_1382") // Heathrow, SFO, LAX, JFK, MIA, LGW, CDG
val airports: RDD[JsonDocument] = sc.couchbaseGet[JsonDocument](airportsSeq ,"travel-sample" )
val airportsByCountry = airports.map(airport => (airport.content().getString("country"), 1)) // map
val majorAirportCount = airportsByCountry.reduce((a,b) => ("Total airport Number", a._2 + b._2))
airports.map(myDocument => {
val id = "mymajorairports::2015::" + myDocument.id()
val content = JsonObject.create().put("name", myDocument.content().getString("airportname"))
.put("country", myDocument.content().get("country"))
.put("code", myDocument.content().getString("faa"))
JsonDocument.create(id, content)
}).saveToCouchbase("default",StoreMode.UPSERT)
</code></pre>
<br />
So now we've just wrote our first Spark application with Couchbase (or maybe ever!).<br />
Simple Spark init, simple reduce function, with get and set to the Couchbase cluster.<br />
<br />
Next time, on those foundations, we will build another a bit more complicated solution.<br />
<br />
Roi.<br />
<div class="MsoNormal">
</div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
</div>
<!--EndFragment-->
<br />
<div class="MsoNormal" style="margin-left: .25in;">
</div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-26961022130312327192015-11-09T13:54:00.003+02:002015-11-09T13:54:39.874+02:00NoSQL Document DB's Joins rundown Couchbase 4.0 vs MongoDB 3.2<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Hi all,<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">There is a lot of heat in the NoSQL (Not Only SQL) realms lately.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Especially if we take the Document databases,
which are based on JSON to store data.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 13.5pt;">Little less than a week ago MongoDB came out with some
significant release called in the misleading name "3.2" they've added
some quite interesting features, one interesting feature is joins. That version, by no mean is a minor version.</span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">The latter were also introduced by Couchbase in
the 4.0 major release which included many new features and the most prominent
is probably the N1QL language - which is basically a SQL for JSON, which released in early October 2015.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">It's as SQL as it gets for NoSQL databases, it
more or less a super-set and a subset of SQL as it has some features that does
not apply to relational DB - such as NEST & UNNEST of documents,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">As of NEST, think of it, as promoting an array
inside a documents to it's own "SQL table", on which we can perform
queries.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">The N1QL language is just another mean of
accessing and querying data from Couchbase, in addition to Key-Value system and
the View mechanism (the Map-Reduce).<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">One of the most talked about feature is of
course join.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Joining 2 or more documents to one reduces the
amount of traffic on the network causing faster response times by the
application consuming the data.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">So while Couchbase were following the rule
"use what you already know" with the N1QL,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">the Mongo team suggested another approach to the
join,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">the went on an introduced another keyword called
$lookup,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">While that works perfectly - it's not neat, and
you will catch some learning curve on the way to perfection, while on Couchbase
you just do - SQL joins.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Both DB's join feature is available as community
& enterprise editions feature.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">So let's join!<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><br /></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><u>In Couchbase,</u><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Let’s use the "travel-sample" that is
bundled with it,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">I have a route document which looks like that:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "airline":
"AF",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "airlineid":
"airline_137",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "destinationairport":
"CDG",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "distance":
573.0051071016999,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "equipment": "E90
AR8 E70",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "id": 10007,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "sourceairport":
"TRN",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "stops": 0,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "type":
"route"<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 13.5pt;">I would like to check, which airline corresponds to the route.</span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">which portrait with the following document:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">{<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "callsign":
"AIRFRANS",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "country":
"France",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "iata":
"AF",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "icao":
"AFR",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "id": 137,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "name": "Air
France",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "type":
"airline"<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Up until now, the way I could "join" those two documents, was by code in my application.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">take the first document, figure out the
airlineid field, then go back and get the airline document by id.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 18px;">So while it's still possible to do it, N1QL introduced the concept of join. </span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">and that is the Query:<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">SELECT airline.*, route. Airline,
route.airlineid, route.destinationairport, route.distance, route.equipment,
route.id, route.sourceairport, route.stops, route.type<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">FROM `travel-sample` route<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">JOIN `travel-sample` airline ON KEYS route.airlineid<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">WHERE route.id = 10007<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 18px;"><i>notes about that query above:</i></span></div>
<div class="MsoNormal">
<i><span style="font-size: 18px;">1) </span><span style="font-size: 13.5pt;"> I would recommend of not using "star" in your application, but for testing purposes only</span></i></div>
<div class="MsoNormal">
<i><span style="font-size: 13.5pt;">2) notice the back tick in the bucket name, this is not an </span><span style="font-size: 18px;">apostrophe</span><span style="font-size: 13.5pt;">.</span></i></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><o:p><br /></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">of which the result is:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">a merge of those two documents<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><br /></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "airline":
"AF",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "airlineid":
"airline_137",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "callsign":
"AIRFRANS",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "country":
"France",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "destinationairport":
"CDG",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "distance": 573.0051071016999,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "equipment": "E90
AR8 E70",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "iata": "AF",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "icao": "AFR",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "id": 10007,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "name": "Air
France",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "sourceairport":
"TRN",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "stops": 0,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "type":
"route"<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">or if we want all of the documents just remove
the route.id.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Pure plain SQL.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">we can do it programmatically, via the cbc-linq
command line, or through the Query Workbench (CBQ) which is currently under
developer preview (expected to be released on next Couchbase release).<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><u>In MongoDB</u></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">We can only do join programmatically </span><span style="font-size: 13.5pt;">with
the aggregation pipeline.</span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Note, that in Couchbase we are joining on keys,
and in Mongo on fields.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><u>Assume the following changes:<o:p></o:p></u></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">1) We have two collections, one for routes, and
one for the airlines.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">2) The field "id" in the airline
document is "airline_137" and not just 137, <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">{<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "callsign":
"AIRFRANS",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "country":
"France",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "iata":
"AF",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "icao":
"AFR",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> <b><i>"id":
"airline_137",</i></b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "name": "Air
France",<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> "type":
"airline"<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">So the lookup will look like that: <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">db.routes.aggregate([<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><span style="mso-tab-count: 3;"> </span>{
$match: <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><span style="mso-tab-count: 4;"> </span>id:
10007<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><span style="mso-tab-count: 3;"> </span>}},<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><span style="mso-tab-count: 3;"> </span>{
$lookup: {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><span style="mso-tab-count: 4;"> </span>from: "airlines"<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><span style="mso-tab-count: 4;"> </span>localField: "airlineid"<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><span style="mso-tab-count: 4;"> </span>foreignField: "id"<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><span style="mso-tab-count: 4;"> </span>as:<span style="mso-tab-count: 1;"> "</span>combined_airline_doc"<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><span style="mso-tab-count: 1;"> </span><span style="mso-tab-count: 2;"> </span>}}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";"><span style="mso-tab-count: 3;"> </span>]);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">The table below compares the two databases join
wise:<o:p></o:p></span></div>
<table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150"></td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-left-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";"><b>Couchbase
4.0<o:p></o:p></b></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-left-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.2pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";"><b>Mongo
3.2</b><o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";"><b>Complexity</b><o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Simple
(SQL joins)<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt; width: 150.2pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Complex
(new language)<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";"><b>Syntax</b><o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Similar
to SQL joins<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt; width: 150.2pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">New
$lookup keyword<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";"><b>Join
type<o:p></o:p></b></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Left
Outer joins\inner<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt; width: 150.2pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Left
outer joins\inner<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 15.7pt; mso-yfti-irow: 4;">
<td style="border-top: none; border: solid windowtext 1.0pt; height: 15.7pt; mso-border-top-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";"><b>Learning
curve<o:p></o:p></b></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Flat
(SQL)<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.7pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.2pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Steep
(new query language)<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 5;">
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";"><b>Functionality<o:p></o:p></b></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Good<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0in 5.4pt 0in 5.4pt; width: 150.2pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Good<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 75.1pt; mso-yfti-irow: 6;">
<td style="border-top: none; border: solid windowtext 1.0pt; height: 75.1pt; mso-border-top-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";"><b>Query
path<o:p></o:p></b></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 75.1pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Query
Service, Split across the cluster, or with MDS do not load on data nodes<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 75.1pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.2pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Primary
Shard<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">the
pipeline commands distributed workload with scatter gather (the gather on one
shard)<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 29.2pt; mso-yfti-irow: 7;">
<td style="border-top: none; border: solid windowtext 1.0pt; height: 29.2pt; mso-border-top-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";"><b>Join
on<o:p></o:p></b></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 29.2pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Within
or with other buckets<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 29.2pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.2pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">collections<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 29.2pt; mso-yfti-irow: 8; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid windowtext 1.0pt; height: 29.2pt; mso-border-top-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<b><span style="font-family: ""times new roman"","serif"; mso-bidi-font-family: "Times New Roman"; mso-bidi-language: HE;">V</span><span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">ersion<o:p></o:p></span></b></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 29.2pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.15pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Community<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 29.2pt; padding: 0in 5.4pt 0in 5.4pt; width: 150.2pt;" valign="top" width="150">
<div class="MsoNormal">
<span style="font-family: Times; mso-bidi-font-family: "Times New Roman";">Community<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Limitations with MongoDB joins:<o:p></o:p></span></div>
<ul type="disc">
<li class="MsoNormal" style="color: black; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Only in Aggregation pipeline,
programmatically.<o:p></o:p></span></li>
<li class="MsoNormal" style="color: black; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><b><span style="font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Right collection for $lookup
cannot be sharded (only primary shard contains the unsharded collection) –
implementation limitation</span></b><span style="font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></li>
<li class="MsoNormal" style="color: black; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Indexes are used only in the first
state of the pipeline – before manipulation data<o:p></o:p></span></li>
<li class="MsoNormal" style="color: black; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">No right outer joins<o:p></o:p></span></li>
</ul>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Limitation with Couchbase joins:<o:p></o:p></span></div>
<ul type="disc">
<li class="MsoNormal" style="color: black; mso-list: l1 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">No Right outer joins<o:p></o:p></span></li>
<li class="MsoNormal" style="color: black; mso-list: l1 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Joins are only on the keys (as in
key-value or object-id)<o:p></o:p></span></li>
</ul>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">So this was a light roundup on the new join
features on the 2 biggest document databases here.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">As for the winner here in that round, it seems
like Couchbase wins the trophy here, in terms of usability, testability, tools, ease of use and distribution.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Hope you've enjoyed.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Times; font-size: 13.5pt; mso-bidi-font-family: "Times New Roman";">Roi.<o:p></o:p></span></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="380">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNormal">
<br /></div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com2tag:blogger.com,1999:blog-2769632048026714340.post-78288342991636872682015-10-21T16:12:00.001+03:002015-10-21T16:45:16.181+03:00Windows 10 - Microsoft's Last OS?Hi all,<br />
<br />
After a long while I haven't wrote a thing, i've decided to come back to the blogging stage.<br />
I will start on a short overview about windows 10 + an opnion of mine about that OS<br />
I wrote in the great "The News Website".<br />
<br />
please have a look<br />
http://thenewswebsite.com/windows-10-overview/<br />
<br />
<br />
From now on I will focus more about BigData and NoSql hot topics that conquered the world of programming, designing and our world in general!<br />
<br />
And remember! today it's the Back to the futrue's future!Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-79084211445181691322013-11-16T22:58:00.002+02:002015-10-21T16:07:24.454+03:00Casing vs Dictionary in C#<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
So you need to decide on which route to take in your code according to a
specific condition<br />
maybe you need a pretty large converter.</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br />
You are facing several options, one, is to code a lot of ifs<br />
option which will be unreadable, unmaintainable and very difficult to code.<br />
The other two are switch case statement or let a dictionary invoke some action.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
So what is the better option? Dictionary or casing?</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
what is a better performer, what is cleaner in the code?<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
So let's write some code to explore it!<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br />
I've opened a new Console application and added a class, named <span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;">CaseWayNumbers</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--></span><o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">CaseWayNumbers</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">void</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> Selector(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> num)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">switch</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (num)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 1:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 2:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 3:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 4:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 5:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 6:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 7:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 8:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 9:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 10:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 11:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">default</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">private</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">void</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing()<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">And a second class, </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; line-height: 107%; mso-highlight: white;">DictionaryWayNumbers</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">DictionaryWayNumbers</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">private</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">readonly</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Dictionary</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Action</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">> _caseDictionary;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DictionaryWayNumbers()<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Dictionary</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Action</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">>();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(1, () => {
});<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(2, () => {
});<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(3, () => {
});<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(4, () => {
});<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(5, () => {
});<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(6, () => {
});<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(7, () => {
});<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(8, () => {
});<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(9, () => { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(10, () => {
});<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(11, () => {
});<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">void</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> Selector(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> num)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Action</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> action ;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.TryGetValue(num, </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">out</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> action);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">if</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (action != </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">null</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">) action.Invoke();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">And to test if there's any significance if it's number or strings,
<br />
I've added some two other classes,<br />
to deal with the strings.<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">CaseWay</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">void</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> Selector(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> str)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">switch</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (str)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"abit"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"bus"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"car"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"door"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"eye"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"fuel"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"google"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"heisenberg"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"imply"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"justify"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">case</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"kiosk"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">default</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">break</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">private</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">void</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DoSomthing()<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span dir="LTR"></span><span dir="LTR"></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><span dir="LTR"></span><span dir="LTR"></span> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">DictionaryWay</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">private</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">readonly</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Dictionary</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Action</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">> _caseDictionary;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DictionaryWay()<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Dictionary</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Action</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">>();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"abit"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, ()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"bus"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, ()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"car"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">,()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"door"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">,()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"eye"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">,()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"fuel"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, ()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"google"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, ()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"heisenberg"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, ()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"imply"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, ()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"justify"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, ()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.Add(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"kiosk"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, ()
=> { });<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">void</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> Selector(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> str)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Action</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> action;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> _caseDictionary.TryGetValue(str, </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">out</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> action);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">if</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (action != </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">null</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">) action.Invoke();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> </span><span dir="RTL" lang="HE" style="font-family: Arial, sans-serif; font-size: 9.5pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">And finally
some program to run it all and see what is performing better.<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Program</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">static</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">void</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> Main(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">[] args)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> strArr = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">[] { </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"abit"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"bus"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"car"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"door"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"eye"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"fuel"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"google"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"heisenberg"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"imply"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"justify"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"kiosk"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> numArr = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">[] { 1,2,3,4,5,6,7,8,9,10,11};<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> caseWay = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">CaseWay</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> dictionaryWay = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">DictionaryWay</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> caseWayNumbers = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">CaseWayNumbers</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> dictionaryWayNumbers = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">DictionaryWayNumbers</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Stopwatch</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw.Start();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">for</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> i = 0; i < 1000000; i++)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> s </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> strArr)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> caseWay.Selector(s);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw.Stop();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw2 = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Stopwatch</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw2.Start();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">for</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> i = 0; i < 1000000; i++)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> s </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> strArr)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> dictionaryWay.Selector(s);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw2.Stop();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw3 = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Stopwatch</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw3.Start();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">for</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> i = 0; i < 1000000; i++)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> num </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> numArr)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">
caseWayNumbers.Selector(num);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw3.Stop();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw4 = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Stopwatch</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw4.Start();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">for</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> i = 0; i < 1000000; i++)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> num </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> numArr)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">
dictionaryWayNumbers.Selector(num);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> sw4.Stop();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Console</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.WriteLine(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"Case with
strings: {0}"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, sw.ElapsedMilliseconds);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Console</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.WriteLine(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"dictionary
with strings: {0}"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, sw2.ElapsedMilliseconds);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Console</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.WriteLine(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"Case with
numbers: {0}"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">, sw3.ElapsedMilliseconds);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Console</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.WriteLine(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"dictionary
with numbers: {0}"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">,sw4.ElapsedMilliseconds);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;">And here are the run results (run on release mode):</span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikBYmMUk5BoKFeR3dnMl6ny_Bpyd5YtcQ6hpIaWvlK82ZiMYKvhwDdLjGP2F-hAQAX1l9KlGqZFQJ9G0rp66evE1KBDzBDSGMmZHm1C1FocAwy8cG13NS7Ofg23bLAo9xlOhoQr7R0gR0M/s1600/results.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="202" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikBYmMUk5BoKFeR3dnMl6ny_Bpyd5YtcQ6hpIaWvlK82ZiMYKvhwDdLjGP2F-hAQAX1l9KlGqZFQJ9G0rp66evE1KBDzBDSGMmZHm1C1FocAwy8cG13NS7Ofg23bLAo9xlOhoQr7R0gR0M/s400/results.JPG" width="400" /></a></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigk5sPuoIa3RCooRgtJKyBnjLHBDLkcrj2fopuy5_4_91stoyf8UBQyOtK1oH24Y2J5QRnYvpcpzUuB0D9fj9PXA0B7ljIPayC6RisiyA_uqkl2s09pV4zgP_EuxMQNxhAvaFL-19Z4YCl/s1600/results.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></a>
<br />
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<u>Conclusion</u></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
as you can see, using the switch case statement is slightly better on strings but much better on numbers.</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
In my opinion, it's cleaner with dictionary, and it's a better way to go if performance is not an issue, or that function is not called frequently, it shrinks the code lines, and a little bit easier to maintain.</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span dir="RTL" lang="HE" style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><o:p><br /></o:p></span></div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-2085147185300218152013-09-06T22:10:00.002+03:002013-09-07T10:48:34.725+03:00Simple MEF Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
MEF is a great tool to create plugins. And a great way to extend your
application.</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
With MEF (or Managed Extensibility Framework) you can create a separate dll which
implements an interface and if you build the application correctly the new
functionality will work right away.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
And the greatest thing about it, it's a part of the framework ever since
version 4.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
So here we start:<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
First we create a console application:</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtucMX4tAXewEa8I2DCOSbZp0r4eCfnjoT1UaKpt2qK-QPg97IwkiKNl4uxTbzMR208J2FrxJf6tDhUHlbA0eIlEXNzWuIVGFd29GTDMu_a8cC58bi4LCgnCIFD39GcMpt-k26fducXPzX/s1600/newProject.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="275" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtucMX4tAXewEa8I2DCOSbZp0r4eCfnjoT1UaKpt2qK-QPg97IwkiKNl4uxTbzMR208J2FrxJf6tDhUHlbA0eIlEXNzWuIVGFd29GTDMu_a8cC58bi4LCgnCIFD39GcMpt-k26fducXPzX/s400/newProject.PNG" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
And a new Class Library Named Contracts.<br />
In that project we will store the solution wide interfaces.<br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
In the newly created project add an interface, named INotification<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
public interface INotification<br />
{<br />
string Notification { get; }<br />
}</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
After we finished with the interface we will create a new class library
named "Notifications".<br />
There, we will store the implementing classes of <span dir="LTR" msonormal="" style="direction: ltr; unicode-bidi: embed;">
Add a reference to the Contracts class library and implement a
HelloNotification Class,<br />
and for System.ComponentModel.Composition<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
[Export(typeof(INotification))]<br />
public class HelloNotification : INotification<br />
{<br />
public string Notification<br />
{<br />
get<br />
{<br />
return "Hello World, Mef Style!";<br />
}<br />
}<br />
}</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
The Export attribute tells the MEF mechanism to export the class as
INotification and if someone imports the INotification from somewhere else he
will get an instance of the exported class.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
Now, in order to tell MEF mechanism where to search for the Exported
tags, we need to build a little<br />
BootStrapper which loads the exported types upon startup.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br />
public class BootStrapper<br />
{<br />
public CompositionContainer Run()<br />
{<br />
var mefCatalog = new AggregateCatalog();<br />
<br />
var executablePath = Assembly.GetExecutingAssembly().Location;<br />
var executableDirectory = Path.GetDirectoryName(executablePath); <br />
<br />
mefCatalog.Catalogs.Add(new DirectoryCatalog(executableDirectory));<br />
<br />
var container = new CompositionContainer(mefCatalog);<br />
container.ComposeParts(this);<br />
<br />
return container;<br />
}<br />
}<br />
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
The two last lines before the return statement are responsible of composing
the classes from the catalog into the MEF Container<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
In order for that code to work, we need to set the OutputPath of each
project to the directory of the executable. (With exception of the MefSample
Project).<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
Go to Project Properties, Build tab, and look for Output group.</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<o:p></o:p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBDgE7I1pS2xE2FoimRRqm45TudPoVWhYYJIX1yyqy7QPHQS_F4bycdyYEe5Kko55_CObFyBVhR2kHLLJaoENwJ2ir4J6pNp8enm4LtfHfiAtKIVwajEzt4knB9s89RHhd7Rjq9Cu211_J/s1600/build.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBDgE7I1pS2xE2FoimRRqm45TudPoVWhYYJIX1yyqy7QPHQS_F4bycdyYEe5Kko55_CObFyBVhR2kHLLJaoENwJ2ir4J6pNp8enm4LtfHfiAtKIVwajEzt4knB9s89RHhd7Rjq9Cu211_J/s1600/build.jpg" /></a></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
Now we have one project which implement the INotification Interface, and
we want to use it.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
So first we run the BootStrapper to get the exported classes.<br />
then we use it!<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
But how?<br />
We have 2 ways of doing so.<br />
The first way is to use the [Import] Attribute.<br />
The Import Attribute marks the field or property as good for exported class
assignment.<br />
but it won't going to work unless someone will satisfy the import,<br />
so after we marked the property as [Import] we tell the container to satisfy
the imports by SatisfyImportsOnce on the object which needs it. In our case
it's "this" (Program class)<br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
After that we can use the field or property as normal object which
implements the interface.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
public class Program<br />
{<br />
[Import]<br />
INotification _notification;<br />
<br />
public void Run()<br />
{<br />
var bootstrapper = new BootStrapper();<br />
var container = bootstrapper.Run();<br />
<br />
container.SatisfyImportsOnce(this);<br />
Console.WriteLine(_notification.Notification);<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
var program = new Program();<br />
program.Run();<br />
}<br />
}<br />
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
But, this will only work if we know we have one exported class only.<br />
If we have two of that kind, it will crash, because the MEF doesn't know which
one to take.<br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
Now add another class to the notification project.<br />
Let's call it SecondNotification which
implements INotification as
well.<br />
And exported by the Type of the interface.<br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
[Export(typeof(INotification))]<br />
public class SecondNotification : INotification<br />
{<br />
public string Notification<br />
{<br />
get { return "2nd Hello World, Mef Style!"; }<br />
}<br />
}</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
Now if we try to run the program we will get an exception:<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
1) More than one export was found that matches the constraint: <o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
ContractName Contracts.INotification<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
RequiredTypeIdentity Contracts.INotification<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
Resulting in: Cannot set import 'MefSample.Program._notification
(ContractName="Contracts.INotification")' on part
'MefSample.Program'.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
Element: MefSample.Program._notification (ContractName="Contracts.INotification")
--> MefSample.Program<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
The Mef tells you it cannot resolve the correct class for the contract.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
We can easily solve it by changing the Import attribute to a new
attribute.<br />
[ImportMany], and change the field
type to IEnumerable<inotification></inotification></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
so our Program class will look as follows:<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
public class Program<br />
{<br />
[ImportMany]<br />
IEnumerable<inotification> _notifications;</inotification><br />
<br />
public void Run()<br />
{<br />
var bootstrapper = new BootStrapper();<br />
var container = bootstrapper.Run();<br />
<br />
container.SatisfyImportsOnce(this);<br />
<br />
foreach (var notification in _notifications)<br />
Console.WriteLine(notification.Notification);<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
var program = new Program();<br />
program.Run();<br />
}<br />
}</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
Please take note that the printing is now running in a foreach loop on
all of the imported values.<o:p></o:p></div>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt; line-height: 107%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-language: HE; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><br clear="all" style="mso-special-character: line-break; page-break-before: always;" />
</span>
<br />
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<o:p> </o:p>You can use the MEF in another way as well.</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
We can ditch the Import attributes and use the container directly.<br />
The way we do it is by using the method GetExportedValue<interface>() of
the Container.<o:p></o:p></interface></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
So for now comment out the Export Attribute from the SecondNotification Class<br />
and make the following changes in the Program Class.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
public class Program<br />
{<br />
public void Run()<br />
{<br />
var bootstrapper = new BootStrapper();<br />
var container = bootstrapper.Run();<br />
<br />
var notification = container.GetExportedValue<inotification>();</inotification><br />
<br />
Console.WriteLine(notification.Notification);<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
var program = new Program();<br />
program.Run();<br />
}<br />
}</div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
Now we are getting the export not by an attribute but by direct
reference to the container.<o:p></o:p></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
If we want a several Classes, we would do as we did before.<br />
Uncomment the export we did several like above<br />
and notice we get the same exception as above.<br />
Now all we need to do is the GetExportedValues<inotification>() method and
That’s it!. <o:p></o:p></inotification></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span>
public class Program<br />
{<br />
public void Run()<br />
{<br />
var bootstrapper = new BootStrapper();<br />
var container = bootstrapper.Run();<br />
<br />
var notifications = container.GetExportedValues<inotification>();</inotification><br />
<br />
foreach (var notification in notifications)<br />
Console.WriteLine(notification.Notification);<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
var program = new Program();<br />
program.Run();<br />
}<br />
}<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> </span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> <o:p></o:p></span></div>
<br />
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
Now you’ve created your very first MEF Project with ease!<o:p></o:p><br />
<br />
Code samples can be downloaded from <a href="http://sdrv.ms/18IoEq4" target="_blank">here</a></div>
</div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-84268162148767951092013-07-27T12:35:00.001+03:002013-07-27T12:37:48.699+03:00הערות/תיעוד - Comments<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: right;">
<span style="font-family: Arial, sans-serif;">הערות בקוד, זה כלי מאוד מפתה. </span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span><br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">התרגלנו אליו עוד בערש לימודינו, ולפעמים הערה פה ושם במקום טוב כן יכולה לעזור.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span>
<br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">אבל יש בעיה עם הערות. הערות גורמות לעומס על הקוד.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span>
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">במקום לכתוב קוד שניתן להבין בקלות נתקעים על סנכרון בין ההערות לבין הקוד.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
<o:p></o:p></span><br />
<div class="MsoNormal" dir="RTL">
</div>
<div style="text-align: right;">
<span style="font-family: Arial, sans-serif;">שמעתי פעם על ראש צוות אחד שאמר, אני לא רוצה בכלל לקרוא את הקוד, אלא
רק את ההערות.</span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span><br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">אני חושב שזה נבע מאיכות ירודה של קוד. ששמות המשתנים והפונקציות לא היו מובנים
מספיק,</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span>
<br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">או אפילו שהפונקציות היו גדולות מדי ובעלות כמה תפקידים. והוא פשוט התייאש.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
<o:p></o:p></span>
<div class="MsoNormal" dir="RTL">
</div>
<div style="text-align: right;">
<span style="font-family: Arial, sans-serif;">הערות הם סוג של פיצוי על כישלון להסביר את עצמנו בקוד.</span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span><br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">אם מישהו מגיע למצב שהוא צריך לכתוב הערה הוא, אותו אדם צריך לשאול את עצמו איך
אני כותב את הקוד טוב יותר כדי שרק מקריאה של הקוד יבינו את המשמעות של
ה"משפט" שכתבתי כרגע?</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span>
<br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">ורק אם הוא ניסה מספיק זמן, רק אז הוא יכול לשקול לכתוב הערה.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
<o:p></o:p></span>
<div class="MsoNormal" dir="RTL">
</div>
<div style="text-align: right;">
<span style="font-family: Arial, sans-serif;">פעם תיעדתי שורות רבות בקוד שלי, אבל התיעוד היה טוב רק לרגע הנתון
שבו נכתב הקוד.</span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span><br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span lang="HE" style="font-family: Arial, sans-serif;">עם הזמן הבנתי שקוד טוב ונקי לא צריך את ההערות, ושההערות רק גורמות לבלאגן שצריך
לתחזק, <u>אף אחד לא באמת מתחזק הערות</u>. קוד משתנה, עובר </span><span dir="LTR">Refactor</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span>-ים, מתייעל, ומשתבח.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span><span lang="HE"></span>
<br />
<div style="font-family: Arial, sans-serif; text-align: right;">
<span lang="HE"><span style="font-family: Arial, sans-serif;">ההערות כמעט תמיד לא, נוצר מצב שההערות גורמות למידע מוטעה על הקוד. ההערות מספרות
סיפור אחד, והקוד בכלל מספר סיפור אחר. זה קורה וזה כואב.</span></span></div>
<span lang="HE">
</span>
<div style="text-align: right;">
<span lang="HE"><span style="font-family: Arial, sans-serif;"><br /></span></span></div>
<span lang="HE">
<div dir="rtl" style="text-align: right;">
<span style="font-family: Arial, sans-serif;"></span></div>
<div dir="rtl" style="text-align: right;">
<span style="font-family: Arial, sans-serif;">יש רק מספר מקומות בהם לדעתי חובה לרשום הערות:</span><br />
<span style="font-family: Arial, sans-serif;">1) תיעוד של INTERFACES</span><br />
<div style="text-align: right;">
<span style="font-family: Arial, sans-serif;">2) <span style="font-size: 15px; line-height: 16px;">אם צריך להכניס todo לצורך refactor עתידי.</span></span></div>
</div>
</span><div dir="rtl" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span></div>
<div dir="rtl" style="text-align: right;">
</div>
<div class="MsoNormal" dir="rtl" style="text-align: right;">
</div>
<div dir="rtl" style="text-align: right;">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span><br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span lang="HE" style="font-family: Arial, sans-serif;">סוג מאוד לא נחוץ של הערות שלפעמים מתכנתים נוקטים בו הוא הערות על </span><span dir="LTR">Properties</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> שמסבירים את עצמם, או סתם רעש לדוגמא:</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span>
<br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span lang="HE" style="font-family: Arial, sans-serif;"><br /></span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span dir="LTR"></span><span dir="LTR"></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><span dir="LTR"></span><span dir="LTR"></span> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Person</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">//Default
Constructor</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> Person()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">// the
Date of birth of the Person</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">DateTime</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> DateOfBirth { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">set</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">// the first name of the Person</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FirstName { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">set</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">// the
last name of the Person</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> LastName { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">set</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">// the
address of the Person</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> Address { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">set</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">//List
of friends</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">List</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Person</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">> Friends { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">set</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">//
Returns the age of the Person</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">double</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> Age<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">if</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (DateOfBirth == </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">null</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> ) </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> 0;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">DateTime</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.Now - DateOfBirth).TotalDays/365;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: left; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><span dir="RTL" lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: rtl; text-align: right; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" dir="RTL">
</div>
<div style="text-align: right;">
<span style="font-family: Arial, sans-serif;">השאלה היא פשוטה, למה לרשום הערות למשהו שהוא מראש מסביר את עצמו?</span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span><br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">ההערות האלו מבלבלות ומסיחות את הדעת מהקוד שהוא ברור מאליו.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span>
<br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span lang="HE" style="font-family: Arial, sans-serif;">או למשל ההערה שה-</span><span dir="LTR">Constructor</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> הוא דיפולטי, זה ברור
מאליו, לא?</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span>
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">בכל זאת יש מתכנתים בעיקר צעירים שמרגישים צורך לתעד כל שורה בקוד.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
<o:p></o:p></span><br />
<div class="MsoNormal" dir="RTL">
</div>
<div style="text-align: right;">
<span style="font-family: Arial, sans-serif;">דוגמא נוספת להערות שהיום הם פשוט רעש אלו הערות ה"לוח
שינויים".</span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span><br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span lang="HE" style="font-family: Arial, sans-serif;">פעם שלא היה ממש </span><span dir="LTR">Source Control</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span>, למשל בסביבות ישנות של- </span><span dir="LTR">C</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> או </span><span dir="LTR">NATURAL</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span>/</span><span dir="LTR">Cobol</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span>,</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span>
<br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">היה צורך של ממש לתעד שורות ולא למחוק כלום. הקוד נהיה ממש מסורבל מלא הערות ורק
כדי למצוא משהו לקח זמן רב ויקר.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span>
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">מה עוד שעד שהגענו לקוד היינו צריכים לגלול דפים על גבי דפים.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
<div style="text-align: right;">
<span lang="HE" style="font-family: Arial, sans-serif;">היום אין צורך בזה משום שכל </span><span dir="LTR">Source Control</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> שמכבד את עצמו כבר מכיר
תיעוד על כל נגיעה בקוד ומי בדיוק ביצע את השינוי ומה היה לפני זה.</span></div>
</span><br />
<div class="MsoNormal" dir="RTL" style="direction: rtl; text-align: right;">
<br /></div>
<div class="MsoNormal" dir="RTL" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">הלוג הזה היה נראה משהו כמו:<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span dir="LTR"></span><span dir="LTR"></span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"><span dir="LTR"></span><span dir="LTR"></span>/* Changes Log</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"> *
=====================================================================</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"> * RK001 - 2009/7/1 - Bug Fix in Person Name</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"> * RK002 - 2009/8/1 - Refactor in Person </span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"> * RK003 - 2010/1/1 - added method
AddFriend(otherPerson)</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"> * RK004 - 2010/2/1 - added method
UnFriend(perosn);</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"> * RK005 - 2010/3/1 - some bug fixes</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: left; unicode-bidi: embed;">
<span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"> */</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: rtl; text-align: right; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="RTL">
</div>
<div style="text-align: right;">
<span lang="HE" style="font-family: Arial, sans-serif;">עם כל מיני קישקושים בקוד של מי ביצע </span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR"><span dir="LTR"></span><span dir="LTR"></span>(RK001)</span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span><br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-family: Arial, sans-serif;">ועל כל שינוי היינו צריכים לרוץ לתחילת הקובץ</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span>
<br />
<div class="MsoNormal" dir="RTL">
</div>
<div style="text-align: right;">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"></span><br />
<div style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span lang="HE" style="font-family: Arial, sans-serif;"> אם היום אתם עדיין מתעדים ככה, ותרו. הוא
מיותר בסביבת קוד מנוהלת </span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR"><span dir="LTR"></span><span dir="LTR"></span>–</span><span dir="RTL"></span><span dir="RTL"></span><span style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> </span><span dir="LTR">Source
Controlled</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span>.</span></span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">
</span>
<br />
<div class="MsoNormal" dir="RTL">
</div>
<div style="text-align: right;">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<span lang="HE"></span><br />
<div style="text-align: right;">
<span lang="HE"><span style="font-family: Arial, sans-serif;"><br /></span></span></div>
<span lang="HE">
<!--[if !supportLineBreakNewLine]-->
<!--[endif]--></span><span dir="LTR"><o:p></o:p></span><br />
<div class="MsoNormal" dir="RTL" style="direction: rtl; text-align: right;">
<br /></div>
<br />
<div class="MsoNormal" dir="RTL" style="text-align: right;">
<br /></div>
</div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-33705544136226555702013-07-15T22:16:00.004+03:002013-07-15T22:16:57.287+03:00ואלו שמות - And those are the names...<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" dir="RTL">
</div>
<div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;">עד עכשיו דיברנו על שמות משתנים והחשיבות שלהם,</span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;">אך עוד לא דיברנו על נושאים חשובים כמו שמות קלאסים ומתודות, או על טעויות נפוצות
במתן שמות באופן כללי.</span></div>
<o:p></o:p></span><br />
<div class="MsoNormal" dir="RTL">
</div>
<div style="direction: rtl; text-align: right;">
<span lang="HE" style="font-family: Arial, sans-serif;">אנשים רבים נוטים לתת שמות לקלאסים שלהם</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR" lang="HE"><span dir="LTR"></span><span dir="LTR"></span>
</span><span lang="HE" style="font-family: Arial, sans-serif;">באופן אינטואיטיבי כשם-עצם, ולמתודות כפועל. וזה נכון וטוב. הקוד צריך
לזרום כמו סיפור.</span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><div style="direction: rtl; text-align: right;">
<span lang="HE" style="font-family: Arial, sans-serif;">לדוגמא, השורה הבאה בקוד</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR"><span dir="LTR"></span><span dir="LTR"></span>:</span></div>
</span><br />
<div class="MsoNormal" style="direction: ltr; unicode-bidi: embed;">
</div>
<div style="direction: rtl; text-align: left;">
var
xmlResposeBuilder = new XMLResponseBuilder();</div>
<div style="direction: rtl; text-align: left;">
var xmlRequest = xmlRequestBuilder.Build(someObj);</div>
<o:p></o:p><br />
<div class="MsoNormal" dir="RTL">
</div>
<div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;">הקוד מספר לנו מה הוא הולך לעשות, </span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><div style="direction: rtl; text-align: right;">
<span lang="HE" style="font-family: Arial, sans-serif;">אנחנו הולכים לבנות מ-</span><span dir="LTR">someObj</span><span dir="RTL"></span><span dir="RTL"></span><span style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> <span lang="HE">סוג של בקשת
</span></span><span dir="LTR">XML</span><span dir="RTL"></span><span dir="RTL"></span><span style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> <span lang="HE">למישהו.</span></span></div>
</span><span style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;"><span lang="HE">שימו לב, ששם ה-</span></span><span dir="LTR">Class</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> הוא אכן שם עצם, והמתודה
היא הפעולה שהוא צריך לבצע.</span></div>
</span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;">רצוי להקפיד על המוסכמה האינטואיטיבית הזאת למען זרימת הקוד.</span></div>
<o:p></o:p></span><br />
<div class="MsoNormal" dir="RTL" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">דוגמאות טובות לשמות קלאסים הן:<o:p></o:p></span></div>
<div class="MsoNormal" style="direction: rtl; text-align: left; unicode-bidi: embed;">
ResponseParser,
IdGenerator, StringInputValidator, NewsFinder<o:p></o:p></div>
<div class="MsoNormal" dir="RTL" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">דוגמאות טובות לשמות מתודות הן:<o:p></o:p></span></div>
<div class="MsoNormal" style="direction: rtl; text-align: left; unicode-bidi: embed;">
GetName,
SetName, IsDefault, Parse, Build, Delete, Add<o:p></o:p></div>
<div class="MsoNormal" dir="RTL" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">ושהם קשורות לקלאס שלהם, הכוונה של מה המתודות עושה – מתבהרת.<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal" dir="RTL">
</div>
<div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;">אז עבדנו לפי הכללים והחלטנו להתחכם,</span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><div style="direction: rtl; text-align: right;">
<span lang="HE" style="font-family: Arial, sans-serif;">בעברי הרחוק, כתבתי פונקציה לסביבת </span><span dir="LTR">unix</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> שהורגת את כל התהליכים
ללא אב, תהליכים אלו נקראים</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR" lang="HE"><span dir="LTR"></span><span dir="LTR"></span> </span><span lang="HE" style="font-family: Arial, sans-serif;">לעיתים
"זומבים", "יתומים" או "רוחות רפאים" (</span><span dir="LTR">Zombie/Orphan/Ghost</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span>) ומתכנתים בסביבה הזאת יודעים על מה מדובר
כאשר השמות הללו עולים לאוויר.</span></div>
</span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><div style="direction: rtl; text-align: right;">
<span lang="HE" style="font-family: Arial, sans-serif;">הבעיה שקצת התחכמתי, היה לי קצת משעמם באותו יום ושמעתי אלבום של מטאליקה, תוך כדי
עבודה כמובן. קראתי לפונקציה הזאת </span><span dir="LTR">KillEmAll</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span>, ממש נחתה עלי השראה.</span></div>
</span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;">אחרי לא מעט זמן, מתכנת אחר היה צריך לתחזק משהו באיזור.</span></div>
<div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;">מקריאה ראשונית לא ממש הבין מה הפונקציה הזאת עושה והיה צריך להיכנס אליה.</span></div>
<div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;">זה לא מצב תקין, למרות שבזמנו חשבתי שזה מצחיק ונחמד ויכניס טיפה עניין לקוד.</span></div>
<div style="direction: rtl; text-align: right;">
<span lang="HE" style="font-family: Arial, sans-serif;">שם טוב לפונקציה היה </span><span dir="LTR">KillAllOrphanProcesses</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> או </span><span dir="LTR">KillAllZombieProcesses</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> והוא לא היה צריך לקרוא
לי או להיכנס לקוד.... או לקלל אותי בשלב מסוים, הוא לא צחק.</span></div>
<div style="direction: rtl; text-align: right;">
<span lang="HE" style="font-family: Arial, sans-serif;"><br /></span></div>
</span><br />
<div class="MsoNormal" dir="RTL">
</div>
<div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;">באופן עקרוני, שמות ארוכים מדי לא מומלצים כי הם נוטים לבלבל וליצור
חוסר בהירות, ועדיף שמות קצרים ככל האפשר שמתארים את טווח הפעולה של האובייקט או
הפונקציה.</span></div>
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><div style="direction: rtl; text-align: right;">
<span lang="HE" style="font-family: Arial, sans-serif;">לדוגמא, קרה לי מקרה לא מזמן באחד הפרויקטים שהיו כמה אובייקטים משותפים שהקידומת
שלהם הייתה בסגנון של </span><span dir="LTR">BankAccountData</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> ולאחר מכן כל מיני שמות
פעולה, כמו </span><span dir="LTR">Parser</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span>, </span><span dir="LTR">Builder</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span> או </span><span dir="LTR">Mapper</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span>. הבעיה שהשמות היו קצת
ארוכים אז הציעו לקצר את הקידומת ל-</span><span dir="LTR">BAD</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: Arial, sans-serif;"><span dir="RTL"></span><span dir="RTL"></span>,</span></div>
</span><span lang="HE"><div style="direction: rtl; font-family: Arial, sans-serif; text-align: right;">
<span style="font-family: Arial, sans-serif;">כמובן שזה לא עבר, הבעיה עם הקיצורים הללו הם שהם נוטים להיות מובנים למי שכתב
אותם, ולאחר מכן שוקעים בתהום של הלא נודע, אנשים פוחדים לשנות וככה נהיים תקועים
עם שם לא מוצלח במיוחד, שגם קצת קשה לחפש.</span></div>
<!--[if !supportLineBreakNewLine]--><div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<!--[endif]--><span style="font-family: Arial, sans-serif;"><o:p></o:p></span></span><br />
<br />
<div style="direction: rtl; text-align: right;">
<span style="font-family: Arial, sans-serif; font-size: 11pt; line-height: 107%;">אני לא
יכול להדגיש יותר את חשיבות השמות בתכנות, זאת אחת מאבני הבניין הכי חשובות.</span></div>
<span dir="RTL" lang="HE"><div style="font-family: Arial, sans-serif; font-size: 11pt; line-height: 107%; text-align: right;">
<span style="font-family: Arial, sans-serif; font-size: 11pt; line-height: 107%;">אנחנו חושבים בשמות, חיים עם שמות והכי קל לנו להבין שמות.</span></div>
<div style="font-family: Arial, sans-serif; font-size: 11pt; line-height: 107%; text-align: right;">
<span style="font-family: Arial, sans-serif; font-size: 11pt; line-height: 107%;">שמות טובים יהפכו את הקוד שלכם לקריא וניתן לתחזוקה. שמות לא טובים יהפכו אותו
למסורבל ותסכול רב מקרב מי שיבוא לתחזק אותו אחר כך.</span></div>
<!--[if !supportLineBreakNewLine]--><div style="text-align: right;">
<span style="font-family: Arial, sans-serif; font-size: 15px; line-height: 16px;"><br /></span></div>
<!--[endif]--></span></div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-53676708141873315732013-07-10T23:34:00.002+03:002013-07-10T23:34:40.493+03:00שמות נכונים למשתנים <div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" dir="rtl" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">אז בפוסט נתנו שמות שניתן להבין מהם את הסיפור של הקוד.<br />
אבל זה לא הכל,<br />
שאנחנו נותנים שמות למשתנים עלינו להיות זהירים ולהימנע מדו-משמעות ולרמזים שגויים
בשמות בקוד.<br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></span></div>
<div class="MsoNormal" dir="rtl" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">לדוגמא, מתכנתים רבים אוהבים לקצר שמות ולאגד אותם בראשי תיבות
שלעיתים מרמזים לאנשים שונים משמעות שונה.<br />
למשל<o:p></o:p></span></div>
<div class="MsoNormal" dir="rtl" style="text-align: right; unicode-bidi: embed;">
</div>
<div dir="ltr" style="text-align: left;">
String
awk;</div>
<div dir="ltr" style="text-align: left;">
Strung ls</div>
<o:p></o:p><br />
<div class="MsoNormal" dir="rtl" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">בפלטפורמות</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR"><span dir="LTR"></span><span dir="LTR"></span> unix </span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">למינהם
השמות הללו מבטאים שפת סקריפטים ורשימת קבצים, בהתאמה.<br />
אפילו אם נראה ש</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR"><span dir="LTR"></span><span dir="LTR"></span> awk </span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">זה קיצור טוב ל</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR"><span dir="LTR"></span><span dir="LTR"></span>-acknowledge
</span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">ו</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR"><span dir="LTR"></span><span dir="LTR"></span>-ls </span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">אולי נשמע כמו קיצור טוב ל</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR"><span dir="LTR"></span><span dir="LTR"></span>-lowSpecs </span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">המנעו מכך, זה יכול להוליך שולל</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR"><span dir="LTR"></span><span dir="LTR"></span>.</span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="rtl" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">או מקרה אחר ואולי אפילו קצת יותר נפוץ שנתקלתי בו לא מעט זה להוסיף
את המימוש לשם המשתנה. גם אני חטאתי בזה בעברי אבל מומלץ מאוד להמנע מזה גם לצורך
שינויי מימוש עתידיים וגם לצורך בהירות.<o:p></o:p></span></div>
<div class="MsoNormal" dir="rtl" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">למשל, מקרה מאוד נפוץ הוא עם </span><span dir="LTR">list</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span>. אנשים רבים משתמשים בשם
המשתנה עם סיומת </span><span dir="LTR">LIST</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span>.<br />
מומלץ להמנע מכך.<br />
לדוגמא, יש לך רשימת חברים.</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR"><span dir="LTR"></span><span dir="LTR"></span> FriendsList</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span> אבל בעתיד אולי זאת לא
תיהיה רשימה, אתה תחטא לאמת ולכוונה המקורית של המשורר שפשוט התכוון לחברים, </span><span dir="LTR">Friends</span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="rtl" style="text-align: right;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">כעת אתם יודעים קצת על שמות אבל לפעמים אתם גם רוצים לדבר עליהם עם
הצוות,<br />
להעביר רעיונות ואולי אפילו לקבל ביקורת בונה, אתם צריכים לתת שמות שניתן לבטא.<br />
למשל שם כמו: </span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR" lang="HE"><span dir="LTR"></span><span dir="LTR"></span> </span><span dir="LTR">imgEnc</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span> הוא שם פחות טוב מ-</span><span dir="LTR">ImageEncoder</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span>.<br />
רק משום קל יותר לבטא אותו.<br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></span></div>
<div dir="rtl" style="text-align: right;">
<span dir="RTL" lang="HE" style="font-family: "Arial","sans-serif"; font-size: 11.0pt; line-height: 107%; mso-ansi-language: EN-US; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-language: HE; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">בפוסט
הבא אדבר על שמות נכונים לפונקציות, קלאסים וחיות אחרות</span></div>
</div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-69262782116362045022013-07-03T23:54:00.002+03:002013-07-03T23:55:27.944+03:00שמות בעלי משמעות<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">חלק מאוד
חשוב בקוד ובקוד נקי הם השמות של אבני הבניין שמשמים לבניית התוכנה.<br />
אנחנו משתמשים בשמות לכל דבר, גם בחיים, כדי לסווג דברים, וגם כדי לספר את הסיפור.<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">קוד
תוכנה עם שמות נכונים יכול לספר את הסיפור של התוכנה גם ללא להכנס לתיעוד מעיק.<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">לכן,
כצעד ראשון רצוי להשתמש בשמות שמגלים את המשמעות של האובייקט.<br />
לתת שמות טובים לוקח זמן, לפעמים מתעכבים על הנושא קצת וזה מרגיש שזה
"מבזבז" זמן, אבל בעתיד שמישהו, אפילו מי שכתב את הקוד, בא לתחזק את
הקוד הרבה מאוד זמן פיענוח נחסך.<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">לדוגמא, <o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; text-align: justify; unicode-bidi: embed;">
Int x; // current number of people in the room<o:p></o:p><br />
<br /></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">השם </span><span dir="LTR">x</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span> לא אומר כלום, והיינו חייבים לתת תיעוד ש</span><span dir="LTR">x</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span> הוא ככה וככה. במקום זאת היינו יכול לחסוך
את התיעוד ופשוט לרשום את מה ש-</span><span dir="LTR">x</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span> מייצג. מספר האנשים
הנוכחי בחדר.<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; tab-stops: 220.4pt; text-align: justify; unicode-bidi: embed;">
Int currentNumberOfPeopleInTheRoom; <o:p></o:p><br />
<br /></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">ואז, בכל
מקום שיהיה המשתנה הזה, נוכל לדעת מה הוא ללא צורך לחפש את התיעוד עליו.<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">כדי
להמחיש את הכח של נתינת שמות נכונים, קחו כדוגמא את הפונקציה הבאה:<o:p></o:p></span><br />
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span dir="LTR"></span><span dir="LTR"></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><span dir="LTR"></span><span dir="LTR"></span> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">private</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">List</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">> GetThem(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> p1, </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> p2, </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> p3)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> theList = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">List</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">>();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">for</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> i = p2; i < p3; i++)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">if</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (i % p1 == 0)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> theList.Add(i);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> theList;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; text-align: justify; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><o:p></o:p></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">הקוד
מעלה הרבה שאלות, וקצב ה-</span><span dir="LTR">WTF/Minute</span><span dir="RTL"></span><span dir="RTL"></span><span style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span> <span lang="HE">גבוה,
כזכור, זהו המדד היחידי לקוד נקי.<o:p></o:p></span></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">האם אתם
מבינים מקריאה ראשונית זריזה מה היא עושה?<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">מה זה </span><span dir="LTR">theList</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span>? מה היא מכילה?<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">מה זה </span><span dir="LTR">p1,2,3</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span> מבלי להכנס לקוד?<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">מה
המשמעות של ההשוואה ל-0?<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">ומי זאת
הפונקציה </span><span dir="LTR">GetThem</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span> בכלל למה זה עושה </span><span dir="LTR">GET</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span>?<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">עכשיו
תקראו את הפונקציה הבאה, כל השינוי היה שינויי שמות שמתאימים ורומזים מה היא עושה<o:p></o:p></span></div>
<span dir="RTL" lang="HE" style="font-family: "Arial","sans-serif"; font-size: 11.0pt; line-height: 107%; mso-ansi-language: EN-US; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-language: HE; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br clear="all" style="mso-special-character: line-break; page-break-before: always;" />
</span>
<br />
<div class="MsoNormal" dir="LTR" style="direction: ltr; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span dir="LTR"></span><span dir="LTR"></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><span dir="LTR"></span><span dir="LTR"></span> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">private</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">List</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">> GetAllNumbersDividedByDividerInRange(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> divider, </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> lowerRange, </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> upperRange)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">const</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> NO_REMAINDER = 0;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> numbers = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">List</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">>();<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">for</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> number = lowerRange; number < upperRange; number++)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">if</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (number % divider == NO_REMAINDER)<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> numbers.Add(number);<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<br /></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; margin-bottom: 0.0001pt; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> numbers;<o:p></o:p></span></div>
<div class="MsoNormal" dir="LTR" style="direction: ltr; text-align: justify; unicode-bidi: embed;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><o:p></o:p><br />
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">מספר
השורות לא השתנה, גם הסיבוכיות של הקוד נשארה כשהייתה, אבל הקריאות של הקוד השתנתה
פלאים. וניתן להבין מה הפונקציה עושה בשניות.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" dir="RTL" style="text-align: justify;">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">בפוסט
הבא נמשיך עם חשיבות השמות בקוד, שווה לחכות </span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR" style="font-family: Wingdings; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-char-type: symbol; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-symbol-font-family: Wingdings;"><span dir="LTR"></span><span dir="LTR"></span>J</span><span dir="LTR"><o:p></o:p></span></div>
</div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0tag:blogger.com,1999:blog-2769632048026714340.post-49911182555252244342013-06-18T21:45:00.001+03:002013-06-18T21:54:42.654+03:00קוד נקי -Clean Code - והכרות<div dir="rtl" style="text-align: right;" trbidi="on">
<br />
<div class="MsoNormal" dir="RTL">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">אז.... איך מתחילים .... ? מי אני, אני רועי כץ, מהנדס מחשבים</span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR" lang="HE"><span dir="LTR"></span><span dir="LTR"></span> </span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">וראש צוות בקבוצת סלע, כבר 6 שנים בתחום התוכנה הכולל מספר שפות תכנות
ומתודולוגיות פיתוח שונות, מאד אוהב לחקור ולהכיר טכנולוגיות ומתודלוגיות חדשות,
וכן גם היום אני מתרגש ונהנה מהעבודה עם קוד<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br />
אני מתכוון לכתוב על כל מיני נושאים שאני אפגוש ביום יום במסגרת העבודה וגם דברים
שאחקור באופן יזום.<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">אני מאמין גדול ב"לימוד קהילתי" ומאמין כי בעזרת משוב
ושאלות מכם קוראים יקרים אשתפר גם בעצמי, אז .... קדימה הגיבו ושאלו כמה שיותר.<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL">
<br /></div>
<div class="MsoNormal" dir="RTL">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">לאחרונה נחשפתי לעולם ה-</span><span dir="LTR">Clean Code</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span> קוד קריא ובעיקר נח מאוד
לתחזוקה.<br />
פיתוח בשיטה זו הוא חלק חשוב מעולמות </span><span dir="LTR">AGILE</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span>, ועוד יותר מכך פותר הרבה
בעיות של הרחבה (</span><span dir="LTR">Scale Out</span><span dir="RTL"></span><span dir="RTL"></span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span>) של קוד, כמעט כמטה קסמים
– אם שומרים על עקרונות הקוד הנקי.<br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">אז מה זה בעצם </span><span dir="LTR">Clean Code</span><span dir="RTL"></span><span dir="RTL"></span><span style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span> <span lang="HE">? אם
הולכים על ההסבר הפשוט ביותר מה זה בכלל קוד נקי ואיך ניתן למדוד אותו, אפשר לסכם
אותו במשפט אחד:<o:p></o:p></span></span></div>
<div class="MsoNormal" dir="RTL">
<i><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">כאשר אתה נמצא ב-</span></i><i><span dir="LTR">Code Review</span></i><span dir="RTL"></span><span dir="RTL"></span><i><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span dir="RTL"></span><span dir="RTL"></span>, ככול שכמות השאלות
"מה זה לעזאזל" חלקי דקה קטנה יותר, כך הקוד שלך נקי יותר. </span></i></div>
<div class="MsoNormal" dir="RTL">
<i><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></i></div>
<div class="MsoNormal" dir="RTL">
<span style="font-family: Arial, sans-serif;">או בצורה קצת יותר גרפית (נלקח מאתר 9gag):</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://d24w6bsrhbeh9d.cloudfront.net/photo/5602106_700b.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="251" src="http://d24w6bsrhbeh9d.cloudfront.net/photo/5602106_700b.jpg" width="320" /></a></div>
<div class="MsoNormal" dir="RTL">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal" dir="RTL">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">אנשים רבים כותבים קוד, ומתגאים בו. לעיתים בצדק, לעיתים פשוט מחוסר
ידע שניתן לכתוב קטע קוד בצורה טובה יותר.<br />
יצירת קוד היא אומנות, קומפוזיציה.<br />
בשביל להיות אומן קוד, צריכים שני דברים עיקריים, את הידע בשביל ליצור את הקוד ואת
האימון, העבודה והתלכלכות בקוד. לכתוב קוד
נקי זאת עבודה קשה, אך משתלמת.<o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal" dir="RTL">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">ברור כי אין תוכנה ללא באגים אבל אפשר להמעיט מכמות הבאגים אם נעבור לפתח בקוד
נקי. התמונה תהיה ברורה יותר, המעקב נכון יותר, זמן יחסך והבאגים פשוט יצופו מעל
פני השטח ויגלו את עצמם..... </span><span dir="LTR"></span><span dir="LTR"></span><span dir="LTR" style="font-family: Wingdings; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-char-type: symbol; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-symbol-font-family: Wingdings;"><span dir="LTR"></span><span dir="LTR"></span>J</span><span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span></div>
<div class="MsoNormal" dir="RTL">
<span dir="LTR" style="font-family: Wingdings; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-char-type: symbol; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-symbol-font-family: Wingdings;"><br /></span></div>
<div class="MsoNormal" dir="RTL">
<span lang="HE" style="font-family: "Arial","sans-serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Arial; mso-bidi-theme-font: minor-bidi; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">בפוסטים הקרובים אפרט כל אחד מעקרונות הקוד הנקי,אבנה את ההסברים עם
דוגמאות קוד (נקי כמובן ....)<o:p></o:p></span></div>
</div>
Roi Katzhttp://www.blogger.com/profile/02768446975378753087noreply@blogger.com0