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
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1
slide-2
SLIDE 2

VA DERS

slide-3
SLIDE 3

(Q: What does it say?)

VA DERS

slide-4
SLIDE 4

VA DERS

(A: “Space Invaders”)

slide-5
SLIDE 5

am U us

slide-6
SLIDE 6

am U us

(A: “Ambiguous”)

slide-7
SLIDE 7

convention — configuration

slide-8
SLIDE 8

convention — configuration

(A: “Convention over configuration”)

slide-9
SLIDE 9

Welcome!

slide-10
SLIDE 10

A Grok T alk Brandon Craig Rhodes November 2007

slide-11
SLIDE 11

What's a convention?

slide-12
SLIDE 12

Conventions are traditionally extras.

slide-13
SLIDE 13

Conventions begin as

  • ptional practices to

keep code sane

slide-14
SLIDE 14

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

slide-15
SLIDE 15

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

slide-16
SLIDE 16

“We're putting cover sheets

  • n all the TPS reports

before they go out.”

slide-17
SLIDE 17

What if ... ?

slide-18
SLIDE 18

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

slide-19
SLIDE 19

A simple example:

slide-20
SLIDE 20

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

View

“Index”

slide-21
SLIDE 21

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

View

“Index”

A class you've written A page template you've written The configuration file you need to hook them up!

slide-22
SLIDE 22

Conventions are traditionally ignored by the computer

slide-23
SLIDE 23

But, what if ... ?

slide-24
SLIDE 24

What if the framework assumed, in the absence of

  • ther configuration, that

Index goes with index.pt?

slide-25
SLIDE 25

Result:

slide-26
SLIDE 26

<html> <body> <h1>Title</h1> </body></html> index.pt

View

“Index”

All explicit configuration has disapperaed

slide-27
SLIDE 27

Advantages Ensue!

slide-28
SLIDE 28

Advantages of CoC:

  • 1. Less repetition
slide-29
SLIDE 29

Advantages of CoC:

  • 1. Less repetition
  • 2. Conventions get used,

because they matter

slide-30
SLIDE 30

Advantages of CoC:

  • 1. Less repetition
  • 2. Conventions get used,

because they matter

  • 3. No loss of flexibility
slide-31
SLIDE 31

So, who does CoC?

slide-32
SLIDE 32

Actually a very old Computer Science concept

slide-33
SLIDE 33

Example: FORTRAN assumed, in the absence

  • f a declaration, that i

and j were integers, and that x and y were floating-point

slide-34
SLIDE 34

But when did it take off for web applications?

slide-35
SLIDE 35

2004

slide-36
SLIDE 36

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

slide-37
SLIDE 37

Q:

slide-38
SLIDE 38

Why talk about Grok?

slide-39
SLIDE 39

It's only a year old!

slide-40
SLIDE 40

Django and TurboGears are each two years old

slide-41
SLIDE 41

A:

slide-42
SLIDE 42

Because Grok is built atop Zope 3

slide-43
SLIDE 43

Zope 3 started in 2001, production release 2004

slide-44
SLIDE 44

Grok brings ease

  • f configuration to an

existing framework

slide-45
SLIDE 45

Zope 3 is more mature

slide-46
SLIDE 46

Zope 3 is powerful

slide-47
SLIDE 47

Zope 3 provides a powerful component framework

slide-48
SLIDE 48

But

slide-49
SLIDE 49

It requires configuration

slide-50
SLIDE 50

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

slide-51
SLIDE 51

<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" />

slide-52
SLIDE 52

But not Grok!

slide-53
SLIDE 53

Grok is friendly

slide-54
SLIDE 54

More specifically

slide-55
SLIDE 55

Grok is a friendly cave man

slide-56
SLIDE 56
slide-57
SLIDE 57

Grok wields a club

slide-58
SLIDE 58
slide-59
SLIDE 59

In fact

slide-60
SLIDE 60

Grok wields a large club

slide-61
SLIDE 61
slide-62
SLIDE 62

Grok uses his club to smash ZCML

slide-63
SLIDE 63

<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" />

slide-64
SLIDE 64

Grok offers us his club

slide-65
SLIDE 65
slide-66
SLIDE 66

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

slide-67
SLIDE 67

Let's create a Grok instance!

slide-68
SLIDE 68

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

slide-69
SLIDE 69

The instance comes with a web page already displaying!

slide-70
SLIDE 70

What's the formula?

slide-71
SLIDE 71

Grok's Threefold Way

slide-72
SLIDE 72

Grok's Threefold Way

  • 1. An object at the URL
slide-73
SLIDE 73

Grok's Threefold Way

  • 1. An object at the URL
  • 2. A view for that object
slide-74
SLIDE 74

Grok's Threefold Way

  • 1. An object at the URL
  • 2. A view for that object
  • 3. A template for the view
slide-75
SLIDE 75

<html> <body> <h1>Title</h1> </body></html> index.pt <html><body> <h1>Welcome</h1> </body></html> http://.../index

View

“index”

Application Object

“MyApp”

slide-76
SLIDE 76

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

slide-77
SLIDE 77

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

slide-78
SLIDE 78

<html>... <html>...</html> http://.../contents “index”

LOTR Application Object

“lotr” m m <html>... “contents” http://.../ <html>...</html>

Character

“Aragorn”

Battle

“Pelennor” <html>... “index” http://.../Aragorn/ <html>...</html> <html>... “index” http://.../Pelennor/ <html>...</html>

