<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 1% Problems</title>
	<atom:link href="http://cafe.elharo.com/programming/1-problems/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/programming/1-problems/</link>
	<description>Longer than a blog; shorter than a book</description>
	<lastBuildDate>Wed, 19 Jun 2013 14:00:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Martin Valjavec</title>
		<link>http://cafe.elharo.com/programming/1-problems/comment-page-1/#comment-1382080</link>
		<dc:creator>Martin Valjavec</dc:creator>
		<pubDate>Tue, 29 Jan 2013 16:19:30 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=871#comment-1382080</guid>
		<description><![CDATA[Why is getBytes(Charsets.UTF-8) better than getBytes()? In my experience the real problem is that the developer often does not know what&#039;s correct: it often is not even defined what should be correct. In that case getBytes() - the system default, whatever it is at execution time - might be the correct enconding to be used and UTF-8 might be wrong ... or maybe not. Who defines this? Perhaps not the programmer. And who defines how to find out who defines this? In some organizations: nobody.

So this is not a &quot;programmer&#039;s only&quot; problem.]]></description>
		<content:encoded><![CDATA[<p>Why is getBytes(Charsets.UTF-8) better than getBytes()? In my experience the real problem is that the developer often does not know what&#8217;s correct: it often is not even defined what should be correct. In that case getBytes() &#8211; the system default, whatever it is at execution time &#8211; might be the correct enconding to be used and UTF-8 might be wrong &#8230; or maybe not. Who defines this? Perhaps not the programmer. And who defines how to find out who defines this? In some organizations: nobody.</p>
<p>So this is not a &#8220;programmer&#8217;s only&#8221; problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Cowan</title>
		<link>http://cafe.elharo.com/programming/1-problems/comment-page-1/#comment-1109440</link>
		<dc:creator>John Cowan</dc:creator>
		<pubDate>Sat, 11 Aug 2012 19:18:43 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=871#comment-1109440</guid>
		<description><![CDATA[Explicit column sizes are a database smell.  I don&#039;t know of a single RDBMS that stores fixed-length strings differently from variable-length strings, so the only effect of declaring a fixed-length string as a table column is that you will sooner or later get into trouble.  Just say VARCHAR(65535) or whatever the upper limit of your database is, and save yourself a world of annoyance.]]></description>
		<content:encoded><![CDATA[<p>Explicit column sizes are a database smell.  I don&#8217;t know of a single RDBMS that stores fixed-length strings differently from variable-length strings, so the only effect of declaring a fixed-length string as a table column is that you will sooner or later get into trouble.  Just say VARCHAR(65535) or whatever the upper limit of your database is, and save yourself a world of annoyance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Werner Slosse</title>
		<link>http://cafe.elharo.com/programming/1-problems/comment-page-1/#comment-1102331</link>
		<dc:creator>Werner Slosse</dc:creator>
		<pubDate>Fri, 03 Aug 2012 10:48:08 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=871#comment-1102331</guid>
		<description><![CDATA[Developing client-server applications, whether RMI, CORBA, SOAP, etc is used, and/or uploading/downloading files in between client and server, I encounter the getBytes() and new String(byte[]) problem regularly.  When not specifying the character set encoding (and not specified/overridden in JRE or cmd-line settings or args), the JRE takes the default system encoding.  The default on a (Western-European) WinXP is windows-1252, on Unix/Linux it often is ISO-8859-1 (to name two, not in a particular order).  Having files even worsens the case, as reading/writing files in text mode (Reader/Writer) has the same &quot;problem&quot;: the default encoding.

Java String is Unicode, for sure.  But, whenever converting from bytes to text (and vice versa), it&#039;s a good idea to know what the encoding should be, and to apply it.  A simple test: write a file on WinXP (or Vista/7) in Notepad, save it, and open in IE (or another browser).  In the browser one can often explicitly change the encoding, and check what text is shown.  Do you actually know what your default OS encoding is?  &quot;Latin 1&quot; is not the same on all systems, ISO-8859-1 is not the same as windows-1252, note the differences in the C1 range (codepoints 0x80 to 0x9F).

Besides the byte/text problem, there&#039;s an additional layer: the font.  Even if the bytes/text/encoding are correct, it may not show correctly on screen, because the font used by the (G)UI does not know the [glyph for the] character.  On the other side of the spectrum, there may be a database.  And sure enough, a database engine/database/table/column has a character set encoding. E.g. running with a default windows-1252, storing a Czech character into a database may not be possible.  When UTF-8 is used as encoding on the DB, the column size may not suffice (some databases will interpret a varchar 16 as 16 bytes, not 16 characters; so if you want to store 16 non-US-ASCII chars in a varchar column, size should be around 3..4 times 16).

All of the above result in myself often requesting Wireshark logs instead of application logs or UI screenshots.  I want to see the raw bytes of the data in between client and server.  If the bytes are correct, the data is correct (e.g. payload in a CORBA message or an XML message).  If there&#039;s still a problem, it&#039;s in the interpretation of those bytes.

Indeed, in that 1% where there&#039;s an error in that area, it&#039;s difficult to track down.  Assuming an ID (input text) is US-ASCII, and all of a sudden an ID contains &#252;, causing trouble in the client or server application.]]></description>
		<content:encoded><![CDATA[<p>Developing client-server applications, whether RMI, CORBA, SOAP, etc is used, and/or uploading/downloading files in between client and server, I encounter the getBytes() and new String(byte[]) problem regularly.  When not specifying the character set encoding (and not specified/overridden in JRE or cmd-line settings or args), the JRE takes the default system encoding.  The default on a (Western-European) WinXP is windows-1252, on Unix/Linux it often is ISO-8859-1 (to name two, not in a particular order).  Having files even worsens the case, as reading/writing files in text mode (Reader/Writer) has the same &#8220;problem&#8221;: the default encoding.</p>
<p>Java String is Unicode, for sure.  But, whenever converting from bytes to text (and vice versa), it&#8217;s a good idea to know what the encoding should be, and to apply it.  A simple test: write a file on WinXP (or Vista/7) in Notepad, save it, and open in IE (or another browser).  In the browser one can often explicitly change the encoding, and check what text is shown.  Do you actually know what your default OS encoding is?  &#8220;Latin 1&#8243; is not the same on all systems, ISO-8859-1 is not the same as windows-1252, note the differences in the C1 range (codepoints 0&#215;80 to 0x9F).</p>
<p>Besides the byte/text problem, there&#8217;s an additional layer: the font.  Even if the bytes/text/encoding are correct, it may not show correctly on screen, because the font used by the (G)UI does not know the [glyph for the] character.  On the other side of the spectrum, there may be a database.  And sure enough, a database engine/database/table/column has a character set encoding. E.g. running with a default windows-1252, storing a Czech character into a database may not be possible.  When UTF-8 is used as encoding on the DB, the column size may not suffice (some databases will interpret a varchar 16 as 16 bytes, not 16 characters; so if you want to store 16 non-US-ASCII chars in a varchar column, size should be around 3..4 times 16).</p>
<p>All of the above result in myself often requesting Wireshark logs instead of application logs or UI screenshots.  I want to see the raw bytes of the data in between client and server.  If the bytes are correct, the data is correct (e.g. payload in a CORBA message or an XML message).  If there&#8217;s still a problem, it&#8217;s in the interpretation of those bytes.</p>
<p>Indeed, in that 1% where there&#8217;s an error in that area, it&#8217;s difficult to track down.  Assuming an ID (input text) is US-ASCII, and all of a sudden an ID contains &uuml;, causing trouble in the client or server application.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sony Mathew</title>
		<link>http://cafe.elharo.com/programming/1-problems/comment-page-1/#comment-1093917</link>
		<dc:creator>Sony Mathew</dc:creator>
		<pubDate>Thu, 26 Jul 2012 17:19:04 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=871#comment-1093917</guid>
		<description><![CDATA[Perhaps you could elaborate on why Calendar and Date are error prone? Also why UTF-8 must be specified? Doesn&#039;t Java maintain all Strings as UTF-16?]]></description>
		<content:encoded><![CDATA[<p>Perhaps you could elaborate on why Calendar and Date are error prone? Also why UTF-8 must be specified? Doesn&#8217;t Java maintain all Strings as UTF-16?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Hahn</title>
		<link>http://cafe.elharo.com/programming/1-problems/comment-page-1/#comment-1090049</link>
		<dc:creator>Robert Hahn</dc:creator>
		<pubDate>Mon, 23 Jul 2012 00:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=871#comment-1090049</guid>
		<description><![CDATA[Good points. 

But it looks to me like so many of these problems can and should be automated away. GetBytes() should default to utf-8 encoding. Strings should be automatically be escaped, doing extra work if you DON&#039;T want them escaped. The conventions of yesterday should not be the conventions of today.]]></description>
		<content:encoded><![CDATA[<p>Good points. </p>
<p>But it looks to me like so many of these problems can and should be automated away. GetBytes() should default to utf-8 encoding. Strings should be automatically be escaped, doing extra work if you DON&#8217;T want them escaped. The conventions of yesterday should not be the conventions of today.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Cowan</title>
		<link>http://cafe.elharo.com/programming/1-problems/comment-page-1/#comment-1089969</link>
		<dc:creator>John Cowan</dc:creator>
		<pubDate>Sun, 22 Jul 2012 20:30:27 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=871#comment-1089969</guid>
		<description><![CDATA[I entirely agree, but my experience is that bugs like this always fall to the bottom of triage lists, since existing tests aren&#039;t catching them and they produce no obvious bad behavior.  So even though it would take only a brief time to get them fixed, they never have the priority.]]></description>
		<content:encoded><![CDATA[<p>I entirely agree, but my experience is that bugs like this always fall to the bottom of triage lists, since existing tests aren&#8217;t catching them and they produce no obvious bad behavior.  So even though it would take only a brief time to get them fixed, they never have the priority.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
