bugGNU Octave - Bugs: bug #51801, OO: constructor without arguments

 
 

bug #51801: OO: constructor without arguments

Submitter:  None
Submitted:  Sun 20 Aug 2017 12:03:43 PM UTC
   
 
Category:  Documentation Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Documentation
Status:  Need Info Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 22 Aug 2017 02:30:33 PM UTC, comment #5: 

There is another bug: in the new release, the default constructor
without is no longer invoked.
instead it seems as if a void default constructor
merely applying class(...) is invoked.

Ernst Reissner <ernstreissner>
Tue 22 Aug 2017 02:24:41 PM UTC, comment #4: 

@mike
you ask what i suggest:
We read in the manual:

Ideally, even when the constructor is called with no arguments
it should return a valid object.


We should say why:

Ideally, even when the constructor is called with no arguments
it should return a valid object
because octave invokes the constructor with no arguments
to determine the default value.

https://www.mathworks.com/help/matlab/matlab_oop/class-constructor-methods.html

The default value is used for padding values into an array.
If you write a(5)=1 where a is undefined,
a(1),...,a(4) are padded with the default value which is 0.

Accordingly, if you have a class say pn which allows argument 1
and if you write a(5)=1 where a is undefined,
a(1),...,a(4) are padded with the default value
which is determined invoking pn().


What is strange: in the newest release, octave does no longer invoke pn() 4 times as it used to do.
So i ask myself how it determines the default value.

Is there another bug here???

Ernst Reissner <ernstreissner>
Mon 21 Aug 2017 08:05:53 PM UTC, comment #3: 

For example


 classdef myclass < handle
  properties
    value
  endproperties
  methods
    function self = myclass (value)
      if (nargin < 1)
        error ("myclass: VALUE argument is required");
      endif
      self.value = value;
    endfunction
  endmethods
endclassdef


Mike Miller <mtmiller>
Group Member
Mon 21 Aug 2017 08:05:16 PM UTC, comment #2: 

Even for a classdef class, a user may choose to not allow construction of an object without any arguments if they want to, there is nothing wrong with that.

For example


classdef myclass < handle
  properties
    value
  endproperties
  methods
    function self = myclass (value)
      if (nargin < 1)
        error ("myclass: VALUE argument is required");
      endif
      self.value = value;
    endfunction
  endmethods
endclassdef

Mike Miller <mtmiller>
Group Member
Mon 21 Aug 2017 07:59:32 PM UTC, comment #1: 

Are you suggesting that the wording should be changed from "it should return a valid object" to "it must return a valid object"?

I disagree with that, however this is only describing the situation for legacy style classes. What we need is a rewrite of the OO section of the manual to cover classdef classes, which do always return a valid object, because it's not even left up to the user to assign a return value.

Mike Miller <mtmiller>
Group Member
Sun 20 Aug 2017 12:03:43 PM UTC, original submission:  

In the manual, Section 34.1 we read:

Ideally, even when the constructor is called with no arguments
it should return a valid object.


That is too weak.
Say, the class has name pn, then pn() defines the default value.
Default values are known (yet not mentioned in the documentation)
for primitive types:
As a consequence, writing a(3,3)=1 fills up a with zeros:
a =
   0   0   0
   0   0   0
   0   0   1
Along the same lines, pn() is the default value
and so a(3,3)=pn(1)
yields
a =
   0   0   0
   0   0   0
   0   0   1
also, where the 1 is created by pn(1)
and the 0 by pn() (not pn(0))!

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ernstreissner (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-08-21 mtmiller Severity3 - Normal 2 - Minor
        Item GroupNone Documentation
        StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code