HNHacker News
TopNewBestAskShowJobs

saila

575 karma · joined February 20, 2019

submissionscomments
saila··on Visualizing 13M Bluesky users
I used to see a lot of furry accounts in the Discover feed, but I mute them when I see them, and now I rarely see them any more. I don't have anything against furries, but it's not content I'm interested in. This is more a comment that Bluesky does seem to have an algorithm (at least in the Discover feed) that is sensitive to what you do or don't show interest in. Or it could just be that a lot more people have joined recently, so the furry stuff just isn't as prevalent.
saila··on Local Variables as Accidental Breadcrumbs for Faster Debugging
I don't think Python is special in this regard. I have the same issue with .NET/C# stack traces.

With Python, you can run your program under pdb, which will automatically enter break on exceptions, and you can easily print locals.

https://docs.python.org/3/library/pdb.html

saila··on Show HN: Posting v1 – The modern HTTP client that lives in your terminal
This is awesome. Here are a couple bits of feedback:

- It took me a while to find the Metadata tab to edit a request's name, I guess because I don't think of the name and description as metadata (even if in a technical sense they are, relative to the request config). My inclination would be to make this the first tab and rename it to Info.

- I somehow managed to save two requests into the same file with no warning/confirmation from the UI.

- When using the up/down arrows to navigate between requests in a collection, I found it counterintuitive to have to hit Enter to actually select the request.

saila··on Show HN: BandMatch – “Tinder” but for finding musicians to create bands/collab
Considering how important style is in most genres, I think the swipe interface could be a good way to quickly find better potential matches, assuming there's a pre-filter based on your selected genres.

If I was looking to start a band today, I'd definitely give this kind of thing a try.

saila··on Should you use upper bound version constraints?
The general rule I use is that libraries should not specify upper bounds on dependencies but applications should.

I use Poetry for all my projects, but I agree that it exacerbates the issue somewhat with its default npm-style version syntax.

saila··on Tenets
I've recently started using Lighthouse to test sites for accessibility compliance, and you can easily get a score of 100 without actually addressing all the accessibility issues a site might have. So, if you're not conscientious, you can just point at the score and say "all good" while your site might still have major issues.

I assume the same is true of the other checks Lighthouse does for performance, best practices, etc.

Lighthouse and other such tools are a good starting point, and using them is better than doing nothing, but a thorough understanding of accessibility etc is necessary to create truly accessible and performant sites.

saila··on $20k bounty was claimed
I used to be one of those devs, thinking I had the most beautiful coding style.

When I embraced formatters, I started spending so much less time and effort keeping the style "correct" and worrying about how other people on the team format code. I love just hitting save in my editor and having the code formatted without having to fiddle with quotes, wrapping, etc.

With regard to bike-shedding about style, it mostly goes away once a team adopts one of the standard formatters for a given language. That's sort of the whole point.

saila··on Zoom Fatigue Is Real, According to Brain Scans
I'm typically looking at the top half of one person's head, the side of a few other people's, and probably up someone's nose. Any time there's eye contact, it's extremely bizarre/unsettling.

The idea that having cameras on will convey body language like in person conversations seems patently false, partly because of the above and partly because most people moderate their expressions to an extreme while on camera.

saila··on Nicotine (2016)
I was an occasional smoker for over a decade and only got addicted to nicotine when I started vaping. It's more anecdata, but I don't think vaping is any less addictive than smoking cigarettes, and for many people vaping will increase their likelihood of addiction just because it's easier to vape unnoticed and there's no natural stopping point like there is with cigarettes.

I've also temporarily quit nicotine and caffeine when I got sick, and I think part of the reason is that the withdrawal effects are less noticeable and/or maybe you attribute them to the illness. Also, if you get sick enough to take time off from work, that tends to coincide with the worst withdrawal effects, which last about three days in my experience.

saila··on Bringing garbage collected programming languages efficiently to WebAssembly
I was just looking at the status of IronPython, and it's on Python 3.4, which has been end-of-life for nearly five years. I'm not sure that indicates practical usability for most developers. Only C#, VB, and maybe F# actually seem like a safe choice on .NET. (PowerShell too, but that's a different use case.) So, just because something has been, or can be, done "in theory" doesn't mean all that much.

Unless you were intending this as a criticism of .NET?

I could see WASM actually pulling this off.

saila··on Choosing the Right Rust Web Framework: An Overview
I've been learning .NET recently and there are several choices for building a webapp, such as MVC, Razor pages, and Blazor (further split into server vs web assembly). MVC uses Razor views, Razor pages use Razor pages, and Blazor uses Razor components. MVC without the V is apparently the recommended way to create APIs.

I spent quite a bit of time trying to understand the distinction between these options and when you would choose one over the other, and I would have to disagree that it's a no-brainer choice. Perhaps if you've been in the .NET ecosystem for years and have followed the changes but definitely not if you're new to it.

