Better HN
topnewbestaskshowjobs
Log inSign up

travisd

821 karma · joined Nov 12, 2020 (6y ago) · 141 submissions

Submissions

comment 2w ago · link · parent

I think it'll bite some people, but probably is the better default for JSON specifically. Most of the nil-maps-become-null thing is just an extension of Go defaulting to nil for empty arrays and maps, which is usually not what you expect when you're writing a JSON schema like

    type ListUsersResponse struct {
        Users []User `json:"users"`
    }
in Go. It's pretty common have code like

    userRows := db.Query(...)
    var users []api.User
    for _, user := range userRows {
        users = append(users, api.User{...})
    }
where you don't _really_ intend for the default nil-ness to leak out. (Apologies for any broken syntax, I'm realizing in real time that it's been a while since I've written Go)

comment 3w ago · link · parent

Yeah, this is basically what we do. It ends up a bit more ergonomic to not have explicit result types because union types are pretty easy in Python. For example, we have functions like

    # courses.py
    def create(...) -> Course | ErrInvalid:
and they get used like

    match courses.create(...):
        case courses.Course() as course:
            # We use `course` below.
            pass
        case courses.ErrInvalid() as err:
            # Error conditions are usually translated into early returns
            raise fastapi.HTTPException(
                status.HTTP_422_UNPROCESSABLE_ENTITY, err.message
            )
    
    return APICourseCreateResponse(id=course.id, ...)
