2014/04/28

The Next Generation of Programmers

People try to put us d-down (Talkin' 'bout my generation)
Just because we g-g-get around (Talkin' 'bout my generation)
Things they do look awful c-c-cold (Talkin' 'bout my generation)
Yeah, I hope I die before I get old (Talkin' 'bout my generation)

This is my generation
This is my generation, baby

 -- "My Generation", The Who

In a PyCon US 2014 keynote, Jessica McKellar outlined the programming-education problem that exists in US high schools, including lack of teaching and gender imbalance (the 'leaky pipeline' of women in science). She went on highlighting some steps the community could take to help fix it, from policy, student engagement, supporting teachers, and curriculum development. LWN.net provides a good summary on that speech.

"In fact, computer science is the most gender-skewed class."

Jessica is also our PyCon APAC 2014 keynote speaker and education panelist. I believe these programming-education topics will inspire us on how the next generation education looks like.

"If one teacher (Jill Pala) can make that big of a difference, what can a 200,000-member community do?"

So, what will you do in the coming year to help the next generation of Python programmers?

2014/03/27

Plone Theme Barceloneta

隨著 Diazo 和 Mockup 成為 Plone 5 的預設架構,佈景主題也將進入新時代,由 plonetheme.barceloneta 取代 plonetheme.sunburst 成為預設的佈景主題模組。

它的安裝相依需求是 plone.app.theming 模組,這在 setup.py 和 profiles/default/metadata.xml 有載明,在 configure.zcml 則看得到下列三個模組會被載入:

<include package="plone.app.theming" />
<include package="plone.app.widgets" />
<include package="mockup" zcml:condition="installed mockup" />

Diazo 已經存在不少範例,累積一些實戰經驗,但是 Mockup 還處於初步階段,公開的文件還不多。值得注意的是 plone.app.widgets 開始成為表單欄位的輸入介面。

使用 @@manage-viewlets 會看到混亂的畫面,或許還要再修整。

它的 CSS 檔案在 static/barceloneta.min.css,想要修改它,看起來要遵循特定步驟,但還不清楚該怎樣做。

TinyMCE Toolbar Missing

Plone 表單的 RichText 欄位,預設使用 TinyMCE 編輯器,在正體中文環境下,如果遇到 Toolbar 無法顯示的問題,可以執行下列確認動作。

首先要確認 Products.TinyMCE 的版本,這問題在 1.3.5 版本 (2013-08-14 release) 之後有處理掉,而 Plone 4.3.2 預設搭配 Products.TinyMCE 1.3.5,理論上會解決這問題。

因為 Plone 4.3.2 只有 Linux 和 Mac OS X 的安裝檔,Windows 使用者要是下載 Plone 4.3.1 安裝檔,就會遇到這問題。

除了在 Linux 安裝新版 Plone 之外,如果想要手動修訂這問題,可以找到 eggs/Products.TinyMCE-x.y.z-py2.7.egg/Products/TinyMCE/utility.py 檔案,自行加上需要的修訂內容

         AVAILABLE_LANGUAGES = set(
         'sq ar hy az eu be bn nb bs br bg ca ch zh hr cs da dv nl en et fi fr gl '
         'ka de el gu he hi hu is id ia it ja ko lv lt lb mk ms ml mn se no nn fa '
-        'pl pt ps ro ru sc sr ii si sk sl es sv ta tt te th tr tw uk ur cy vi zu'.split())
+        'pl pt ps ro ru sc sr ii si sk sl es sv ta tt te th tr zh-cn zh-tw uk ur cy vi zu'.split())

         if 'LANGUAGE' in context.REQUEST:
-            results['language'] = context.REQUEST.LANGUAGE[:2]
-            if results['language'] not in AVAILABLE_LANGUAGES:
+            if context.REQUEST.LANGUAGE in AVAILABLE_LANGUAGES:
+                results['language'] = context.REQUEST.LANGUAGE
+            elif context.REQUEST.LANGUAGE[:2] in AVAILABLE_LANGUAGES:
+                results['language'] = context.REQUEST.LANGUAGE[:2]
+            else:
                 results['language'] = "en"
         else:
             results['language'] = "en"

如果還是不行,可以用 Google Chrome Browser 的 Inspector 檢查 JavaScript 的狀況,這些資訊通常可當作下一步追蹤的線索。

2014/01/23

Empower Through Education

籌備 PyCon APAC 2014 之際,我們尋找既有的 Brochure 資訊,發現 Python Software Foundation (PSF) 有個 Python Brochure Project,整理了一份 34頁的文件。簡單看了申請辦法,出錢 1500美金左右,可取得 480份。

Brochure 有一篇名為 Learning to Program with Python 的短文,說明 Python 如何被應用在教育領域。易學易用,是 Python 的特色,使得它適合用於中小學或大學入門程式設計的場合,它舉了 OLPC (One Laptop per Child)ExpEYES 兩個例子。

