Code review comment for lp:~frankban/juju-quickstart/env-manage-fields

Revision history for this message
Gary Poster (gary) wrote :

LGTM and nice work, with consideration of various fairly trivial
comments.

I'm interested in bac's comments. Calling something Zope-like these
days is unfortunately not a complement. Perhaps he's referring to using
classes for fields? Certainly these fields could be data as well: your
classes really simply have some flags and some functions, and the
validation functions could be composed (more?) attractively
functionally, to my eyes. That said, while I am intrigued by the idea
of simplifying the fields into data, and think it might be a win, I
don't think it will be a big enough win to justify refactoring at this
time; and I think people with an OOP bent might not like the refactoring
at all.

Moreover, maybe that's not anywhere close to what bac means?

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py
File quickstart/models/fields.py (right):

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode24
quickstart/models/fields.py:24: each provider type is associated to a
sequence of fields. Those fields describe
...associated with a sequence of fields.

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode49
quickstart/models/fields.py:49: - autogenerated: indicates this is a
string field that can be
It strikes me that this functionality is along a different logical axis
than field type. I'd be tempted to have the code look for a generate
method, for instance, as a flag: if it exists, it can autogenerate (a
string, a number, whatever). I don't think this is very important: just
a suggestion.

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode53
quickstart/models/fields.py:53: edited using the usual input edit
widget.
Which effectively means multi-line string, right? Might as well be
explicit about it.

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode56
quickstart/models/fields.py:56: - name: the name identifying a specific
piece of information
Is this...

the key identifying a specific piece of information in the environments
data

...or not? Might be good to clarify, either way.

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode83
quickstart/models/fields.py:83: self, name, label=None, help='',
required=True, editable=True):
I generally prefer flags to default to false, but I think this is
probably the right compromise between clarity and convenience for
required and editable...unless we can choose different names?

optional=False, readonly=False

readonly conveys the idea well. Less sure about "optional"

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode84
quickstart/models/fields.py:84: """Initialize a field, only the name
identifier is required."""
Run-on sentence. Any of the following are better

Initialize a field. Only...
Initialize a field; only...

I prefer the period in this case.

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode100
quickstart/models/fields.py:100: if isinstance(value, str):
When would this happen? Or is this just insurance?

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode117
quickstart/models/fields.py:117: return value
Maybe "return self.normalize(value) so you can show the intended use?

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode122
quickstart/models/fields.py:122:
Maybe call out that this has no field_type because it is the default?

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode135
quickstart/models/fields.py:135: value = self.normalize(value)
You could delete this line if you make my suggested change to the base
class' validate method.

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode156
quickstart/models/fields.py:156: Return None if the value is an empty
string or None: in this case the
I suggest the following.

  Return None if the value is an empty string or None. In these cases,
the field value is considered not set.

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode186
quickstart/models/fields.py:186: if self.required:
The duplication of this code from the base class is one possible
argument for the greater flexibility of using functional composition to
build validation. Not suggesting the change, because that would slow
things down, but I'm comparing this in my mind with an approach in the
"Functional Javascript" book I've been reading.

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode218
quickstart/models/fields.py:218: the default value (True or False) to
use if the value is unset (None).
Seems like the default functionality could be shared in the base class.
If you wanted to be paranoid, you could even run it through the
"validate" function.

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode238
quickstart/models/fields.py:238: class AutoGeneratedField(StringField):
AutoGeneratedStringField?

https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode257
quickstart/models/fields.py:257: self.choices = choices
tuple(choices) just to be paranoid?

https://codereview.appspot.com/37820046/diff/1/quickstart/tests/models/test_fields.py
File quickstart/tests/models/test_fields.py (right):

https://codereview.appspot.com/37820046/diff/1/quickstart/tests/models/test_fields.py#newcode63
quickstart/tests/models/test_fields.py:63:
self.assertEqual(unicode(value), field.display(value), value)
I guess it is good that all fields can handle None, but guaranteeing
that None is displayed as u'None' doesn't seem ideal on the face of it.

https://codereview.appspot.com/37820046/

« Back to merge proposal