tail

Cameron Simpson cs at cskk.id.au
Thu May 12 18:29:13 EDT 2022


On 12May2022 19:48, Marco Sulla <Marco.Sulla.Python at gmail.com> wrote:
>On Thu, 12 May 2022 at 00:50, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>>   There's no spec/doc, so one can't even test it.
>
>Excuse me, you're very right.
>
>"""
>A function that "tails" the file. If you don't know what that means,
>google "man tail"
>
>filepath: the file path of the file to be "tailed"
>n: the numbers of lines "tailed"
>chunk_size: oh don't care, use it as is

This is nearly the worst "specification" I have ever seen.

Describe what your function _does_.

Do not just send people to an arbitrary search engine to find possibly 
ephemeral web pages where someone has typed "man tail" and/or (if lucky) 
web pages with the output of "man tail" for any of several platforms.

But this is sounding more and more like a special purpose task to be 
done for your particular use cases. That says it should be in your 
personal toolkit. If it has general applicability, _publish_ your 
toolkit for others to use. You can do that trivially by pushing your 
code repo to any of several free services like bitbucket, gitlab, 
sourcehut, github etc. Or you can go the extra few yards and publish a 
package to PyPI and see if anyone uses it.

Part of your problem is that you think the term "tail" has a specific 
simple obvious meaning. But even to me it means at least 2 things:
- to report the last "n" "lines" of a text file
- to continuously report "new" data appended to a file

These are different, though related, tasks. The latter one is 
particularly easy if done purely for bytes (on systems which allow it).  
As you've had explained to you, the former task is actually very fiddly.

It is fiddly both in boundary conditions and complicated by being 
dependent on the text encoding, which you do not inherently know - that 
implies that you ought to (a) provide a way to specify that encoding and 
(b) maybe have a reasonable fallback default. But that default needs to 
be carefully and precisely explained. And the "find a line ending" 
criteria need to be explained. And the "sync to a character boundary" 
needs to be explained, including where it cannot be done.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list