in reply to Re: Finding the index of a specific element in an array.
in thread Finding the index of a specific element in an array.

I guess it contains an off-by-one error.

No, but it does contain synthetic code.

  • Comment on Re^2: Finding the index of a specific element in an array.

Replies are listed 'Best First'.
Re^3: Finding the index of a specific element in an array.
by JavaFan (Canon) on Jan 25, 2012 at 01:09 UTC
    No, but it does contain synthetic code.
    Yeah, and? Care to show us some 'natural' code which actually describes and solves the problem in hand and that doesn't have any an artifact of the particular method that you have chosen to solve the problem.? The emphasis are verbatim quotes from the article you link to.
      for my $i (0 .. $#array) { next unless $array[$i] == 7; say "The index is $i"; }

      You may quibble that the use of $#array is itself an artifact of the method I've chosen to solve the problem (and I can agree), but there's less synthetic code in this version. Certainly there's iteration and incrementing, but when Perl handles that and the programmer doesn't have to, there's less synthetic code.

        I down voted this because: once you add code to remember the index for use after the loop -- and omit the say :

        my $pos; for my $i (0 .. $#array) { next unless $array[$i] == 7; $pos = i; last; } ## do something with $pos.

        -- your code is at least as synthetic (by the standard of mjd's articles) as JavaFan's, if not more so:


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

        I'm curious to find out why you consider this to be 'natural' code which actually describes and solves the problem in hand, but using a C-style loop to be showing an artifact of the particular method that you have chosen to solve the problem.