va ders q what does it say va ders va ders a space
play

VA DERS (Q: What does it say?) VA DERS VA DERS (A: Space - PowerPoint PPT Presentation

VA DERS (Q: What does it say?) VA DERS VA DERS (A: Space Invaders) am U us am U us (A: Ambiguous) convention configuration convention configuration (A: Convention over configuration) Welcome! A Grok T alk


  1. VA DERS

  2. (Q: What does it say?) VA DERS

  3. VA DERS (A: “Space Invaders”)

  4. am U us

  5. am U us (A: “Ambiguous”)

  6. convention — configuration

  7. convention — configuration (A: “Convention over configuration”)

  8. Welcome!

  9. A Grok T alk Brandon Craig Rhodes November 2007

  10. What's a convention?

  11. Conventions are traditionally extras.

  12. Conventions begin as optional practices to keep code sane

  13. “We always capitalize the names of classes in the code we write for this department.”

  14. “If you have a class Foo , name its corresponding page template foo.pt .”

  15. “We're putting cover sheets on all the TPS reports before they go out.”

  16. What if ... ?

  17. What if your web framework used conventions rather than config files?

  18. A simple example:

  19. View “Index” app.config <configure view=”index” class=”Index” template= “index.pt” /> index.pt <html> <body> <h1>Title</h1> </body></html>

  20. A class you've View written “Index” app.config <configure The configuration view=”index” class=”Index” file you need to template= hook them up! “index.pt” /> index.pt A page template <html> <body> <h1>Title</h1> you've written </body></html>

  21. Conventions are traditionally ignored by the computer

  22. But, what if ... ?

  23. What if the framework assumed , in the absence of other configuration, that Index goes with index.pt ?

  24. Result:

  25. View “Index” All explicit configuration has disapperaed index.pt <html> <body> <h1>Title</h1> </body></html>

  26. Advantages Ensue!

  27. Advantages of CoC: 1. Less repetition

  28. Advantages of CoC: 1. Less repetition 2. Conventions get used, because they matter

  29. Advantages of CoC: 1. Less repetition 2. Conventions get used, because they matter 3. No loss of flexibility

  30. So, who does CoC?

  31. Actually a very old Computer Science concept

  32. Example: FORTRAN assumed, in the absence of a declaration, that i and j were integers, and that x and y were floating-point

  33. But when did it take off for web applications?

  34. 2004

  35. Python frameworks: 2005 — Django, Turbogears 2006 — Pylons, Grok

  36. Q:

  37. Why talk about Grok?

  38. It's only a year old!

  39. Django and TurboGears are each two years old

  40. A:

  41. Because Grok is built atop Zope 3

  42. Zope 3 started in 2001, production release 2004

  43. Grok brings ease of configuration to an existing framework

  44. Zope 3 is more mature

  45. Zope 3 is powerful

  46. Zope 3 provides a powerful component framework

  47. But

  48. It requires configuration

  49. Raw Zope 3 requires you to use its Zope Configuration Markup Language (ZCML)

  50. <configure xmlns="http://namespaces.zope.org/zope" i18n_domain="zope" > <permission id="zope.Public" title="[public-permission] Public" description="Special permission indicating unconditional access. Public resources are always accessible." /> <utility component=".vocabulary.PermissionsVocabulary" name="Permissions" /> <utility component=".vocabulary.PermissionIdsVocabulary" name="Permission Ids" /> <include file="globalmodules.zcml" /> <include file="_protections.zcml" /> <utility provides=".interfaces.IAuthentication" component=".principalregistry.principalRegistry" />

  51. But not Grok!

  52. Grok is friendly

  53. More specifically

  54. Grok is a friendly cave man

  55. Grok wields a club

  56. In fact

  57. Grok wields a large club

  58. Grok uses his club to smash ZCML

  59. <configure xmlns="http://namespaces.zope.org/zope" i18n_domain="zope" > <permission id="zope.Public" title="[public-permission] Public" description="Special permission indicating unconditional access. Public resources are always accessible." /> <utility component=".vocabulary.PermissionsVocabulary" name="Permissions" /> <utility component=".vocabulary.PermissionIdsVocabulary" name="Permission Ids" /> <include file="globalmodules.zcml" /> <include file="_protections.zcml" /> <utility provides=".interfaces.IAuthentication" component=".principalregistry.principalRegistry" />

  60. Grok offers us his club

  61. So that our web apps can be configured using convention instead of XML

  62. Let's create a Grok instance!

  63. (Brandon, pause the slides, and show how to create a Grok instance. Name it “MyApp”.)

  64. The instance comes with a web page already displaying!

  65. What's the formula?

  66. Grok's Threefold Way

  67. Grok's Threefold Way 1. An object at the URL

  68. Grok's Threefold Way 1. An object at the URL 2. A view for that object

  69. Grok's Threefold Way 1. An object at the URL 2. A view for that object 3. A template for the view

  70. http://.../index <html><body> Application View <h1>Welcome</h1> Object “index” </body></html> “MyApp” index.pt <html> <body> <h1>Title</h1> </body></html>

  71. Let's add some more Python objects, more Grok Views, and more templates

  72. (Brandon, go add some models and further views to your application)

  73. http://.../ LOTR “index” m <html>...</html> Application <html>... Object m http://.../contents “lotr” “contents” <html>...</html> <html>... http://.../Aragorn/ Character “index” <html>...</html> “Aragorn” <html>... http://.../Pelennor/ Battle “index” <html>...</html> “Pelennor” <html>...

  74. Isn't that fun?

  75. Time for one more topic

  76. What should it be?

  77. There are several directions we could go

  78. I could show you how easy it is to process form data

  79. We could, in several seconds, have an XML-RPC interface to our models working

  80. We could explore how Zope can generate forms for you

  81. An illustration could be made of how our bare application logic itself benefits from being in a component framework

  82. But instead:

  83. We will look at the contract between a View and a Template

  84. And explore two forms that the contract can take

  85. Let's look back at our code...

  86. Our View classes are pretty anemic

  87. While our templates are out surfing our raw application objects!

  88. (Brandon, go show them your anemic View classes and your object-surfing templates)

  89. Let's call templates which surf the raw application objects “Muscular templates”

  90. Advantages of muscular templates: 1. Quick

  91. Advantages of muscular templates: 1. Quick 2. Fast

  92. Advantages of muscular templates: 1. Quick 2. Fast 3. Easy

  93. But...

  94. There are also disadvantages to muscular templates

  95. Disadvantages of muscular templates: 1. Difficult to read

Recommend


More recommend