<?xml version='1.0' encoding='utf-8' ?>
<!--  If you are running a bot please visit this policy page outlining rules you must respect. http://www.livejournal.com/bots/  -->
<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:media='http://search.yahoo.com/mrss/'>
<channel>
  <title>Warrior Tang</title>
  <link>http://tangaroa.livejournal.com/</link>
  <description>Warrior Tang - LiveJournal.com</description>
  <lastBuildDate>Thu, 09 Jul 2009 03:49:50 GMT</lastBuildDate>
  <generator>LiveJournal / LiveJournal.com</generator>
  <lj:journal>tangaroa</lj:journal>
  <lj:journalid>300139</lj:journalid>
  <lj:journaltype>personal</lj:journaltype>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/353971.html</guid>
  <pubDate>Thu, 09 Jul 2009 03:49:50 GMT</pubDate>
  <title>The Facebook Panopticon, part 2</title>
  <link>http://tangaroa.livejournal.com/353971.html</link>
  <description>&lt;p&gt;Facebook just recommended my dad as a potential Facebook Friend. He lives on the other side of the country. 

&lt;p&gt;&lt;a href=&quot;http://tangaroa.livejournal.com/350161.html&quot;&gt;See earlier for the background and et cetera as to why this is very strange.&lt;/a&gt;

&lt;p&gt;I&apos;m leaning towards thinking that they linked me up to a data mine based on the email address that I used to sign up with the service. I want to know what their database looks like and what information they have on me.</description>
  <comments>http://tangaroa.livejournal.com/353971.html</comments>
  <lj:music>The Cranberries - Zombie</lj:music>
  <media:title type="plain">The Cranberries - Zombie</media:title>
  <lj:mood>tired</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>3</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/353671.html</guid>
  <pubDate>Thu, 09 Jul 2009 03:06:51 GMT</pubDate>
  <title>Notes from work - image path relative to CSS, MySQL table locking, and project LoC count</title>
  <link>http://tangaroa.livejournal.com/353671.html</link>
  <description>&lt;p&gt;The website has a header image that is displayed on all pages.
Since the site has multiple directories of different depth, the
original coders could not use an image tag because the relative
path to the image is different from different directories. They
could have chosen to use an absolute path, but they didn&apos;t. Their
solution was to make the iamge path relative to the CSS file by
loading the image in CSS.&lt;/p&gt;

&lt;pre&gt;div#headerImg {
   background:url(../images/banner.jpg) ;&lt;/pre&gt; 


&lt;p&gt;The relative path to the CSS file is different for the
different directories, but the original developers were content
to hardcode the different depths to load the CSS file.&lt;/p&gt;

&lt;p&gt;I wanted to make the header image link to the site index page,
but that is a little hard to do when there is no image tag to wrap
the anchor tag around. If you know how to do it, it&apos;s only a
&lt;em&gt;little&lt;/em&gt; hard. I can&apos;t wrap an A around an image that is
not there, but I can put one inside the div. Then it takes some
CSS to make the anchor a clickable block.&lt;/p&gt;

&lt;pre&gt;/* Allow clicking on the banner */
#headerImg a { display: block; width: 100%; height: 84px;}&lt;/pre&gt;


&lt;p&gt;Note: I added PHP code to autodetect the &quot;../&quot; depth, but the
current header image system works so I haven&apos;t fixed it.&lt;/p&gt;
&lt;a name=&quot;cutid1&quot;&gt;&lt;/a&gt;
&lt;hr /&gt;

&lt;p&gt;MySQL table locking stupidity: if you lock a table, you can&apos;t
select from an alias of that table.&lt;/p&gt;

&lt;pre&gt;mysql&amp;gt; lock tables foo read;
Query OK, 0 rows affected (0.00 sec)

mysql&amp;gt; select * from foo f;
ERROR 1100 (HY000): Table &apos;f&apos; was not locked with LOCK TABLES

mysql&amp;gt; select * from foo;
+------+
| bar  |
+------+
|    0 |
| NULL |
+------+

2 rows in set (0.00 sec)&lt;/pre&gt;

&lt;p&gt;The solution is to &quot;lock tables foo f&quot;, specifying the alias.&lt;/p&gt;


&lt;a name=&quot;cutid2&quot;&gt;&lt;/a&gt;
&lt;hr /&gt;

&lt;p&gt;I measured the original program&apos;s size against the current version
that I&apos;m working on and will hopefully be allowed to deploy tomorrow. 
My version is much smaller, but this is not a measure of my awesome skills
as much as it is a measure of how much the previous programmers relied
on copy-and-paste whenever they were asked to add a new feature that was
similar to an existing one. Here are the numbers:&lt;/p&gt;

&lt;pre&gt;PHP:
  9390 = Original size in lines of PHP code (including comments and HTML).
- 1691 LoC in unused files moved to &quot;unused&quot; folders.
  7699 = Original size of active PHP.
- 1706 LoC of net savings by &lt;a href=&quot;http://tangaroa.livejournal.com/352563.html&quot;&gt;replacing 1905 LoC with 199 LoC&lt;/a&gt;
-  900 (Estimated) saved by consolidating HTML headers to one location.
-   92 net of further optimizations and new code (I&apos;ve been adding features too)
  5001 = LoC of current program.
&lt;/pre&gt;

&lt;pre&gt;JS:
 1005 = Original Javascript.
- 318 net of optimizations and new code.
  687 = Current Javascript.&lt;/pre&gt;

&lt;p&gt;The new version has 31 PHP files. The old version had 76 PHP files of
which 21 were not used (so 55 active files) and 23 were removed by that
one great optimization that saved 1706 LoC (so the rest of it was 32
files).&lt;/p&gt;

&lt;p&gt;Looking at byte size, my lines of code are on average larger than those
of the original programmers:
&lt;pre&gt;
PHP Original: 268182 bytes in 9390 LoC (28.56B per L) 
PHP New: 154719 bytes in 5001 LoC (30.93B per L)
JS Original: 27840 / 1005 (27.7)
JS New: 20223 / 687 (29.4)&lt;/pre&gt;

&lt;p&gt;If I had kept bytes-per-line the same, this difference would be
worth an additional 415 lines of PHP and the difference in Javascript
would account for an additional 42 lines. Since longer lines are harder
to read, this is something that the original developers had over me.
Their code was clean. Mine isn&apos;t that much worse, but I will sometimes
stuff things together to save space and there are even a couple places
where I used the ugly operator (?:) to save myself from writing five
lines of branching.&lt;/p&gt;

