LPTHW - Day 145 Gothons Are Getting Classy - Part 3

Part 3 on exercise 42 of LPTHW. Today is all about `__dict__` attribute in  Python  object. Several special properties about this attribute.

a) This special attribute is one of the five predefined attributes of a class. There other fours are `__name__`, `__bases__`, `__doc__`, and `__module__`.

b) As the name (dict) implies, this attribute is a dictionary object (Note to self: remember, almost everything is an object in Python), one of the built-in data type in Python. A dictionary is a set of key:value pairs surrounded by braces. Example is `{'foo' : 1, 'bar' : 2, 'baz' : 3}`.

Example 0:
>>> class Foo(object):
........ pass

>>> f = Foo()
>>> f.a = 'a'
>>> f.b = 'b'
>>> f._dict_
{'a': 'a', 'b': 'b'}

c) Namespace is a container that stores a set of identifiers. A container ensures uniqueness and hierarchy to all identifiers. Using a dictionary object which support these two characteristics, you can implement (identifies as keys, different data types as values ) a namespace in both modules and classes in Python. Some examples 3 of common namespace usage:

Example 1:
identifier /home/kianmeng/.bashrc (unique location)
namespace /home/kianmeng (path)
local name .bashrc (file name)

Example 2:
identifies www.example.com (url)
namespace example.com (domain)
local name www (host name)

d) Object attributes referencing and assignment can be done in both ways of dot notation or direct dictionary manipulation. Comparison of both are shown below:

Example 3: Dot notation
a = o.foo
o.foo = b

Example 4: Direct dictionary manipulation
a = o.___dict___["foo"]
o.___dict___["foo"] = a

e) If an attribute is not found in current child class __dict__ object, Python will lookup the attribute in the parent class `__dict__` object. Attribute assignment only can be done within the current child class and not the parent class.

Retrospection on Using Kohana PHP Framework

Some retrospection on an old project done using Kohana PHP framework. There are quite a few things that I wish can be done differently. After some googling to identify the exact version of the framework, the project was running on 3.0.X.

The web application can be made more secure by using a better folder structure similar to customized layout for CodeIgniter. The main index.php file should be put into separate public folder or document root folder. Structure as shown:
├── application 
├── modules 
├── system 
├── public_html 
│   └── index.php

All assets files (css, js, and img) should be also put under a folder called assets and under public_html as well.
├── public_html 
│   └── assets
│       ├── js
│       ├── css
│       ├── img

We can shorten the development time of the project if Twitter’s Bootstrap was chosen as the CSS framework. Quite a lot of time was spent on tweaking the user interface and in the end, the web application still look quite butt-ugly.

Should have use Mercurial instead of Git. I was starting to learn DVCS and Git is not a proper choice for someone from Subversion background. The experience is excruciating painful and stupid as well. The reason we went for git because in term of pricing, Github is cheaper than Bitbucket for private project. But now, bitbucket is cheaper, how can you compare to unlimited free repositories?

Both authentication and authorization were hacked up work. Very rigid and painful to modify as well. Access Control List (ACL) is a damn hard to do it right.

Picking Kohana was a wrong choice at that moment. As the framework has gone through several rewrite, documentation is limited and most of the time you have to refer to the code itself. I should have picked Codeigniter and DataMapper ORM combination instead, at least I know now the development time can be shorten. This does not mean that Codeigniter is better, just more stable and more documentation available.

What’s next? Going to upgrade or rewrite the web app to the latest version 3.2.x and try to do things differently this time. I also have to relearn Kohana again as it has been awhile since I last looked at it.