It has worked (for us at least) pretty well to reduce the number of unhandled errors that make their way into Sentry. The granularity of the error types depends on the need (e.g., sometimes we just have an `ErrInvalid` that returns a message which gets displayed to the user, but sometimes we'll have ErrInvalidAddress or ErrInvalidTaxCode to be more specific for the context).

And yeah, without nodiscard, we try™ to only do this on functions that return values that the caller will definitely need to use. Also combined with exhaustiveness checks on switch statements by default.

comment 3w ago · link · parent

it’s maybe less “pythonic” but at $dayjob we’ve very actively moved away from exceptions for things in favor of things that are statically type checked. too many things that become runtime bugs instead of type checking bugs.

with match now being available, we even return explicit error objects and the ergonomics are pretty good (reminds me of rust).

comment 2mo ago · link · parent

The AI generated images are classic slop to the point of being actively distracting.

5.

Judge orders Kalshi cease Washington operations (starting August 20)(atg.wa.gov ↗)

9 points · by travisd · 3mo ago · 1 comment

comment 9mo ago · link · parent

I found two separate bugs in GCP products. One with gVisor where it would sometimes null-truncate large network packets (this was very hard to diagnose – why is my JSON full of null bytes?) and one where Cloud Run broke sudo sporadically (sudo in a FaaS is definitely niche, I had essentially containerized a very old application written by undergraduates).

Both times they were serious production bugs that took at least a week to resolve, though I only had the lowest tier of support package.

comment 10mo ago · link · parent

At $DAYJOBSTARTUP, we do hackathons twice a year. At the most recent one, an engineer sat down with a designer and set him up with Cursor. The designer looked like a kind in a candy shop, he was so excited to be able to rapidly prototype with natural language and not be clicking in Figma for hours.

A month later, he comes back to the engineering team with a 10k line "index.html" file asking "How do I hand this off?" (he was definitely smart enough to know that just passing that file to us was not gonna fly). We decided to copy the designs into Figma for the handoff, both because that was the existing way we did design/engineering handoffs and also because creating high fidelity designs (e.g., "this color from our design system" and "this standard spacing value") isn't in Cursor's wheelhouse.

We're probably going to spend more time working on a better setup for him. At the very least he should be working against our codebase and components and colors and design tokens. But I'm very curious to see where it goes from here.

comment 10mo ago · link · parent

packets udp bar walk a into

comment 10mo ago · link · parent

Many of these package managers get invoked countless times per day (e.g., in CI to prepare an environment and run tests, while spinning up new dev/AI agent environments, etc).

comment 1y ago · link · parent

Starbucks is airport drink/food for me. Being able to order as I enter the TSA line and pick it up on the way to the gate is unmatched convenience, and the coffee options at airports generally aren't great.

comment 1y ago · link · parent

Of course! It helped your friend realize what kind of person you are and hopefully spurred them to find better friends who possess actual human empathy.

comment 2y ago · link · parent

Making an HTTP request and dealing with JSON data is a weed-out question at best. Not sure if you are interpreting the grandparent comment as actually having them write a JSON parser, but I don't think that's what they meant.

comment 2y ago · link · parent

I don’t want to disparage your work, OP, but micro-optimizing text files is often not very effective, especially after gzip. I’m curious to see if there’s any noticeable difference for a representative gzipped CSS file (since these assets are almost always served from a CDN with compression).

comment 2y ago · link · parent

Thanks! I hate it!

comment 2y ago · link · parent

I highly highly highly recommend the book “Two Wheels Good: The History and Mystery of the Bicycle.” It explores the origin, the various social implications across various cultures (it often became a symbol of perversion due to its association with women’s liberation), and even the modern day e-bike movement. 12/10 book, very well written too.

comment 2y ago · link · parent

Based on the article, it sounds like this doesn't activate a device's microphone at all. If it did, most (all?) browsers would give a pop-up requesting permission for that.

comment 3y ago · link · parent

Pardon the pedantry, but this reflects the casual/conversational uses of “hash function” not the more general definition. To be a hash function, it just has to map a set to another set of fix sized values (usually some finite set of the natural numbers).

Returning unrelated (distant) hashes for similar inputs is a possible property of a hash function, and oftentimes a desirable one (especially for cryptography), but there are in fact use cases where one wants similar inputs to map to similar (or the same) hash. https://en.m.wikipedia.org/wiki/Locality-sensitive_hashing

comment 3y ago · link · parent

It's worth noting that it's much less of a problem in Python due to the lack of ergonomic closures/lambdas. You have to construct rather esoteric looking code for it to be a problem.

    add_n = []
    for n in range(10):
        add_n.append(lambda x: x + n)
    add_n[9](10)  # 19
    add_n[0](10)  # 19
This isn't to say it's *not* a footgun (and it has bit me in Python before), but it's much worse in Go due to the idiomatic use of goroutines in a loop:

    for i := 0; i < 10; i++ {
        go func() { fmt.Printf("num: %d\n", i) }()
    }

comment 3y ago · link · parent

Curious to know -- how do these kinds of things affect accessibility for visually impaired people? If you're using a screenreader, do these kinds of things work?

comment 3y ago · link · parent

Yep, I think those things are all related.

comment 3y ago · link · parent

Go generally is pretty conservative about that kind of thing (namely, compiler optimizations). Go generally abides by a “what you write is what you get” kind of thing, especially when it comes to “non-local” optimizations. It’s generally opposed to anything that’s “clever.” (Just my feeling as someone who uses Go pretty often and who respects the choice they’ve made on that spectrum).

comment 3y ago · link · parent

I suspect this is a bad-faith argument, but just to be clear, NPR get's a tiny fraction of its funding from the government *and* maintains editorial independence.

> The news organization says that is inaccurate and misleading, given that NPR is a private, nonprofit company with editorial independence. It receives less than 1 percent of its $300 million annual budget from the federally funded Corporation for Public Broadcasting.

comment 3y ago · link · parent

We’re not talking about why Seattle is far from Miami. American city sprawl is largely a recent phenomenon (post WWII) and was enabled by the rise of the personal automobile. Even the sprawl-iest of cities (Houston, TX) used to be respectably dense and walkable. The need for a car to achieve basic needs (groceries, school, work) is a phenomenon well less than 100 years old. America has this problem in part because it’s much younger than a lot of European cities, but it’s certainly not purely a function of topography.

comment 3y ago · link · parent

Parent comment is concerned with privacy, not authenticity. They're not worried that someone modified their code, they're worried that someone saw it.

comment 3y ago · link · parent

The author just spends the final paragraphs… guessing?

> TypeScript… JavaScript… Going to guess it's similar.

> I haven't touched Java for almost a decade

> I don't really know enough Rust to be able to comment with any confidence

comment 3y ago · link · parent

Oil is a decently interesting “competitor” in this space. They’ve also acknowledged the dual nature of shell as REPL and programming language.

https://www.oilshell.org/blog/2021/01/why-a-new-shell.html

27.

Don't Deploy Applications with Terraform(medium.com ↗)

4 points · by travisd · 3y ago · discuss

28.

Stacked PRs: code changes as narrative(aviator.co ↗)

3 points · by travisd · 3y ago · discuss

comment 3y ago · link · parent

Since the author is responding to comments here: are there any changes coming soon that necessitated this?

comment 4y ago · link · parent

Lot of people confused here -- the "running JavaScript when the browser is idle" part is a bit misleading.

It doesn't run stuff when you're the tab is backgrounded (browsers already heavily reduce what sites can do when not in focus[1]). Instead, it just lets you delay work until the page isn't doing anything else (such as rendering the page). For example, you might do this when updating a visualization on a page so that the other updates can complete first (e.g., update the input UI and redraw the visualization when that's done).

[1] https://blog.chromium.org/2020/11/tab-throttling-and-more-pe...

12345