slide-79
SLIDE 79

Isn't that fun?

slide-80
SLIDE 80

Time for one more topic

slide-81
SLIDE 81

What should it be?

slide-82
SLIDE 82

There are several directions we could go

slide-83
SLIDE 83

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

slide-84
SLIDE 84

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

slide-85
SLIDE 85

We could explore how Zope can generate forms for you

slide-86
SLIDE 86

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

slide-87
SLIDE 87

But instead:

slide-88
SLIDE 88

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

slide-89
SLIDE 89

And explore two forms that the contract can take

slide-90
SLIDE 90

Let's look back at our code...

slide-91
SLIDE 91

Our View classes are pretty anemic

slide-92
SLIDE 92

While our templates are out surfing our raw application objects!

slide-93
SLIDE 93

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

slide-94
SLIDE 94

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

slide-95
SLIDE 95

Advantages of muscular templates:

  • 1. Quick
slide-96
SLIDE 96

Advantages of muscular templates:

  • 1. Quick
  • 2. Fast
slide-97
SLIDE 97

Advantages of muscular templates:

  • 1. Quick
  • 2. Fast
  • 3. Easy
slide-98
SLIDE 98

But...

slide-99
SLIDE 99

There are also disadvantages to muscular templates

slide-100
SLIDE 100

Disadvantages of muscular templates:

  • 1. Difficult to read
slide-101
SLIDE 101

Disadvantages of muscular templates:

  • 1. Difficult to read
  • 2. ... and thus, to audit
slide-102
SLIDE 102

Disadvantages of muscular templates:

  • 1. Difficult to read
  • 2. ... and thus, to audit
  • 3. They know your model
slide-103
SLIDE 103

The alternative:

slide-104
SLIDE 104

Muscular Views

slide-105
SLIDE 105

Let's return to our application's design

slide-106
SLIDE 106

And look at one

  • f its pages
slide-107
SLIDE 107

<html>... <html>...</html> http://.../contents “index”

LOTR Application Object

“lotr” m m <html>... “contents” http://.../ <html>...</html>

Character

“Aragorn”

Battle

“Pelennor” <html>... “index” http://.../Aragorn/ <html>...</html> <html>... “index” http://.../Pelennor/ <html>...</html>

slide-108
SLIDE 108

Character

“Aragorn” <html>... “index” http://.../Aragorn/ <html>...</html>

slide-109
SLIDE 109

The object and the view both have names in a traditional Zope page template...

slide-110
SLIDE 110

Character

“Aragorn” <html>... “index” http://.../Aragorn/ <html>...</html>

context

slide-111
SLIDE 111

Character

“Aragorn” <html>... “index” http://.../Aragorn/ <html>...</html>

context view

slide-112
SLIDE 112

But instead of using these default names, we can provide our own View namespace

slide-113
SLIDE 113

We do so by creating a namespace() method on

  • ur View
slide-114
SLIDE 114

(Brandon, go make your CharacterIndex View more muscular)

slide-115
SLIDE 115

What are the advantages of muscular Views?

slide-116
SLIDE 116

(Phrased differently: “Why on earth would you ever do that?!”)

slide-117
SLIDE 117

(Because, of course, we've added more code to our app without adding any new functionality!)

slide-118
SLIDE 118

Advantages:

  • 1. Your models can now evolve

without breaking your page templates

slide-119
SLIDE 119

Advantages:

  • 2. Page templates cannot

reveal data not delivered explicitly in namespace()

slide-120
SLIDE 120

Advantages:

  • 3. If you write some fake Views

returning static data from namespace(), your template writers can start work Day 1

slide-121
SLIDE 121

Advantages:

  • 4. Your Views are easy to test

(call namespace() and check result), templates are too (try them with static data)

slide-122
SLIDE 122

We'll conclude

slide-123
SLIDE 123

Grok

slide-124
SLIDE 124
slide-125
SLIDE 125

Advantages:

  • 1. Easy, fun

2. 3. 4. 5.

slide-126
SLIDE 126

Advantages:

  • 1. Easy, fun
  • 2. Powerful framework

3. 4. 5.

slide-127
SLIDE 127

Advantages:

  • 1. Easy, fun
  • 2. Powerful framework
  • 3. Deploys with buildout

4. 5.

slide-128
SLIDE 128

Advantages:

  • 1. Easy, fun
  • 2. Powerful framework
  • 3. Deploys with buildout
  • 4. Shares code with Plone

5.

slide-129
SLIDE 129

Advantages:

  • 1. Easy, fun
  • 2. Powerful framework
  • 3. Deploys with buildout
  • 4. Shares code with Plone
  • 5. Vibrant community
slide-130
SLIDE 130

Of course, there are also disadvantages

slide-131
SLIDE 131

Disadvantages

  • 1. Not yet 1.0
slide-132
SLIDE 132

Disadvantages

  • 1. Not yet 1.0
  • 2. Security could be easier
slide-133
SLIDE 133

Disadvantages

  • 1. Not yet 1.0
  • 2. Security could be easier
  • 3. Online docs still weak

(buy PvW Zope 3 book!)

slide-134
SLIDE 134

Disadvantages

  • 1. Not yet 1.0
  • 2. Security could be easier
  • 3. Online docs still weak
  • 4. Community is 6h off
slide-135
SLIDE 135

Thank you! Any questions?