[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: framework proposal - was Re: [pygame] Re: Distribution of Work



On Wed, 8 Oct 2003, Michael wrote:

> > I do my best to keep my code concise and make it look neat, but I optimize
> > for modern monitors.  However, I always send email or post to usenet at 80
> > columns, so it felt a bit awkward posting my source. :-/
> 
> I'm afriad I'm stuck in the rut of trying to keep my code within 80 
> columns whenever possible. To some degree that probably means I go 
> overboard with simplifying and breaking stuff into functions. I'm not 
> quite as crazy about it as I used to be though. At one point I'd never 
> embed one code loop inside another without breaking the inner loop into 
> it's own function. It makes code neat but makes finding names for all 
> your functions problematic. Also I was told Python doesn't inline such 
> minor functions when compiling so I guess it is bad for optimization.

I've moved away from hardened style rules towards loose guidelines and aiming
for what reads more easily in a specific instance.  I still try to avoid long
lines, but don't fight it when it's difficult (e.g. when calling OpenGL).

I find that Python's clarity makes me feel like I can more easily get away
with compressing several lines into one.  For example from the source I
posted:

  self.dirtyRects.extend( [sprite.rect for sprite in sprites] )

which I feel is cleaner than the corresponding code spread over several
lines, as you might see in a language like Java:

  ArrayList rects = new ArrayList() ;
  Iterator  iter  = sprites.iterator() ;
  while( sprites.hasNext() ) {
    rects.append( sprites.next().getRect() ) ;
  }
  dirtyRects.appendList( rects ) ;

The python has a longer line with more going on, but splitting it up doesn't
improve it.


-Jasper
procrastinating in the guise of running off on a tangent