Commits

Anonymous committed f4f6782

PYPTUG presentation, from java to burma

  • Participants
  • Parent commits c7eebbd

Comments (0)

Files changed (18)

islanders/LICENSE

+Copyright (c) 2012 Francois Dion (francois.dion@gmail.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+

islanders/Puppy.py

+""" This module is my container for the attributes of a puppy """
+
+age=None

islanders/README.md

+PYPTUG hands on session
+=======================
+
+From Java to Burma by Francois Dion
+-----------------------------------
+
+http://www.pyptug.org/2013/08/pyptug-meeting-august-26th.html
+
+This information was presented at PYPTUG meeting, august 26th 2013. 
+
+Getters and setters are an engrained pattern for the islanders of Java, C++ and some other islanders. Naturally, as these islanders travel to Myanmar and encounter The Python (well, yes, we do know that Python is from that TV show, and not the reptile, be it a Burmese or other kind), they continue these ancient customs.
+
+In this hands on session, we will show you how to keep it simple and we will get deep into attributes, properties, descriptors and have fun with them.
+
+See also http://pyptug.blogspot.com and http://raspberry-python.blogspot.com
+
+Francois Dion's demonstration code is distributed under the MIT license (see LICENSE)

islanders/cpp/README.md

+# CPP example
+
+typical getter / setter
+
+To generate the executable:
+
+g++ puppy.cpp -o puppy
+
+and ./puppy to run it

islanders/cpp/puppy.cpp

+#include <iostream>
+using namespace std;
+
+class Puppy
+{
+
+	int m_Age;
+	
+	public:
+	
+	int  getAge() const { 
+		return m_Age; 
+	}
+	
+	void setAge(int age) {
+		m_Age = age;
+	}
+	
+};
+
+int main( int argc, const char* argv[] )
+{
+ Puppy benji;
+
+ benji.setAge(1);
+ cout << "age :" << benji.getAge() << endl;
+}

islanders/csharp/README.md

+# C sharp example
+
+Should not be your typical getter / setter for C sharp, as it does have properties, but in the wild, that is quite common, due to Java background of a lot of people. In the hands on, we talked about this in detail.
+
+To compile:
+gmcs puppy.cs
+
+To run:
+mono puppy.exe

islanders/csharp/puppy.cs

+using System;
+
+public class Puppy
+{
+   private int puppyAge;
+
+   public int GetAge()
+   {
+       return puppyAge;
+   }
+
+   public void SetAge(int value)
+   {
+       puppyAge = value;
+   }
+   
+   static public void Main ()
+   {
+       Puppy benji = new Puppy ();
+       
+       benji.SetAge(1);
+   	   Console.WriteLine ("age: " + benji.GetAge());
+   }
+}

islanders/dogyears.py

+class DogYears(object):
+    def __get__(self, instance, owner=None):
+        dog_years = (21+(instance.age-2)*4) if instance.age >=2\
+                    else 10.5*instance.age
+        return dog_years
+

islanders/java/Puppy.class

Binary file added.

islanders/java/Puppy.java

+public class Puppy{
+   
+   private int age;
+
+   public Puppy(){
+   }
+
+   public void setAge( int theAge ){
+       age = theAge;
+   }
+
+   public int getAge( ){
+       return age;
+   }
+   public static void main(String []args){
+      Puppy benji = new Puppy();
+
+      benji.setAge( 2 );
+
+      /* Call another class method to get puppy's age */
+      System.out.println("age :" + benji.getAge( )); 
+   }
+}

islanders/java/README.md

+# Java example
+
+typical getter / setter
+
+To compile:
+javac Puppy.javac
+
+To run:
+java Puppy

islanders/presentation/benji.png

Added
New image

islanders/presentation/java.jpg

Added
New image

islanders/presentation/presentation.html

+<!DOCTYPE html>
+<!--
+  Copyright 2010 Google Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+  Original slides: Marcin Wichary (mwichary@google.com)
+  Modifications: Ernest Delgado (ernestd@google.com)
+                 Alex Russell (slightlyoff@chromium.org)
+
+  landslide modifications: Adam Zapletal (adamzap@gmail.com)
+                           Nicolas Perriault (nperriault@gmail.com)
+-->
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <meta http-equiv="X-UA-Compatible" content="chrome=1">
+    <title>Hands on Python: From Java to Burma</title>
+    <!-- Styles -->
+    
+    <link rel="stylesheet" media="print" href="file:///usr/local/lib/python2.7/dist-packages/landslide/themes/default/css/print.css">
+    <link rel="stylesheet" media="screen, projection" href="file:///usr/local/lib/python2.7/dist-packages/landslide/themes/default/css/screen.css">
+    
+    
+    <!-- /Styles -->
+    <!-- Javascripts -->
+    
+    <script type="text/javascript" src="file:///usr/local/lib/python2.7/dist-packages/landslide/themes/default/js/slides.js"></script>
+    
+    
+    <!-- /Javascripts -->
+</head>
+<body>
+  <div id="blank"></div>
+  <div class="presentation">
+    <div id="current_presenter_notes">
+      <div id="presenter_note"></div>
+    </div>
+    <div class="slides">
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide">
+          <div class="inner">
+            
+            <header><h1>Hands on Python: From Java to Burma</h1></header>
+            
+            
+            <section><p>by <em>Francois Dion</em> @f_dion</p>
+<p><img alt="PYPTUG" src="file:///home/fdion/pyptug/islanders/presentation/pyptug.png" /></p>
+<p>PYPTUG @WFU Monday August 26th 2013</p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              1/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide">
+          <div class="inner">
+            
+            <header><h1>Hands on Python: From Java to Burma</h1></header>
+            
+            
+            <section><p><img alt="Java" src="file:///home/fdion/pyptug/islanders/presentation/java.jpg" /></p>
+<h2>The Islanders</h2>
+<p>Getters and setters are an engrained pattern for the islanders of Java, C++ and some other islanders. Naturally, as these islanders travel to Myanmar and encounter The Python (well, yes, we do know that Python is from that TV show, and not the reptile, be it a Burmese or other kind), they continue these ancient customs.</p>
+<p>In this hands on session, we will show you how to keep it simple and we will get deep into attributes, properties, descriptors and have fun with them.</p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              2/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide">
+          <div class="inner">
+            
+            <header><h1>Meet Benji</h1></header>
+            
+            
+            <section><p><img alt="Benji" src="file:///home/fdion/pyptug/islanders/presentation/benji.png" /></p>
+<p>Attributes?</p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              3/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide">
+          <div class="inner">
+            
+            <header><h1>Attributes</h1></header>
+            
+            
+            <section><ul>
+<li>age</li>
+<li>gender</li>
+<li>race</li>
+<li>color</li>
+<li>height</li>
+<li>weight</li>
+<li>vaccinated</li>
+<li>hair</li>
+<li>bark</li>
+</ul></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              4/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide has_code">
+          <div class="inner">
+            
+            <header><h1>Namespaces</h1></header>
+            
+            
+            <section><h2>Just like math</h2>
+<p>age=1</p>
+<h2>My age and Benji's age</h2>
+<p>print(age)</p>
+<p>How is the computer supposed to know if it is my age, your age 
+or Benji's age.</p>
+<p>We need a container to hold all the attributes for benji, and a
+completely different one for you and I.</p>
+<h2>Puppy, Human</h2>
+<div class="highlight"><pre><span class="lineno">1</span> <span class="n">Puppy</span><span class="o">.</span><span class="n">age</span>
+<span class="lineno">2</span> <span class="n">Human</span><span class="o">.</span><span class="n">age</span>
+</pre></div>
+
+<p>We can do it with modules or with classes, but...</p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              5/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide has_code">
+          <div class="inner">
+            
+            <header><h1>Modules</h1></header>
+            
+            
+            <section><div class="highlight"><pre><span class="lineno">1</span> <span class="kn">import</span> <span class="nn">Puppy</span>
+</pre></div>
+
+<p><em>hands on</em></p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              6/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide has_code">
+          <div class="inner">
+            
+            <header><h1>Class</h1></header>
+            
+            
+            <section><div class="highlight"><pre><span class="lineno">1</span> <span class="k">class</span> <span class="nc">Puppy</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+</pre></div>
+
+<p><em>hands on</em></p>
+<p>What if I wanted to add dog years?</p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              7/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide has_code">
+          <div class="inner">
+            
+            <header><h1>Java</h1></header>
+            
+            
+            <section><div class="highlight"><pre><span class="lineno"> 1</span> <span class="kd">public</span> <span class="kd">class</span> <span class="nc">Puppy</span><span class="o">{</span>
+<span class="lineno"> 2</span> 
+<span class="lineno"> 3</span>     <span class="kd">private</span> <span class="kt">int</span> <span class="n">age</span><span class="o">;</span>
+<span class="lineno"> 4</span> 
+<span class="lineno"> 5</span>     <span class="kd">public</span> <span class="nf">Puppy</span><span class="o">(){</span>
+<span class="lineno"> 6</span>     <span class="o">}</span>   
+<span class="lineno"> 7</span>     <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setAge</span><span class="o">(</span> <span class="kt">int</span> <span class="n">theAge</span> <span class="o">){</span>
+<span class="lineno"> 8</span>         <span class="n">age</span> <span class="o">=</span> <span class="n">theAge</span><span class="o">;</span>
+<span class="lineno"> 9</span>     <span class="o">}</span>
+<span class="lineno">10</span>     <span class="kd">public</span> <span class="kt">int</span> <span class="nf">getAge</span><span class="o">(</span> <span class="o">){</span>
+<span class="lineno">11</span>         <span class="k">return</span> <span class="n">age</span><span class="o">;</span>
+<span class="lineno">12</span>     <span class="o">}</span>
+<span class="lineno">13</span> 
+<span class="lineno">14</span>     <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="n">String</span> <span class="o">[]</span><span class="n">args</span><span class="o">){</span>
+<span class="lineno">15</span>         <span class="n">Puppy</span> <span class="n">benji</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Puppy</span><span class="o">();</span>
+<span class="lineno">16</span> 
+<span class="lineno">17</span>         <span class="n">benji</span><span class="o">.</span><span class="na">setAge</span><span class="o">(</span> <span class="mi">2</span> <span class="o">);</span>
+<span class="lineno">18</span> 
+<span class="lineno">19</span>         <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;age:&quot;</span> <span class="o">+</span> <span class="n">benji</span><span class="o">.</span><span class="na">getAge</span><span class="o">(</span> <span class="o">));</span> 
+<span class="lineno">20</span>     <span class="o">}</span>
+<span class="lineno">21</span> <span class="o">}</span>
+</pre></div>
+</section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              8/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide has_code">
+          <div class="inner">
+            
+            <header><h1>C++</h1></header>
+            
+            
+            <section><div class="highlight"><pre><span class="lineno"> 1</span> <span class="cp">#include &lt;iostream&gt;</span>
+<span class="lineno"> 2</span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
+<span class="lineno"> 3</span> 
+<span class="lineno"> 4</span> <span class="k">class</span> <span class="nc">Puppy</span><span class="p">{</span>
+<span class="lineno"> 5</span>     <span class="kt">int</span> <span class="n">m_Age</span><span class="p">;</span>
+<span class="lineno"> 6</span> 
+<span class="lineno"> 7</span>     <span class="nl">public:</span> 
+<span class="lineno"> 8</span>     <span class="kt">int</span>  <span class="n">getAge</span><span class="p">()</span> <span class="k">const</span> <span class="p">{</span> 
+<span class="lineno"> 9</span>         <span class="k">return</span> <span class="n">m_Age</span><span class="p">;</span> 
+<span class="lineno">10</span>     <span class="p">}</span>
+<span class="lineno">11</span>     <span class="kt">void</span> <span class="n">setAge</span><span class="p">(</span><span class="kt">int</span> <span class="n">age</span><span class="p">)</span> <span class="p">{</span>
+<span class="lineno">12</span>         <span class="n">m_Age</span> <span class="o">=</span> <span class="n">age</span><span class="p">;</span>
+<span class="lineno">13</span>     <span class="p">}</span>
+<span class="lineno">14</span> <span class="p">};</span>
+<span class="lineno">15</span> 
+<span class="lineno">16</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">(</span> <span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">argv</span><span class="p">[]</span> <span class="p">)</span>
+<span class="lineno">17</span> <span class="p">{</span>
+<span class="lineno">18</span> <span class="n">Puppy</span> <span class="n">benji</span><span class="p">;</span>
+<span class="lineno">19</span> 
+<span class="lineno">20</span> <span class="n">benji</span><span class="p">.</span><span class="n">setAge</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
+<span class="lineno">21</span> <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;age:&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">benji</span><span class="p">.</span><span class="n">getAge</span><span class="p">()</span> <span class="o">&lt;&lt;</span> <span class="n">endl</span><span class="p">;</span>
+<span class="lineno">22</span> <span class="p">}</span>
+</pre></div>
+</section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              9/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide has_code">
+          <div class="inner">
+            
+            <header><h1>C# seen in the wild</h1></header>
+            
+            
+            <section><div class="highlight"><pre><span class="lineno"> 1</span> <span class="k">using</span> <span class="nn">System</span><span class="p">;</span>
+<span class="lineno"> 2</span> 
+<span class="lineno"> 3</span> <span class="k">public</span> <span class="k">class</span> <span class="nc">Puppy</span>
+<span class="lineno"> 4</span> <span class="p">{</span>
+<span class="lineno"> 5</span>     <span class="k">private</span> <span class="kt">int</span> <span class="n">puppyAge</span><span class="p">;</span>
+<span class="lineno"> 6</span>     <span class="k">public</span> <span class="kt">int</span> <span class="nf">GetAge</span><span class="p">()</span>
+<span class="lineno"> 7</span>     <span class="p">{</span>
+<span class="lineno"> 8</span>         <span class="k">return</span> <span class="n">puppyAge</span><span class="p">;</span>
+<span class="lineno"> 9</span>     <span class="p">}</span>   
+<span class="lineno">10</span>     <span class="k">public</span> <span class="k">void</span> <span class="nf">SetAge</span><span class="p">(</span><span class="kt">int</span> <span class="k">value</span><span class="p">)</span>
+<span class="lineno">11</span>     <span class="p">{</span>
+<span class="lineno">12</span>         <span class="n">puppyAge</span> <span class="p">=</span> <span class="k">value</span><span class="p">;</span>
+<span class="lineno">13</span>     <span class="p">}</span>
+<span class="lineno">14</span>     <span class="k">static</span> <span class="k">public</span> <span class="k">void</span> <span class="nf">Main</span> <span class="p">()</span>
+<span class="lineno">15</span>     <span class="p">{</span>
+<span class="lineno">16</span>         <span class="n">Puppy</span> <span class="n">benji</span> <span class="p">=</span> <span class="k">new</span> <span class="n">Puppy</span> <span class="p">();</span>
+<span class="lineno">17</span> 
+<span class="lineno">18</span>         <span class="n">benji</span><span class="p">.</span><span class="n">SetAge</span><span class="p">(</span><span class="m">1</span><span class="p">);</span>
+<span class="lineno">19</span>         <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span> <span class="p">(</span><span class="s">&quot;age: &quot;</span> <span class="p">+</span> <span class="n">benji</span><span class="p">.</span><span class="n">GetAge</span><span class="p">());</span>
+<span class="lineno">20</span>     <span class="p">}</span>
+<span class="lineno">21</span> <span class="p">}</span>
+</pre></div>
+</section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              10/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide has_code">
+          <div class="inner">
+            
+            <header><h1>C# with properties</h1></header>
+            
+            
+            <section><div class="highlight"><pre><span class="lineno"> 1</span> <span class="k">public</span> <span class="k">class</span> <span class="nc">Puppy</span>
+<span class="lineno"> 2</span> <span class="p">{</span>
+<span class="lineno"> 3</span>     <span class="k">private</span> <span class="kt">string</span> <span class="n">puppyAge</span><span class="p">;</span>
+<span class="lineno"> 4</span> 
+<span class="lineno"> 5</span>     <span class="k">public</span> <span class="kt">string</span> <span class="n">age</span>
+<span class="lineno"> 6</span>     <span class="p">{</span>
+<span class="lineno"> 7</span>         <span class="k">get</span> <span class="p">{</span> <span class="k">return</span> <span class="n">puppyAge</span><span class="p">;</span> <span class="p">}</span>
+<span class="lineno"> 8</span>         <span class="k">set</span> <span class="p">{</span> <span class="n">puppyAge</span> <span class="p">=</span> <span class="k">value</span><span class="p">;</span> <span class="p">}</span>
+<span class="lineno"> 9</span>     <span class="p">}</span>
+<span class="lineno">10</span>     <span class="k">static</span> <span class="k">public</span> <span class="k">void</span> <span class="nf">Main</span> <span class="p">()</span>
+<span class="lineno">11</span>     <span class="p">{</span>
+<span class="lineno">12</span>         <span class="n">Puppy</span> <span class="n">benji</span> <span class="p">=</span> <span class="k">new</span> <span class="n">Puppy</span> <span class="p">();</span>
+<span class="lineno">13</span> 
+<span class="lineno">14</span>         <span class="n">benji</span><span class="p">.</span><span class="n">SetAge</span><span class="p">(</span><span class="m">1</span><span class="p">);</span>
+<span class="lineno">15</span>         <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span> <span class="p">(</span><span class="s">&quot;age: &quot;</span> <span class="p">+</span> <span class="n">benji</span><span class="p">.</span><span class="n">GetAge</span><span class="p">());</span>
+<span class="lineno">16</span>     <span class="p">}</span>
+<span class="lineno">17</span> 
+<span class="lineno">18</span> <span class="p">}</span>
+</pre></div>
+</section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              11/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide">
+          <div class="inner">
+            
+            <header><h1>Always start with attributes</h1></header>
+            
+            
+            <section><h2>Unless you have a good reason not to.</h2>
+<h2>You can always come back and change to properties later on.</h2>
+<p><em>hands on</em></p>
+<p>(next page is definition of property class)</p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              12/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide has_code">
+          <div class="inner">
+            
+            <header><h1>Properties</h1></header>
+            
+            
+            <section><div class="highlight"><pre><span class="lineno"> 1</span> <span class="k">class</span> <span class="nc">property</span><span class="p">(</span><span class="nb">object</span><span class="p">)</span>
+<span class="lineno"> 2</span> <span class="o">|</span>  <span class="nb">property</span><span class="p">(</span><span class="n">fget</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">fset</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">fdel</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="bp">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">property</span>
+<span class="lineno"> 3</span> <span class="o">|</span>  <span class="n">attribute</span>
+<span class="lineno"> 4</span> <span class="o">|</span>  
+<span class="lineno"> 5</span> <span class="o">|</span>  <span class="n">fget</span> <span class="ow">is</span> <span class="n">a</span> <span class="n">function</span> <span class="n">to</span> <span class="n">be</span> <span class="n">used</span> <span class="k">for</span> <span class="n">getting</span> <span class="n">an</span> <span class="n">attribute</span> <span class="n">value</span><span class="p">,</span> <span class="ow">and</span>
+<span class="lineno"> 6</span> <span class="o">|</span>  <span class="n">fset</span> <span class="ow">is</span> <span class="n">a</span> <span class="n">function</span> <span class="k">for</span> <span class="n">setting</span><span class="p">,</span> <span class="ow">and</span> <span class="n">fdel</span> <span class="n">a</span> <span class="n">function</span> <span class="k">for</span> <span class="k">del</span><span class="s">&#39;ing,</span>
+<span class="lineno"> 7</span> <span class="o">|</span>  <span class="n">an</span> <span class="n">attribute</span><span class="o">.</span>  <span class="n">Typical</span> <span class="n">use</span> <span class="ow">is</span> <span class="n">to</span> <span class="n">define</span> <span class="n">a</span> <span class="n">managed</span> <span class="n">attribute</span> <span class="n">x</span><span class="p">:</span>
+<span class="lineno"> 8</span> <span class="o">|</span>  <span class="k">class</span> <span class="nc">C</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+<span class="lineno"> 9</span> <span class="o">|</span>      <span class="k">def</span> <span class="nf">getx</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_x</span>
+<span class="lineno">10</span> <span class="o">|</span>      <span class="k">def</span> <span class="nf">setx</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">_x</span> <span class="o">=</span> <span class="n">value</span>
+<span class="lineno">11</span> <span class="o">|</span>      <span class="k">def</span> <span class="nf">delx</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_x</span>
+<span class="lineno">12</span> <span class="o">|</span>      <span class="n">x</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">getx</span><span class="p">,</span> <span class="n">setx</span><span class="p">,</span> <span class="n">delx</span><span class="p">,</span> <span class="s">&quot;I&#39;m the &#39;x&#39; property.&quot;</span><span class="p">)</span>
+</pre></div>
+
+<p><em>hands on</em></p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              13/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide has_code">
+          <div class="inner">
+            
+            <header><h1>Decorators</h1></header>
+            
+            
+            <section><div class="highlight"><pre><span class="lineno">1</span> <span class="o">|</span>  <span class="n">Decorators</span> <span class="n">make</span> <span class="n">defining</span> <span class="n">new</span> <span class="n">properties</span> <span class="ow">or</span> <span class="n">modifying</span> <span class="n">existing</span> <span class="n">ones</span>
+<span class="lineno">2</span> <span class="o">|</span>  <span class="n">easy</span><span class="p">:</span>
+<span class="lineno">3</span> <span class="o">|</span>  <span class="k">class</span> <span class="nc">C</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+<span class="lineno">4</span> <span class="o">|</span>      <span class="nd">@property</span>
+<span class="lineno">5</span> <span class="o">|</span>      <span class="k">def</span> <span class="nf">x</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_x</span>
+<span class="lineno">6</span> <span class="o">|</span>      <span class="nd">@x.setter</span>
+<span class="lineno">7</span> <span class="o">|</span>      <span class="k">def</span> <span class="nf">x</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">_x</span> <span class="o">=</span> <span class="n">value</span>
+<span class="lineno">8</span> <span class="o">|</span>      <span class="nd">@x.deleter</span>
+<span class="lineno">9</span> <span class="o">|</span>      <span class="k">def</span> <span class="nf">x</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_x</span>
+</pre></div>
+
+<p><em>hands on</em></p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              14/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide">
+          <div class="inner">
+            
+            <header><h1>Descriptors</h1></header>
+            
+            
+            <section><p>Going deep now, for those that are starting to get overwhelmed,
+as an exercise, try to add other attributes to your Puppy class.
+Ignore my talking. For the others, hold on to your hats.</p>
+<h2>Defined</h2>
+<p><em>In general, a descriptor is an object attribute with
+“binding behavior”, one whose attribute access has been overridden
+by methods in the descriptor protocol.</em></p>
+<h2>Say what?</h2>
+<p>For our intent and purpose, we are talking about the main use
+of descriptors in daily coding: custom descriptors</p>
+<ul>
+<li>can allow reuse of properties</li>
+<li>specialized behaviour when accessed, set or deleted</li>
+</ul>
+<p>In fact, we do that now with <em>property</em>, which is a descriptor, and
+so would be <em>staticmethod</em> and <em>classmethod</em>.</p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              15/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide">
+          <div class="inner">
+            
+            <header><h1>Descriptors - continued</h1></header>
+            
+            
+            <section><h2>accessed, set or deleted</h2>
+<p><em>Those methods are __get__(), __set__(), and __delete__(). 
+If any of those methods are defined for an object, it is said to be
+a descriptor.</em></p>
+<h2>Let's do it</h2>
+<p><em>hands on</em></p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              16/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+      <!-- slide source: slides.md -->
+      <div class="slide-wrapper">
+        <div class="slide">
+          <div class="inner">
+            
+            <header><h1>Hands on Python: From Java to Burma</h1></header>
+            
+            
+            <section><p>by <em>Francois Dion</em> @f_dion</p>
+<p><img alt="PYPTUG" src="file:///home/fdion/pyptug/islanders/presentation/pyptug.png" /></p>
+<p>PYPTUG @WFU Monday August 26th 2013</p></section>
+            
+          </div>
+          <div class="presenter_notes">
+            <header><h1>Presenter Notes</h1></header>
+            <section>
+            
+            </section>
+          </div>
+          <footer>
+            
+            <aside class="source">
+              Source: <a href="slides.md">slides.md</a>
+            </aside>
+            
+            <aside class="page_number">
+              17/17
+            </aside>
+          </footer>
+        </div>
+      </div>
+      
+    </div>
+  </div>
+  
+  <div id="toc" class="sidebar hidden">
+    <h2>Table of Contents</h2>
+    <table>
+      <caption>Table of Contents</caption>
+      
+      <tr id="toc-row-1">
+        <th><a href="#slide1">Hands on Python: From Java to Burma</a></th>
+        <td><a href="#slide1">1</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-2">
+        <th><a href="#slide2">Hands on Python: From Java to Burma</a></th>
+        <td><a href="#slide2">2</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-3">
+        <th><a href="#slide3">Meet Benji</a></th>
+        <td><a href="#slide3">3</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-4">
+        <th><a href="#slide4">Attributes</a></th>
+        <td><a href="#slide4">4</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-5">
+        <th><a href="#slide5">Namespaces</a></th>
+        <td><a href="#slide5">5</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-6">
+        <th><a href="#slide6">Modules</a></th>
+        <td><a href="#slide6">6</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-7">
+        <th><a href="#slide7">Class</a></th>
+        <td><a href="#slide7">7</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-8">
+        <th><a href="#slide8">Java</a></th>
+        <td><a href="#slide8">8</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-9">
+        <th><a href="#slide9">C++</a></th>
+        <td><a href="#slide9">9</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-10">
+        <th><a href="#slide10">C# seen in the wild</a></th>
+        <td><a href="#slide10">10</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-11">
+        <th><a href="#slide11">C# with properties</a></th>
+        <td><a href="#slide11">11</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-12">
+        <th><a href="#slide12">Always start with attributes</a></th>
+        <td><a href="#slide12">12</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-13">
+        <th><a href="#slide13">Properties</a></th>
+        <td><a href="#slide13">13</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-14">
+        <th><a href="#slide14">Decorators</a></th>
+        <td><a href="#slide14">14</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-15">
+        <th><a href="#slide15">Descriptors</a></th>
+        <td><a href="#slide15">15</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-16">
+        <th><a href="#slide16">Descriptors - continued</a></th>
+        <td><a href="#slide16">16</a></td>
+      </tr>
+      
+      
+      <tr id="toc-row-17">
+        <th><a href="#slide17">Hands on Python: From Java to Burma</a></th>
+        <td><a href="#slide17">17</a></td>
+      </tr>
+      
+      
+    </table>
+  </div>
+  
+  <div id="help" class="sidebar hidden">
+    <h2>Help</h2>
+    <table>
+      <caption>Help</caption>
+      <tr>
+        <th>Table of Contents</th>
+        <td>t</td>
+      </tr>
+      <tr>
+        <th>Exposé</th>
+        <td>ESC</td>
+      </tr>
+      <tr>
+        <th>Full screen slides</th>
+        <td>e</td>
+      </tr>
+      <tr>
+        <th>Presenter View</th>
+        <td>p</td>
+      </tr>
+      <tr>
+        <th>Source Files</th>
+        <td>s</td>
+      </tr>
+      <tr>
+        <th>Slide Numbers</th>
+        <td>n</td>
+      </tr>
+      <tr>
+        <th>Toggle screen blanking</th>
+        <td>b</td>
+      </tr>
+      <tr>
+        <th>Show/hide slide context</th>
+        <td>c</td>
+      </tr>
+      <tr>
+        <th>Notes</th>
+        <td>2</td>
+      </tr>
+      <tr>
+        <th>Help</th>
+        <td>h</td>
+      </tr>
+    </table>
+  </div>
+  <script>main()</script>
+</body>
+</html>

islanders/presentation/puppy.cs

+

islanders/presentation/pyptug.png

Added
New image

islanders/presentation/slides.md

+# Hands on Python: From Java to Burma
+
+
+by _Francois Dion_ @f_dion
+
+
+![PYPTUG](pyptug.png)
+
+
+PYPTUG @WFU Monday August 26th 2013
+
+---
+
+# Hands on Python: From Java to Burma
+
+![Java](java.jpg)
+
+## The Islanders
+
+Getters and setters are an engrained pattern for the islanders of Java, C++ and some other islanders. Naturally, as these islanders travel to Myanmar and encounter The Python (well, yes, we do know that Python is from that TV show, and not the reptile, be it a Burmese or other kind), they continue these ancient customs.
+
+In this hands on session, we will show you how to keep it simple and we will get deep into attributes, properties, descriptors and have fun with them.
+
+---
+
+# Meet Benji
+
+![Benji](benji.png)
+
+Attributes?
+
+---
+
+# Attributes
+
+- age
+- gender
+- race
+- color
+- height
+- weight
+- vaccinated
+- hair
+- bark
+
+---
+
+# Namespaces
+
+## Just like math
+
+age=1
+
+## My age and Benji's age
+
+print(age)
+
+How is the computer supposed to know if it is my age, your age 
+or Benji's age.
+
+We need a container to hold all the attributes for benji, and a
+completely different one for you and I.
+
+## Puppy, Human
+
+    !python
+    Puppy.age
+    Human.age
+
+We can do it with modules or with classes, but...
+
+---
+
+# Modules
+
+    !python
+    import Puppy
+    
+*hands on*
+
+---
+
+# Class
+
+    !python
+    class Puppy(object):
+
+*hands on*
+
+What if I wanted to add dog years?
+
+---
+
+# Java
+
+    !java
+	public class Puppy{
+	
+		private int age;
+		
+		public Puppy(){
+		}	
+		public void setAge( int theAge ){
+			age = theAge;
+		}
+		public int getAge( ){
+			return age;
+		}
+		
+		public static void main(String []args){
+			Puppy benji = new Puppy();
+		
+			benji.setAge( 2 );
+		
+			System.out.println("age:" + benji.getAge( )); 
+		}
+	}
+	
+---
+
+# C++
+
+    !c++
+	#include <iostream>
+	using namespace std;
+	
+	class Puppy{
+		int m_Age;
+		
+		public:	
+		int  getAge() const { 
+			return m_Age; 
+		}
+		void setAge(int age) {
+			m_Age = age;
+		}
+	};
+
+	int main( int argc, const char* argv[] )
+	{
+	Puppy benji;
+	
+	benji.setAge(1);
+	cout << "age:" << benji.getAge() << endl;
+	}
+
+---
+
+# C# seen in the wild
+
+	!c#
+	using System;
+	
+	public class Puppy
+	{
+		private int puppyAge;
+		public int GetAge()
+		{
+			return puppyAge;
+		}	
+		public void SetAge(int value)
+		{
+			puppyAge = value;
+		}
+		static public void Main ()
+		{
+			Puppy benji = new Puppy ();
+			
+			benji.SetAge(1);
+			Console.WriteLine ("age: " + benji.GetAge());
+		}
+	}
+
+---
+
+# C# with properties
+
+	!c#
+	public class Puppy
+	{
+		private string puppyAge;
+	
+		public string age
+		{
+			get { return puppyAge; }
+			set { puppyAge = value; }
+		}
+		static public void Main ()
+		{
+			Puppy benji = new Puppy ();
+			
+			benji.SetAge(1);
+			Console.WriteLine ("age: " + benji.GetAge());
+		}
+
+	}
+
+---
+
+# Always start with attributes
+
+## Unless you have a good reason not to. 
+
+## You can always come back and change to properties later on.
+
+*hands on*
+
+(next page is definition of property class)
+
+---
+
+# Properties
+
+    !python
+	class property(object)
+	|  property(fget=None, fset=None, fdel=None, doc=None) -> property
+	|  attribute
+	|  
+	|  fget is a function to be used for getting an attribute value, and
+	|  fset is a function for setting, and fdel a function for del'ing,
+	|  an attribute.  Typical use is to define a managed attribute x:
+	|  class C(object):
+	|      def getx(self): return self._x
+	|      def setx(self, value): self._x = value
+	|      def delx(self): del self._x
+	|      x = property(getx, setx, delx, "I'm the 'x' property.")
+	
+*hands on*
+
+---
+
+# Decorators
+
+	!python
+	|  Decorators make defining new properties or modifying existing ones
+	|  easy:
+	|  class C(object):
+	|      @property
+	|      def x(self): return self._x
+	|      @x.setter
+	|      def x(self, value): self._x = value
+	|      @x.deleter
+	|      def x(self): del self._x
+
+[wiki.python.org/moin/PythonDecorators]: http://wiki.python.org/moin/PythonDecorators
+
+*hands on*
+
+---
+
+# Descriptors
+ 
+Going deep now, for those that are starting to get overwhelmed,
+as an exercise, try to add other attributes to your Puppy class.
+Ignore my talking. For the others, hold on to your hats.
+
+## Defined
+
+*In general, a descriptor is an object attribute with
+“binding behavior”, one whose attribute access has been overridden
+by methods in the descriptor protocol.*
+
+## Say what?
+
+For our intent and purpose, we are talking about the main use
+of descriptors in daily coding: custom descriptors
+
+- can allow reuse of properties
+- specialized behaviour when accessed, set or deleted
+
+In fact, we do that now with *property*, which is a descriptor, and
+so would be *staticmethod* and *classmethod*.
+
+---
+
+# Descriptors - continued
+
+## accessed, set or deleted
+
+*Those methods are \_\_get\_\_(), \_\_set\_\_(), and \_\_delete\_\_(). 
+If any of those methods are defined for an object, it is said to be
+a descriptor.*
+
+## Let's do it
+
+*hands on*
+
+---
+
+# Hands on Python: From Java to Burma
+
+
+by _Francois Dion_ @f_dion
+
+
+![PYPTUG](pyptug.png)
+
+
+PYPTUG @WFU Monday August 26th 2013

islanders/pythonhist.txt

+# attributes are your friend
+class Puppy(object):
+    age=1
+benji=Puppy()
+benji.age
+dir(Puppy)
+class Puppy(object):
+    age=None
+    dog_years=None
+
+benji=Puppy()
+benji.age=1
+
+# problem...
+benji.dog_years
+# solution
+help(property)
+
+
+
+# I need getters/setters, panic? no.
+class Puppy(object):
+    def getage(self): return self._age
+    def setage(self,value): self._age=value
+    age=property(getage,setage)
+
+benji=Puppy()
+benji.age=2
+benji.age
+
+
+
+
+class Puppy(object):
+    @property
+    def age(self): return self._age
+    @age.setter
+    def age(self,value): self._age=value
+
+
+
+# saving time by importing dogyears instead of typing it
+# dogyears.DogYears() is a descriptor
+from dogyears import *
+class Puppy(object):
+    @property
+    def age(self): return self._age
+    @age.setter
+    def age(self,value): self._age=value
+    dog_years=DogYears()
+
+# last line above, dog_years will look like a property, but is a
+# custom descriptor
+    
+benji=Puppy()
+benji.age=1.2
+benji.dog_years
+quit()