4 ms·
Finally 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?
by zamalek 13y ago
Finally 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.
- arethuza 13y agoLet me guess - the XML was sent over a SOAP web service that looked pretty much like: string DoStuff(string arg) Where the service call takes a string that actually contains XML and returns a string that actually contains XML.... My own "Worst use of XML" was someone wanting to use quite complex XML documents as a key in a database....
- mbennett 13y agoXML is like violence, if it doesn't work, use more.
- mbq 13y agoImagine that there is a performance bottleneck there and substring is, like 500x faster than engaging a proper XML parser; what would you do? Obviously it is likely an effect of a global design flaw, but such things are very hard to fix.
- zamalek 13y agoFind a different XML parser or adopt a different way of reading the XML (DOM vs. SAX; or just a different library that performs better). I see where you are coming from though. The problem with XML is that it is used to solve problems that it shouldn't be solving - it's a great technology when used correctly (XMPP is a great example of how XML can make other transfer formats look like a dress rehearsal). In most cases, as you said, "global design flaw" - a good indicator that you are abusing XML is if you are not using xmlns attributes and if you do not have multiple namespace (because in that case JSON is simpler, faster and makes more sense).
- lmm 13y agoWhat's the advantage of XMPP? I find the one time when I don't hate xml is when it doesn't have namespaces or schemata, as then it's just a slightly more verbose JSON.
- zamalek 13y agoNot much is that special in terms of the XEPs (extension protocols) that they have defined. When you innovate with it though, man you really see the power of correct XML. You can slap custom elements pretty much anywhere you want, as long as you have your own namespace (and it's recommended you only place them under <message> or <iq> elements). Say you have some proprietary technology in a client application, with XMPP you can throw an element under the <message> that your client can recognise and act on. For everyone else provide a hyperlink within the <body> element and serve up a web page for them. If they are using your client "bam!" instant added functionality - but if they are on device X which you do not support they are not left out in the cold.
- mpweiher 13y ago
- chrismorgan 13y agoString typing, or stringly typed interfaces (parody of strong typing) is a phrase in common use. HTTP is a good example of something normally using string typing; most web servers treat headers, for example, as text, rather than as data, and so you end up with a lot of invalid stuff because of misunderstandings about what the values actually are or how they should be interpreted or written. That's a trap that I'm dodging in rust-http; in there, (known) headers are data, serialised to text only for transmission, not text. (I'll freely admit, however, that this is an approach I would never take in Python; I'm confident it would lead to more errors than the alternative.)
- coolsunglasses 13y agoHave you looked at how Happstack leverages the type system?
- pdpi 13y agoI adopted the naming I once saw someone use for this, which is "stringly typed code".