Talk:Convert seconds to compound duration: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 37: Line 37:
:::* the current spec requires that 0 seconds be displayed as an empty string.
:::* the current spec requires that 0 seconds be displayed as an empty string.
:::* fractional seconds would not conflict at all with the current spec (though might require some implementations change)
:::* fractional seconds would not conflict at all with the current spec (though might require some implementations change)
:::* years (and centuries) might be something of a problem because the relation between weeks and years is not simple. But it would be doable if the task defined a year as (for example) 52.1786 weeks. The numbers would be a bit nonsensical, but the other option would be be that you have to specify the starting second. And if you are going to do that you might as well do months as well (but this of course changes the task into something very different - see also [[Talk:Holidays_related_to_Easter]] and [[Talk:Last_Friday_of_each_month]] for some of the issues which might be relevant for that kind of a task).
:::* years (and centuries) might be something of a problem because the relation between weeks and years is not simple. But it would be doable if the task defined a year as (for example) 52.1786 weeks. The numbers would be a bit nonsensical, but the other option would be be that you have to specify the starting second. And if you are going to do that you might as well do months as well (but this of course changes the task into something very different - see also [[Talk:Holidays_related_to_Easter]] and [[Talk:Last_Friday_of_each_month]] for some of the issues which might be relevant for that kind of a task.
:::* Negative seconds might also change the task, if you wanted to go there. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 19:35, 20 June 2015 (UTC)
:::* Negative seconds might also change the task, if you wanted to go there. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 19:35, 20 June 2015 (UTC)

Revision as of 19:35, 20 June 2015

Task is ready for accepting solutions!

I've created it as a draft task for now as a formality, but I consider the task description finished - unless of course there is feedback demanding changes. So code away, and say if anything is unclear! --Smls (talk) 21:56, 6 June 2015 (UTC)‎

Hi, the usual process is to wait for at least four different language implementations from four people and no unanswered questions on the talk page before promotion from draft to full task status. This helps the task to mature without too many people doing implementations if problems are found.
I enjoyed doing the Python example and found the task description gave me the info I needed. Thanks. --Paddy3118 (talk) 03:41, 7 June 2015 (UTC)

About the python examples

The first python example doesn't run, because of undefined t. The second one runs, but if fed 0 seconds as input, it gives a blank in return, which is probably not ideal. Other examples may be doing the same thing, but I haven't checked.

Another issue: is it really necessary to post code in the interactive prompt format? It makes testing the code unpleasant because of the ">>>" prompt, and the mixed tab/space indentations looks like crap in my text editor. It may be useful to show users how to use the interactive shell, but since majority of coding is not going to be done in this fashion, having half of the python examples on RC so presented is overdoing it. --Ledrug (talk) 04:40, 7 June 2015 (UTC)

The current specification clearly states that the result for 0 seconds should be blank (or the empty string). I'm fine with that - makes for a clean implementation. Specifically:
  • However, only include quantities with non-zero values in the output (e.g. ...).
  • Meanwhile, as a curiosity question - would the python language spec lose anything if it were changed so that prompts (at least the default prompt) were neutral? Copy and paste of lines containing previously run statements is indeed a handy tool... --Rdm (talk) 11:42, 7 June 2015 (UTC)
    I hadn't thought about the 0 specifically, but I did qualify the problem statement by writing that the function "takes a positive integer" (which I wrote to exclude negative numbers, but actually excludes the 0 as well). In other words: An input of 0 is outside the scope of the task. You can handle it however you want. In practice, the cleanest way would be to reject non-positive numbers with a descriptive error message, but such boiler-plate input validation is not what the task is meant to be about, so it is not mandatory. Simply assuming that the function will only be called with positive numbers, is fine for this task. --Smls (talk) 12:30, 7 June 2015 (UTC)
    I post some small examples of code as entered in the command line prompt because it is a distinguishing feature of the language. Other languages may have a REPL but Pythons' REPL is used, in fact, the Python tutorial uses the REPL.
    I understand that it may cause problems in cut-n-paste trying out of examples, but the REPL adds to Pythons approachability I think and stands out as a distinguishing feature when compared to other examples. --Paddy3118 (talk) 20:19, 7 June 2015 (UTC)
    I have fixed the first Python example. Thanks for pointing out my error.
    Another point on keeping REPL examples is that it looks a lot more like IPython and IPython notebook input which is growing in popularity it seems. --Paddy3118 (talk) 20:29, 7 June 2015 (UTC)

    possible optional or extra credit

    Some options that would be a nice addition:

    •   ability to handle an input value of   0   (zero) seconds
    •   ability to handle fractional seconds, such as:   123.7
    •   ability to handle higher time units, such as:   years, centuries

    -- Gerard Schildberger (talk) 10:36, 20 June 2015 (UTC)

    Hmm...
    • the current spec requires that 0 seconds be displayed as an empty string.
    • fractional seconds would not conflict at all with the current spec (though might require some implementations change)
    • years (and centuries) might be something of a problem because the relation between weeks and years is not simple. But it would be doable if the task defined a year as (for example) 52.1786 weeks. The numbers would be a bit nonsensical, but the other option would be be that you have to specify the starting second. And if you are going to do that you might as well do months as well (but this of course changes the task into something very different - see also Talk:Holidays_related_to_Easter and Talk:Last_Friday_of_each_month for some of the issues which might be relevant for that kind of a task.
    • Negative seconds might also change the task, if you wanted to go there. --Rdm (talk) 19:35, 20 June 2015 (UTC)