Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #81 (closed defect: fixed)

Opened 14 years ago

Last modified 12 years ago

In turbogears.controllers, Root should be renamed to RootController

Reported by: michele Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TurboGears Version: 0.8
Severity: trivial Keywords:
Cc:

Description

This is just a cosmetic issue. Anyway, since Root extends Controller IMHO (to mantain cosistency and since Root is a Controller) it should be renamed to RootController?.

Compare this ipotetic controllers.py:

class Blog(Root):
   ...

class Gallery(Controller):
   ...

class Whatever(Controller):
   ...

with this:

class Blog(RootController):
  ...

class Gallery(Controller):
   ...

class Whatever(Controller):
   ...

the last one makes more clear that the Blog class is one of the controllers, particularly the one that controls our application root.

I known that actually you don't need to extend the Controller class, but in the future I hope that TG will take more advantage from OOP and inheriting from Controller (and/or maybe CRUDController, CoolController?...) will give us some cool behaviors for free.

Also explicit is better than implicit. :-)

For TG users this change will only require a small modification of their controllers.py, right?

What do you think?

Change History

comment:1 Changed 14 years ago by michele

Also regarding this, what about change the quickstart script so that the our controllers.py will look like this one:

import turbogears
# instead of:
# from turbogears import controllers
# use:
from turbogears.controllers import Controller, RootController

class Root(RootController):
    @turbogears.expose(html="test.templates.welcome")
    def index(self):
        import time
        return dict(now=time.ctime())

class Whatever(Controller):
   pass

Looking at the source code, if I'm not in mistake all functions defined in turbogears.controllers (flash, expose...) are already imported by the first import. With the second import statement you list the tg controllers base class (so new users known that they should use them) and also avoid the need to type controllers.BaseClass? every time:

class Root(controllers.Root)
  ..

class Hello(controllers.Controller)
  ...

class Seven(controllers.Controller)
  ..

Again I know that these one are only cosmetic issue, but personally I found them to make the code more readable and explicit, or more pythonic.

comment:2 Changed 14 years ago by michele

I think the same arguments also applies for the new Feed module by Elvelind, so Feed should really be FeedController?.

This ensures consistency since you are always deriving your controller from a controller base class:

Controller RootController? FeedController? ...

It also helps to avoid strange questions as: "why is the Root class of the wiki20 demo trying to inherit from itself?"

comment:3 Changed 14 years ago by elvelind@…

  • Status changed from new to closed
  • Resolution set to fixed

comment:4 Changed 14 years ago by kevin

  • Milestone set to 0.9
Note: See TracTickets for help on using tickets.