skariel/webalchemy — pull request #143 by joaoventura (2014-01-30 16:13:34+00:00)
Title: Added docstrings, comments, and 'pythonized' the code a little

This is my effort to add some comments and documentation to the server.py file as I understand the source-code so far..

I have also moved functions to the top of the file (it is usually considered a python best practice), and created a new method on the WebSocketHandler to handle local document initialization. The initialization code was inside the "on_message" method, and I've moved it outside as the other "on_message handlers" are.

In general, minimal code per function is considered a good practice. In my own projects I try to keep functions with less than 20-25 lines, and an entire file with less than 200-250 lines of pythonized code. I find it to be very readable that way. The server.py has now the double, so it means that some things should move (PrivateDataStore should be elsewhere, the handlers in their own module, etc.)

Finally, I have also "pythonized" some of the code, but did not change any functionalities. Things like:

```python
if not to_session_ids:
lst = self.sharedhandlers.keys()
else:
lst = to_session_ids
```

were changed to one-liners (with more explicit variable names):

```python
session_ids = to_session_ids if (to_session_ids) else self.sharedhandlers.keys()
```

I've tested with the Hello World and it is working as usual, so I am almost sure I did not break anything.. :)