Live data from Hacker News

The best – but not good – way to limit string length

adam-p.ca

41–48 of 48 posts

Re: The best – but not good – way to limit string length

#41
post #29

Best advice I've heard is to never use the character type in your programming language. Instead, store characters in strings. An array of strings can be used as a string of characters. In this approach, characters become opaque blobs of bytes. This makes it easy to get the two numbers you care about: length in characters and size in bytes. There is some overhead for this, so maybe a technique more suited to backends.…

> length in characters and size in bytes you change the word you use as if those words have inherent meanings that we can draw upon. they don't. it would be more clear to write "length in characters and length in bytes" [linguistically speaking, words don't carry meanings, it is us who ascribe meaning to words. we use words to say what we want to say, but words don't limit us in what we can say]

You are correct. It's just that I am loquacious by nature and often use a plethora of words when a paucity would better and more succinctly convey meaning precisely.

My bad!

Re: The best – but not good – way to limit string length

#42

This is why my website is going to be ASCII only.

Nah, you gotta go at least one further back and use EBCDIC. Or go all the way to a BCD and you get to save more bits (only need 6) and can avoid dealing with case-sensitivity as well (only uppercase latin letters)!

Re: The best – but not good – way to limit string length

#43
post #40
post #14

This doesn't seem to cover truncation, but rather acceptance/rejection. If you are given something with "too many" codepoints, but need to use it anyways it seems like it would make sense to truncate it on a grapheme cluster boundary.

I added a section with brief discussion of rejection, truncation, and the perils therein. https://adam-p.ca/blog/2025/04/string-length/#what-to-do-whe...

Thanks!

Re: The best – but not good – way to limit string length

#44
post #28

Earlier quoted context omitted.

Which is a reasonable and clean solution - I love simplicity of ASCII like every programmer does. Except ASCII is not enough to represent my language, or even my name. Unicode is complex, but I'm glad it's here. I'm old enough to remember the absolute nightmare that was multi-language support before Unicode and now the problem of encodings is... almost solved.

> ASCII is not enough to represent my language, or even my name. Hebrew and Arabic don't include vowels. While you think that writing your language needs vowels, we can tell from the existence of Hebrew and Arabic that you are probably wrong. It would take some getting used to, but just like that "scramble the letters in the middle of words, you can still read": https://www.sciencealert.com/word-jumble-meme-first-las…

No, you can't.

Robię Ci łaskę vs robię ci laskę is a very big difference.

Re: The best – but not good – way to limit string length

#45
post #28

Earlier quoted context omitted.

> ASCII is not enough to represent my language, or even my name. Hebrew and Arabic don't include vowels. While you think that writing your language needs vowels, we can tell from the existence of Hebrew and Arabic that you are probably wrong. It would take some getting used to, but just like that "scramble the letters in the middle of words, you can still read": https://www.sciencealert.com/word-jumble-meme-first-las…

No, you can't. Robię Ci łaskę vs robię ci laskę is a very big difference.

you let your fingers hit the keyboard before thinking at all.

in english, we have laws that sanction the selling of street drugs, and other laws that sanction funding for women's sports. in the first case, sanction means "forbid", and in the second case it means "encourage". although these usages are opposite in meaning, the words are used on a daily basis and nobody gets confused because context is everything.

Robię Ci łaskę could mean "badass" and robię ci laskę could mean "bad ass": if you read "robie ci laske" in ASCII (hey, i'm thinking that rhymes) nobody (except you) would be confused by that, it's not how functioning brains work.

i provided enough evidence in my original comment that you should have been able to realize that i was already talking about the issue you are pointing out so to rebut what i suggest you need to account for what i said and not argue against a strawman's tabula rasa

Re: The best – but not good – way to limit string length

#46
post #28

Earlier quoted context omitted.

> ASCII is not enough to represent my language, or even my name. Hebrew and Arabic don't include vowels. While you think that writing your language needs vowels, we can tell from the existence of Hebrew and Arabic that you are probably wrong. It would take some getting used to, but just like that "scramble the letters in the middle of words, you can still read": https://www.sciencealert.com/word-jumble-meme-first-las…

It's hilarious that the guy telling people to go back to ASCII is the one saying "stop clinging to the past".

whoosh

Re: The best – but not good – way to limit string length

#47
post #28

Earlier quoted context omitted.

Which is a reasonable and clean solution - I love simplicity of ASCII like every programmer does. Except ASCII is not enough to represent my language, or even my name. Unicode is complex, but I'm glad it's here. I'm old enough to remember the absolute nightmare that was multi-language support before Unicode and now the problem of encodings is... almost solved.

> ASCII is not enough to represent my language, or even my name. Hebrew and Arabic don't include vowels. While you think that writing your language needs vowels, we can tell from the existence of Hebrew and Arabic that you are probably wrong. It would take some getting used to, but just like that "scramble the letters in the middle of words, you can still read": https://www.sciencealert.com/word-jumble-meme-first-las…

What would be neat is an ASCII or byte-encoding that simplified foreign language into ascii encoding on the data side to being basically ascii than recording it for display, only supporting a subset, unfortunately but eliminating all these edge cases and moving them away from the logic and database layers.

Re: The best – but not good – way to limit string length

#48
post #31
post #28

Earlier quoted context omitted.

> ASCII is not enough to represent my language, or even my name. Hebrew and Arabic don't include vowels. While you think that writing your language needs vowels, we can tell from the existence of Hebrew and Arabic that you are probably wrong. It would take some getting used to, but just like that "scramble the letters in the middle of words, you can still read": https://www.sciencealert.com/word-jumble-meme-first-las…

Once again, I request that 95% of the world's population change the way it does almost everything, so that I can simplify my code. Thank you for writing this comment; it's cleared up some self-esteem issues I've been having about whether I'm clever enough to start my own company.

pot. kettle. unicode itself was the 95% change request, and this particular discussion is sparked by anguish about that change and people such as yourself who want to discuss their anguish about the change.

and you simply ignored the points that I went to the trouble to write down, and rather than considering them or thinking about them, you just started screaming "status quo status quo"

Post reply on HN