in reply to Re^2: 5.40 released
in thread 5.40 released

He was simply showing some of the features of the 5.40.0 release, not trying to demonstrate some beautiful or optimized code, making such nitpicking seem pretty out of place and off topic.

Replies are listed 'Best First'.
Re^4: 5.40 released
by GrandFather (Saint) on Jun 13, 2024 at 09:19 UTC

    I semi-agree with anonymonk here - the Cish cruft got in the way of me seeing the point trying to be made. I saw C code and essentially skipped everything else. I find it really hard to imagine why you would want to write C in Perl as a preferred option. Why not just write C in C?

    However I agree with cavac that the implicit variable should be avoided, but not to the extent of eschewing map and grep etc.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

      Well, since i needed the iterator VALUE in the code, so for(0..9) was not an option. This is quite often the case in my code. To avoid mixing too many styles of constructs, i limited my coding style to use C-Style.

      Plus, as mentioned, i often port between JavaScript, C/C++ and Perl, as well as doing a lot of Arduino development. For my use cases, for(0..9) is the cruft, proper C-Style loops are the norm ;-)

      But, as i said, that's just the style guide for my own projects.

        Well, since i needed the iterator VALUE in the code, so for(0..9) was not an option.

        I'm not sure how this follows. Could you explain why this condition precludes the perlish loop?


        🦛

        Well, since i needed the iterator VALUE in the code, so for(0..9) was not an option. This is quite often the case in my code. To avoid mixing too many styles of constructs, i limited my coding style to use C-Style.

        for my $i(0..9){...}

        Or am I missing something?

Re^4: 5.40 released
by Anonymous Monk on Jun 13, 2024 at 03:25 UTC
    I guess you're right about being off topic. Sorry I was just trying to be informative. Was triggered by reading that trinary (sic) is hard to read after seeing a multiple parameter loop in perl that was supposed to be easy to read... 🤷

    $ternary = $can ? be_really_easy : to_read_btw;
      No worries. I'm a big fan of ternary expressions myself. However, I don't get all the hate for for(my $i = 0; $i < 10; $i++). Just because it's not unique to perl doesn't it make it non-perl.

        I don't get all the hate for for(my $i = 0; $i < 10; $i++)

        It's extremely hard to read and error prone. for my $i ( 0 .. 9 ) is so much clearer. This is true for this trivial case, and even more so for anything more complex. It's also a lot slower, but that's a secondary considering by far.

          I don't get all the hate for for(my $i = 0; $i < 10; $i++). Just because it's not unique to perl doesn't it make it non-perl.

        (my $i = 0; $i < 10; $i++)
        
        This rarely makes sense in Perl. There's an entire freakin program unnecessarily stuffed up in those parenthesis! First we have to declare and initialize a variable, then we set a condition on the operation, and finally we iterate. It's pretty cool and all but compared to what perl can do it looks like a messy hack in some language that lacks implicit variables. I think that's cargo cult perl and may contribute to several bad reputations related to readability, line noise and our beloved sigils.

        (my $i = 0; $i < 10; $i++)
        
        vs
        
        (0 .. 9)
        
        The Perl Way eliminates the unnecessary 9 symbols ($$$;;++=<), 5 spaces, 5 letters and a variable because the range operator sets our condition and gives us an implicit iterating iterator for free! Of course sometimes an explicit variable is required to avoid clobbering an implicit inner construct:
        my $i (0 .. 9)
        
        I do understand Cavac's desire to keep codebases consistent by having Perl constructs emulate C and Javascript, and it's wonderful that Perl can emulate them with ease (ironically by adding "line noise"), while they can't hope to emulate the elegant simplicity of implicit Perl. Anyway that's why we hate it :-)