• Triggered By Mediocre Code (Posting On Python-List Prohibited)

    From Lawrence D'Oliveiro@ldo@nz.invalid to comp.lang.python on Sun Aug 25 21:53:31 2024
    From Newsgroup: comp.lang.python

    Looking at this article about the top three languages for getting
    programming jobs <https://www.zdnet.com/article/want-a-programming-job-make-sure-you-learn-these-three-languages/>,
    naturally I couldn’t help noticing the code in the screenshot at the
    top (my transcription):

    bufferedNumber = str(doc.GetTime().GetFrame(docFps))
    if len(bufferedNumber)<4:
    for x in range(len(bufferedNumber),4):
    bufferedNumber = "0" + bufferedNumber

    I mean, really? Four lines to do what could be done in a single
    expression?

    Was that written by a PHP programmer, do you think?
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Paul Rubin@no.email@nospam.invalid to comp.lang.python on Sun Aug 25 15:07:45 2024
    From Newsgroup: comp.lang.python

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:
    I mean, really? Four lines to do what could be done in a single
    expression? Was that written by a PHP programmer, do you think?

    It is not fluent Python, that's for sure. No idea about PHP though. I
    have been wondering about PHP recently. The language is painful but
    the implementation has some attractions and it's widely available. So
    I've wondered if it might be feasible to have a front end for it similar
    to Typescript or Purescript.

    Is this what you had in mind?

    bufferedNumber = f'{doc.GetTime().GetFrame(docFps):04}'
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lawrence D'Oliveiro@ldo@nz.invalid to comp.lang.python on Sun Aug 25 23:49:48 2024
    From Newsgroup: comp.lang.python

    On Sun, 25 Aug 2024 15:07:45 -0700, Paul Rubin wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    I mean, really? Four lines to do what could be done in a single
    expression? Was that written by a PHP programmer, do you think?

    It is not fluent Python, that's for sure. No idea about PHP though. I
    have been wondering about PHP recently. The language is painful but the implementation has some attractions and it's widely available.

    I earn part of my living from it. It’s something I use when I have to
    (e.g. writing WordPress plugins). I don’t know what these “attractions” are that you speak of: Python is at least as widely available, and it does better than PHP at Web-based programming (supposedly PHP’s bread and
    butter) because ASGI-based frameworks allow common handling of WebSocket connections together with regular HTTP ones, which is more awkward in PHP.

    Is this what you had in mind?

    bufferedNumber = f'{doc.GetTime().GetFrame(docFps):04}'

    Printf style makes it explicit that it is an integer, and nothing else
    will do:

    bufferedNumber = "%0.4d" % doc.GetTime().GetFrame(docFps)

    The irony of my putdown is that PHP can do it about as simply. But don’t expect your typical PHP programmers to know that ...
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From rbowman@bowman@montana.com to comp.lang.python on Mon Aug 26 03:01:18 2024
    From Newsgroup: comp.lang.python

    On Sun, 25 Aug 2024 23:49:48 -0000 (UTC), Lawrence D'Oliveiro wrote:

    The irony of my putdown is that PHP can do it about as simply. But don’t expect your typical PHP programmers to know that ...

    It has had amazing longevity for something that was born as Personal Home Page.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Paul Rubin@no.email@nospam.invalid to comp.lang.python on Mon Aug 26 13:25:48 2024
    From Newsgroup: comp.lang.python

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:
    Printf style makes it explicit that it is an integer, and nothing else
    will do:
    bufferedNumber = "%0.4d" % doc.GetTime().GetFrame(docFps)

    bufferedNumber = f'{doc.GetTime().GetFrame(docFps):04d}'

    seems to handle it too.

    Regarding PHP, many shared hosting vendors offer it without offering
    Python. It's easier with PHP to serve many customers with a single PHP instantiation
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lawrence D'Oliveiro@ldo@nz.invalid to comp.lang.python on Mon Aug 26 21:52:41 2024
    From Newsgroup: comp.lang.python

    On Mon, 26 Aug 2024 13:25:48 -0700, Paul Rubin wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    Printf style makes it explicit that it is an integer, and nothing else
    will do:

    bufferedNumber = "%0.4d" % doc.GetTime().GetFrame(docFps)

    bufferedNumber = f'{doc.GetTime().GetFrame(docFps):04d}'

    seems to handle it too.

    Note that “04d” is not quite the same as “0.4d”.

    Regarding PHP, many shared hosting vendors offer it without offering
    Python. It's easier with PHP to serve many customers with a single PHP instantiation

    I’m sure they do. It’s typically offered via the “mod_php” module that executes within an Apache web server process. Turns out there is an interesting technical limitation of this, though: it doesn’t handle WebSockets very well.

    Python has ASGI, which offers your choice of Web frameworks founded on async/await and asyncio. Instead of running as an addon module in the Web server, the Python code runs in a separate process, with its own
    independent flow of control. This is much more versatile.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Paul Rubin@no.email@nospam.invalid to comp.lang.python on Mon Aug 26 15:06:03 2024
    From Newsgroup: comp.lang.python

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:
    Note that “04d” is not quite the same as “0.4d”.

    For non-negative numbers, I think 04d does what the original verbose
    code did. 0.4d for an integer isn't valid in an f-string. With
    old-style formatting and negative numbers, 0.4d pads differently than
    04d, and the original verbose code appears to be plain wrong, formatting
    -1 as "00-1" if I'm not mistaken.

    Python has ASGI, which offers your choice of Web frameworks founded on async/await and asyncio. Instead of running as an addon module in the Web server, the Python code runs in a separate process, with its own
    independent flow of control. This is much more versatile.

    Yes, and the separate processes use more machine resources which is why
    low end hosting places prefer PHP.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lawrence D'Oliveiro@ldo@nz.invalid to comp.lang.python on Tue Aug 27 03:04:52 2024
    From Newsgroup: comp.lang.python

    On Mon, 26 Aug 2024 15:06:03 -0700, Paul Rubin wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    0.4d for an integer isn't valid in an f-string.

    I wonder why not?

    Python has ASGI, which offers your choice of Web frameworks founded on
    async/await and asyncio. Instead of running as an addon module in the
    Web server, the Python code runs in a separate process, with its own
    independent flow of control. This is much more versatile.

    Yes, and the separate processes use more machine resources which is why
    low end hosting places prefer PHP.

    Separate PHP apps need separate web server processes, anyway.

    You only need one process per Python app. The thing with ASGI is it *can* handle multiple connections at once, you know.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Paul Rubin@no.email@nospam.invalid to comp.lang.python on Tue Aug 27 09:48:49 2024
    From Newsgroup: comp.lang.python

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:
    0.4d for an integer isn't valid in an f-string.
    I wonder why not?

    Alternatively I wonder why it is valid in traditional format. I might
    check the docs. I have never looked into this before.

    Separate PHP apps need separate web server processes, anyway.

    I had thought the opposite, but I'm not much of a PHP user.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From piergiorgio.sartor.this.should.not.be.used@piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de to comp.lang.python on Tue Aug 27 19:38:34 2024
    From Newsgroup: comp.lang.python

    On 25/08/2024 23.53, Lawrence D'Oliveiro wrote:
    Looking at this article about the top three languages for getting
    programming jobs <https://www.zdnet.com/article/want-a-programming-job-make-sure-you-learn-these-three-languages/>,
    naturally I couldn’t help noticing the code in the screenshot at the
    top (my transcription):

    bufferedNumber = str(doc.GetTime().GetFrame(docFps))
    if len(bufferedNumber)<4:
    for x in range(len(bufferedNumber),4):
    bufferedNumber = "0" + bufferedNumber

    I mean, really? Four lines to do what could be done in a single
    expression?

    Was that written by a PHP programmer, do you think?

    That the more correct question would be:
    What is easier to read? And to debug?
    The four line version or the one liner?

    To paraphrase someone:
    "If the length of a program would be
    measured by the time needed to understand
    it, some program would be too short to
    be short."

    Because the world is plenty of one liner
    nobody (almost) doesn't understand.

    There is even a category in the OCC
    (https://www.ioccc.org/).

    Don't get me wrong, I like and dislike
    one liner.
    Namely, I like mine and dislike the others :-)

    bye,
    --

    piergiorgio

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lawrence D'Oliveiro@ldo@nz.invalid to comp.lang.python on Tue Aug 27 23:40:15 2024
    From Newsgroup: comp.lang.python

    On Tue, 27 Aug 2024 09:48:49 -0700, Paul Rubin wrote:

    Separate PHP apps need separate web server processes, anyway.

    I had thought the opposite, but I'm not much of a PHP user.

    A PHP code page is written to respond to a single HTTP request and return
    a single response. So to handle multiple simultaneous requests, you need multiple instances of that code running. mod_php can’t do that within a single process (I don’t think), so you need a separate process for each simultaneous connection. (Of course Web servers have techniques for
    keeping and reusing those worker processes, to avoid doing fork(2) calls
    all the time.)

    With Python ASGI, you control what happens. A single process can handle multiple connections, if you so choose.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Paul Rubin@no.email@nospam.invalid to comp.lang.python on Tue Aug 27 23:01:33 2024
    From Newsgroup: comp.lang.python

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:
    With Python ASGI, you control what happens. A single process can
    handle multiple connections, if you so choose.

    Oh, I see what you mean. Yes you can write an ASGI server without multitasking, similar to node.js. Ugh. See:

    https://www.youtube.com/watch?v=bzkRVzciAZg

    NSFW warning: this video is very funny but contains lots of swearing.
    Better use headphones if you view it at the office.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lawrence D'Oliveiro@ldo@nz.invalid to comp.lang.python on Wed Aug 28 06:54:26 2024
    From Newsgroup: comp.lang.python

    On Tue, 27 Aug 2024 23:01:33 -0700, Paul Rubin wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    With Python ASGI, you control what happens. A single process can handle
    multiple connections, if you so choose.

    Oh, I see what you mean. Yes you can write an ASGI server without multitasking, similar to node.js. Ugh.

    Why “Ugh”? It avoids the overheads of multiple processes (where these are unnecessary), and the pitfalls of multiple threads.
    --- Synchronet 3.20a-Linux NewsLink 1.114