software design question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Roth

    #16
    Re: software design question


    "Jorge Godoy" <godoy@ieee.org > wrote in message
    news:l69kf1-9e8.ln1@winterm ute.g2ctech...[color=blue]
    > On Sunday 08 February 2004 01:24 John Roth wrote in
    > <102bb30d5422pd 4@news.supernew s.com>:
    >[color=green]
    > > I suspect you've got the callback logic backwards. The basic
    > > layering pattern is "call down, notify up," and it's the upper
    > > layer's responsibility to request the notification.
    > >
    > > To explicate: the GUI module calls the domain
    > > module for service. It also calls the domain module
    > > to register callbacks, passing the function that it
    > > want's called.
    > >
    > > When the domain layer has something it wants to
    > > tell the GUI layer, it simply runs a (possibly empty)
    > > list of callback functions.[/color]
    >
    > Can you exemplify it?
    >
    > I'm very interested on such approach and I'm going to read a little
    > more about it, but examples in Python would help a lot.[/color]

    A simple notify class:
    ---------------------------------------------
    class Notify(object):
    def __init__(self):
    self.listenerLi st = []

    def sendMessage(sel f, event):
    for callback in self.listenerLi st:
    callback(event)
    return

    def addListener(sel f, callback):
    self.listenerLi st.append(callb ack)

    def removeListener( self, callback):
    self.listenerLi st.remove(callb ack)
    ---------------------------------------------

    Here's a place where I instantiate it:

    --------------------------------------------------------------
    class ALocation(objec t):
    def __init__(self):
    self._latitude = LatitudeContain er()
    self._longitude = LongitudeContai ner()
    self._placeName = StringContainer ()
    self._titleNoti fier = A4Base.Notify.N otify()
    self._latitude. addListener(sel f._titleUpdated )
    self._longitude .addListener(se lf._titleUpdate d)
    ---------------------------------------------------------------

    and the routine that uses this notifier:

    --------------------------------------------------------
    def _titleUpdated(s elf, event):
    self._titleNoti fier.sendMessag e(event)
    --------------------------------------------------------

    LatitudeContain er and LongitudeContai ner both derive
    from BaseContainer (through StringContainer , but that
    doesn't add anything to this example):

    -------------------------------------------------------
    class BaseContainer(o bject):
    def __init__(self):
    self._notifier = A4Base.Notify.N otify()
    def addListener(sel f, callback):
    return self._notifier. addListener(cal lback)
    def removeListener( self, callback):
    return self._notifier. removeCallback( callback)
    def _sendMessage(se lf, message):
    return self._notifier. sendMessage(mes sage)
    ---------------------------------------------------------

    here's the routine in LatitudeContain er that fires
    off the notification:

    ------------------------------------------------------
    def _setStringValue (self, value):
    self.parseLat(v alue)
    if self._stringVal ue != value:
    self._stringVal ue = value
    self._sendMessa ge(value)
    -------------------------------------------------------

    HTH

    John Roth


    [color=blue]
    >
    >
    > TIA,
    > --
    > Godoy. <godoy@ieee.org >[/color]


    Comment

    • Dang Griffith

      #17
      Re: software design question

      On 8 Feb 2004 08:18:06 -0800, llothar@web.de (Lothar Scholz) wrote:
      [color=blue]
      >Uwe Mayer <merkosh@hadiko .de> wrote in message news:<c057uq$4p h$1@news.rz.uni-karlsruhe.de>.. .
      >[color=green]
      >> Do you think there is a reason why in Java every class got to be put into
      >> one source file - or is this just a bad language restriction?[/color]
      >
      >This has to do with dynamic loading. Nothing else.[/color]

      It might have something to do with something else, since it is a false
      statement, not a language restriction:
      ---------- cut here ----------
      // multiclass.java
      // demonstrates two classes in one source file.

      class multiclass
      {
      public static void main(String args[])
      {
      System.out.prin tln(bork.bork() );
      }
      }

      class bork
      {
      public static String bork()
      {
      return "Bork!";
      }
      }
      ---------- ereh tuc ----------

      --dang

      Comment

      • Uwe Mayer

        #18
        Re: software design question

        Lothar Scholz wrote:
        [color=blue][color=green]
        >> Is 500 lines a good count to start splitting up the code?[/color]
        > No !
        > My modules are normally between 1000-3000 lines. Having to much files
        > (worst case scenario is PHP) is just another form of spaghetti code.
        > With so small files you should focus on the task that needs to be done
        > and only if you really do two different things in one module you
        > should decide to split it. Maybe a merge would help you more then
        > splitting.[/color]

        What IDE /Editor do you use? I currently use Emacs and I find it very hard
        to skip back and forth between methods and functions in larger files.

        Ciao
        Uwe

        Comment

        • Josiah Carlson

          #19
          Re: software design question

          [color=blue][color=green]
          >>No !
          >>My modules are normally between 1000-3000 lines. Having to much files
          >>(worst case scenario is PHP) is just another form of spaghetti code.
          >>With so small files you should focus on the task that needs to be done
          >>and only if you really do two different things in one module you
          >>should decide to split it. Maybe a merge would help you more then
          >>splitting.[/color]
          >
          >
          > What IDE /Editor do you use? I currently use Emacs and I find it very hard
          > to skip back and forth between methods and functions in larger files.[/color]

          I would imagine he uses his own editor: http://www.python-ide.com

          I also don't have any issues editing 1-3k line files using my own
          editor: http://pype.sourceforge.net (PyPE itself is ~3900 lines).

          I believe the major difference, at least in terms of scalability, has to
          do with the existance of a browsable source tree (aka a class browser).
          It has helped me significantly.

          - Josiah

          Comment

          • Michele Simionato

            #20
            Re: software design question

            llothar@web.de (Lothar Scholz) wrote in message news:<6ee58e07. 0402080823.75df 2850@posting.go ogle.com>...[color=blue][color=green]
            > > Is 500 lines a good count to start splitting up the code?[/color]
            >
            > No !
            > My modules are normally between 1000-3000 lines. Having to much files
            > (worst case scenario is PHP) is just another form of spaghetti code.[/color]

            Oh! As a comparison, my modules are typically 100-200 lines long. I don't
            feel they are spaghetti, since they are collected in directories with
            well chosen names and/or in packages. Also, they are typically intended
            to be reusable. Moreover, I feel much easier to edit simultaneously
            three or four buffers than to navigate back and forth on a very long single
            buffer. Finally, I don't want to be too dependent on the editor features, so
            small modules are a win should I need to use Notepad (God save me! ;)

            P.S. once I computed the average lenght of modules in the standard library.
            The result was something like 200 lines.

            Michele Simionato

            Comment

            • Josiah Carlson

              #21
              Re: software design question

              > Moreover, I feel much easier to edit simultaneously[color=blue]
              > three or four buffers than to navigate back and forth on a very long single
              > buffer.[/color]

              Depending on the features of your editor, going to different locations
              in the current buffer (even offset by many lines) can be arbitrarily
              trivial. When you have a source tree, you are a double-click away from
              any class/function/method (or even properly-formed comments, depending
              on the editor support). For those cases when keyboards shortcuts are
              convenient, some editors have per-line bookmarks that allow you to hop
              to often-used code portions very quickly.

              I'm sure all of this can be done with Emacs (perhaps even Vim), if you
              know how to do it.

              [color=blue]
              > P.S. once I computed the average lenght of modules in the standard library.
              > The result was something like 200 lines.[/color]

              Sounds like a histogram is in order. Maybe I'll do it this weekend when
              I have the time.

              - Josiah

              Comment

              • Uwe Mayer

                #22
                Re: software design question

                Josiah Carlson wrote:
                [color=blue][color=green]
                >> What IDE /Editor do you use? I currently use Emacs and I find it very
                >> hard to skip back and forth between methods and functions in larger
                >> files.[/color]
                >
                > I would imagine he uses his own editor: http://www.python-ide.com
                >
                > I also don't have any issues editing 1-3k line files using my own
                > editor: http://pype.sourceforge.net (PyPE itself is ~3900 lines).[/color]

                I did some browsing and found another, quite nice one:


                For small programs its the total overkill. It may be more usefull if you're
                developing graphical programs, since it supports compiling Qt .ui files,
                got some menubar entries for Qt Reference Manual, QLinguist,
                QXXXDialog-Wizards, etc. (if you happen to like that sort of editor).

                Nice features I found include:
                - Unittest support (i.e. for rapid prototyping)
                - refactoring tools
                [color=blue]
                > I believe the major difference, at least in terms of scalability, has to
                > do with the existance of a browsable source tree (aka a class browser).
                > It has helped me significantly.[/color]

                What I am missing includes:
                - browsable source tree :(
                - Emacs's comment-box
                - Emacs keyboard shortcuts

                If there anybody knows some other nice Editors you know, I'd like to know
                about them.

                Ciao
                Uwe

                Comment

                • Josiah Carlson

                  #23
                  Re: software design question

                  >>I would imagine he uses his own editor: http://www.python-ide.com[color=blue][color=green]
                  >>
                  >>I also don't have any issues editing 1-3k line files using my own
                  >>editor: http://pype.sourceforge.net (PyPE itself is ~3900 lines).[/color]
                  >
                  > I did some browsing and found another, quite nice one:
                  > http://www.die-offenbachs.de/detlev/eric3.html
                  >
                  > For small programs its the total overkill. It may be more usefull if you're
                  > developing graphical programs, since it supports compiling Qt .ui files,
                  > got some menubar entries for Qt Reference Manual, QLinguist,
                  > QXXXDialog-Wizards, etc. (if you happen to like that sort of editor).[/color]

                  Yeah, I found Eric3 a while ago as well. My one problem is that I
                  couldn't get it to work with windows, every binary for QT that I tried
                  didn't want to work.
                  [color=blue]
                  > What I am missing includes:
                  > - browsable source tree :(
                  > - Emacs's comment-box
                  > - Emacs keyboard shortcuts[/color]

                  Eric3 doesn't have a browsable source tree?

                  There is an editor called SPE (Stani's Python Editor). It has comments
                  and a browsable source tree. I don't know if it has the keyboard
                  shortcuts. One thing that stops me from using it (as opposed to my own
                  editor) is that it is really slow. Start messing around with multiple
                  buffers, or files larger than a few hundred lines. Ick.

                  - Josiah

                  Comment

                  • Bengt Richter

                    #24
                    Re: software design question

                    On Tue, 10 Feb 2004 23:47:12 -0800, Josiah Carlson <jcarlson@nospa m.uci.edu> wrote:
                    [color=blue][color=green]
                    >> Moreover, I feel much easier to edit simultaneously
                    >> three or four buffers than to navigate back and forth on a very long single
                    >> buffer.[/color]
                    >
                    >Depending on the features of your editor, going to different locations
                    >in the current buffer (even offset by many lines) can be arbitrarily
                    >trivial. When you have a source tree, you are a double-click away from
                    >any class/function/method (or even properly-formed comments, depending
                    >on the editor support). For those cases when keyboards shortcuts are
                    >convenient, some editors have per-line bookmarks that allow you to hop
                    >to often-used code portions very quickly.
                    >
                    >I'm sure all of this can be done with Emacs (perhaps even Vim), if you
                    >know how to do it.
                    >
                    >[color=green]
                    >> P.S. once I computed the average lenght of modules in the standard library.
                    >> The result was something like 200 lines.[/color]
                    >
                    >Sounds like a histogram is in order. Maybe I'll do it this weekend when
                    >I have the time.
                    >[/color]
                    A quick data point:
                    [color=blue][color=green][color=darkred]
                    >>> import os
                    >>> wc = os.popen(r'wc D:\Python23\Lib \*py').readline s()
                    >>> sum([int(x.split()[0]) for x in wc[:-1] if x])/float(len(wc)-1)[/color][/color][/color]
                    412.61621621621 623[color=blue][color=green][color=darkred]
                    >>> print wc[-1][/color][/color][/color]
                    76334 250898 2657018 Totals

                    Gotta go...

                    Regards,
                    Bengt Richter

                    Comment

                    • Josiah Carlson

                      #25
                      Re: software design question

                      > A quick data point:[color=blue]
                      >[color=green][color=darkred]
                      > >>> import os
                      > >>> wc = os.popen(r'wc D:\Python23\Lib \*py').readline s()
                      > >>> sum([int(x.split()[0]) for x in wc[:-1] if x])/float(len(wc)-1)[/color][/color]
                      > 412.61621621621 623[color=green][color=darkred]
                      > >>> print wc[-1][/color][/color]
                      > 76334 250898 2657018 Totals
                      >
                      > Gotta go...[/color]

                      I'm going to have to remember wc. That is sweet.

                      - Josiah

                      Comment

                      Working...