&lt;p&gt;Part of the bytes-per-line difference is a matter of style. The
original programmers placed &quot;)&quot; and &quot;{&quot; on separate lines when opening
a branch. I&apos;m used to merging them on one line them as &quot;){&quot; and I have
sometimes forgotten to keep to the project&apos;s style when I&apos;m not 
paying attention. The parts of the Javascript file that I wrote
or significantly modified average 32.1 bytes per line, but that drops
to 30.5 if I fix my code to the project style. We can drop the number
to 28.6 by choosing to ignore one function that is a solid block of 
long DOM methods (it averages 58.3), but that&apos;s still above the
original coders&apos; average.&lt;/p&gt;

&lt;p&gt;If I wanted to be haughty, and I do, I might claim to write longer
and more detailed comments. Sometimes I do, but that&apos;s not the whole
story.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;For your amusement, here is that horrifying Javascript function that
I wrote with the DOM functions and 58.3 byte per line average. I don&apos;t think
it reveals any secrets and I don&apos;t think my employer would care if it did.&lt;/p&gt;

&lt;blockquote&gt;&lt;small&gt;&lt;pre&gt;function resizeToScreen()
{&lt;br /&gt;
  // Resize map to fit smaller screens
  //if(window.innerWidth &amp;lt; 1000)
  //{
    var infoboxWidth = parseInt(window.getComputedStyle(document.getElementById(&quot;infopane&quot;),&quot;&quot;).width);
    var infoboxHeight = parseInt(window.getComputedStyle(document.getElementById(&quot;infopane&quot;),&quot;&quot;).height);
    var diffWidth = (window.innerWidth - infoboxWidth) - 25; // extra space for vertical scrollbar.
//  document.getElementById(&quot;GE_APP_Container&quot;).style.width = (diffWidth&amp;lt;200?200:(diffWidth&amp;gt;1000?1000:diffWidth)) + &quot;px&quot;;
    document.getElementById(&quot;GE_APP_Container&quot;).style.width = intBounded(diffWidth, 200, 1000) + &quot;px&quot;;
    document.getElementById(&quot;container&quot;).style.minWidth = window.innerWidth + &quot;px&quot;;
    document.getElementsByClassName(&quot;backcontent&quot;).item(0).style.minWidth = window.innerWidth + &quot;px&quot;;
  //}
  window.onresize = resizeToScreen;
}&lt;/pre&gt;&lt;/small&gt;&lt;/blockquote&gt;</description>
  <comments>http://tangaroa.livejournal.com/353671.html</comments>
  <lj:music>Genesis - Land of Confusion</lj:music>
  <media:title type="plain">Genesis - Land of Confusion</media:title>
  <lj:mood>geeky</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/353373.html</guid>
  <pubDate>Tue, 07 Jul 2009 16:13:16 GMT</pubDate>
  <title>More notes from work - NULL and 0 in a SQL database</title>
  <link>http://tangaroa.livejournal.com/353373.html</link>
  <description>&lt;p&gt;I noticed something unusual thing about the database. The designers 
never use NULL. Where a NULL might be used, there is a zero in the field
instead.  

&lt;p&gt;I can see a potential reason for avoiding NULL because NULL
complicates database querying logic. 
For example, it can be expected that a record with a NULL value will not
show up in a list of &quot;any number between one and ten&quot;. One might not
expect that a list of &quot;any number NOT between one and ten&quot; will also
leave out the NULL record! NULL is not a number or anything.
It represents an unknown value, the lack of any information. To get
every record where there is not a number between one and ten, the
query would have to be along the lines of &quot;number IS NULL OR (number
&amp;lt;= 10 AND number &amp;gt;= 1)&quot;. 

&lt;p&gt;A problem with using zero to mean &quot;no data&quot; is that there is no
zero record in the corresponding table with the related data for
that data field. This makes it difficult to add foreign keys to
guarantee relational integrity. I could add a zero field and call
it &quot;Unknown&quot;, but then our web forms break. There is probably an easy
solution to that but I have not looked into it yet. If I convert all
the zero records to NULLs, I don&apos;t know what will break, if anything
does.

&lt;p&gt;At first I thought the use of zero instead of NULL was too widespread
for it not to be intentional. Then I discovered how the zeros were being
added. It&apos;s not intentional, it&apos;s a MySQLism.&lt;/p&gt;

&lt;p&gt;In &lt;a href=&quot;http://tangaroa.livejournal.com/351257.html&quot;&gt;an earlier
post&lt;/a&gt;, I mentioned how the original developers write all their
inputs as &apos;strings&apos; and that this should cause the inserts into numeric
fields to fail in just about every database but MySQL. MySQL converts
strings into numbers. I assume that &apos;123abc&apos; would be converted to 123,
but I haven&apos;t confirmed this. If the insert routine got no information
from the original data source, if it tries to insert &apos;$foo&apos; but $foo
is empty, it will send MySQL a null string &apos;&apos; which MySQL converts
to zero, not NULL.

&lt;p&gt;For the non-CS major, a null string is not NULL.
The null string is a string of zero characters, while NULL is no
string, no information.&lt;/p&gt;

&lt;a name=&quot;cutid1&quot;&gt;&lt;/a&gt;
&lt;pre&gt;mysql&amp;gt; create table foo ( bar int);
Query OK, 0 rows affected (0.06 sec)

mysql&amp;gt; insert into foo values (&apos;&apos;);
Query OK, 1 row affected, 1 warning (0.02 sec)

mysql&amp;gt; select * from foo;
+------+
| bar  |
+------+
|    0 |
+------+
1 row in set (0.00 sec)

mysql&amp;gt; insert into foo values (NULL);
Query OK, 1 row affected (0.00 sec)

mysql&amp;gt; select * from foo;
+------+
| bar  |
+------+
|    0 |
| NULL |
+------+&lt;/pre&gt;



&lt;p&gt;That explains the most common case. However, there are also a couple
of places where zero was intentionally used instead of NULL: a database
field which defaults to zero instead of NULL, and an update query which
uses zero. I will have to try using NULL there and see what breaks.
&lt;/p&gt;</description>
  <comments>http://tangaroa.livejournal.com/353373.html</comments>
  <lj:music>Butthole Surfers - Pepper</lj:music>
  <media:title type="plain">Butthole Surfers - Pepper</media:title>
  <lj:mood>geeky</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/353073.html</guid>
  <pubDate>Mon, 06 Jul 2009 01:50:14 GMT</pubDate>
  <title>Interesting article on the Smithsonian redesign</title>
  <link>http://tangaroa.livejournal.com/353073.html</link>
  <description>&lt;p&gt;&lt;a href=&quot;http://hnn.us/articles/89473.html&quot;&gt;A historian gripes about the redesigned Smithsonian Museum resembling a &quot;shopping mall&quot;&lt;/a&gt;. Excerpts:

&lt;blockquote&gt;&lt;p&gt;Whole huge exhibits have disappeared. The first floor used to house an exhibit entitled &quot;Information Age: People, Information and Technology.&quot; This was a 14,000 square foot display with over 900 original artifacts: Samuel Morse’s telegraphs, Alexander Bell&apos;s telephones, a Hollerith punched card machine, a German ENIGMA encoder, the ENIAC computer, the TELESTAR test satellite, and a selection of early personal computers, among many other artifacts. This has all been crated-up and stored away in a warehouse somewhere and replaced by &quot;Julia Child’s Kitchen.&quot;&lt;/p&gt;

&lt;p&gt;[...] one hugely popular and impressive exhibit in the “old” museum was the Foucault Pendulum (which was removed prior to the current renovations). The Foucault Pendulum consisted of a 52-foot cable suspended from the ceiling down through a round opening in the second floor, with a 240 lb. brass globe at the end. A row of candles was set up on the first floor, and the motion of the pendulum over the course of the day, as it knocked down the candles one-by-one, demonstrated the earth’s motion. This was a very physical—one is tempted to say, 19th century—way to communicate something fundamental about the physics of our planet. Now this sort of information is conveyed only on touch-screen video monitors.&lt;/p&gt;
&lt;/blockquote&gt;</description>
  <comments>http://tangaroa.livejournal.com/353073.html</comments>
  <lj:music>Weird Al - Couch Potato</lj:music>
  <media:title type="plain">Weird Al - Couch Potato</media:title>
  <lj:mood>calm</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>3</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/352979.html</guid>
  <pubDate>Thu, 02 Jul 2009 03:57:55 GMT</pubDate>
  <title>Firefox 3.5, now with 10% faster Javascript! </title>
  <link>http://tangaroa.livejournal.com/352979.html</link>
  <description>&lt;p&gt;&lt;a href=&quot;http://www.mozilla.com/firefox&quot;&gt;Firefox 3.5 is out&lt;/a&gt;,
featuring &lt;a href=&quot;http://tech.slashdot.org/story/09/07/01/1828254/Firefox-35-Benchmarked-Close-To-Original-Chrome&quot;&gt;an overhauled Javascript engine that is supposed to be much faster
than it used to be.&lt;/a&gt;. Naturally, I want to see how it holds up on
&lt;a href=&quot;http://tangaroa.livejournal.com/346496.html&quot;&gt;the simple little
graphics demos&lt;/a&gt; that I wrote in Javascript for a
computer graphics class because I couldn&apos;t get OpenGL to display
anything and we didn&apos;t have GLUT (which was all that our OpenGL book
taught) on the open lab machines anyways.&lt;/p&gt;

&lt;a name=&quot;cutid1&quot;&gt;&lt;/a&gt;
&lt;p&gt;&lt;small&gt;There is a strange story beside that: I was YELLED AT REALLY
LOUDLY for asking if there was a process to suggest new software, because
&lt;a href=&quot;http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=131997&quot;&gt;&quot;WE HAVE TO PAY LICENSING FEES&quot;&lt;/a&gt;. Some figurehead of IT charged
out of his office to stop me from writing down the name of the software
on a piece of paper that I was insidiously planning to give to a
receptionist in a defiant act of antisocial rebellion against the
authority of this guy that neither me nor the receptionist knew
existed. And he spoke English, not whatever language you&apos;re
thinking. Anyway, back to the article.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;So I installed FF3.5 and I ran it on those Javascript graphics 
demos. A point of warning here before anyone mistakenly interprets
these numbers to mean anything useful: benchmarks will usually stress
one or two parts of a system without giving a comprehensive overview
of how the whole system operates in normal practice. These tests in
particular don&apos;t represent anything that people actually do with
Javascript in normal practice. Times are in seconds, lower is better
unless you&apos;re a psychic monster that feeds off impatience.&lt;/p&gt;


&lt;table&gt;
&lt;tr&gt;&lt;th&gt;&lt;th&gt;Firefox 3.0.10&lt;/th&gt;&lt;th&gt;Firefox 3.5&lt;/th&gt;&lt;th&gt;Speedup&lt;/th&gt;&lt;/tr&gt;

&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;http://web.cs.sonoma.edu/~dturover/timing/aaline.html&quot;&gt;Anti-Aliased Bresenham Line&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;2.20&lt;/td&gt;&lt;td&gt;2.00&lt;/td&gt;&lt;td&gt;9.7%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;http://web.cs.sonoma.edu/~dturover/timing/bresline.html&quot;&gt;Bresenham Line, Enterprise Edition&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;54.01&lt;/td&gt;&lt;td&gt;49.55&lt;/td&gt;&lt;td&gt;9.0%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;http://web.cs.sonoma.edu/~dturover/timing/hermite3.html&quot;&gt;Hermite Spline (disconnected)&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;15.59&lt;/td&gt;&lt;td&gt;14.58&lt;/td&gt;&lt;td&gt;7.0%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;http://web.cs.sonoma.edu/~dturover/timing/hermite5.html&quot;&gt;Hermite Spline (connected)&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;26.86&lt;/td&gt;&lt;td&gt;26.84&lt;/td&gt;&lt;td&gt;0.1%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;http://web.cs.sonoma.edu/~dturover/timing/rotate.html&quot;&gt;Rotating Square&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;61.47&lt;/td&gt;&lt;td&gt;56.99&lt;/td&gt;&lt;td&gt;7.8%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Circle (part of Sphere)
&lt;td&gt;2.02&lt;/td&gt; &lt;td&gt;0.96&lt;/td&gt; &lt;td&gt;110.3%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;http://web.cs.sonoma.edu/~dturover/timing/sphere.html&quot;&gt;Sphere&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;3.58&lt;/td&gt; &lt;td&gt;2.43&lt;/td&gt; &lt;td&gt;47.1%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;http://web.cs.sonoma.edu/~dturover/timing/triangle.html&quot;&gt;Triangle with moving lights&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;20.51&lt;/td&gt; &lt;td&gt;8.62&lt;/td&gt; &lt;td&gt;137.9%&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;Average speedup by graphics type:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Image-based particles: 6%&lt;/li&gt;
&lt;li&gt;Table-based buffers: 76%&lt;/li&gt;
&lt;li&gt;Animations: 32% (almost all in Triangle)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The new Firefox is faster than the old Firefox. It&apos;s an improvement.
Don&apos;t look a gift horse in the mouth. In particular, the circle and sphere
render much faster (although the aaline doesn&apos;t show the same improvement)
and the developers fixed most of whatever was slowing down the triangle
test.&lt;/p&gt;

&lt;p&gt;Now I&apos;ll look a gift horse in the mouth. The results from the new
Firefox beat Opera on the hermite3 and bresline tests that Opera bogs
down on, and it beat Chrome on the aaline and sphere tests, but otherwise
none of its scores beat those of Opera, Chrome, or Safari. (Note:  Chrome and
Safari were tested on different computers, but FF3.0.x tested similarly
on all three machines.) Of the three browsers, Firefox is still the slowest
overall in these mostly useless, in no way real-world benchmarks.&lt;/p&gt;</description>
  <comments>http://tangaroa.livejournal.com/352979.html</comments>
  <lj:music>Butthole Surfers - Pepper</lj:music>
  <media:title type="plain">Butthole Surfers - Pepper</media:title>
  <lj:mood>geeky</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/352563.html</guid>
  <pubDate>Wed, 01 Jul 2009 03:59:44 GMT</pubDate>
  <title>Removing redundant code</title>
  <link>http://tangaroa.livejournal.com/352563.html</link>
  <description>&lt;p&gt;I waited to investigate one part of the source tree because it wasn&apos;t a high priority (as nobody seemed to use it) and it looked more complex than the rest. While most directories have one or two PHP files, this had an index PHP and five separate directories having three to five PHP files in each. When I did finally open up the files to see what they did, this turned out to be one of the simpler parts of the program and one of the most redundant.&lt;/p&gt;

&lt;p&gt;The five directories each correspond to a table in the database. Each directory contains separate 80-100 line PHP scripts for displaying the table, displaying the interface for editing a single record, displaying the interface for adding a new record, running the SQL to edit a single record, and running the SQL to add a new record. All five tables have a very similar schema: there is an ID field, a description, and two tables have a third field.&lt;/p&gt;

&lt;p&gt;There is lots of redundancy between the five directories, as the file that does an operation for table X is very similar to the file that does the same operation for table Y. One could (and I did) use variables to say which table is being operated on and what the names of the fields are. There is also redundancy between the files in each directory in handling CGI variables and displaying HTML. This can be alleviated by handling all the CGI variables in one place and printing all the common HTML in one place.&lt;/p&gt;

&lt;p&gt;The new system uses one front-end file of almost exactly 100 lines and one back-end file of about 90 lines including comments and sanity checks for the new variables. ~1900 LoC --&amp;gt; ~200 LoC and the directory tree goes away. That&apos;s a nice result for a few hours of work.&lt;/p&gt;

&lt;p&gt;I also used one of those &lt;a href=&quot;http://tangaroa.livejournal.com/349232.html&quot;&gt;&lt;tt&gt;do{...}while(false)&lt;/tt&gt; constructs&lt;/a&gt; to easily &lt;tt&gt;break&lt;/tt&gt; out of the backend file without halting the frontend file and while keeping all the variables in the same scope. It works for the purpose and lets the code logic flow in one direction.&lt;/p&gt;

&lt;p&gt;One of the things that brought me to this part of the code is because I&apos;m going through the whole codebase to make all the files share a common source for the HTML header and the opening body and containers. The code was originally written so that each separate PHP file had its own HTML headers. That is being fixed. The whole program likely started as three or so PHP files and grew through copying and pasting as new requirements came in to the few dozens that there are now.&lt;/p&gt;</description>
  <comments>http://tangaroa.livejournal.com/352563.html</comments>
  <lj:music>Ozzy Osbourne - Mama I&apos;m Coming Home</lj:music>
  <media:title type="plain">Ozzy Osbourne - Mama I&apos;m Coming Home</media:title>
  <lj:mood>geeky</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/352276.html</guid>
  <pubDate>Sun, 28 Jun 2009 19:12:23 GMT</pubDate>
  <title>ID4&apos;s writers</title>
  <link>http://tangaroa.livejournal.com/352276.html</link>
  <description>The movie Independence Day was on TV last night. I noticed that the dialogue was excellently written. The characters&apos; lines are very expressive of their character and contribute to the plot while being clear, snappy, and often humorous. I wondered who the writers were and what else they have done. Three cheers for &lt;a href=&quot;http://www.imdb.com/title/tt0116629/&quot;&gt;IMDB&lt;/a&gt;! The writing is credited to the film&apos;s producer and director, &lt;a href=&quot;http://www.imdb.com/name/nm0000386/&quot;&gt;Roland Emmerlich&lt;/a&gt; and &lt;a href=&quot;http://www.imdb.com/name/nm0002041/&quot;&gt;Dean Devlin&lt;/a&gt;. They were also responsible for the Stargate movie and the American Godzilla movie, and Emmerlich wrote The Day After Tomorrow (the movie where the Northern Hemisphere gets flash-frozen), but they have not done much else of note.</description>
  <comments>http://tangaroa.livejournal.com/352276.html</comments>
  <lj:music>Heart - Crazy On You</lj:music>
  <media:title type="plain">Heart - Crazy On You</media:title>
  <lj:mood>blah</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/352061.html</guid>
  <pubDate>Fri, 26 Jun 2009 05:18:42 GMT</pubDate>
  <title>Variable naming in borrowed code, and other mini-wtfs</title>
  <link>http://tangaroa.livejournal.com/352061.html</link>
  <description>&lt;p&gt;In some places it is obvious that the code I&apos;m working with is copied
and pasted from a web forum example. I am in favour of borrowing code from
other people and projects so long as their legal rights are respected, and
code that someone posts to a web forum ought to be considered public domain.
What annoys me is the use of unique and expressive variable names like
&lt;a href=&quot;http://lists.evolt.org/archive/Week-of-Mon-20070212/188288.html&quot;&gt;$flightdateListMonth&lt;/a&gt; that mean something to the original program
but not this one which, for example, does not have flights.

&lt;hr /&gt;

&lt;p&gt;One file uses multiple HTML tags with the same @id. The @id is supposed
to be unique to one node in the entire document, but the code uses it like
a class. This works in Firefox, but it is not linguistically correct.

&lt;hr /&gt;

&lt;p&gt;Doing it wrong in both PHP and HTML at the same time:&lt;/p&gt;

&lt;blockquote&gt;&quot;&amp;lt;option id=&apos;Year&apos; value=\&quot;&quot;.$y.&quot;\&quot;&amp;gt;&quot;.$y.&quot;&amp;lt;/option&amp;gt;&quot;&lt;/blockquote&gt;

&lt;p&gt;It looks like the developer got single and double quotes confused.
A single-quoted version would work like this:

&lt;blockquote&gt;&apos;&amp;lt;option id=&quot;Year&quot; value=&quot;.$y.&apos;&quot;&amp;gt;&apos;.$y.&apos;&amp;lt;/option&amp;gt;&apos;&lt;/blockquote&gt;

&lt;p&gt;The benefit of using double quotes is that variables are interpreted
inside them so you do not need to concatenate.

&lt;blockquote&gt;&quot;&amp;lt;option id=\&quot;Year\&quot; value=\&quot;$y\&quot;&amp;gt;$y&amp;lt;/option&amp;gt;&quot;&lt;/blockquote&gt;</description>
  <comments>http://tangaroa.livejournal.com/352061.html</comments>
  <lj:music>Moody Blues - Story In Your Eyes</lj:music>
  <media:title type="plain">Moody Blues - Story In Your Eyes</media:title>
  <lj:mood>blah</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/351934.html</guid>
  <pubDate>Thu, 25 Jun 2009 16:42:09 GMT</pubDate>
  <title>You Really Can&apos;t Do That On Television</title>
  <link>http://tangaroa.livejournal.com/351934.html</link>
  <description>&lt;p&gt;&lt;a href=&quot;http://www.imdb.com/title/tt0078714/trivia&quot;&gt;According to IMDB:&lt;/a&gt;

&lt;blockquote&gt;The 1987 &quot;Adoption&quot; episode was never seen in the U.S.
again following its original airing, and it never aired in Canada.
Among the scenes that led to the banning is the one where Valerie
and Lance adopt Doug because it was cheaper than buying a dog.
The studio master of this episode has a large label on it reading
&quot;DO NOT AIR&quot;. By 1987, there were fifteen episodes pulled from the
rotation for Nickelodeon: the banned &quot;Adoption&quot; episode, all thirteen
1981 episodes, and the 1982 &quot;Cosmetics&quot; episode. Including Alasdair&apos;s
&quot;Crusher Wallace, the school bully&quot; and the censored locker monster
skits. While telling jokes, one of the kids is eaten alive in front
of the cast.
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/You_Can%27t_Do_That_on_Television#Notable_episodes&quot;&gt;According to Wikipedia:&lt;/a&gt;
&lt;blockquote&gt;two rather risque sketches were cut and replaced with less offensive sketches
from dress rehearsal:
&lt;ul&gt;
&lt;li&gt;An &quot;Opposite&quot; sketch where a teacher shows his anatomy class a pornographic movie.
&lt;li&gt;A sketch where Ross sells his father&apos;s issues of Playboy magazine to Ben and Alasdair.
&lt;/ul&gt;
&lt;/blockquote&gt;</description>
  <comments>http://tangaroa.livejournal.com/351934.html</comments>
  <lj:music>Monty Python - I Bet They Won&apos;t Play This Song On The Radio</lj:music>
  <media:title type="plain">Monty Python - I Bet They Won&apos;t Play This Song On The Radio</media:title>
  <lj:mood>amused</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/351598.html</guid>
  <pubDate>Sun, 21 Jun 2009 04:41:08 GMT</pubDate>
  <title>The hard sell</title>
  <link>http://tangaroa.livejournal.com/351598.html</link>
  <description>There was a spam in my inbox with the subject line &quot;Open or die in hell&quot;.</description>
  <comments>http://tangaroa.livejournal.com/351598.html</comments>
  <lj:music>Tonic - Queen</lj:music>
  <media:title type="plain">Tonic - Queen</media:title>
  <lj:mood>amused</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/351257.html</guid>
  <pubDate>Sat, 20 Jun 2009 19:05:43 GMT</pubDate>
  <title>Notes from work</title>
  <link>http://tangaroa.livejournal.com/351257.html</link>
  <description>&lt;p&gt;Upon opening up a PHP file, I found a very large comment block
from the previous maintainer who recommend adding an $additionalSQL
variable to the code and seeing if &quot;the huge if/else blocks can be
reduced to a few if(){ $additionalSQL = &quot; and ...&quot; } blocks&quot;. 

&lt;p&gt;For each input to the script, the code had if/else to
generate different SQL WHERE clauses depending on if
the previous inputs were received. In many cases, the only
difference in the SQL in each branch was the presence or
absence of &quot;and &quot; at the start. Fixing it by the last
maintainer&apos;s recommendations brought a 22KB file down to 12KB
and made it much easier to read.&lt;/p&gt;

&lt;hr&gt;
&lt;p&gt;The same source file had a 4-deep nested SQL query which ground 
my workstation to a halt for two minutes while it ran. The original
programmer was familiar with WHERE foo IN (select ...) but not JOIN.
In other words, the SQL developer knew set theory but not SQL. I made
it a 2-deep query of half the size and it runs nicely now.

&lt;hr /&gt;
&lt;p&gt;The same source file had a strange method to tell if any of several 
tests ran. There is a value called $nothing_happened which is
incremented if a test is not run, and then this value is compared to
the total number of tests in the code (manually counted) to make
sure they are different. I made it a boolean that is set to true when
any test does run. Instead of checking $nothing_happened against a number
that needs maintenance if the code changes, the code now works so that
$nothing_happened is true if nothing happened. That&apos;s more sensible, eh? 
&lt;hr /&gt;
&lt;p&gt;To produce several CSV field headers at once, the code does this:&lt;/p&gt;

&lt;pre&gt;fwrite($fp, &quot;User Name&quot;.&apos;,&apos;);
fwrite($fp, &quot;Start Date&quot;.&apos;,&apos;);
fwrite($fp, &quot;End Date&quot;.&quot;\n&quot;);&lt;/pre&gt;

&lt;p&gt;That can all be replaced with one fwrite() call and one string.&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;Strange programming practice: throughout the program, integers
in SQL code are treated as &apos;strings&apos;. If I am not mistaken, this
behaviour breaks every database except for MySQL because trying
to insert a string value into an integer container produces a data
type mismatch. The code also puts field and table names in
`backquotes`, which is a MySQL-only syntax. At first I thought
the original programmers must know better than me, now I&apos;m
pretty sure they&apos;re doing it wrong and/or just copying stuff from
phpMyAdmin which puts backquotes on everything.&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;The program includes a large Javascript source file. Part of
the largeness is repeated code. There was one original 50-line
function that was copied and tweaked a little bit for a slightly
different purpose. Twice. By giving the original function two
extra variables, a parameter to branch on, and 10 lines of
branching code, the two newer functions could be reduced to
one-liners that just call the first function.&lt;/p&gt;

&lt;p&gt;There was also some repeated code to toggle the visibility
of features on the page. Each feature has its own fooIsVisible
variable, its own data variable, and its own toggle function.
Object-orientation to the rescue! I made a class containing all
of the above and made instances of the class for each feature. 
The global toggle functions are now one-liners and I might be
able to get rid of them entirely if the instances are in the
scope of the code that uses these functions.

&lt;p&gt;All in all, I cut the Javascript down by 150 lines. 
I love being able to measure my productivity in negative lines
of code.</description>
  <comments>http://tangaroa.livejournal.com/351257.html</comments>
  <lj:music>Weird Al - Couch Potato</lj:music>
  <media:title type="plain">Weird Al - Couch Potato</media:title>
  <lj:mood>geeky</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/351162.html</guid>
  <pubDate>Fri, 19 Jun 2009 02:35:41 GMT</pubDate>
  <title>WaPost fires Froomkin</title>
  <link>http://tangaroa.livejournal.com/351162.html</link>
  <description>&lt;a href=&quot;http://www.politico.com/blogs/michaelcalderone/0609/Froomkin_out_at_Washington_Post.html&quot;&gt;The Washington Post fired blogger Dan Froomkin, one of their most popular writers&lt;/a&gt;. I liked reading him.</description>
  <comments>http://tangaroa.livejournal.com/351162.html</comments>
  <lj:music>Green Day - Uptight</lj:music>
  <media:title type="plain">Green Day - Uptight</media:title>
  <lj:mood>blah</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/350728.html</guid>
  <pubDate>Thu, 18 Jun 2009 18:15:28 GMT</pubDate>
  <title>How much does the bailout cost?</title>
  <link>http://tangaroa.livejournal.com/350728.html</link>
  <description>&lt;a href=&quot;http://www.ritholtz.com/blog/2009/06/bailout-costs-vs-big-historical-events/&quot;&gt;Cost of &quot;bailout&quot; versus inflation-adjusted major historical costs like the New Deal and Iraq War.&lt;/a&gt;</description>
  <comments>http://tangaroa.livejournal.com/350728.html</comments>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/350580.html</guid>
  <pubDate>Thu, 18 Jun 2009 06:07:39 GMT</pubDate>
  <title>Civil unrest in Iran</title>
  <link>http://tangaroa.livejournal.com/350580.html</link>
  <description>Iran is in a situation that could possibly lead to another revolution. 

Mahmoud Ahmadinejad won re-election in the first round with an improbable 63%-34% victory over the nearest candidate Mir Mousavi, with other candidates gaining negligible amounts. No one expected it to be that big a blowout, protests broke out, and Mousavi endorsed further protests. 

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.eurasianet.org/departments/insightb/articles/eav061709c.shtml&quot;&gt;There seems to be a power struggle between two parties in government.&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;http://www.casavaria.com/cafesentido/2009/06/17/3052/rafsanjani-calls-for-emergency-meeting-of-assembly-of-experts/&quot;&gt;report that Expediency Discernment Council chairman Hashemi Rafsanjani
as called an emergency meeting of the Assembly of Experts, which has
the authority to depose Ayatollah Khamenei.&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;http://www.jpost.com/servlet/Satellite?cid=1245184856983&amp;amp;pagename=JPost%2FJPArticle%2FShowFull&quot;&gt;Members of Iran&apos;s World Cup soccer team wore green wristbands in support of Mousavi
for the first half of a qualifying match against South Korea in Seoul.&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;http://www.fivethirtyeight.com/search/label/iran&quot;&gt;The U.S. 
elections blog fivethirtyeight.com has several postings on Iran&apos;s election
results&lt;/a&gt;, including one noting that
&lt;a href=&quot;http://www.fivethirtyeight.com/2009/06/iran-does-have-some-fishy-numbers.html&quot;&gt;fourth place candidate Mehdi Karroubi is reported to have performed 
abysmally in districts that he won in 2005.&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;http://kojayi.wordpress.com/2009/06/16/ayatollah-montazeris-letter/&quot;&gt;Grand Ayatollah Hussein Ali Montazeri urged police to disobey any
orders they might receive from the government to attack protesters&lt;/a&gt;
and &lt;a href=&quot;http://kojayi.wordpress.com/2009/06/17/ayatollah-montazeri-issues-a-fatwa/&quot;&gt;issued a fatwah forbidding violence against the protesters.&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;http://www.msnbc.msn.com/id/31411475/ns/technology_and_science-tech_and_gadgets/&quot;&gt;There is an information war between the protesters and the government.&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;http://cyrusfarivar.com/blog/?p=2169&quot;&gt;A list of information sources about the events in Iran.&lt;/a&gt;
Via &lt;a href=&quot;http://www.boingboing.net/2009/06/17/iran-elections-crisi.html&quot;&gt;BoingBoing&lt;/a&gt;.&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;http://www.slate.com/id/2220520/&quot;&gt;Christopher Hitchens has
a report in Slate which is biased to the point of becoming
entertainment&lt;/a&gt;. &lt;/li&gt;

&lt;/ul&gt;</description>
  <comments>http://tangaroa.livejournal.com/350580.html</comments>
  <lj:music>The Beatles - The Ballad of John and Yoko</lj:music>
  <media:title type="plain">The Beatles - The Ballad of John and Yoko</media:title>
  <lj:mood>tired</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/350400.html</guid>
  <pubDate>Wed, 17 Jun 2009 04:02:33 GMT</pubDate>
  <title>Opera&apos;s latest web browser is also a web server</title>
  <link>http://tangaroa.livejournal.com/350400.html</link>
  <description>&lt;p&gt;&lt;a href=&quot;http://www.theregister.co.uk/2009/06/16/opera_unite/&quot;&gt;This is interesting...&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;Rather than compete with the cloud-based services that are currently so popular, Opera is proposing, and enabling, a return to how the internet used to work: everyone runs their own host device, with their own applications running on their own hardware, which can then be accessed from anywhere using any web browser.&lt;/blockquote&gt;

&lt;p&gt;Immediate problems that I see: browser incompatibility (duh), keeping the served data available online somewhere after you turn your system off, and the case of wanting to run the browser or the server but not both. At least they have name resolution figured out:&lt;/p&gt;

&lt;blockquote&gt;Routing is handled by servers at Opera, and the computer on your desk is addressed as &quot;unite://computername.username.operaunite.com&quot;.&lt;/blockquote&gt;</description>
  <comments>http://tangaroa.livejournal.com/350400.html</comments>
  <lj:music>Portishead - Glory Box</lj:music>
  <media:title type="plain">Portishead - Glory Box</media:title>
  <lj:mood>calm</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/350161.html</guid>
  <pubDate>Thu, 11 Jun 2009 04:37:00 GMT</pubDate>
  <title>The Facebook Panopticon</title>
  <link>http://tangaroa.livejournal.com/350161.html</link>
  <description>&lt;p&gt;I have a seekrit Facebook account to keep in touch with a few school buddies who only keep in touch with each other over Facebook. Being my typically paranoid self, I have as little of my personal information on there as possible: fake birthdate, fake name, and so on. Today, Facebook offered up a suggestion that I add as a friend an ex-coworker at the place I used to work at two years ago. I have no Facebook connection to the workplace, just to the school buddies. None of the school buddies worked at that place. The ex-coworker got out of school and married and settled years ago.

&lt;p&gt;This leads to the question: How the hell did they do that? Also, which departments of which governments and corporations have access to this technology? And how can I get my hands on this power to abuse it for my own selfish interests?

&lt;p&gt;I assume that part of the formula is based on my IP-derived geographic location, since that&apos;s about the only thing I can think of that would match and be in the Facebook database. I doubt that it&apos;s matching on techie keywords from wall talk because I&apos;ve been posting twitter shit. Facebook does have one real e-mail address of mine that they could probably match to a third-party data mine that might have my whole life history in it, or they could use it to search the web and pull down information tying me to the job and the ex-coworker.</description>
  <comments>http://tangaroa.livejournal.com/350161.html</comments>
  <lj:music>Europe - The Final Countdown</lj:music>
  <media:title type="plain">Europe - The Final Countdown</media:title>
  <lj:mood>uncomfortable</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>4</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/349795.html</guid>
  <pubDate>Wed, 10 Jun 2009 03:11:31 GMT</pubDate>
  <title>w3tardedness: Form method attributes must be lower case </title>
  <link>http://tangaroa.livejournal.com/349795.html</link>
  <description>&lt;p&gt;&lt;a href=&quot;http://www.w3.org/TR/REC-html32.html#form&quot;&gt;From HTML 3.2&lt;/a&gt;

&lt;dl&gt;
&lt;dt&gt;method&lt;/dt&gt;
&lt;dd&gt;When the action attribute specifies an HTTP server, the method attribute determines which HTTP method will be used to send the form&apos;s contents to the server. It can be either GET or POST, and defaults to GET.&lt;/dd&gt;
&lt;/dl&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.1&quot;&gt;From HTTP 1.1:&lt;/a&gt;&lt;/p&gt;

&lt;dl&gt;
&lt;dt&gt;5.1.1 Method&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;The Method  token indicates the method to be performed on the resource identified
by the Request-URI. The method is case-sensitive.&lt;/p&gt;

&lt;pre&gt;Method         = &quot;OPTIONS&quot;                ; Section 9.2
               | &quot;GET&quot;                    ; Section 9.3
               | &quot;HEAD&quot;                   ; Section 9.4
               | &quot;POST&quot;                   ; Section 9.5
               | &quot;PUT&quot;                    ; Section 9.6
               | &quot;DELETE&quot;                 ; Section 9.7&lt;/pre&gt;
&lt;/dl&gt;
&lt;hr /&gt;

&lt;p&gt;From the w3c Validator:
&lt;blockquote&gt;value of attribute &quot;method&quot; cannot be &quot;POST&quot;; must be one of &quot;get&quot;, &quot;post&quot;&lt;/blockquote&gt;

&lt;hr /&gt;
&lt;p&gt;What seems to have happened is that during the switchover to XHTML back around 2000, the decision was made to make everything lower case including options that were supposed to be upper-case parameters for another case-sensitive protocol. The form method attribute is just a layer of indirection now; &quot;get&quot; translates to &quot;GET&quot; but you aren&apos;t supposed to know that, you are just supposed to use &quot;get&quot;. In the w3c&apos;s defense, it would have been odd to have the set of values for this one attribute remain upper-case while the rest of the language went to lower case. I still think the decision to make HTML case-sensitive was ridiculous.&lt;/dd&gt;</description>
  <comments>http://tangaroa.livejournal.com/349795.html</comments>
  <lj:music>The Mighty Mighty Bosstones - Nevermind Me</lj:music>
  <media:title type="plain">The Mighty Mighty Bosstones - Nevermind Me</media:title>
  <lj:mood>blah</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/349669.html</guid>
  <pubDate>Wed, 10 Jun 2009 02:57:36 GMT</pubDate>
  <title>More minor code WTFs</title>
  <link>http://tangaroa.livejournal.com/349669.html</link>
  <description>&lt;p&gt;I code my php the old-fashioned way where the include goes at the top of the file and the globals that are to be imported into a function&apos;s scope have to be redeclared in that function.

&lt;pre&gt;include(&apos;backend&apos;);
func(){
  global $g_foo;
  ... // rest of function
}
func2(){
  global $g_bar;
  ... // rest of function
}&lt;/pre&gt;

&lt;p&gt;The code I&apos;m working with uses a looser style that re-includes the needed backend files at the beginning of each function, which brings all of their globals into the current scope without having to declare them individually.

&lt;pre&gt;func(){
  include(&apos;backend&apos;);
  ... // rest of function
}
func2(){
  include(&apos;backend&apos;);
  ... // rest of function
}&lt;/pre&gt;

&lt;p&gt;Disaster occurs when the two styles are mixed. When a page with a global include runs a function that repeats the include, the repeated include can break things. If the include in the function uses require_once() or include_once() and the file had been included globally by earlier code, the file is not included and the function does not get the globals it needs; but if anything other than *_once() is used when the file had been included before, any global code in the file will be run twice.

&lt;p&gt;There is a third include style both of us use which assumes the files containing certain functions to have been loaded by earlier code, so the include is left out entirely.
&lt;hr /&gt;
&lt;p&gt;Another wtf: lots of single quotes in output HTML.

&lt;pre&gt;if(condition){
  echo &quot;
  &amp;lt;li&amp;gt;&amp;lt;a href=&apos;dest.php&apos; class=&apos;foo&apos; bar=&apos;baz&apos;&amp;gt;link&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
  ... etc ...
  &quot;;
} else if(condition2){
  echo &quot;
  &amp;lt;li&amp;gt;&amp;lt;a href=&apos;dest.php&apos; class=&apos;foo&apos; bar=&apos;baz&apos;&amp;gt;link&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
  ... etc ...
  &quot;;
}&lt;/pre&gt;

&lt;p&gt;This avoids having to \escape every quotation mark but it produces invalid HTML that is not supposed to function correctly in any browser. We are lucky enough that the common browsers support this syntax, but this made my Graphviz script miss the links when I was trying to generate a logic flow of the website. I replaced all the HTML chunks with &lt;a href=&quot;http://us.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc&quot;&gt;&amp;lt;&amp;lt;&amp;lt;HEREDOCs&lt;/a&gt; using proper quoting.

&lt;p&gt;Then I noticed it was the same block of HTML code being repeated after each condition, sometimes with very minor changes that could be handled with variables. I&apos;ll have to look into simplifying that later.</description>
  <comments>http://tangaroa.livejournal.com/349669.html</comments>
  <lj:music>The Mighty Mighty Bosstones - 128</lj:music>
  <media:title type="plain">The Mighty Mighty Bosstones - 128</media:title>
  <lj:mood>geeky</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/349232.html</guid>
  <pubDate>Thu, 04 Jun 2009 05:10:14 GMT</pubDate>
  <title>A small WTF</title>
  <link>http://tangaroa.livejournal.com/349232.html</link>
  <description>&lt;p&gt;Here is an interesting construct:
&lt;pre&gt;
do { // once, with early exit possible
        if(isAdmin()){
                $state = 4;
                break;
        }
        if($state == 0){
                $state = 1;
                break;
        }
        if($err){
                $state = 3;
                break;
        }
        $state = 2;
} while(FALSE); // do once
&lt;/pre&gt;

&lt;p&gt;It&apos;s like they forgot that the &lt;tt&gt;else&lt;/tt&gt; statement existed.
&lt;p&gt;The construct found a use later in the code where the branches were based on the results of SQL queries and other things that needed a few lines of code to prepare them. 

&lt;pre&gt;
do { 
  $query1=prepare_stuff()
  if(mysql_query($query1)){
    break;
  }
  $query2=prepare_stuff()
  if(mysql_query($query2)){
    break; 
  // etc. 
while(FALSE);
&lt;/pre&gt;

&lt;p&gt;The preparation code is kept closest to where it is used, making the code easier to read in this case. If &lt;tt&gt;if-else&lt;/tt&gt; had been used, all of the preparation code would have been at the top in one big chunk.</description>
  <comments>http://tangaroa.livejournal.com/349232.html</comments>
  <lj:music>Queensryche - Walk in the Shadows</lj:music>
  <media:title type="plain">Queensryche - Walk in the Shadows</media:title>
  <lj:mood>tired</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/349088.html</guid>
  <pubDate>Thu, 04 Jun 2009 02:32:41 GMT</pubDate>
  <title>It&apos;s conservative head explodey time</title>
  <link>http://tangaroa.livejournal.com/349088.html</link>
  <description>&lt;p&gt;Via Olbermann: &lt;a href=&quot;http://www.cnn.com/2009/CRIME/06/02/new.york.robber.mercy/index.html?eref=rss_topstories&quot;&gt;An armed shopkeeper foiled a robbery!&lt;/a&gt; Score one for self defense. Then he converted the robber to Islam. Wait, what? Righty heads go bewm!
&lt;hr /&gt;
&lt;p&gt;And this one will confuse the conservapedia set: &lt;a href=&quot;http://dsc.discovery.com/news/2009/06/02/chimpanzee-tool-kit-02.html&quot;&gt;chimpanzees use five distinct wooden tools to collect honey from beehives.&lt;/a&gt;</description>
  <comments>http://tangaroa.livejournal.com/349088.html</comments>
  <lj:music>Natalie Merchant - Wonder</lj:music>
  <media:title type="plain">Natalie Merchant - Wonder</media:title>
  <lj:mood>blah</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/348924.html</guid>
  <pubDate>Mon, 01 Jun 2009 02:42:58 GMT</pubDate>
  <title>Manga is mainstream</title>
  <link>http://tangaroa.livejournal.com/348924.html</link>
  <description>&lt;a href=&quot;http://www.animenewsnetwork.com/news/2009-05-29/new-york-times-manga-best-seller-list-may-17-23&quot;&gt;The New York Times has a bestseller list for manga.&lt;/a&gt;</description>
  <comments>http://tangaroa.livejournal.com/348924.html</comments>
  <lj:music>The Hellen Kellers - Not Going Home</lj:music>
  <media:title type="plain">The Hellen Kellers - Not Going Home</media:title>
  <lj:mood>geeky</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/348634.html</guid>
  <pubDate>Sun, 31 May 2009 05:01:58 GMT</pubDate>
  <title>Achievement Unlocked!</title>
  <link>http://tangaroa.livejournal.com/348634.html</link>
  <description>&lt;img src=&quot;http://farm4.static.flickr.com/3388/3580800958_4df86cf05b_o.png&quot; alt=&quot;Banned from Crooks and Liars&quot; /&gt;</description>
  <comments>http://tangaroa.livejournal.com/348634.html</comments>
  <lj:music>The Moody Blues - I&apos;m Just A Singer</lj:music>
  <media:title type="plain">The Moody Blues - I&apos;m Just A Singer</media:title>
  <lj:mood>discontent</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>5</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/348322.html</guid>
  <pubDate>Sat, 30 May 2009 22:04:13 GMT</pubDate>
  <title>Second opinion, or &quot;album bands&quot; vs &quot;live bands&quot;</title>
  <link>http://tangaroa.livejournal.com/348322.html</link>
  <description>&lt;p&gt;I recently went to a rock concert of several different local
bands and came away with bad feelings about it. It wasn&apos;t that the bands
sucked but that they all sucked in the exact same way. It was all bad
thrash metal. The singers screamed incoherently, the guitars ran together
into a cacophonic mesh instead of complementing each other, and the drums 
pounded over everything.

&lt;p&gt;The organizers gave out sampler CDs as I left. The bands on the CD are
&lt;em&gt;different&lt;/em&gt; from what I heard at the concert. There are &lt;em&gt;melodies&lt;/em&gt;.
Some of the same songs are actually soft.

&lt;p&gt;It makes me wonder if the amplifiers ruined the concert. I&apos;ve heard of the
&quot;loudness war&quot; affecting the quality of recorded and computerized music formats.
Might any audiophiles reading this know if the same effect applies to live analog
music?</description>
  <comments>http://tangaroa.livejournal.com/348322.html</comments>
  <lj:music>Attila and Dave Project - Smoke and Mirrors</lj:music>
  <media:title type="plain">Attila and Dave Project - Smoke and Mirrors</media:title>
  <lj:mood>tired</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>7</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/348084.html</guid>
  <pubDate>Tue, 26 May 2009 01:19:54 GMT</pubDate>
  <title>Timeslayer of the nonce</title>
  <link>http://tangaroa.livejournal.com/348084.html</link>
  <description>&lt;a href=&quot;http://www.newgrounds.com/portal/view/486811&quot;&gt;Hex Empire&lt;/a&gt;</description>
  <comments>http://tangaroa.livejournal.com/348084.html</comments>
  <lj:music>Ringo Starr - It Don&apos;t Come Easy</lj:music>
  <media:title type="plain">Ringo Starr - It Don&apos;t Come Easy</media:title>
  <lj:mood>tired</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://tangaroa.livejournal.com/347657.html</guid>
  <pubDate>Tue, 26 May 2009 00:12:33 GMT</pubDate>
  <title>Hariri investigation points to Hezbollah</title>
  <link>http://tangaroa.livejournal.com/347657.html</link>
  <description>&lt;p&gt;&lt;a href=&quot;http://www.spiegel.de/international/world/0,1518,626412,00.html&quot;&gt;A UN investigation has produced evidence strongly connecting Hezbollah
to the assassination of prominent Lebanese politician Rafik Hariri,
but was keeping the information secret until someone leaked it to
Der Speigel.&lt;/a&gt; Lebanon has an election in about two weeks. One would think
this information might be important for the voters to know. Also, Syria deserves an apology for being blamed earlier if they had nothing to do with it.&lt;/p&gt;</description>
  <comments>http://tangaroa.livejournal.com/347657.html</comments>
  <lj:music>Modest Mouse - Float On</lj:music>
  <media:title type="plain">Modest Mouse - Float On</media:title>
  <lj:mood>tired</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
</channel>
</rss>
