Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
User IDs probably shouldn't be passed around as ints (rachelbythebay.com)
8 points by behnamoh on May 28, 2024 | hide | past | favorite | 3 comments


My thoughts on this: only the database cares that an ID is an integer. Outside systems typically don't mind IDs as strings, so why not use strings? It's not like we're doing math on IDs


ints as user ids are fine, a language with tons of footguns isn't


The two common ways of dealing with this: 1. use a distinct type if your language supports it--ideally it could be zero-cost abstraction (such as in Go), 2. any int or boolean argument should be a keyword one so errors are clearly visible:

  ban_account(user_id: i);




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: