<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>python Archives | Programming Zen</title>
	<atom:link href="https://programmingzen.com/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>https://programmingzen.com/tag/python/</link>
	<description>Meditations on programming, startups, and technology</description>
	<lastBuildDate>Fri, 11 Oct 2019 03:38:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">1397766</site>	<item>
		<title>Exploring Mathematics with Matplotlib and Python</title>
		<link>https://programmingzen.com/exploring-mathematics-with-matplotlib-and-python/</link>
					<comments>https://programmingzen.com/exploring-mathematics-with-matplotlib-and-python/#comments</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Sat, 03 Aug 2019 20:36:47 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[exploration]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[matplotlib]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://programmingzen.com/?p=2097</guid>

					<description><![CDATA[<p>We, humans, are visual creatures. We evolved reasonable abstraction capabilities but we shine when we can visualize the problem at hand. This is why I&#x2019;m a big fan of Data Visualization as a discipline. Data has the answers. Visualization helps us better understand and interpret them. (For a great introduction to the subject, consider taking the Data Visualization course by my colleague Alex Aklson, Ph.D.) Perhaps, above all, I like the exploratory nature of visualizing data. We must be mindful of clustering illusions and type I errors, but it&#x2019;s fun to explore unbridled, feeding our intuition and the part of </p>
<p>The post <a href="https://programmingzen.com/exploring-mathematics-with-matplotlib-and-python/">Exploring Mathematics with Matplotlib and Python</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>We, humans, are visual creatures. We evolved reasonable abstraction capabilities but we shine when we can visualize the problem at hand.</p>



<p>This is why I&#8217;m a big fan of Data Visualization as a discipline. Data has the answers. Visualization helps us better understand and interpret them.</p>



<p>(For a great introduction to the subject, consider taking the <a href="https://www.coursera.org/learn/python-for-data-visualization" target="_blank" rel="noreferrer noopener" aria-label="Data Visualization course (opens in a new tab)">Data Visualization course</a> by my colleague Alex Aklson, Ph.D.) </p>



<p>Perhaps, above all, I like the exploratory nature of visualizing data. We must be mindful of <a rel="noreferrer noopener" aria-label="clustering illusions (opens in a new tab)" href="https://en.wikipedia.org/wiki/Apophenia" target="_blank">clustering illusions</a> and type I errors, but it&#8217;s fun to explore unbridled, feeding our intuition and the part of our brain that seeks patterns.</p>



<p>Let&#8217;s consider an example. Take a look at this list of numbers.</p>



<p class="has-background has-pale-cyan-blue-background-color">[21, 71, 41, 35, 41, 83, 48, 62, 26, 40, 46, 90, 50, 23, 11, 86, 95, 4, 50, 25, 93, 19, 67, 10, 27, 38, 78, 6, 71, 15, 11, 13, 10, 89, 3, 52, 98, 65, 97, 17, 64, 25, 33, 78, 28, 25, 85, 68, 2, 72, 63, 50, 9, 2, 52, 61, 62, 73, 89, 77, 10, 95, 5, 85, 46, 89, 70, 47, 20, 51, 6, 4, 51, 44, 79, 24, 63, 55, 99, 92, 29, 63, 16, 78, 15, 6, 91, 85, 8, 71, 23, 63, 67, 28, 44, 86, 83, 98, 57, 91]</p>



<p>Notice anything interesting?</p>



<p>If you look at it hard enough, chances are your brain will come up with something. Don&#8217;t feel bad if it didn&#8217;t as this is just a list of 100 random numbers (technically, pseudo-random numbers).</p>



<p>If we chart these points, we get a representation of this randomness.</p>



<div class="wp-block-image"><figure class="aligncenter"><img fetchpriority="high" decoding="async" width="1600" height="1100" src="https://i2.wp.com/programmingzen.com/wp-content/uploads/2019/08/random-100.png?fit=1024%2C704&amp;ssl=1" alt="100 random draws." class="wp-image-2104" srcset="https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/random-100.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/random-100.png?resize=300%2C206&amp;ssl=1 300w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/random-100.png?resize=768%2C528&amp;ssl=1 768w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/random-100.png?resize=1024%2C704&amp;ssl=1 1024w" sizes="(max-width: 1060px) 100vw, 1060px" /></figure></div>



<p>There is no pattern to be had. Charting these scattered points is not entirely useless, however.</p>



<p>Knowing full well that my brain will try to find a pattern, I let it play and noticed something. Nothing too surprising, but some dots appear to line up. This can easily be seen above y = 40, for example.</p>



<p>Well, big deal, some numbers are randomly repeated. Yes, but&#8230; now, I&#8217;m curious. How often are numbers repeated?</p>



<p>Let&#8217;s chart once more, this time using the frequency of occurrence on the y-axis.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="1600" height="1100" src="https://i2.wp.com/programmingzen.com/wp-content/uploads/2019/08/100.png?fit=1024%2C704&amp;ssl=1" alt="Frequency of random occurrences with N=100." class="wp-image-2105" srcset="https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/100.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/100.png?resize=300%2C206&amp;ssl=1 300w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/100.png?resize=768%2C528&amp;ssl=1 768w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/100.png?resize=1024%2C704&amp;ssl=1 1024w" sizes="(max-width: 1060px) 100vw, 1060px" /></figure></div>



<p>This looks a little less random, doesn&#8217;t it? With this set of 100 draws, the range appears to be between 0 (the number wasn&#8217;t drawn) and 4 repetitions (in the case of number 63).</p>



<p>(This conjured some unrelated thoughts about the <a href="https://en.wikipedia.org/wiki/Survivorship_bias" target="_blank" rel="noreferrer noopener" aria-label="survivorship bias (opens in a new tab)">survivorship bias</a>. I humorously imagined the top dots on the chart selling books to the lower dots about how to succeed. But I digress.)</p>



<p>It&#8217;s also visually obvious that there are fewer and fewer numbers as the frequency of repetition goes up. This makes sense. The odds of a number being present at least once are fairly high:</p>



<p style="text-align:center"><img decoding="async" src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+P_%7B1%7D+%3D+1+-+%28%5Cfrac%7B99%7D%7B100%7D%29%5E%7B100%7D+%5Capprox+0.6339+%5Capprox+63%5C%25&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="&#92;displaystyle P_{1} = 1 - (&#92;frac{99}{100})^{100} &#92;approx 0.6339 &#92;approx 63&#92;%" class="latex" /></p>



<p>While the odds of it being repeated 100 times are virtually zero:</p>



<p style="text-align:center"><img decoding="async" src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+P_%7B100%7D+%3D+%5Cfrac%7B1%7D%7B100%5E%7B100%7D%7D+%3D+1%5Ctimes%7B10%7D%5E%7B-200%7D+%5Capprox+0%5C%25&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="&#92;displaystyle P_{100} = &#92;frac{1}{100^{100}} = 1&#92;times{10}^{-200} &#92;approx 0&#92;%" class="latex" /></p>



<p>Every other frequency falls in between these two bounds.</p>



<p>Okay, cool, with 100 draws we seem to have quite a few numbers repeating 3 times, with one number even repeating 4 times.</p>



<h2 class="wp-block-heading">A hypothesis emerges</h2>



<p>We can hypothesize that as the number of draws increases, we might see a larger number of maximum repetitions as well. With 100, we comfortably hit 3 repetitions with several numbers, and we even had a 4. What happens with 1000, 10,000, 100,000 draws?</p>



<p>It feels like the odds of a number appearing even more frequently by chance should go up.</p>



<p>In other words, the maximum number of repetitions, as a function of the number of draws, should diverge. Very slowly, mind you, but it should diverge.</p>



<p>Hmm, slowly diverge. Logarithmically, perhaps? Just a hunch, but let&#8217;s throw caution to the wind, and hazard an even stronger hypothesis.</p>



<p>With n=100, observation leads us to a fairly safe guess. Namely, it&#8217;s very likely that at least one number will repeat at least 3 times. 3, in our case, happens to be <img decoding="async" src="https://s0.wp.com/latex.php?latex=%5Clog%7Bn%7D+%2B+1&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="&#92;log{n} + 1" class="latex" />.</p>



<p>I bet the odds aren&#8217;t too bad for <img decoding="async" src="https://s0.wp.com/latex.php?latex=%5Clog%7Bn%7D+%2B+2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="&#92;log{n} + 2" class="latex" /> either, but <img decoding="async" src="https://s0.wp.com/latex.php?latex=%5Clog%7Bn%7D+%2B+1&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="&#92;log{n} + 1" class="latex" /> seems extremely likely.</p>



<p>So our guess/hypothesis becomes:</p>



<p class="has-background has-pale-cyan-blue-background-color">Given n integers randomly selected from 1 to n, there is a high probability that at least one number will be repeated at least log n + 1 times.</p>



<p>This would imply:</p>



<table class="wp-block-table aligncenter has-fixed-layout"><tbody><tr><td>n</td><td>Repetitions</td></tr><tr><td>1000</td><td>4</td></tr><tr><td>10,000</td><td>5</td></tr><tr><td>100,000</td><td>6</td></tr></tbody></table>



<p>Let&#8217;s fire up good ol&#8217; Python and see where we land.</p>



<p>When I ran the code (shown at the end) for n = 1000 I got the following chart.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="1600" height="1100" src="https://i1.wp.com/programmingzen.com/wp-content/uploads/2019/08/1000.png?fit=1024%2C704&amp;ssl=1" alt="Frequency of random occurrences with N=1000.
" class="wp-image-2122" srcset="https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/1000.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/1000.png?resize=300%2C206&amp;ssl=1 300w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/1000.png?resize=768%2C528&amp;ssl=1 768w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/1000.png?resize=1024%2C704&amp;ssl=1 1024w" sizes="(max-width: 1060px) 100vw, 1060px" /></figure></div>



<p>Look at all those points on y = 4. Even <img decoding="async" src="https://s0.wp.com/latex.php?latex=%5Clog%7Bn%7D+%2B+2+%3D+5&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="&#92;log{n} + 2 = 5" class="latex" /> is holding up. Methinks, we are onto something.</p>



<p>Let&#8217;s try n = 10,000.</p>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" decoding="async" width="1600" height="1100" src="https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/10000.png?fit=1024%2C704&amp;ssl=1" alt="Frequency of random occurrences with N=10,000." class="wp-image-2123" srcset="https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/10000.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/10000.png?resize=300%2C206&amp;ssl=1 300w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/10000.png?resize=768%2C528&amp;ssl=1 768w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/10000.png?resize=1024%2C704&amp;ssl=1 1024w" sizes="auto, (max-width: 1060px) 100vw, 1060px" /></figure></div>



<p>Yup. We expected some numbers to be repeated 5 times, and we got quite a few of those.</p>



<p>Okay, time to bring out the big guns. n=100,000.</p>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" decoding="async" width="1600" height="1100" src="https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/100_000.png?fit=1024%2C704&amp;ssl=1" alt="Frequency of random occurrences with N=100,000." class="wp-image-2124" srcset="https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/100_000.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/100_000.png?resize=300%2C206&amp;ssl=1 300w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/100_000.png?resize=768%2C528&amp;ssl=1 768w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2019/08/100_000.png?resize=1024%2C704&amp;ssl=1 1024w" sizes="auto, (max-width: 1060px) 100vw, 1060px" /></figure></div>



<p>It looks like it still holds. There is a multitude of numbers with 6 repetitions.</p>



<h2 class="wp-block-heading">So what</h2>



<p>OK, so we started off with random data and through visualization and a bit of intuition, we came up with a pretty neat (if conservative) rule about how often numbers repeat by chance. Along with some room to refine our guess and experiment further.</p>



<p>This is the essence of science. You observe phenomena, formulate a hypothesis, and then try to prove or disprove it through experimentation.</p>



<p>Now, before the rigorous mathematicians among my readers have a conniption, all this doesn&#8217;t prove the hypothesis above. Of course.</p>



<p>What does highly likely even mean in this context? Is it 90%, or 99.999% How does it vary as n varies? You&#8217;ll want to analytically verify this and calculate what the actual odds for the occurrence of at least <img decoding="async" src="https://s0.wp.com/latex.php?latex=%5Clog%7Bn%7D+%2B+1&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="&#92;log{n} + 1" class="latex" /> and <img decoding="async" src="https://s0.wp.com/latex.php?latex=%5Clog%7Bn%7D+%2B+2&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="&#92;log{n} + 2" class="latex" /> repetitions are.</p>



<p>I have not had the time to take this further step (the solution is likely not as trivial as it first looks). At the risk of enraging you with a flashback from your college days, I&#8217;m afraid I&#8217;ll have to leave this as an exercise for the reader. 😉</p>



<p>But this fun exploration is what got us to the hypothesis and these follow up questions in the first place. Historically, people have often figured out some mathematical relation or hint of it before they could rigorously prove it or had the exact answer.</p>



<p>The Babylonians come to mind, as they might have figured out the Pythagorean Theorem before they had a rigorous proof:</p>



<blockquote style="text-align:left" class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>The famous and controversial Plimpton 322 clay tablet, believed to date from around 1800 BCE, suggests that the Babylonians may well have known the secret of right-angled triangles (that the square of the hypotenuse equals the sum of the square of the other two sides) many centuries before the&nbsp;Greek&nbsp;Pythagoras. The tablet appears to list 15 perfect Pythagorean triangles with whole number sides, although some claim that they were merely academic exercises, and not deliberate manifestations of Pythagorean triples.</p><cite>&#8212; <a rel="noreferrer noopener" aria-label="Luke Mastin (opens in a new tab)" href="https://www.storyofmathematics.com/sumerian.html" target="_blank">Luke Mastin</a></cite></blockquote>



<p>Computer simulation and data visualization have just opened us up to a world of mathematical exploration not previously accessible to any human.</p>



<h2 class="wp-block-heading">Plotting in Python with Matplotlib</h2>



<p>If all the math above isn&#8217;t very interesting to you, the Python 3 code I used to plot the charts may be of greater interest.</p>



<p>This is the code in its entirety.</p>



<pre class="wp-block-code"><code>import matplotlib.pyplot as plt
import random

MAX_NUM = 1000

x_values = range(1, MAX_NUM + 1)
values = [random.randint(1, MAX_NUM) for x in x_values]
y_values = [values.count(x) for x in x_values]

plt.style.use("seaborn")
fig, ax = plt.subplots()
ax.scatter(x_values, y_values, s=10)

ax.set_title(f"Random Number Occurrences (N = {MAX_NUM})", fontsize=18)
ax.set_xlabel("Number", fontsize=14)
ax.set_ylabel("Occurrences", fontsize=14)

ax.tick_params(axis="both", which="major", labelsize=14)

plt.show()</code></pre>



<p>Let&#8217;s break it down. We start off by importing <code>pyplot</code> from <code>matplotlib</code> and <code>random</code> since we&#8217;ll be generating pseudo-random numbers.</p>



<p>In truth, we could use <code>secrets</code> for better randomness, but it&#8217;s overkill here and the results are unaffected.</p>



<pre class="wp-block-code"><code>
import matplotlib.pyplot as plt
import random</code></pre>



<p><br>We then set our input size (<code>MAX_NUM</code>), generate that number of random values (<code>values</code>) and aggregate their frequency in <code>y_values</code>.</p>



<pre class="wp-block-code"><code>MAX_NUM = 1000

x_values = range(1, MAX_NUM + 1)
values = [random.randint(1, MAX_NUM) for x in x_values]
y_values = [values.count(x) for x in x_values]</code></pre>



<p><br>Here we set some styling for the chart so that it looks a bit better. We pick the <code>seaborn</code> style, set the thickness of the dots (10 made them fairly visible), and set the labels for the axes.</p>



<pre class="wp-block-code"><code>plt.style.use("seaborn")
fig, ax = plt.subplots()
ax.scatter(x_values, y_values, s=10)

ax.set_title(f"Random Number Occurrences (N = {MAX_NUM})", fontsize=18)
ax.set_xlabel("Number", fontsize=14)
ax.set_ylabel("Occurrences", fontsize=14)

ax.tick_params(axis="both", which="major", labelsize=14)</code></pre>



<p>Finally, we show the graph.</p>



<pre class="wp-block-code"><code>plt.show()</code></pre>



<p>Let me know if you enjoy this type of exploration and I might create a few more posts like this. Or conversely, feel free to tell me why I&#8217;m wrong about everything, in the comments below. 🙂</p>



<p><em>Special thanks to John McGowan of <a href="http://www.mathematical-software.com/" target="_blank" rel="noreferrer noopener" aria-label="Mathematical Sofware (opens in a new tab)">Mathematical Sofware</a>. I&#8217;m immensely grateful for his comments on an earlier draft of the article, although any errors remain my own.</em></p>
<p>The post <a href="https://programmingzen.com/exploring-mathematics-with-matplotlib-and-python/">Exploring Mathematics with Matplotlib and Python</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/exploring-mathematics-with-matplotlib-and-python/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2097</post-id>	</item>
		<item>
		<title>On Programming Languages as Languages</title>
		<link>https://programmingzen.com/programming-languages-as-languages/</link>
					<comments>https://programmingzen.com/programming-languages-as-languages/#comments</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Thu, 27 Nov 2014 16:05:32 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Ruby]]></category>
		<guid isPermaLink="false">http://programmingzen.com/?p=1571</guid>

					<description><![CDATA[<p>When you look up the word &#x201C;Language&#x201D; in the dictionary, you&#x2019;ll find a few variations of similar definitions. My trusty Google Dictionary extension in Chrome, offers up a first definition that is rather obvious, but nevertheless: The method of human communication, either spoken or written, consisting of the use of words in a structured and conventional way. The second definition is more interesting because it allows me to make a point about programming languages. It goes like this: The system of communication used by a particular community or country. Look at that. Isn&#x2019;t that beautiful? Let&#x2019;s cut the country stuff, </p>
<p>The post <a href="https://programmingzen.com/programming-languages-as-languages/">On Programming Languages as Languages</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When you look up the word “Language” in the dictionary, you’ll find a few variations of similar definitions. My trusty <a href="https://chrome.google.com/webstore/detail/google-dictionary-by-goog/mgijmajocgfcbeboacabfgobmjgjcoja?hl=en">Google Dictionary extension</a> in Chrome, offers up a first definition that is rather obvious, but nevertheless:</p>
<blockquote><p>The method of human communication, either spoken or written, consisting of the use of words in a structured and conventional way.</p></blockquote>
<p>The second definition is more interesting because it allows me to make a point about programming languages. It goes like this:</p>
<blockquote><p>The system of communication used by a particular community or country.</p></blockquote>
<p>Look at that. Isn’t that beautiful? Let’s cut the country stuff, and shorten it to, “The system of communication used by a particular community”. Tell me that it’s not a spectacular definition of programming languages as well.</p>
<p>We can look at programming languages in two possible ways. They can be a means for us to instruct the computer, and incidentally communicate with fellow programmers, or they can allow us to communicate with other programmers in specific terms that are ultimately executable.</p>
<p>The first interpretation is technically more accurate. Or, more specifically, the worst kind of accurate.</p>
<p>I like to think of programming languages as languages because, outside of trivial programs, above all else they enable programmers to communicate with one another when it comes to resolving a problem or completing a particular task, while incidentally producing code that is also understood by computers via “translators” (e.g., compilers and interpreters).</p>
<p>There are plenty of benefits that can be derived from thinking about programming in terms of the second interpretation.</p>
<p>When you view programming in this light, you start considering the value of comments expressing the “why” and code expressing the “how”. Tests become a way to communicate to a fellow programmer <a id="fnref:1" class="footnote" title="see footnote" href="#fn:1">[1]</a> that a change to the codebase has violated a given requirement. Above all, writing idiomatic code becomes important.</p>
<p>Remember the Google Dictionary definition. “The system of communication of a particular community”. It is in fact the community, for better or for worse, that sets the guidelines and de facto style of a particular programming language.</p>
<p>Since we are operating in a system of communication, programming is a bit like driving: predictability is important. That’s why in the Ruby community we have the <a href="https://en.wikipedia.org/wiki/Principle_of_least_astonishment">principle of least surprise</a> <a id="fnref:2" class="footnote" title="see footnote" href="#fn:2">[2]</a> and in the Python community one finds the “There should be one – and preferably only one – obvious way to do it” mantra. <a id="fnref:3" class="footnote" title="see footnote" href="#fn:3">[3]</a></p>
<p>When you think of programming languages as a series of conventions adopted by a community, and incidentally understood by the computer, you avoid recklessly monkey patching classes just because you can. You know that doing so leads to unexpected results and miscommunications with other programmers.</p>
<p>You also avoid features which are technically legal in the language, but rare and confusing to fellow experienced developers in that particular language. For an example of this, take a look a the <a href="https://nithinbekal.com/posts/ruby-flip-flop/">Flip-Flop</a> operator in Ruby (a reminiscence of its Perl heritage). Technically legal Ruby, even useful at times, however you shouldn’t use it because only a handful of fellow Rubyists will understand what you’re doing. <a id="fnref:4" class="footnote" title="see footnote" href="#fn:4">[4]</a> Worse yet, it will be hard to Google for an answer unless you are familiar with its name already.</p>
<p>When you’re first picking up a human language, you learn the meaning of common words. Then you use simple sentences that you memorize from books, people around you, songs, movies, and TV shows. Then you try to mimic the idioms you see used by mother tongue speakers. Often you won’t get them right at first, resulting in comical variations that are close, but not quite right, to those of native speakers.</p>
<p>When it comes to programming languages things really aren’t all that different. That’s why it’s critically important to read other people’s code, write code and receive feedback in code reviews, do peer programming, take part in open source contribution, and engage in other forms of social interaction pertaining to code. Doing so is immensely important when it comes to truly mastering a programming language.</p>
<p>Another consequence of this emphasis on communication among programmers through a common, precise, language whose style, conventions, and idioms are defined by the community is that you should choose your communities carefully. What are the community’s priorities? If there is no love for beautiful, clear, elegant, easy to understand code, tread very carefully. <a id="fnref:5" class="footnote" title="see footnote" href="#fn:5">[5]</a></p>
<p>As someone who had to learn English as an adult, pretty much from scratch, I can tell you that I find many parallels between the experience of learning a new language and that of a new programming language.</p>
<p>Even if the two are not a perfect match &#8211; and seeing a programming language as a human language is an imperfect metaphor &#8211; I feel that thinking of it in these terms has allowed me to quickly acquire key skills in the programming languages that I needed or wanted to learn.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">At times, that other programmer is just your future self. <a class="reversefootnote" title="return to article" href="#fnref:1">&#8593;</a></li>
<li id="fn:2">Well, at least that doesn’t surprise Ruby’s creator, <a href="https://en.wikipedia.org/wiki/Yukihiro_Matsumoto">Matz</a>. <a class="reversefootnote" title="return to article" href="#fnref:2">&#8593;</a></li>
<li id="fn:3">Run <code>import this</code> in your iPython shell. What, you’re not using iPython? Stop reading. Go <a href="https://ipython.org/">install it</a>. <a class="reversefootnote" title="return to article" href="#fnref:3">&#8593;</a></li>
<li id="fn:4">Idiomatic code can be hard to understand by inexperienced programmers. And that’s fine, as long as reasonably experienced developers can parse its meaning. If nine out of ten programmers in your own community are unable to understand what you are doing, you are equivalent to someone who intentionally uses archaic words in conversation. You end up sounding <em>grandiloquent</em> for no good reason. <a class="reversefootnote" title="return to article" href="#fnref:4">&#8593;</a></li>
<li id="fn:5">At the risk of getting backlash for these remarks, the PHP community comes to mind. Or even the JavaScript community prior to jQuery and Node.js. There were excellent PHP and JavaScript developers back in the day of course, but the community as a whole had a tendency to hack things together, as long as it worked. Somehow. <a class="reversefootnote" title="return to article" href="#fnref:5">&#8593;</a></li>
</ol>
</div>
<p>The post <a href="https://programmingzen.com/programming-languages-as-languages/">On Programming Languages as Languages</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/programming-languages-as-languages/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1571</post-id>	</item>
	</channel>
</rss>
