Re:The Absolute Minimum Every Software Developer Must Know A...
by galad87 on Monday October 02, 2023 @09:41AM
(#37737963)
Swift string type has got many different views, like UTF-8, UTF-16, Unicode Scalar, etc… so if you want to count the bytes or cut over a specific byte you still can.
[ Parent
| on HN ]
Re:The Absolute Minimum Every Software Developer Must Know A...
by dathinab on Monday October 02, 2023 @09:48AM
(#37738056)
that's not the issue
defaults matter
as in they should things you can just use by-default without thinking about it
as swift is deeply rooted in UI design having a default of glyphs make sense
and as rust is deeply rooted in unix server and system programming utf-8 bytes make a lot of sense
through the moment your language becomes more general purpose you could argue having a default in any way is wrong and it should have multiple more explicit methods.
Re:The Absolute Minimum Every Software Developer Must Know A...
by toast0 on Monday October 02, 2023 @11:24AM
(#37739341)
> as in they should things you can just use by-default without thinking about it
That time has passed. If you want to know the length of a string, you really should indicate what length type you mean.
Re:The Absolute Minimum Every Software Developer Must Know A...
by hot_gril on Monday October 02, 2023 @11:42AM
(#37739585)
There was no string.length in Swift for a while. Then they added one that just does what the user expects, get the number of grapheme clusters. If a user figures out that this isn't what they want, they can go use the other length method.
Re:The Absolute Minimum Every Software Developer Must Know A...
by dathinab on Wednesday October 04, 2023 @09:09AM
(#37764540)
except if it's server swift code, then it doesn't do what the user expects at all
Re:The Absolute Minimum Every Software Developer Must Know A...
by hot_gril on Wednesday October 04, 2023 @02:32PM
(#37769576)
The most common reason I can think of a server wanting the string length is because it's enforcing a character limit in some field, in which case it does what the user expects. You aren't often manually managing memory in Swift. On top of that, Swift on server is probably rare to begin with.