• Re: What does this code do ?

    From David Brown@21:1/5 to wij on Tue May 28 08:57:50 2024
    On 28/05/2024 07:34, wij wrote:
    On Mon, 2024-05-27 at 14:37 +0200, Bonita Montero wrote:
    #include <iostream>
    #include <vector>
    #include <numeric>

    using namespace std;

    int main()
    {
    vector<double> row;
    double k = 1, f = 1, fRev = 1;
    do
    row.emplace_back( fRev ),
    f *= k++,
    fRev = 1 / f;
    while( fRev );
    auto acc = [&]( size_t n ) { return accumulate( make_reverse_iterator( >> row.begin() + n ), row.rend(), 0.0 ); };
    size_t n = row.size();
    for( double e = acc( n ), eNext; (eNext = acc( n - 1 )) == e; --n, e = >> eNext );
    cout << n << endl;
    }


    There might be several issues in the program.

    Don't know what it does but felt the general problem of C++: Overly expressive.
    Expressive to improve quality? reading/error detect?


    To be clear - it is indicative of a problem with some programmers, not
    the language. Bonita would write smart-arse code in any language. C++
    just gives such programmers more ways to write bad code than some other languages.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vir Campestris@21:1/5 to Bonita Montero on Thu May 30 17:09:14 2024
    On 28/05/2024 08:03, Bonita Montero wrote:
    21 lines should be readable anyway, no matter which style.

    Go find an APL programme, then tell me you still believe that.

    Andy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Vir Campestris on Thu May 30 17:09:18 2024
    Vir Campestris <[email protected]d> writes:
    On 28/05/2024 08:03, Bonita Montero wrote:
    21 lines should be readable anyway, no matter which style.

    Go find an APL programme, then tell me you still believe that.

    Or pretty much any perl program. Write-once/read-never language.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Scott Lurndal on Thu May 30 23:01:40 2024
    On 5/30/24 13:09, Scott Lurndal wrote:
    Vir Campestris <[email protected]d> writes:
    On 28/05/2024 08:03, Bonita Montero wrote:
    21 lines should be readable anyway, no matter which style.

    Go find an APL programme, then tell me you still believe that.

    APL was my third programming language, after Fortran II and BASIC. I
    learned it and wrote several programs in it around 1977. About thirty
    years later, after having done almost no programming in APL, I came
    across a printout of my code that I had saved. I found it quite clear
    and easy to read. I couldn't write new code without consulting a
    reference manual, but I could read my old code.

    Or pretty much any perl program. Write-once/read-never language.

    I've never understood what gave perl that reputation. I worked nearly 30
    years on a project that required me to occasionally write perl code and
    to read perl code written by others. I didn't find it any harder to
    understand than the C code we were writing. There's fancy tricks that
    you can do with perl that can be very hard to follow, but for precisely
    that reason, we avoided writing such code.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to James Kuyper on Fri May 31 09:17:31 2024
    On 31/05/2024 05:01, James Kuyper wrote:
    On 5/30/24 13:09, Scott Lurndal wrote:
    Vir Campestris <[email protected]d> writes:
    On 28/05/2024 08:03, Bonita Montero wrote:
    21 lines should be readable anyway, no matter which style.

    Go find an APL programme, then tell me you still believe that.

    APL was my third programming language, after Fortran II and BASIC. I
    learned it and wrote several programs in it around 1977. About thirty
    years later, after having done almost no programming in APL, I came
    across a printout of my code that I had saved. I found it quite clear
    and easy to read. I couldn't write new code without consulting a
    reference manual, but I could read my old code.

    Or pretty much any perl program. Write-once/read-never language.

    I've never understood what gave perl that reputation. I worked nearly 30 years on a project that required me to occasionally write perl code and
    to read perl code written by others. I didn't find it any harder to understand than the C code we were writing. There's fancy tricks that
    you can do with perl that can be very hard to follow, but for precisely
    that reason, we avoided writing such code.


    I think its reputation is that Perl was popular for small scripts, and
    in such scripts people often have little concern for future maintenance,
    code re-use, and the like. They use these "fancy tricks" and write "write-only" code. If you later need to write a similar script, it's
    usually just as fast to write it from scratch - but that's okay for
    short scripts.

    I haven't done any Perl programming, but I've modified a couple of Perl programs, and had no problem with that.

    These days, in most new code that at one time would have been written in
    Perl, is now written in Python. It's less tempting to write
    incomprehensible Python than it is to write incomprehensible Perl - it
    doesn't have the same kind of tricks. But I've seen (and written)
    plenty of small bits of Python that take extra thought to understand afterwards. Not everything needs to be readable or maintainable -
    sometimes it is sufficient if it just works there and then.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vir Campestris@21:1/5 to James Kuyper on Sat Jun 1 20:47:32 2024
    On 31/05/2024 04:01, James Kuyper wrote:
    APL was my third programming language, after Fortran II and BASIC. I
    learned it and wrote several programs in it around 1977. About thirty
    years later, after having done almost no programming in APL, I came
    across a printout of my code that I had saved. I found it quite clear
    and easy to read. I couldn't write new code without consulting a
    reference manual, but I could read my old code.

    My introduction to APL was a programme published in a scientific paper.
    This was before email and the internet, so I had to type it in.

    I never got all the typos out. No doubt some of them were in the
    published paper. That probably didn't help my degree, but TBH I can't
    really say I suffered - my first employer had a policy of looking for
    people who had messed up their degree by playing with the computer too much.

    But I never want to see APL ever again. I'm not sure I have!

    Andy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)