News for hackers. Stuff that matters.
Re:Why I'm still using Python by snowpid on Sunday January 01, 2023 @06:52AM (#34205605)
why?
Re:Why I'm still using Python by pharmakom on Sunday January 01, 2023 @12:28PM (#34208442)
In F# list comprehensions, for example, you can have full blown expressions such as loops and conditionals. This is really nice for templating.

    [
      if List.isEmpty items then
        p “No items”
      else
        ul
          [
             for item in items do
               li [ item ]
          ]
    ]
Re:Why I'm still using Python by snowpid on Monday January 02, 2023 @06:41AM (#34216883)
so?

if len(items) == 0: return [p("no items")] else: ul( [ li(item) for item in items ] )

I am also not a fan of convoluted list comprehension (in python) so powerful is not necessarly a good thing.

Re:Why I'm still using Python by pharmakom on Monday January 02, 2023 @08:09AM (#34217474)
That only works in a single purpose function.

And consider this example:

    [
      h1 “items”

      if List.isEmpty items then
        p “No items”
      else
        ul
          [
             for item in items do
               li [ item ]
          ]
    ]
Re:Why I'm still using Python by snowpid on Monday January 02, 2023 @09:33AM (#34218246)
h1(items) + rest of my code... I might see what are you using for but I am not sure if concenating implicitly (or with line breaks / spaces) is a good design decision for a language.
Re:Why I'm still using Python by pharmakom on Monday January 02, 2023 @09:55AM (#34218489)
The yield keyword is optional. The result is a List<HtmlElement>

I don’t see how this can be done in Python without using mutation, which makes code scattered across multiple statements

Re:Why I'm still using Python by snowpid on Monday January 02, 2023 @11:26AM (#34219726)
your example has also multiply statements. The question is more important: Which syntax to a more generally better readability. (as this is solvable in most languages)
Re:Why I'm still using Python by pharmakom on Monday January 02, 2023 @11:52AM (#34220133)
No, it is built from pure expressions. This means that our list is defined in one block (everything within the [ ] tokens) and immutability is enforced by the compiler.