saila··on Ask HN: Is anyone using PyPy for real work?
I use pyenv myself, but that is beside the point. The two examples above are using different strategies to install python3 versus pypy. A valid comparison would use a package manager for both or pyenv for both.
saila··on Ask HN: Is anyone using PyPy for real work?
For a more apples to apples comparison, you would install pypy using your package manager, e.g. apt install pypy3 or brew install pypy3. On Linux, you might have to add a package repo first.
saila··on Angular v16
I haven't used it, but there's at least one active Angular meta framework: https://analogjs.org
saila··on Neverssl Uses SSL
They support SSL because some browsers force https, but they then force a redirect to a non-SSL page. Seems reasonable. I think I may be missing the point of this being posted on HN. Does it cause issues in certain workflows or something?
saila··on Returning to Nim from Python and Rust
Coming from a mostly-Python background myself, I'm curious if you've looked into F# for this. It's succinct like Python, gives you type safety, and you can use .NET libraries.
saila··on Rewrite it in Rust
Your comment is quite unnecessarily vitriolic, but I do love the notion that it's possible to become cool by learning a new programming language.

Besides, all the common languages we use now, whether or old or new, have all gone through a phase like this. I bet people made similar commentary about C back in the day too.

saila··on Rewrite it in Rust
I don't think it's fair to say Rust is a "latest craze" language. Maybe five years ago, but not now. Numerous tools have been (re)written in it and supplanted old tools in at least some cases.

Additionally, there are reasons given in the linked issue. I guess you could debate about whether they're good reasons (they sound reasonable to me), but you can't say they're proposing it for no reason just because you don't like or agree with the reasons.

To that point, as someone who learned a decent amount of C and C++ a long time ago, I would probably never get involved in a C/C++ project nowadays, but I've been learning Rust these past few years and would definitely get involved in a Rust project if I had the chance.

And to be clear, I'm not bashing C/C++ at all. They're venerable and appreciated, but I have little to no interest in working with them, and it seems to me that this is a fairly common sentiment.

saila··on How to improve Python packaging
I use `pip install --user pipx` to install pipx, but I think a better option when using homebrew would be `brew install pipx`. With the latter, doing a `brew upgrade` should keep python and pipx in step.

EDIT: Thinking about this some more, doing `brew install pipx` would keep pipx from breaking on brew upgrades, but I guess your installed scripts would still fail if you upgrade from Python 3.N to 3.N+1.

So the only solution, I think, is to keep around all the versions of Python you use, assuming you don't want to upgrade all your scripts when upgrading Python.

I use pyenv to manage Python versions rather than Homebrew, and this seems to avoid the issues you're having, because the Python version used to install whichever tool via pipx sticks around until I explicitly uninstall it.

saila··on How to improve Python packaging
If you don't mind adding a pyproject.toml, you could use pipx[1] to install these scripts. The directory structure would look like this:

    <name>/
        pyproject.toml
        <name>.py
The pyproject.toml would look like this (using poetry, but you could use a different tool for this):

    [tool.poetry]
    # NOTE: Set <name> to your project name
    name = "<name>"
    description = "My Script"
    version = "0.0.0"
    authors = ["Me <me@example.com>"]

    [tool.poetry.dependencies]
    python = "^3.11"
    requests = "^2.28.2"

    [tool.poetry.scripts]
    # NOTE: Change <name> to match your package name in [tool.poetry]
    <name> = "<name>:main"

    [build-system]
    requires = ["poetry-core"]
    build-backend = "poetry.core.masonry.api"
Then you'd run `pipx install -e .` and the the executable script will be installed in ~/.local/bin.

[1] https://pypa.github.io/pipx/

saila··on Underappreciated challenges with Python packaging
I don't think there's a consensus, but there are some good modern options. I think poetry is a good choice, and it seems to be fairly popular. I use it for all my Python projects and haven't found a compelling reason to switch to another option in the past few years.

As to the question of whether you should ever use pip to install packages globally, the answer is almost always no. For command line tools, the best option IMO is pipx. The second best option is pip install --user.

If you're developing a library or application, you should always isolate it in a virtualenv, which is something poetry will handle for you when you run `poetry install`.

saila··on Python 2 removed from Debian
You can do something similar in Python:

    utf8_bytes: bytes = bytes(input_string, encoding="utf-8")
    
    # Perform the conversion from one encoding to the other.
    unicode_string: str = str(utf8_bytes, encoding="utf-8")
    ascii_bytes: bytes = bytes(unicode_string, encoding="ascii")
    
    # The conversion could also be written as:
    ascii_bytes: bytes = utf8_bytes.decode("utf-8").encode("ascii")
    
    output_string: str = str(ascii_bytes, encoding="ascii")
The biggest difference is that the conversion step requires you to explicitly decode the bytes to a unicode string and then encode the unicode string back to bytes rather than providing a convert() method that does this internally.

