821 karma · joined Nov 12, 2020 (6y ago) · 141 submissions
comment 2w ago · link · parent
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
# 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
with match now being available, we even return explicit error objects and the ergonomics are pretty good (reminds me of rust).
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
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
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 2y ago · link · parent
comment 2y ago · link · parent
comment 3y ago · link · parent
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
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
comment 3y ago · link · parent
> 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
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 4y ago · link · parent
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...