[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: let's keep printf, puts, and scanf
From: |
edmund ronald |
Subject: |
Re: let's keep printf, puts, and scanf |
Date: |
Thu, 21 Apr 2016 16:38:59 +0200 |
Printf seems a useful thing to have around ...
On Apr 21, 2016 10:23, "Kai Torben Ohlhus" <address@hidden> wrote:
>
> On Thu, Apr 21, 2016 at 6:05 AM Mike Miller <address@hidden> wrote:
>>
>> > Another observation is, that the Octave language has the nice feature to
>> > make 2 real implementations and 4 convenience m-file wrappers to get all the
>> > work done. Instead Octave currently provides 6 "real" (more redundant)
>> > implementations in file-io.cc. Means, if any serious error is detected, the
>> > code has to be touched more than once! Needless to say, that the source file
>> > with important code is bloated up to 3k lines of code, so it's harder for
>> > newcomers to get into it.
>>
>> True. That's why I suggested it might make sense to turn some of them
>> into m-file wrappers, just not labeled as deprepcated. In #octave, jwe
>> made the point that these functions have hardly had any bugs reported at
>> all and the code, even though it is in C++ routines, is still very small
>> and easily maintainable. They are mostly wrappers around octave_stream.
>
> [...]
>>
>> Personally I think we should keep printf forever, there's no reason to
>> get rid of it, it's a useful convenient wrapper to have, yes even though
>> fprintf without a file argument is the same exact thing.
>
>
> Yes, maybe deprecation is no option at all then. But I think we should use the power of Octave, to make the code base as easy as possible, if the m-file does not result in a total performance penalty.
>
> tic; for i = 1:5, printf_m("%s", "hi everyone"); end, disp(toc)
> 6.3205e-04
> tic; for i = 1:5, printf("%s", "hi everyone"); end, disp(toc)
> 2.1100e-04
> tic; for i = 1:20000, printf_m("%s", "hi everyone"); end, disp(toc)
> 1.5331
> tic; for i = 1:20000, printf("%s", "hi everyone"); end, disp(toc)
> 1.5113
>
> function numbytes = printf_m (varargin)
>
> if (nargin < 1)
> print_usage ();
> endif
>
> numbytes = fprintf (varargin{:});
>
> endfunction
>
>> > @Mike: you mean varargin{:}?
>> > http://hg.savannah.gnu.org/hgweb/octave/file/96518f623c91/scripts/deprecated/usage.m
>> > Can you explain, what this does better? I would like to mention this in
>> > https://www.gnu.org/software/octave/doc/v4.0.1/Variable_002dlength-Argument-Lists.html
>> > if it is not documented elsewhere.
>>
>> Yes, varargin is a cell array while varargin{:} expands to a cs-list,
>> which is what is necessary for the elements of the cell array to be
>> interpreted as distinct arguments.
>>
>> args = {"one", "two", "three"};
>> func (args)
>>
>> vs
>>
>> func (args{:})
>>
>> The first calls func with a single argument which is a cell array, the
>> second calls func with 3 arguments.
>
> [...]
>
> Thank you for the explanation Mike, as I had to notice, this is already documented in the example -.-
>
> So if there are no objections, or an unmistakably no, I will come up with a reduced version of the cset, only making puts, fputs, printf and scanf (not deprecate) M-files next week.
>
> Kai
- let's keep printf, puts, and scanf, Mike Miller, 2016/04/20
- Re: let's keep printf, puts, and scanf, John W. Eaton, 2016/04/20
- Re: let's keep printf, puts, and scanf, siko1056, 2016/04/20
- Re: let's keep printf, puts, and scanf, Mike Miller, 2016/04/21
- Re: let's keep printf, puts, and scanf, Kai Torben Ohlhus, 2016/04/21
- Re: let's keep printf, puts, and scanf, John W. Eaton, 2016/04/21
- Re: let's keep printf, puts, and scanf,
edmund ronald <=