<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Databases and Life</title>
	<atom:link href="http://www.databasesandlife.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.databasesandlife.com</link>
	<description>Adrian Smith's blog</description>
	<lastBuildDate>Thu, 26 Apr 2012 13:28:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Underscores in numbers</title>
		<link>http://www.databasesandlife.com/underscores-in-numbers/</link>
		<comments>http://www.databasesandlife.com/underscores-in-numbers/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 13:28:13 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.databasesandlife.com/?p=948</guid>
		<description><![CDATA[One feature I miss from my Perl days, which I&#8217;ve never seen in another language*. I am writing a test loop and I want it to run 10k times. So I write, in Java: for (int i = 0; i &#60; 10000; i++) { ... } Nothing surprising about that. But in Perl I could [...]]]></description>
			<content:encoded><![CDATA[<p>One feature I miss from my Perl days, which I&#8217;ve never seen in another language*. I am writing a test loop and I want it to run 10k times. So I write, in Java:</p>
<pre>
for (int i = 0; i &lt; 10000; i++) { ... }
</pre>
<p>Nothing surprising about that. But in Perl I could write:</p>
<pre>
for (my $i = 0; $i &lt; 10_000; $i++) { ... }
</pre>
<p>You can put underscores anywhere when writing number literals, and they will get ignored by Perl. So you can make such large numbers a lot more readable.</p>
<p>It isn&#8217;t a huge feature, it could easily be implemented by other languages such as Java, only&#8230;.. it isn&#8217;t. The fact that it would be easy to implement only adds to the existing annoyance created by the lack of the feature itself.</p>
<p>However I only have one criticism of this feature and that&#8217;s that you can put the underscores <em>anywhere</em>. Therefore it&#8217;s possible to write 10_0000 which looks a lot like 10k. I think I would limit the use of underscores only to every 3 digits. Otherwise the feature (increased readability) would have exactly the opposite effect.</p>
<p><em>* I&#8217;m sure it exists though, don&#8217;t cuss me up for this statement, I&#8217;ve only programmed C, C++, Perl, PHP, Java, Objective-C, Javascript for longer periods of time!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.databasesandlife.com/underscores-in-numbers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>IDE reverse auto-complete</title>
		<link>http://www.databasesandlife.com/ide-reverse-auto-complete/</link>
		<comments>http://www.databasesandlife.com/ide-reverse-auto-complete/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 16:03:55 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.databasesandlife.com/?p=940</guid>
		<description><![CDATA[It just occurred to me that the following might be possible, and not only is it possible, Eclipse already does it. Normally IDE auto-complete works forwards, i.e. you declare your variables, and then when you come to use them, they are suggested. But it can/does also work the other way around. You use a variable [...]]]></description>
			<content:encoded><![CDATA[<p>It just occurred to me that the following might be possible, and not only is it possible, Eclipse already does it.</p>
<p>Normally IDE auto-complete <strong>works forwards</strong>, i.e. you declare your variables, and then when you come to use them, they are suggested.</p>
<p>But it <strong>can/does also work the other way around</strong>. You use a variable which is undefined, then place your cursor above the usage and start to declare it, and it fills in name of the variable you want to define for you.</p>
<p><center><img src="http://www.databasesandlife.com/blog-attachments/20120408-auto-complete.png" alt="" width="250" height="160" /></center></p>
]]></content:encoded>
			<wfw:commentRss>http://www.databasesandlife.com/ide-reverse-auto-complete/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;childs&#8221; is not a word</title>
		<link>http://www.databasesandlife.com/childs/</link>
		<comments>http://www.databasesandlife.com/childs/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 10:12:38 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Broken]]></category>

		<guid isPermaLink="false">http://www.databasesandlife.com/?p=921</guid>
		<description><![CDATA[I&#8217;ve seen this quite a few times, and I feel it&#8217;s worth mentioning, as it perhaps isn&#8217;t obvious. The plural of the word child is children and not childs. org.apache.wicket.MarkupContainer (add method)]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen this quite a few times, and I feel it&#8217;s worth mentioning, as it perhaps isn&#8217;t obvious. The plural of the word <strong>child</strong> is <strong>children</strong> and <em>not</em> <strong>childs</strong>.</p>
<p><a href="http://wicket.apache.org/apidocs/1.4/org/apache/wicket/MarkupContainer.html#add%28org.apache.wicket.Component...%29">org.apache.wicket.MarkupContainer (add method)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.databasesandlife.com/childs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wicket auto-complete text fields</title>
		<link>http://www.databasesandlife.com/wicket-auto-complete-auto-suggest-text-fields/</link>
		<comments>http://www.databasesandlife.com/wicket-auto-complete-auto-suggest-text-fields/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 16:50:35 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.databasesandlife.com/?p=894</guid>
		<description><![CDATA[It&#8217;s modern practice in web applications to augment text fields with suggestions while one types. There are plenty of Javascript libraries out there to do that, and plenty of integrations with the Java web framework Wicket out there as well, but somehow none quite did exactly what I wanted, so I&#8217;ve rolled my own Wicket code (based [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s modern practice in web applications to augment text fields with suggestions while one types. There are plenty of Javascript libraries out there to do that, and plenty of integrations with the Java web framework <a href="http://wicket.apache.org/" target="_blank">Wicket</a> out there as well, but somehow none quite did exactly what I wanted, so I&#8217;ve rolled my own Wicket code (based on JQuery). And here they are.</p>
<p>What I wanted, but what other Wicket / Javascript libraries did not do, were:</p>
<ul>
<li>I wanted to allow the user to type <strong>multiple values</strong>. If you compose a message in Gmail, you want to be able to enter multiple recipients, not just one.</li>
<li>I wanted to have the option to either allow the user to type in <strong>options which were not presented</strong> (e.g. like when composing a message in Gmail, or typing in tags into Stack Overflow) or <strong>restrict</strong> them to the options presented (like recipients in Facebook)</li>
<li>I wanted to either allow the <strong>options to be included in the HTML</strong> page (e.g. for a set of 10 options, there is no point forcing the user to wait for a server round-trip to fetch matching options), or allow the options to be <strong>fetched from the server</strong> (e.g. if there are 1M options, they can&#8217;t be included in the HTML page).</li>
<li>I wanted the <strong>API to be incredibly simple</strong>. I want to include a single <code>&lt;input&gt;</code> into the Wicket HTML document, create the object in Java using a constructor, and attach the data source (client-side or server-side) in a single line.</li>
</ul>
<p>Surprisingly all of the above are not particularly easy to achieve simultaneously. But they are now done:</p>
<ul class="tight">
<li><a href="http://www.databasesandlife.com/blog-attachments/databasesandlife-util-javadoc/com/databasesandlife/util/wicket/MultipleValueAutoSuggestTextField.html"><code>MultipleValueAutoSuggestTextField</code></a> (auto-suggest = can also type in other values)</li>
<li><a href="http://www.databasesandlife.com/blog-attachments/databasesandlife-util-javadoc/com/databasesandlife/util/wicket/MultipleValueAutoCompleteTextField.html"><code>MultipleValueAutoCompleteTextField</code></a> (auto-complete = only those values allowed)</li>
</ul>
<p>And coupled with my newly created extensive multi-lingual location hierarchy database (hierarchy in the sense of 2nd district -&gt; Vienna -&gt; Austria -&gt; Europe -&gt; World, multi-lingual in the sense I have these displayable strings in various languages), allows me to create a MultipleValueLocationTextField subclass, which can be included in a host HTML page in one line of HTML and one line of Java, and which synchronizes its data with a <code>Location[]</code> in the client code (e.g. straight from/to a domain object), and it looks like this:</p>
<p><img src="http://www.databasesandlife.com/blog-attachments/20110830-wicket-auto-complete-drop-down.png" alt="" width="474" height="131" /></p>
<p>The source for the two Wicket fields linked to above is LGPL. <a href="http://www.databasesandlife.com/blog-attachments/databasesandlife-java-util.zip">Download Databases &amp; Life Util ZIP</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databasesandlife.com/wicket-auto-complete-auto-suggest-text-fields/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Converting an SVG to a PDF programmatically</title>
		<link>http://www.databasesandlife.com/svg-to-pdf/</link>
		<comments>http://www.databasesandlife.com/svg-to-pdf/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 13:08:47 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.databasesandlife.com/?p=869</guid>
		<description><![CDATA[Searching for this topic on the web led to various libraries, all of which were no doubt very powerful, all of which were extremely large and difficult to use if one didn&#8217;t know how. Plenty of advice existed on the internet, &#8220;use library X&#8221;, but when the library has hundreds of thousands of lines that [...]]]></description>
			<content:encoded><![CDATA[<p>Searching for this topic on the web led to various libraries, all of which were no doubt very powerful, all of which were extremely large and difficult to use if one didn&#8217;t know how. Plenty of advice existed on the internet, &#8220;use library X&#8221;, but when the library has hundreds of thousands of lines that isn&#8217;t really enough information. I didn&#8217;t even mind in which programming language the solution was to be written.</p>
<p>After hours of searching, reading Javadocs, reading source, and experimenting, I finally came up with the following lines of Java code.</p>
<p>Alas, this method can only convert from a SVG <em>file</em> to a PDF<em> file</em>, i.e. these have to be files existing on the disk, they cannot be URLs, in memory, cannot be streamed, and the SVG cannot be an in-memory DOM object. My SVG is dynamic: I&#8217;m altering/creating it at runtime (after all, if I wasn&#8217;t doing that, I could just save the PDF somewhere statically in the first place and wouldn&#8217;t need to do the conversion). And I want to deliver the PDF to the browser so streaming would be good for me. But no matter, I use <a href="http://download.oracle.com/javase/6/docs/api/java/io/File.html#createTempFile%28java.lang.String,%20java.lang.String%29">File.createTemporaryFile</a> together with <a href="http://download.oracle.com/javase/6/docs/api/java/io/File.html#deleteOnExit()">deleteOnExit</a> to create these files, and just ignore the fact that if the JVM exits abnormally, e.g. the computer suffers from a power failure, these files will never get deleted, and, over a long enough time-span, will fill up the disk until the computer fails.</p>
<p>Here are the lines:</p>
<pre>import org.apache.batik.apps.rasterizer.DestinationType;
import org.apache.batik.apps.rasterizer.SVGConverter;
import ...

<strong>// SVG is created programatically as a DOM Document </strong>
Document svgXmlDoc = ...

<strong>// Save this SVG into a file </strong>
File svgFile = File.createTempFile("graphic-", ".svg");
svgFile.deleteOnExit();
TransformerFactory tFac = TransformerFactory.newInstance();
Transformer transformer = tFac.newTransformer();
DOMSource source2 = new DOMSource(svgXmlDoc);
FileOutputStream fOut = new FileOutputStream(svgFile);
try { transformer.transform(source2, new StreamResult(fOut)); }
finally { fOut.close(); }

<strong>// Convert the SVG into PDF </strong>
File outputFile = File.createTempFile("result-", ".pdf");
outputFile.deleteOnExit();
SVGConverter converter = new SVGConverter();
converter.setDestinationType(DestinationType.PDF);
converter.setSources(new String[] { svgFile.toString() });
converter.setDst(outputFile);
converter.execute();</pre>
<p>And I have the following JARs (search using Google to find the projects and download them):</p>
<ul class="tight">
<li>avalon-framework-4.2.0.jar</li>
<li>batik-all-1.7.jar</li>
<li>commons-io-1.3.1.jar</li>
<li>commons-logging-1.0.4.jar</li>
<li>fop-0.95.jar</li>
<li>log4j-1.2.15.jar</li>
<li>xml-apis-ext.jar</li>
<li>xmlgraphics-commons-1.3.1.jar</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.databasesandlife.com/svg-to-pdf/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How many days until the end of the month?</title>
		<link>http://www.databasesandlife.com/how-many-days-until-the-end-of-the-month/</link>
		<comments>http://www.databasesandlife.com/how-many-days-until-the-end-of-the-month/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 10:40:27 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Software Design]]></category>

		<guid isPermaLink="false">http://www.databasesandlife.com/?p=863</guid>
		<description><![CDATA[It&#8217;s a common enough problem, you want to find out if a date is in a particular month, or you want to know how many days there are left in the current month, and so on. I&#8217;ve seen the following awkward solution plenty of times at different companies: To find out if a day is [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a common enough problem, you want to find out if a date is in a particular month, or you want to know how many days there are left in the current month, and so on.</p>
<p>I&#8217;ve seen the following awkward solution plenty of times at different companies: To find out if a day is within a month, you see if the date in question is greater than the start of the month and less than the end of the month; this seems logical enough. To determine the number of days left, you subtract the date in question from the last date in the month; this also seems reasonable enough.</p>
<p>The trouble is it&#8217;s not particularly easy to find out the last date in a given month. I&#8217;ve seen at least the following solutions:</p>
<ul class="tight">
<li>Using database functions to find the last day of the month</li>
<li>Having an array of 12 elements, maintaining the number of days in each month of the year</li>
<li>Simply using the date &#8220;YYYY-MM-31&#8243;.</li>
</ul>
<p>Using database functions is the best, for sure, as they&#8217;ll do the calculations right, but it&#8217;s still a certain amount of work to connect to the database just for this purpose. Obviously there are libraries such as Java&#8217;s Calendar which will do the same work but again, it&#8217;s a certain amount of effort. The array isn&#8217;t good as you have to introduce further logic to handle leap years. The last approach is obviously ridiculous as there are plenty of months for which such a date is invalid. (But MySQL 4 allows such dates and MySQL 5 doesn&#8217;t; which as part of a database migration project has brought this point to my attention.)</p>
<p>However, there is a much simpler solution, that is to compare the date with the <strong>first day of the next month</strong>. Finding the next month is easy (there are always 12 months in the year).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databasesandlife.com/how-many-days-until-the-end-of-the-month/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>curtime</title>
		<link>http://www.databasesandlife.com/curtime/</link>
		<comments>http://www.databasesandlife.com/curtime/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 15:22:04 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Broken]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.databasesandlife.com/?p=845</guid>
		<description><![CDATA[The MySQL function curtime has (at least) the following issues: The function returns the current time as a number i.e. the time quarter past 8 would be returned from the function as the number 201500. (So if you subtract one from such a number you get 201499 which has no meaning.) The function only returns this [...]]]></description>
			<content:encoded><![CDATA[<p>The MySQL function <a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_curtime">curtime</a> has (at least) the following issues:</p>
<ol>
<li><strong>The function returns the current time as a number</strong> i.e. the time quarter past 8 would be returned from the function as the number 201500. (So if you subtract one from such a number you get 201499 which has no meaning.)</li>
<li><strong>The function only returns this</strong> if you use it in an &#8220;integer context&#8221;, i.e. (x+0) causes x to be evaluated to an integer. (Otherwise it produces a string in a different format.)</li>
<li><strong>At some point the function was changed</strong> not to return an integer but to return a decimal with 6 decimal places. As far as I can tell these 6 decimal places are always zero. The example in the documentation also supports this experience.</li>
<li><strong>There is no way to specify a timezone</strong>. When going from a point in time (e.g. unix time or simply the concept of &#8220;now&#8221;) to/from an external format (hours, minutes, year, &#8230;) you must <em>always specify a timezone</em>. The concept of the &#8220;default timezone&#8221; should just be eradicated and deleted from the world. If I had a time-machine, the first thing I would do is go back and prevent this concept&#8217;s creation. (The user must see the data in their timezone, which on a web application needn&#8217;t be the same as the server&#8217;s. And if you are writing a desktop application, you need to decide explicitly to use the user&#8217;s timezone, as not all data might be for the user, e.g. data from a server or database.)</li>
<li><strong>I don&#8217;t really think the name of the function is very good</strong> (saving characters by abbreviating the name, but why?)</li>
</ol>
<p>Why would you ever use a function? Why would you ever add it to your database product. <em>*Shakes Head*</em></p>
<p>I welcome feedback of the form &#8220;this is an amazing function, I&#8217;ve used it my application and it fitted my need exactly&#8221;. I do really welcome this. Please don&#8217;t hold back.</p>
<p>Related: <a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_curdate">curdate</a>, <a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_now">now</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databasesandlife.com/curtime/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PC fire</title>
		<link>http://www.databasesandlife.com/pc-fire/</link>
		<comments>http://www.databasesandlife.com/pc-fire/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 17:56:01 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.databasesandlife.com/?p=834</guid>
		<description><![CDATA[Last night, I was listening to music, about to go to bed, totally relaxed, and then suddenly smelt that something was burning. I ignored it as I thought it was probably coming from outside. About 30 seconds later the smell was so strong I realized it must be in the room. In panic I just [...]]]></description>
			<content:encoded><![CDATA[<p>Last night, I was listening to music, about to go to bed, totally relaxed, and then suddenly smelt that something was burning. I ignored it as I thought it was probably coming from outside. About 30 seconds later the smell was so strong I realized it must be in the room. In panic I just pulled out all electrical equipment such as the PC etc. (no time to &#8220;shut down&#8221;). The situation seemed to get worse still. I looked up at the light and there was a reasonable amount of smoke in the room.</p>
<p>This whole situation happened within about 60 seconds I think &#8211; from peacefully listening to music, to me having yanked all the power cables out and the room containing a bunch of smoke.</p>
<p>The smoke started to slowly dissipate after I&#8217;d turned everything off. That was good, I still had no idea where it was coming from. After about 30 minutes there was no smoke any more, and confident (or hopeful) that the problem had been solved (at least for the short term) I went to bed, putting off dealing with the actual problem until I was fit again the next day.</p>
<p>My two suspects were either the PC or the light fitment in the room. The light looked OK. I inspected the PC in the light of the day and it also looked fine. No burn marks or anything. I mean for such a lot of smoke, there would need to be physical burn marks, wouldn&#8217;t you think. So I turned the PC on, and about 10 seconds later there was visible smoke, not as much as the night before but still. And the smell of burnt plastic was back. So at least I knew what the source of the problem was.</p>
<p>A bit more inspection (and turning it on a few more times just briefly) led me to see that while the PC was on, thick gray smoke was just pouring out of the PC&#8217;s power supply.</p>
<p>I mean it&#8217;s not the end of the world, PCs can be replaced, nothing bad happened! But I just think of the number of times I&#8217;ve left that PC on and gone to work, or gone to the kitchen, .. it was just as well that happened while I was sitting in front of it!</p>
<p>Here&#8217;s a picture of what the room looked like after the PC being on for about 10 seconds this morning &#8211; the PC wasn&#8217;t even on long enough for the Windows logo to come up yet.</p>
<p><center><br />
<img src="/blog-attachments/20110606-pc-fire.jpg" width=482 height=298><br />
</center></p>
<p>Ah and there&#8217;s another point I should mention. I&#8217;m on some medication for sleeping and depression (not strong medication!) which I have to take an hour before going to bed. I&#8217;d taken that and the hour had passed so I was just about to switch the PC off and go to bed when the incident happened. A slight side-effect I&#8217;ve noticed is that I have increased levels of anxiety. It&#8217;s not bad, but it&#8217;s there.</p>
<p>And believe me, when an unknown source of smoke and burning suddenly appears in your room, having taken medication which increases anxiety is not in any way what you need.</p>
<p>And further, sleeping medication reduces your coordination and concentration etc. This is fine if you want to go to bed (as had been my plan) but is not so ideal if the situation suddenly changes from going to bed into potentially putting out a fire, &#8230; as I was moving from one place to another in the room to try and determine the source of the smoke, I kept on not being able to walk straight and nearly falling over&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databasesandlife.com/pc-fire/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The method invocation operator, and expressions, in PHP</title>
		<link>http://www.databasesandlife.com/the-method-invocation-operator-and-expressions-in-php/</link>
		<comments>http://www.databasesandlife.com/the-method-invocation-operator-and-expressions-in-php/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 14:01:48 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Broken]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.databasesandlife.com/?p=826</guid>
		<description><![CDATA[PHP is a weird language. $x = new Foo(); print $x-&#62;bar(); works fine as you&#8217;d expect. but print new Foo()-&#62;bar(); print (new Foo())-&#62;bar(); all do not work. I do not understand how you can build an expression parser, where the code above works, and the code below does not. It&#8217;s almost as if &#8220;$x = [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is a weird language.</p>
<pre>
$x = new Foo();
print $x-&gt;bar();
</pre>
<p>works fine as you&#8217;d expect. but</p>
<pre>
print new Foo()-&gt;bar();
print (new Foo())-&gt;bar();
</pre>
<p>all do not work.</p>
<p>I do not understand how you can build an expression parser, where the code above works, and the code below does not. It&#8217;s almost as if &#8220;$x = new XXX(xxx)&#8221; a separate case searched for by the parser?</p>
<p>I mean if you have an expression parser capable of handling brackets, i.e. (1+2)*4, and you have the expression (new Foo()) and you have the concept of $object->method() then how can it possibly not work?</p>
<pre>
$ <strong>cat -n x.php</strong>
     1  &lt;?php
     2
     3  class Foo {
     4     function bar() { return 4; }
     5  }
     6
     7  $foo = new Foo();
     8  print $foo-&gt;bar();
     9
    10  print (new Foo())-&gt;bar();

$ <strong>php -e x.php</strong>
Parse error: syntax error, unexpected T_OBJECT_OPERATOR
in /home/adrian/x.php on line 10
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.databasesandlife.com/the-method-invocation-operator-and-expressions-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quotes in CSV Files</title>
		<link>http://www.databasesandlife.com/quotes-in-csv-files/</link>
		<comments>http://www.databasesandlife.com/quotes-in-csv-files/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 16:48:24 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Broken]]></category>

		<guid isPermaLink="false">http://www.databasesandlife.com/?p=814</guid>
		<description><![CDATA[Quotes in CSV files are a classic case of a solution to a problem, which in fact does nothing to solve the problem, but which does increase complexity. The problem: If you have a row of data like foo,bar and you wish to include commas in one data element, you can&#8217;t, as the recipient system [...]]]></description>
			<content:encoded><![CDATA[<p>Quotes in CSV files are a classic case of a solution to a problem, which in fact does nothing to solve the problem, but which does increase complexity.</p>
<p>The problem: If you have a row of data like <strong>foo,bar</strong> and you wish to include commas in one data element, you can&#8217;t, as the recipient system will treat the comma as a field separator as opposed to part of the data. The solution used by programs like Excel: surround such data in double-quotes, i.e. <strong>&#8220;fo,o&#8221;,bar</strong>.</p>
<p>In my opinion, there are two solutions to embedding data in other data (e.g. a string in a CSV file, or a piece of arbitrary text in an XML file):</p>
<ol class="tight">
<li>Either<strong> any character</strong> may be contained within the embedded data</li>
<li>Or <strong>only certain characters</strong> may be contained within the embedded data</li>
</ol>
<p>If you are in situation #2, it doesn&#8217;t really matter <em>how many</em> characters you can/can&#8217;t contain, the fact is, you&#8217;ll have to deal with the situation.</p>
<p>The CSV solution if introducing double-quotes has simply been changed the problem from &#8220;you can&#8217;t use commas&#8221; to &#8220;you can&#8217;t use double-quotes&#8221; which are pretty equivalent problems IMHO. Yet, as with most solutions, the complexity has been increased by its introduction.</p>
<p>There needs to be a solution to the new problem of &#8220;you can&#8217;t use double-quotes&#8221;, and that solution should be to define an escape character e.g. &#8220;\&#8221; to prefix the double-quotes in case you wish to represent them literally. And that solution would work just as well to solve the original &#8220;you can&#8217;t use commas&#8221; problem!</p>
<p>(In fact the solution chosen by Excel is to use two double-quotes to represent a literal double-quote, and not an escape prefix like the backslash: this makes parsing harder and can&#8217;t be used for field separators as they couldn&#8217;t be differentiated from two field separators around an empty field.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databasesandlife.com/quotes-in-csv-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

