Talk:Loops/For with a specified step: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 28: Line 28:
::: Deletion '''very rarely''' adds value.
::: Deletion '''very rarely''' adds value.
::: You may find a contribution 'useless' for your purposes, but we really don't need to know that, and it's '''not''' up to you to make that decision on behalf of others.
::: You may find a contribution 'useless' for your purposes, but we really don't need to know that, and it's '''not''' up to you to make that decision on behalf of others.
::: If you genuinely think that you may have spotted one of the '''very''' rare cases where a deletion could somehow add significant value, and that others have somehow missed what you think you can see, then open that discussion, and see what consensus emerges. At worst, you may learn something. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 18:31, 3 February 2021 (UTC)
::: If you genuinely think that you may have spotted one of the '''very''' rare cases where a deletion could somehow add significant value, and that others have somehow missed what you think you can see, then open that discussion, and see what consensus emerges. At worst, you may learn something.
::: Don't execute the prisoner first, and then consult the court afterwards.
[[User:Hout|Hout]] ([[User talk:Hout|talk]]) 18:31, 3 February 2021 (UTC)

Revision as of 18:35, 3 February 2021

The Ada solution might also consider using simple loop and then applying a (simple) function to generate the “loop variable”. For example, to loop from 0 to 10 by 2, you might loop from 0 to 5 by 1 and then set another var to the loop var times 2 at each step. (This technique is much more common when trying to loop by floating-point quantities, where feeding them directly into a C-like loop is inadvisable in many languages due to the need to manage imprecision in a way that doesn't blow up in your face...) —Donal Fellows 23:38, 12 July 2009 (UTC)

"useless" examples?

The recent purge struck me as rather aggressive. What constitutes a "useless" example? Knowing that the for statement does not support a step of 2 could itself be useful. I feel those examples should be reinstated. --Pete Lomax (talk) 11:40, 3 February 2021 (UTC)

I understand that’s what omit from is for: That a certain task is just simply impossible in a certain language.
I have narrowed down the task, because I think it is generally known counting loops (for-loops) can be written as semantically equivalent conditional loops (while-loops). I don’t need nobody to show me that, it’s “useless” for me and probably many many other users. I consulted this wiki page to see various flavors of how languages provide means to alter step widths (step, range with width specifier, etc.), not to see various flavors of while loops, you know what I mean?
I strongly oppose reinstating dozens of languages inserting a statement to this page, like: “This isn’t possible, but a while-loop can achieve the same: <code example>”. Well, duh!? It’s just noise. Please leave that out and use omit from.
Root (talk) 11:55, 3 February 2021 (UTC)
Since you're here: 1) what was so offensive about the Axe for loop, or rather where on earth is your first new point coming from at all? 2) Why delete Delphi completely and just the code from Dragon? 3) What suddenly changed to make that [Delphi] ten year old example completely unacceptable? There is a reason why this site has draft tasks, and you should be very cautious (and probably discuss things first) before altering a task that was reviewed and promoted to full task status a decade ago. --Pete Lomax (talk) 12:33, 3 February 2021 (UTC)
One of this site's unwritten rules (or at least I thought it was) is that you don't alter the descriptions of tasks which already have solutions without prior discussion and then set about removing implementations that don't fit.
Moreover, languages which don't support the feature in question are generally allowed some latitude to show how they would do it instead. This is much more informative than just omitting the language from the task altogether.
Without this rule, you could probably justify deleting half the examples on the site as not satisfying the task description in some form or another.
Frankly, I was amazed that the admins let the changes stand! --PureFox (talk) 13:12, 3 February 2021 (UTC)
Perhaps the question is not "What constitutes a "useless" example?" but "who decides ?"
being unusually opinionated and incurious about procedure seems unlikely to be an adequate qualification :-)
Prior discussion always produces a higher quality of decision, and wastes less time, than the instant gratification of isolated impulse Hout (talk) 13:21, 3 February 2021 (UTC)
I reckon for-loops are those listed under Loops/For. This task requires a for-loop to be used. If the code example used here uses a language construct that is not shown at Loops/For, I understand it is not a for-loop.
I’ve deleted the Delphi example, because it’s just a semantically equivalent while-loop. You will find the used language construct demonstrated at Loops/While, but not in Loops/For, hence it’s not a for-loop. This requirement, use for loops, already existed before I edited the page.
I have to make one concession though: Deleting the Axe for loop was impetuous. It’s not normal a control variable can be altered inside a for-loop body. In Pascal, for instance, it is illegal to tamper with the counting variable of a for-loop. I probably just read the first sentence “Axe does not support a step size other than 1” and then threw it out.
I haven’t deleted anything from Dragon. I assume you meant E. The E section still contains code for a custom enumerator (stepRange). The semantically equivalent while-loop, though, is unnecessary.
My intentions were to qualify the task requirements, not alter them. It’s difficult to phrase: I wanted to still permit examples like C, where it is just idiomatic, “normal” to write a conditional expression i < 10 and statement i += 2, because for-loops with a step size of 1 look just the same.
Root (talk) 13:37, 3 February 2021 (UTC)
There is a problem with this: even if a language does not have a for/by statement, there may be an idiomatic equivalent that is not a while loop. The most common is probably an iterator/enumerator/generator or whatever you call that, e.g. in Python. Except that the tasks explicitly forbids the case where the enumeration is not suitable to very large ranges, which I suppose means we don't want a solution where we loop other a range that in the background builds a full list of values in memory. Except it's how you do it in R. You also want to delete the R solution? Then we are losing knowledge: how to achieve that task, as idiomatically as possible, even if it's not perfect? Bastet (talk) 16:37, 3 February 2021 (UTC)
Deletion very rarely adds value.
You may find a contribution 'useless' for your purposes, but we really don't need to know that, and it's not up to you to make that decision on behalf of others.
If you genuinely think that you may have spotted one of the very rare cases where a deletion could somehow add significant value, and that others have somehow missed what you think you can see, then open that discussion, and see what consensus emerges. At worst, you may learn something.
Don't execute the prisoner first, and then consult the court afterwards.

Hout (talk) 18:31, 3 February 2021 (UTC)