| kyrbe | merlyn, can you suggest a good book for learning about objects ;) |
| merlyn | you jest. :) Why, my book of course. :) |
| LeoNerd | </plug> |
| yrlnry | Never write a subroutine less than 100 lines. Subroutine calls are expensive. |
| merlyn | heretic! never write a subroutine that doesn't return a coderef. :) |
| kyrbe | yeah, what's the reasoning behind smaller subs? |
| merlyn | it forces you to NAME each step |
| yrlnry | I was going for "diabolical", but if "heretic" is the best I can do, I suppose I'll have to settle for that. |
| merlyn | more self documenting also, when you're doing OO, it's easier to subclass and override parts |
| LeoNerd | Object accessor methods tend to be quite short |
| yrlnry | I write all my Perl programs in continuation-passing style. |
| merlyn | 200-line subroutines are the death of subclassing I pass discontinuations. :) |
| LeoNerd | sub thing { my $self = shift; return $self->{thing} } |
| merlyn | oh - and don't automatically write accessors for all instance vars. people who do that should be shot. they end up with objects that are nothing more than structs. |
| kyrbe | I was told yesterday not to use shift b/c it destroys @_. Any other comments on this? |
| LeoNerd | Oh, sure... but in cases where you expect subclasses to override.. it's good |
| merlyn | I'd destroy that person that's silly advice |
| LeoNerd | Depends if you want to I often go my $self = shift; my ( $arg, $names, $here ) = @_; |
| merlyn | export behavior, not data |
| yrlnry | kyrbe: sounds like terrible advice. |
| merlyn | define your interfaces in terms of what you want the object to do, not what you think the object should know you shouldn't care what the object knows. |
| LeoNerd | Mmm.. Sounds good |
| merlyn | therefore, automatic accessors by default are wrong certainly, a Point will need an X/Y when creatd but you shouldn't care if it stores those as two separate vars, or some single encoded value and you'd probably want a "get x coordinate of point" if it makes sense in your app but what if your app never cared about that? why write code to return "x"? it's all about paying attention when you design and automatically generating accessors makes you not pay attention, and that leads to bad practices. & morning stuff |