4 ms·
More like "ruby optimizes for short strings, and chose 23 at the cut-off point for Reasons."
by danielweber 13y ago
More like "ruby optimizes for short strings, and chose 23 at the cut-off point for Reasons."
- pothibo 13y agoMore to the point, ruby always uses string with more than 23 character. It's strings that are passed to the client and an HTML page is almost always bigger than 23 characters.
- Xylakant 13y agoRuby is a general purpose scripting language that can be used for web development (rails, sinatra) but is often used for different purposes (puppet, chef, vagrant, shoes, ...). And even if you'd assume web development as the only purpose, there's a lot of strings that are shorter than 23 characters: Header for request and responses, form fields passed by the client (usernames, passwords, ...), field names passed in hashes, table and column names, template and file names, URLs or even the occasional, totally rare string in a json structure. It's an optimization with major gain and little loss.
- pothibo 13y agoActually, my comment needs to be understood as an answer to the OP's title "Never create Ruby strings longer than 23 characters". I understand that there's many places where strings are shorter than 23 characters and I never meant to say that this optimization was superfluous. I actually think it's pretty clever.
- yapcguy 13y agoCan't wait for someone to write a new faster better string class which handles strings of any length by internally chopping them into 23 character portions....
- fat0wl 13y agolol yes....... how reasonable. ahah when i saw the title of the article all i could think was "click comments to tune in for the most amusing flamewar this week" but so many of these comments are like "so... its 23 characters.... why not?!" comeon peopleeeee, a bit of an arbitrary internal standard, no? i understand the point about "CONCLUSION: it doesn't matter for a few strings!" but.... comeonnnn it must matter on some level, otherwise why is Rails such a pain in the ass to optimize? these things must add up...
- EpicEng 13y agoWhat non-arbitrary "small string" length would you chose? Btw, the fact that you don't understand it doesn't make it arbitrary. Hint: it's not arbitrary at all.
- fat0wl 13y agoseriously... this? #define RSTRING_EMBED_LEN_MAX ((int)((sizeof(VALUE)*3)/sizeof(char)-1)) explain "3" in terms of your comp sci 101 divine computer law... Ok I get itttt "len/ptr/capa/shared". I've never written an interpreter so I can't rewrite the implementation myself, but I've worked with Rails enough to know that Ruby's is terribly inefficient, and these are problems created in it's abstraction from C, not inherent to C. Maybe this RString case is a minor issue, but it seems to me to lack some rigorousness, to be a performance leak. It's one of those things that makes you wonder "What Would Linus Do?". Although I do understand the points about including it AT ALL to be "free gain, little loss" and the language can't be C, but sometimes I don't know.... Just admit that maybe something is wrong here. Please. you'll be the first Rubyist ever, the dawn of a golden era. I've been intrigued more and more by the Lisp community because many of those devs seem to have a philosophical unwillingness to compromise performance and proper engineering, whereas in Ruby people get mad at you for not embracing the compromises!! Geez. Hint: writing "Hint:" and then saying something really obvious that you learned from the article we all just read makes you sound craaaaaazy obnoxious (Incidentally, it's issues like this that make me thank my lucky stars I do my web work on the JVM now.)
- 13y ago
- vidarh 13y agoI hope that is meant as a joke.