剛好這兩個例子,都有窮人教育工具的味道,在這裡反而比較少聽到討論了,找得到的 OLPC 討論,似乎也停在計畫已偏離初衷的批評,但這種討論方式,並無助核心議題的進展。我相信,這類系統裡的軟體和資訊教育工具,還是值得大家投入關注,期待 Open Source 或商業版本的成果,都能持續累進。

如果資訊知識與應用能力,是每位國民都該培養的技能,那麼程式設計的能力,肯定也在學習過程扮演一個角色。首先,程式設計的本質,在於解決問題,能夠條列執行方法或步驟,讓問題不斷被改善,本身就是設計一個程式。程式設計的學習過程,需要參照現實脈絡,先求科學邏輯的正確,再把成本效益的工程思惟納入,也就是說,解決問題的方法可能有多種,但適用的情境也可能不同,這也是現實世界的真實情況。如果這樣的定義說得通,那麼,視程式設計是資訊素養的核心訓練,實不為過。

程式設計概念的早期教育,不少人已從 K12 階段開始推動,這階段的學習,利用 Scratch 之類的工具,是合適的,但高中生到大一生,使用 Python 當通用式的入門語言,具備更多好處,我認為最關鍵的因素在於,並非每位學生都會走上程式設計的專業道路 (這要繼續學習更多語言和領域技能),但每個人後半輩子的生活與工作,都需要「收集資料、分析數據、連結資料庫或 API、認識網路原理」的相關能力,Python 的 Scripting 特性和豐富的函式庫,有助於投資最小力氣,獲得最大效益,我相信 Python 也是終身學習的好夥伴。

具體來說,不是每個人都需要寫程式碼,但每個人讀程式碼的機會肯定更多,為了解決問題,我們首先要做的事不是自己開發,而是分析自己的需求,尋找既有的合適工具,不足之處再動手客製化。實務經驗是,Scripting 語言更專注於處理問題的核心,型別或編譯的要求,對多數情境像是一種 Premature Optimization。

2013/12/23

Plone portal_css Order Matters

My Plone instances run with EEA Faceted Navigation. But they appear differently between debug mode and production mode with my custom theme. For example, after clicking on the Faceted Criteria tab, we should see Faceted Add Buttons that help assigning widgets. The problem is that Faceted Add Buttons do not appear when debug mode is set as off.

With Chrome browser element inspector, we can check CSS details and find where goes wrong. It is collective.js.jqueryui.custom.min.css missing when I run Plone in production mode.

My workaround is go to portal_css in ZMI, and move down collective.js.jqueryui.custom.min.css. The working order is ploneCustom.css, faceted_edit.css, faceted_view.css, and collective.js.jqueryui.custom.min.css.

2013/12/20

TAL Expression on Conditional Repeat

TAL (Template Attribute Language) Expressions are used in Zope Page Templates (ZPT) to allow template elements to be replaced, repeated, or omitted. The tal:repeat statement replicates a sub-tree of your document once for each item in a sequence. Here is an example to conditionally repeat and display values based on its value quantity and position.

<div tal:define="choices context/my_field|nothing"
     tal:condition="choices">
  <tal:onlyone condition="python: len(choices) == 1">
  <tal:field i18n:translate="">Primary</tal:field>:
  <span tal:replace="python: view.term_title(choices[0])" />
  </tal:onlyone>
  <tal:many condition="python: len(choices) > 1"
            repeat="choice choices">
    <tal:first condition="repeat/choice/start">
    <tal:field i18n:translate="">Primary</tal:field>:
    <span tal:replace="python: view.term_title(choice)" />
    <br />
    <tal:field i18n:translate="">Secondary</tal:field>:
    </tal:first>
    <tal:others condition="not:repeat/choice/start">
    <span tal:replace="python: view.term_title(choice)" />
    <span class="separator" tal:condition="not: repeat/choice/end">,</span>
    </tal:others>
  </tal:many>
</div>

Another common usage is to test a variable before inserting it (the first example tests for existence and truth, while the second only tests for existence):

<p tal:condition="request/message | nothing"
   tal:content="request/message">message goes here</p>

<p tal:condition="exists:request/message"
   tal:content="request/message">message goes here</p>

2013/11/27

Sprint Like Mad

荷蘭 Arnhem 是 Four Digits 公司的所在地,它們舉辦了十一月 Plone Sprint,為期五天,共 35 人參與。

活動裡,有個 Don't Break The Build 規則,會場的大螢幕持續顯示 CI server 的狀態,如果爛掉了,會把爐主的名字秀出來,然後爐主要請其他人吃蛋糕。一週的 sprint 後,多數人都增加不少肥肉。

活動結束時,還有 Party 和 Award。決定 Sprint Award 的方法,是利用分貝計,看哪個隊伍的歡呼聲最大。

技術上的成果包括: New Theme for Plone 5, New Way to Work with JavaScript: Mockup (widgets), Remove Selected Portal Tools from Plone, Make main_template More HTML5 Friendly,更多記錄在 Day 1, Day 2, Day 3, Day 4, Wrapup