Perhaps a convenience method would be nice, something like this, but it somewhat obscures the intermediate decode-to-unicode step:

    ascii_bytes: bytes = utf8_bytes.convert(to_encoding="ascii")
saila··on Python 2 removed from Debian
It's not that complicated nor is it a Python specific issue. This is a good article on the topic:

https://www.joelonsoftware.com/2003/10/08/the-absolute-minim...

A simplistic summary is that you always decode to unicode and always encode to bytes.

Another way to think about it is that Unicode is an idealized character model that is reified into a byte encoding, usually UTF-8, for practical usage.

It seems to me that this is something a lot of developers don't think too much about until they run into some obscure encoding/decoding issue, but it's kind of a fundamental aspect of programming that's worth spending some time grokking.

saila··on Understanding the N + 1 queries problem
You can do the same kind of thing in Django. The approach is a little different, but it's the same basic idea.

https://docs.djangoproject.com/en/4.1/topics/db/managers/#cu...

saila··on Understanding the N + 1 queries problem
Using a typical set of Post & Comment models, where Comment has a foreign key to Post, I couldn't figure out how to do this with just a single query in Django. Using prefetch_related, the 2-query version is pretty straightforward:

    from django.db.models import Count, Prefetch
    from myproject.models import Post, Comment

    # This will fetch the 3 posts first and then the comments for those posts
    query = Post.objects.prefetch_related(
        Prefetch("comments", queryset=Comment.objects.annotate(Count("votes")))
    )
    posts = query[:3]
How would you reduce this to one query using the Django ORM?
saila··on Understanding the N + 1 queries problem
You could probably get this down to two queries, one for posts and one for comments, if you aggregate the vote count when retrieving the comments. I think this is pretty easy to do with most ORMs.

You could also get it down to 1 query using SQL. This is one way to do it based on the schema in the article [postgres, not well tested]:

    with
      latest_posts as (
        select * from post limit 3
      ),
      latest_comments as (
        select
          c.*, count(v.id) as votes
        from
          comment c
        left join
          vote v on v.comment_id = c.id
        where
          c.post_id in (select id from latest_posts)
        group by
          c.id, c.content
      )
    select
      p.*, json_agg(c)
    from
      latest_posts p
    left join
      latest_comments c on c.post_id = p.id
    group by
      p.id, p.title, p.content

    # NOTE: fixed SQL bug noted by @rurabe
Off the top of my head, I'm not sure how you would (or if you could) do this with ActiveRecord, SQLAlchemy, or the Django ORM, but it's probably more complicated than just writing the SQL.

To be clear, I'm not anti-ORM and use them all the time, but it really helps to understand SQL well when using them and to know when it's appropriate to switch to SQL.

saila··on Why I'm still using Python
You can delete references to any object in Python, including functions:

    >>> def f(): None
    ...
    >>> del f
but it's pointless to try to manually manage memory in Python in most cases. If you're processing huge amounts of data, there are probably better approaches than using `del` and/or `gc.collect()` to keep memory usage down (like batching and/or using subprocesses).

My other comment in this thread is relevant too: https://news.ycombinator.com/item?id=34197904

saila··on Why I'm still using Python
Why do your anonymous functions have to live far from where they're used? What's the non-aesthetic difference between this:

    def func(g_func, a, b):
        g_func(a, b)

    def scope():
        c = "c"
        def anon(a, b):
            print(a, b, c)
        print(id(anon))
        return func(anon, "a", "b")
and this:

    def func(g_func, a, b):
        g_func(a, b)

    def scope():
        # NOTE: The `|a, b|: (...)` syntax is made up
        c = "c"
        return func(
            |a, b|: (
                print(a, b, c)
            ),
            "a", "b"
        )
?

Note that the `anon` function in `scope` is only compiled once. You can verify this by copying the first version to a file named `temp.py` and then running `python -m dis temp.py`. You can also run `scope()` twice in a row and see that the same object ID is printed both times.

That said, for purely aesthetic reasons, I would like it if Python had some kind of syntax like version 2, but that's tricky with significant whitespace, and I've never found the lack of such syntax to be particularly limiting in Python.

saila··on Ask HN: What are household items that can be repaired but people often replace?
I've been using the same rechargeable Wahl clippers for about a decade and only shave with a razor on rare occasions because the clippers get close enough for most situations.

It's also possible to repair them to some extent. I've taken the body apart to clean it out, and it seems like it'd be easy enough to replace the battery.

saila··on Go and SQLite in the Cloud
Not saying SQLite wasn't the issue here (impossible to tell based on the information provided), but I've seen a lot of webapps with highly inefficient queries because developers either didn't understand what the ORM was doing or didn't bother to optimize. In a Django app, prefetch_related can make a huge difference (or joinedload when using SQLAlchemy or better initial filtering when using raw SQL).
← PreviousPage 2 of 9Next →