7 ms·
String types are fine. How about your code?
- lmm 13y agoThe conclusion doesn't really match the title. > If there is any takeaway from this entire discussion, it may be that there is a need for multiple string types in strongly-typed languages Yes, yes there is. Until we get that, string types are not fine.
- skrebbel 13y agoGood point! It is my opinion, however, that string types are fine, just not perfect. I should have maybe made that clearer.
- zokier 13y agoYeah, I was bit confused when your conclusions seem to match the original "strings are broken" posts conclusions. The whole problem is that current string types enable broken unsafe behavior on Unicode ("human only" in your parlance) strings. Current string types are broken because they do not enforce the requirement that string operations are done only on plain ASCII ("machine only") strings.
- ipedrazas 13y agowhat if I have to create strings with non ASCII chars? Calling ASCII "machine only" is totally wrong. I agree that encoding/decoding is a pain, but we have different string encodings for a reason.
- quarterto 13y agoIf you got this far, you’ll probably want to hire me as a consultant. Nope.
- skrebbel 13y agoDamn. I'll live, I guess. Thanks for reading till the end anyway!
- ragebol 13y agoPlease consider replacing "may want" with "please consider" or nothing at all. Don't know if you want that...
- tommo123 13y agoI say leave it. Don't reduce your chance of getting paid work just because some smug clown on the internet wanted to score a psuedo-zinger by yelling at his television screen. If anything, change 'probably' to 'might'. Confidence is good, but some people could take 'probably' as an imputation on their ability to comprehend the subject matter. I'd always aim at "That was just the beginning. Whip out your chequebook and then you'll REALLY see what I have to offer" rather than "You sound like you're in trouble."
- skrebbel 13y agoHah :-) Thanks for the support, but if I make an arrogant remark, I have to expect to get snarky responses, right :-) The line was supposed to be taken as a joke, in reference to people signing off their blog posts with "If you read this far, you should probably follow me on Twitter" and the likes. Thanks for your feedback though! I hadn't thought about how people could interpret it as a slight insult to their understanding of the subject matter, so next time I make an arrogant joke I'll try and take stuff like that into account.
- zamalek 13y agoFinally someone who at least touches on one of my massive pet peeves: something I call suck typing (string-duck typing). Have a DateTime? ToString it. Have XML? IndexOf (this one really gets to me). Got some binary data? Base64 it, store in XML (use IndexOf and Substring to access it) and then put that XML in a binary field in the database. I am a strong advocate that suck typing should be a fireable offence. While I think unicode support in languages could be better; there is a lot of truth in this article that surrounds his subject core.
- zokier 13y agoI bet you would love Tcl.
- chrismorgan 13y agoOr NSIS, which I've worked in a lot—the string is the only type. Integer operations will parse it as a number, perform the operation and turn it back into a decimal once more for storage in the string.
- groovy2shoes 13y agoTcl originally did the same thing. Semantically it still does, but values in the Tcl interpreter were changed to a string/union pair so that conversions can be cached.
- arethuza 13y agoYou've seen code that uses basic string manipulation (IndexOf, Substring) to get values from XML? That's nice - although I guess it probably seems natural to those who insist on creating XML by string concatenation...
- this_user 13y agoI have seen people store XML as VARCHAR in a database and send that very same raw XML string as a payload over a SOAP web service. That company also had their own GUI framework that consisted of generating XML by string concatenation and then doing XSLT transformations. I suppose that is what happens when you have team leaders, managers and a chief software architect who have little understanding of technology and its proper use.
- RyanZAG 13y agoMisses the point, I think? There are plenty of times you must alter human text. For example, a word processor with a find/replace function must be able to replace the correct text and not move extra symbols around while doing so. There are thousands of similar examples.
- rbehrends 13y agoYes, but functionality that is about dealing with text for human consumption is properly the function of a library, not the core language, or even a single type in the standard library. Human language and culture is too complex, fuzzy, and variable to hardwire its rules into a programming language specification. Character boundaries and character transformations are really only the beginning of it. Consider finding the end of an English word. Is an apostrophe at the end an actual apostrophe denoting the possessive case (of a plural word) or meant as a closing single quote (even where there are different symbols, they are often mixed up when doing data entry)? How do you pluralize words? You have to consider exceptions to the usual rules (e.g., a dictionary), words that only exist in the plural, languages that don't have the concept of plural words, etc.
- informatimago 13y agoNonetheless, that's what Wolfram is trying to do with his "programming" language. At least it's at the same level. Provide human level rules and knowledge embodied in a computer programming language.
- nabla9 13y agoThe author argues that when string processing becomes complicated, it does not matter and incorrect results are usually OK. Everybody knows about Bobby Tables? How about Mr. เจ้าพระยาบดินทรเดชา Unicode? What if somebody told you that if certain exotic names are entered into the system by certain input method, government officials can't find those people in their searches, including full text search to a police report?
- bcoates 13y ago
- randallsquared 13y ago> Similarly, why would you ever need to take a substring of someone’s name In my experience, you need to do this any time you're displaying someone's name, a place name, an article title, or whatever. Often the display area just isn't that wide, and shifting around other content may not be an option. You need to display enough to let people know what's there, but eventually it needs to be cut off.
- stefan_kendall 13y agoYou need a designer if you ever plan to internationalize. What you're doing won't work - you'll make nonsense phrases.
- burstmode 13y agoGreat, so now that he explained to us how to use strings for human readable text, the last missing bit is a blogpost telling the author how to choose the colors for letters & background. What's the sense in optimizing string usage when half of the audience can't read the lightgray text on slightly-lighter-gray background ?
- agos 13y agoThe colors pass all the accessibility checks on foreground vs. background I've found. Maybe your monitor is a bit off
- skrebbel 13y agoHey, thanks for the feedback. I just picked a random Wordpress.com theme to get started fast (I started blogging 3 days ago). I'll do more effort to pick (or even gasp make) a better theme!
- bjourne 13y agoTalk about throwing out the baby with the bathwater.. The original article was wrong because it proposed replacing strings with arrays of code points. Clearly, that doesn't work. This article is wrong because adding more string types just shuffles the problem around. There is nothing "machine consumable" about strings encoded in a certain anglo-centric character encoding! Just don't even think that thought. "abc" is absolutely not more "machine consumable" than "東京". You don't "hash prose" by transliterating text into ascii characters. It's not impossible to fix the existing string types. Principle of least surprise holds. In cases when it doesn't, the locale is the tie-breaker. E.g. "Scheiße".upper(locale.DE) may be different from "Scheiße".upper(locale.RU).
- lmm 13y agoPlease tell me how to correctly implement search (ideally in scala), such that "Lodz" will match "Łódź". Heck, making "noël" match "noël" is nontrivial. I don't think existing string types are adequate for this (e.g. java.lang.String.equals() gives exceedingly surprising results).
- sp332 13y agoWhy would the strings match? Aren't they completely different? (What language are we talking about, anyway?)
- lmm 13y ago> Why would the strings match? Aren't they completely different? In some theoretical sense, yes. In terms of solving users' problems and providing business value, I need to make it possible for users to find the entry for "Łódź" without typing accents. > (What language are we talking about, anyway?) We're talking about Scala; it runs on the JVM and so java.lang.String is the string type.
- sp332 13y agoOh, so you're coding around your users' inability to type the letters they actually want? That sounds basically impossible... you'd have to pick letters according to how similar they look instead of their meaning in any context. And, I meant human language! :)
- brudgers 13y agoThe problems arise not from strings, they are well understood computationally, and most languages provide sound functions for working with them. The problems arise when strings are held responsible for the side effects of other functions which manipulate the data within strings. In particular, problems arise when some function renders a sequence of characters contained in a string [fundamental string operations such as concatenation tend not to be problematic]. These problems are due to the transition from the mathematical certainty of strings to the heuristics of text rendering. The compromises required to map semantics of human writing systems onto strings via Unicode contributes to this problem...glyphs are not necessarily ordered sequentially or without resolution under a context.
- tambourine_man 13y agoI disagree with the premise of the article. Text is for humans only. If you are connecting computers with no human interaction, binary is much more efficient.
- tel 13y agoHaskell does this somewhat nicely by shunning the built-in String type and having ByteString and Text types. All there (and others) can be created using string literals, though that can be dangerous, but Text is a UTF-16 encoded, ICU-backed human-text monster type which handles upcasing ligatures and even more complex collation send the sort (which is, btw, how you solve the phone book issue, and it's just one C library away). ByteString is a series if bytes that just may happen to be ok to print as human text for debugging. The system makes it hard for you to treat it otherwise by moving the "Char8-assuming" functions to different modules and packages which must be explicitly imported and carry warnings. You convert between them using functions in the Text.Encoding module which may fail like "decodeUtf8'" and "encodeLatin1". There's also a slew of normalizing functions. I really encourage anyone interested in this problem to peruse the Text and Text.ICU documentation. http://hackage.haskell.org/package/text http://hackage.haskell.org/package/text http://hackage.haskell.org/package/text-0.11.3.1/docs/Data-Text-Encoding.html http://hackage.haskell.org/package/text-0.11.3.1/docs/Data-T... http://hackage.haskell.org/package/text-icu http://hackage.haskell.org/package/text-icu http://hackage.haskell.org/package/text-icu-0.6.3.7/docs/Data-Text-ICU-Normalize.html http://hackage.haskell.org/package/text-icu-0.6.3.7/docs/Dat... http://hackage.haskell.org/package/text-icu-0.6.3.7/docs/Data-Text-ICU-Collate.html http://hackage.haskell.org/package/text-icu-0.6.3.7/docs/Dat...
- jonpeda 13y agoTraining programmers to ignore a builtin type, and set up hacks to make string literals use a different type, is hardly "nice".
- deleted 13y ago[deleted]
- aufreak3 13y agoThe post makes a good point about the distinction between two types of text - symbols and human text. Sadly, this is made very complex in our world through the introduction of the markup (and markdown) languages which mix text targeting both machines and humans. As long as you're having to work with embedded structuring or formatting codes, woe betide you. You'll have to deal with script injection, sql injection and what not.