>>>>> "RD" == Rob Dixon <rob.di...@gmx.com> writes:

  RD> On 03/09/2011 21:34, Uri Guttman wrote:
  >> Ron Weidner<xecro...@yahoo.com>  wrote:
  >> 
  >> first off, arrays have nothing (or little) to do with OOP. you are using
  >> arrays inside an object but the code at that point is just plain perl.

  RD> That is a strange assertion. So OO software is more to do with scalars?
  RD> Or hashes? I will buy that Perl objects are generally blessed references
  RD> to hashes, but this is an anonymous array as the value of the base hash
  RD> object.

actually in this example a hash ref is the object. the array in question
is a ref inside the hash. so if you ripped out all the OO code, it would
still have the same issues as he has now. or put it another way, he has
both OO and array issues in his code. but he has no array OO issue. :)

  >>> 
  >>> Can't call method "attrib" on unblessed reference at ./test.pl line 40.
  >>> 
  >>> $config = new Widget();

  RD> That is an "indirect method call" and a nice syntax, especially because
  RD> it looks like C and reads like English, except that it is ambiguous.
  RD> Suffice to say that it is bad manners to call the constructor that way
  RD> (and even those who denounce it will have to look up why it is so bad).

  >> you should call that with a direct method call and declare it with
  >> my. also config is a bad name for a widget object, even in an example.

  RD> OK, so Uri says never to call an object $config, so $config2 should
  RD> suffice. It's not a Widget object Uri, it's the thing that has an array
  RD> of Widgets.

so @widgets or whatever. but it isn't a config in any way shape or
form. name should reflect the usage of the data, not be just a
placeholder or mnemonic.

  >> my $config = Widget->new();

  RD> There is a big difference between

  Widget-> new();

  RD> and

  Widget-> new;

  RD> and more often than not you will want the latter. Much like

not for method calls. both pass no args other than the object itself.

  RD>   use MyModule;

  RD> is more likely to be right than

  RD>   use MyModule ();

that is a very different case as perl itself is parsing and handling
that and will call the import method differently based on it.

  >>> my $i = 0;
  >>> for ($i=0; $i<3; $i++)
  >> 
  >> don't declare $i before the loop. it can be declared in it. also use
  >> perl style loops and not c style when you can:
  >> 
  >> foreach my $i ( 0 .. 3 ) {

  RD> Yes about the declaration, but Uri means

  RD>   foreach my $i (0 .. 2) {

off by one error. common enough. it is why c style loops are harder to
read. my error make a good case for this.

  >> you don't show that method. also your comment's method name doesn't
  >> agree with the actual method name. be consistant.

  RD> No he doesn't. But it's nothing to do with the problem Uri. Also, it's
  RD> 'consistent'.

no it isn't consistant. the name in the comment wasn't the same name in
the call. how you call that consistant is the question.

  >>> $config->add_widget($w); #this is what I'm testing
  >> 
  >> and where is the code for this?

  RD> He hasn't shown it. Ron is a beginner.

right. i am asking him to show all the related code as a teaching
point. 

  >>> }
  >> 
  >>> foreach my $w ( $config->get_widgets() )
  >>> {
  >>> #attrib is tested and working, but this foreach loop is not known to be 
valid code yet.
  >>> print $w->attrib("name"); #<----  This is line 40.
  >> 
  >> again, where is the code for this method? usually you can't debug method
  >> calls without seeing the method code.
  >> 
  >> uri

  RD> So Uri skips over the likely cause of the problem: that the
  RD> 'get_widgets' method probably returns an array reference rather than a
  RD> list.

i didn't look into that. you seem to be in a poor mood again. please be
more careful when you are in such a mood.

uri

-- 
Uri Guttman  --  uri AT perlhunter DOT com  ---  http://www.perlhunter.com --
------------  Perl Developer Recruiting and Placement Services  -------------
-----  Perl Code Review, Architecture, Development, Training, Support -------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to