<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
 xmlns:blogChannel="http://backend.userland.com/blogChannelModule"
 xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
 xmlns:content="http://purl.org/rss/1.0/modules/content/"
 xmlns:atom="http://www.w3.org/2005/Atom"
 xmlns:dcterms="http://purl.org/dc/terms/"
>

<channel>
<title></title>
<link>http://www.shlomifish.org/me/blogs/</link>
<description></description>

<item>
<title>A Perl-based &#x2192;with(...) method</title>
<link>http://community.livejournal.com/shlomif_tech/46303.html</link>
<description>&#x3C;p&#x3E;
Lately, I&#x27;ve been writing some &#x3C;a href=&#x22;http://pdl.perl.org/&#x22;&#x3E;PDL (Perl Data
Language)&#x3C;/a&#x3E; code and noticed that I&#x27;ve been doing the following:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
my $temp_pdl = $pdl-&#x26;gt;&#x2026;-&#x26;gt;final_expr();
my $result_pdl = $temp_pdl-&#x26;gt;where($temp_pdl &#x26;lt; 0);
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
I&#x27;ve been thinking if I could somehow write it like that:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
my $result_pdl = $pdl-&#x26;gt;&#x2026;-&#x26;gt;final_expr()-&#x26;gt;with(sub { $_-&#x26;gt;where($_ &#x26;gt; 0)});
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
Which seems cleaner and more elegant. I went on IRC asking about it and someone
suggested 
&#x3C;tt&#x3E;rindolf: (sub { local $_ = shift; $_ * $_ * $_})-gt;( $obj-&#x26;gt;... );&#x3C;/tt&#x3E; 
(up to an episolon, but naturally this reverses the order and messes with
the flow of the code). Eventually 
&#x3C;a href=&#x22;http://www.shadowcat.co.uk/blog/matt-s-trout/&#x22;&#x3E;Matt S. 
Trout (mst)&#x3C;/a&#x3E; proposed the following solutions:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
sub UNIVERSAL::with
{
    local $_ = shift;
    my $sub = shift;
    return $sub-&#x26;gt;($_,@_);
}

my $_with = sub {
    local $_ = shift;
    my $sub = shift;
    return $sub-&#x26;gt;($_,@_);
};

&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
(I had figured something like that was possible previously, but I was beating
around the bush.)
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
The $_with approach is covered in &#x3C;a href=&#x22;http://www.shadowcat.co.uk/blog/matt-s-trout/madness-with-methods/&#x22;&#x3E;one of Matt&#x27;s blog posts titled &#x22;Madness with
Methods&#x22;&#x3C;/a&#x3E;.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I wondered if it will work with 
&#x3C;a href=&#x22;http://search.cpan.org/dist/autobox/&#x22;&#x3E;autobox&#x3C;/a&#x3E; and mst said that
&#x3C;q&#x3E;I don&#x27;t know and I hope not since the UNIVERSAL approach is evil.&#x3C;/q&#x3E;. But
it does, out-of-the-box:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
#!/usr/bin/perl

use strict;
use warnings;

use autobox;

sub UNIVERSAL::with
{
    local $_ = shift;
    my $sub = shift;
    return $sub-&#x26;gt;($_,@_);
}

my $_with = sub {
    local $_ = shift;
    my $sub = shift;
    return $sub-&#x26;gt;($_,@_);
};

print +(10+1)-&#x26;gt;with(sub { $_ * $_; }), &#x26;quot;\n&#x26;quot;;
print +(10+1)-&#x26;gt;$_with(sub { $_ * $_; }), &#x26;quot;\n&#x26;quot;;
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
This prints 121 twice.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I now wonder what to do with this knowledge. I have some aspirations of
releasing it to the cpan as a mini-module. Still, it&#x27;s really cool.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Finally, I should note that it seems like I&#x27;m going to lose my current
Planet Perl Iron Man karma due to inadequate blogging. Oh well.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>perl</category>
<category>fun</category>
<comments>http://community.livejournal.com/shlomif_tech/46303.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/46303.html</guid>
<pubDate>Mon, 01 Mar 2010 17:22:55 GMT</pubDate>
</item>
<item>
<title>Review: Alternative (to Firefox) Linux Web Browsers</title>
<link>http://community.livejournal.com/shlomif_tech/46078.html</link>
<description>&#x3C;p&#x3E;
Since I&#x27;ve been blogging about &#x3C;a href=&#x22;http://perl-begin.org/&#x22;&#x3E;Perl&#x3C;/a&#x3E;
a lot lately (trying to maintain and advance my
&#x3C;a href=&#x22;http://ironman.enlightenedperl.org/&#x22;&#x3E;Planet Perl Iron Man&#x3C;/a&#x3E;
status), I&#x27;ve been neglecting to blog about other things. So here&#x27;s a
new entry not about Perl, not even about programming - but about web-browsers.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I&#x27;ve been using Firefox (now at version 3.6) as my primary browser on my
Mandriva Linux Cooker system for a while now, and have been mostly happy
with it. Today I wanted to edit 
&#x3C;a href=&#x22;http://en.wikibooks.org/wiki/How_to_Write_a_Program&#x22;&#x3E;this wikibook
titled &#x22;How to Write a Program&#x22;&#x3C;/a&#x3E;. It had been written awfully
(see &#x3C;a href=&#x22;http://en.wikibooks.org/wiki/Talk:How_to_Write_a_Program&#x22;&#x3E;the
discussion page&#x3C;/a&#x3E;), but I was introduced to it after it was made 
&#x3C;a href=&#x22;http://en.wikibooks.org/wiki/Optimizing_Code_for_Speed&#x22;&#x3E;a 
prerquisite of a different wikibook which I&#x27;ve written&#x3C;/a&#x3E;, and decided 
that the dependency should be kept (assuming &#x22;How to Write a Program&#x22; would be 
written better). Now, I could either throw away &#x22;How to Write a Program&#x22;
and start from scratch, or revamp it to submission. Right now, it seems like
it would be a combination of both.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
In any case, after editing it, I&#x27;ve ran into a long-term 
&#x3C;a href=&#x22;https://qa.mandriva.com/show_bug.cgi?id=57864&#x22;&#x3E;bug in Mandriva, or
in my Mandriva setup&#x3C;/a&#x3E; (which is exhibited in any Firefox that is running 
directly on it.), which I&#x27;ve finally reported there (though I believe I had
reported it in the Firefox bugzilla too) and so had been unable to use Firefox
for it.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
So I&#x27;ve been looking for an alternative browser. I ruled out 
&#x3C;a href=&#x22;http://en.wikipedia.org/wiki/Konqueror&#x22;&#x3E;Konqueror&#x3C;/a&#x3E; because
KHTML has been suffering from a lot of bug report, and Konqueror is just
plain annoying. (WebKit has been forked from KHTML, and it proved to be
more popular.). I initially ruled out 
&#x3C;a href=&#x22;http://www.opera.com/&#x22;&#x3E;Opera&#x3C;/a&#x3E; because it&#x27;s not open-source. So
that left me only with WebKit-based browsers. I asked for recommendations
and people on &#x3C;a href=&#x22;irc://irc.freenode.net/#ubnutu-uk&#x22;&#x3E;#ubuntu-uk (great 
channel, BTW)&#x3C;/a&#x3E; recommended &#x3C;a href=&#x22;http://en.wikipedia.org/wiki/Chromium_%28web_browser%29&#x22;&#x3E;Chromium&#x3C;/a&#x3E; and
&#x3C;a href=&#x22;http://en.wikipedia.org/wiki/Epiphany_%28web_browser%29&#x22;&#x3E;GNOME&#x27;s
Epiphany&#x3C;/a&#x3E;, and some other more obscure browsers. I&#x27;ve decided to check them
out.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I decided to go with 
&#x3C;a href=&#x22;http://en.wikipedia.org/wiki/SRWare_Iron&#x22;&#x3E;SRWare Iron&#x3C;/a&#x3E; as
my Chromium browser. The first thing I noticed was that the Linux download
link led to a web forum post - very unprofessional. After downloading and
unpacking the archive, it refused to run -
&#x3C;tt&#x3E;/home/shlomi/apps/iron-linux/iron: error while loading shared libraries:
libbz2.so.1.0: cannot open shared object file: No such file or directory&#x3C;/tt&#x3E;.
A symbolic link to libbz2.so.1.0.0 (done by root) fixed that problem, and
then it crashed with an X error. However, it started the second time and seemed
to run fine (don&#x27;t know what the problem was). I noticed Chromium 
was indeed very fast, but then I ran into a few glitches:
&#x3C;/p&#x3E;

&#x3C;ul&#x3E;

&#x3C;li&#x3E;
No menu bar. WTF? All desktop applications, including web browsers had menu
bars for generations. And I&#x27;m used to invoke the File menu and select
&#x22;New Window&#x22; and &#x22;New Tab&#x22;. But Chromium does not have any menus, and it appears
to be by intentional design (but probably a crappy one).
&#x3C;/li&#x3E;

&#x3C;li&#x3E;
If this wasn&#x27;t enough, there was another more minor but still irritating
annoyance: after clicking on the URL bar and pressing double click, only
the current word is selected as opposed to the Firefox behaviour of selecting
the entire URL.
&#x3C;/li&#x3E;

&#x3C;/ul&#x3E;

&#x3C;p&#x3E;
So I decided to look at Epiphany. Slower than Chromium, but maybe it will
work. Or maybe it won&#x27;t. The first thing I noticed was that it looked 
ugly - very unaesthetic and several widgets in the main window were slightly 
out-of-place. Its URL bar also behaved unlike Firefox in the double click 
respect, which was also annoying.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
So what can I do? I eventually decided to use Opera for editing Wikimedia
wikis until the Firefox-influencing bug is resolved. It is fast, it has a 
menu bar, and double click in the URL bar selects the entire URL. Very nice.
It&#x27;s not open-source, so I&#x27;m trying not to get myself used to it, but seems
like I&#x27;ll need to use it.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
If you haven&#x27;t done so already, I suggest you read 
&#x3C;a href=&#x22;http://www.joelonsoftware.com/navLinks/fog0000000262.html&#x22;&#x3E;the 
&#x22;Joel on Software&#x22; &#x22;must-read&#x22; books recommendations page&#x3C;/a&#x3E;. I haven&#x27;t read
all the books there, but the page itself is also good. Quoting from it from 
our context:
&#x3C;/p&#x3E;

&#x3C;blockquote&#x3E;

&#x3C;p&#x3E;
A few months ago when we released CityDesk, I got an email from a customer
complaining that he was used to doing Alt+F, Alt+S to save files. Unfortunately
due to a tiny, unnoticed bug, that keyboard shortcut saved the file and then
closed it, irritatingly. I had never noticed because I&#x27;m in the habit of doing
Alt+F,S to save files, not Alt+F,Alt+S -- a tiny difference -- and Alt+F,S
worked fine.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Once you get into the habit of doing Alt+F,Alt+S to save, it becomes so
automatic you don&#x27;t think of it as Alt+F,Alt+S. You think of it as save. And
when you push the &#x22;save&#x22; button in your brain and the file you were working on
goes away, it makes you feel like you&#x27;re not in control of your environment.
It&#x27;s a small thing, but about the fourth time that it happens, you&#x27;re going to
be seriously unhappy. That&#x27;s why I spent several hours tracking down this bug
and fixing it. In a bizarre application of Murphy&#x27;s Law, this fix led to a
cascade of events that caused us to waste something like a week, but that&#x27;s
neither here nor there. It was worth the time spent. This is what it means to
be concerned about usability. If you still think that something as small as how
long you hold down the Alt key when you activate a menu command doesn&#x27;t matter,
well, your software is going to make people unhappy. These tiny inconsistencies
are what makes Swing applications so unbearably annoying to use, and in my
opinion it&#x27;s why there are virtually no commercially successful Java GUI
applications.
&#x3C;/p&#x3E;
&#x3C;/blockquote&#x3E;

&#x3C;p&#x3E;
If I can&#x27;t go to &#x22;File &#x2192; New Tab&#x22; in the menubar to start a new tab then I&#x27;m
going to be unhappy. If I have to triple click the URL bar in order to select 
the entire URL, then I&#x27;m going to be unhappy. These tiny things are why I can&#x27;t
use either Chromium or Epiphany. (And frankly, a lack of a menubar is a huge
UI screw-up, not a tiny one).
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
At the moment, I&#x27;m just ranting, but I am planning on reporting these bugs
to the bug trackers of the appropriate projects. I just hope Google won&#x27;t
think the lack of menu-bar in Chromium is a feature. &#x22;Welcome to Google UIs&#x22;.
(Welcome to Google Hell&#x2026;).
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>web browser</category>
<category>firefox</category>
<category>open source</category>
<comments>http://community.livejournal.com/shlomif_tech/46078.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/46078.html</guid>
<pubDate>Thu, 25 Feb 2010 21:21:42 GMT</pubDate>
</item>
<item>
<title>New Perl Quiz-of-the-Whatever: Short Freecell Solutions</title>
<link>http://community.livejournal.com/shlomif_tech/45610.html</link>
<description>&#x3C;p&#x3E;
I published a new
&#x3C;a href=&#x22;http://article.gmane.org/gmane.comp.lang.perl.qotw.discuss/2655&#x22;&#x3E;Perl 
Quiz-of-the-Whatever about finding short Freecell solutions&#x3C;/a&#x3E;. Hope you enjoy
thinking about it. Here is the &#x3C;a href=&#x22;http://perl.plover.com/qotw/&#x22;&#x3E;Perl
Quiz-of-the-Whatever (formerly &#x22;Quiz of the Week&#x22;) information.&#x3C;/a&#x3E;.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>perl</category>
<category>fc-solve</category>
<category>freecell</category>
<comments>http://community.livejournal.com/shlomif_tech/45610.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/45610.html</guid>
<pubDate>Mon, 22 Feb 2010 21:57:30 GMT</pubDate>
</item>
<item>
<title>Solving gaal&#x27;s Circuit Riddle Using Perl</title>
<link>http://community.livejournal.com/shlomif_tech/45409.html</link>
<description>&#x3C;p&#x3E;
&#x3C;a href=&#x22;http://gaal.livejournal.com/234795.html&#x22;&#x3E;gaal (= Gaal Yahas)
mentions a riddle&#x3C;/a&#x3E; on his blog:
&#x3C;/p&#x3E;

&#x3C;blockquote&#x3E;
&#x3C;p&#x3E;
There&#x2019;s a box with three input signals: A, B, C. It has three output signals:
~A, ~B, ~C (that is, the negation of each input).
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Design a circuit satisfying the above description. You have two NOT gates, and
as many AND and OR gates as you like.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
(If you solve this, don&#x2019;t tell me the answer &#x2014; I haven&#x2019;t solved it yet; I just
want to share the misery.)
&#x3C;/p&#x3E;
&#x3C;/blockquote&#x3E;

&#x3C;p&#x3E;
I decided that I will try to solve this riddle on my own
and then attempt to write a solution using a Perl 5 program, which I&#x27;ve
also thought about how to write. As it turned out, I ended up exploring
and eventually completely solving the riddle using a series of Perl programs.
I won&#x27;t mention the final solution here, but I&#x27;ll tell which programs
I wrote to solve them and how I wrote them. The code can be found in 
&#x3C;a href=&#x22;http://bitbucket.org/shlomif/riddle-not-a-not-b-not-c/src/&#x22;&#x3E;its
Mercurial repository&#x3C;/a&#x3E; under the MIT/X11 licence, as I mentioned
in &#x3C;a href=&#x22;http://gaal.livejournal.com/234795.html?thread=936235#t936235&#x22;&#x3E;a 
comment&#x3C;/a&#x3E; to gaal&#x27;s post.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Well, first of all I decided to write a program that will take two negated
expressions of AND and OR gates and see if one can arrive to the final solution
using them and the given inputs (A, B and C). To do this I represented every
such possible expression as its components of (A + ~A) &#xD7; (B + ~B) &#xD7; (C + ~C) - 
8 in total which fit in an 8-bit datum, and which I indexed using an array
of 256 items to see which ones exist in the population. After doing the coding
I realised none of the expressions I tried worked.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Then I decided to see if I there are any two possible expressions that when
added to A, B an C will yield all the necessary outputs. I ran it and indeed
found a single pair (and only a single pair) of such expressions (given as 
numbers) which I was able to analyse. I should note that the programs as 
I&#x27;ve written it using some functions and closures was too slow, so I ended
up writing another Perl script to preprocess the code, and inline the 
functions, which has made everything much faster. (You can find this 
preprocessor in the repository).
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Then I wanted to see if I can indeed construct these expressions from A
, B, and C using two negations. When I had thought about this, I believed
I needed to maintain a collection of expressions&#x27; populations, and to 
keep how many negations were in each. But when I got to code it I thought
of a simpler way: marry all the inputs using AND and OR until no more can
be married, then go over the existing ones and negate each one in turn, then
add the negated vector to the population and marry it with all the rest, and
then do it again for all the existing inputs. Using this I was able to
find a single solution.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Then I had to output the solution. For that, I wrote a recursive expression
dumper, which ended up outputting with many parentheses, so I had to post-
process it a bit.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
The solution I got to was very complicated and I believe it would have taken
me a long time to reach it without resorting to programming. But at least
it saved me a lot of time and head-scratching. 
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>perl</category>
<category>fun</category>
<comments>http://community.livejournal.com/shlomif_tech/45409.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/45409.html</guid>
<pubDate>Fri, 19 Feb 2010 13:28:13 GMT</pubDate>
</item>
<item>
<title>Article Recommendation: &#x22;What Every CSer Should Know about Floating-Point Arithmetic&#x22;</title>
<link>http://community.livejournal.com/shlomif_tech/45104.html</link>
<description>&#x3C;p&#x3E;
I&#x27;ve read the paper 
&#x3C;a href=&#x22;http://docs.sun.com/source/806-3568/ncg_goldberg.html&#x22;&#x3E;&#x22;What 
Every Computer Scientist Should Know About Floating-Point Arithmetic&#x22;&#x3C;/a&#x3E; and
can recommend it as it has many interesting insights. I had received quite a
lot of reports for bugs in 
&#x3C;a href=&#x22;http://search.cpan.org/dist/Statistics-Descriptive/&#x22;&#x3E;the
&#x22;Statistics-Descriptive&#x22; CPAN distribution&#x3C;/a&#x3E; that were caused by expected
floating-point behaviour. Some of them I was able to resolve using some
trickery, and some others possibly can be somewhat mitigated using the insights
I&#x27;ve learnt in the article.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>perl</category>
<category>recommendation</category>
<category>article</category>
<comments>http://community.livejournal.com/shlomif_tech/45104.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/45104.html</guid>
<pubDate>Thu, 11 Feb 2010 05:24:18 GMT</pubDate>
</item>
<item>
<title>NYTProf-3 is Out!</title>
<link>http://community.livejournal.com/shlomif_tech/44836.html</link>
<description>&#x3C;p&#x3E;
&#x3C;a href=&#x22;http://blog.timbunce.org/2009/12/24/nytprof-v3-worth-the-wait/&#x22;&#x3E;Tim
Bunce writes on his blog about the new features in 
Devel-NYTProf version 3&#x3C;/a&#x3E;. Devel-NYTProf is a profiler for the 
&#x3C;a href=&#x22;http://perl-begin.org/&#x22;&#x3E;Perl programming language&#x3C;/a&#x3E;, which has
put all the previous attempts in profiling in the dust, and now it&#x27;s even 
better than before. Enjoy! (Thanks to 
&#x3C;a href=&#x22;http://mail.pm.org/pipermail/sanfrancisco-pm/2010-February/002704.html&#x22;&#x3E;Fred 
Moyer&#x27;s post&#x3C;/a&#x3E; on the San-Fransisco Perl Mongers mailing list).
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>3</category>
<category>version</category>
<category>perl</category>
<category>profiler</category>
<category>release</category>
<category>nytprof</category>
<comments>http://community.livejournal.com/shlomif_tech/44836.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/44836.html</guid>
<pubDate>Fri, 05 Feb 2010 16:31:51 GMT</pubDate>
</item>
<item>
<title>New Page about Text Editors and IDEs for Programmers</title>
<link>http://community.livejournal.com/shlomif_tech/44605.html</link>
<description>&#x3C;p&#x3E;
After answering the questions &#x22;Can anyone recommend a good text editor?&#x22; and 
&#x22;What is a good IDE?&#x22; a few times in the past, I set up 
&#x3C;a href=&#x22;http://www.shlomifish.org/open-source/resources/editors-and-IDEs/&#x22;&#x3E;a
page listing some prominent text editors and Integrated Development
Environments (IDEs)&#x3C;/a&#x3E; for development on my homepage. Currently it includes
only cross-platform open-source text editors and cross-platform open-source
IDEs, but I&#x27;m planning to expand it as time and interest permits. Additions
would be welcome.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
&#x3C;a href=&#x22;http://www.vim.org/&#x22;&#x3E;Vim&#x3C;/a&#x3E; is there and so are XEmacs and
&#x3C;a href=&#x22;http://www.eclipse.org/&#x22;&#x3E;Eclipse&#x3C;/a&#x3E;, and also
&#x3C;a href=&#x22;http://padre.perlide.org/&#x22;&#x3E;Padre, the Perl IDE&#x3C;/a&#x3E; and more 
specialised IDEs such as &#x3C;a href=&#x22;http://eric-ide.python-projects.org/&#x22;&#x3E;the
&#x22;Eric&#x22; Python IDE&#x3C;/a&#x3E;.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<comments>http://community.livejournal.com/shlomif_tech/44605.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/44605.html</guid>
<pubDate>Tue, 02 Feb 2010 19:59:14 GMT</pubDate>
</item>
<item>
<title>&#x5E4;&#x5D2;&#x5D9;&#x5E9;&#x5EA; &#x5E7;&#x5D5;&#x5D3; &#x5E4;&#x5EA;&#x5D5;&#x5D7; &#x5D1;&#x5EA;&#x5DC;-&#x5D0;&#x5D1;&#x5D9;&#x5D1;: 14 &#x5D1;&#x5E4;&#x5D1;&#x5E8;&#x5D5;&#x5D0;&#x5E8; - vtiger CRM</title>
<link>http://community.livejournal.com/shlomif_tech/44385.html</link>
<description>&#x3C;div dir=&#x22;rtl&#x22; align=&#x22;right&#x22;&#x3E;

&#x3C;p&#x3E;
&#x3C;a href=&#x22;http://tel.foss.org.il/&#x22;&#x3E;&#x5DE;&#x5D5;&#x5E2;&#x5D3;&#x5D5;&#x5DF; &#x5D4;&#x5E7;&#x5D5;&#x5D3; &#x5D4;&#x5E4;&#x5EA;&#x5D5;&#x5D7; &#x5D4;&#x5EA;&#x5DC;-&#x5D0;&#x5D1;&#x5D9;&#x5D1;&#x5D9; (&#x5EA;&#x5DC;&#x5D5;&#x5E7;&#x5E1;)&#x3C;/a&#x3E;
&#x5D9;&#x5D9;&#x5E4;&#x5D2;&#x5E9; &#x5E9;&#x5D5;&#x5D1; &#x5DB;&#x5D3;&#x5D9; &#x5DC;&#x5E9;&#x5DE;&#x5D5;&#x5E2; &#x5D0;&#x5EA;
&#x3C;a href=&#x22;http://wiki.osdc.org.il/index.php/Tel_Aviv_Meeting_on_14_February_2010&#x22;&#x3E;&#x5D4;&#x5E8;&#x5E6;&#x5D0;&#x5EA;&#x5D5; &#x5E9;&#x5DC; 
&#x5E8;&#x5DE;&#x5D9; &#x5D4;&#x5D3;&#x5D3;&#x5D9; &#x5D0;&#x5D5;&#x5D3;&#x5D5;&#x5EA; &#x22;&#x5DE;&#x5E2;&#x5E8;&#x5DB;&#x5EA; &#x5E0;&#x5D9;&#x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5DD;.
&#x3C;/p&#x3E;

&#x3C;/div&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<comments>http://community.livejournal.com/shlomif_tech/44385.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/44385.html</guid>
<pubDate>Tue, 02 Feb 2010 18:47:42 GMT</pubDate>
</item>
<item>
<title>Escape from GNU Autohell!</title>
<link>http://community.livejournal.com/shlomif_tech/44103.html</link>
<description>&#x3C;p&#x3E;
I&#x27;ve set up &#x3C;a href=&#x22;http://www.shlomifish.org/open-source/anti/autohell/&#x22;&#x3E;a 
page on my web-site titled &#x22;Escape from GNU Autohell!&#x22;&#x3C;/a&#x3E; about the evils
of the GNU Autotools (GNU Autoconf/Automake/Libtool and other GNU 
auto-brain-damages) and why you should convert to a good alternative such as 
&#x3C;a href=&#x22;http://www.cmake.org/&#x22;&#x3E;CMake&#x3C;/a&#x3E;. The page contains a list of
the many disadvantages of the GNU Autotools, some refutation of common
arguments against CMake, and some links.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
And lo and behold, some time after writing the page I spent hours dealing
with yet another Autohell problem:
&#x3C;a href=&#x22;https://qa.mandriva.com/show_bug.cgi?id=57319&#x22;&#x3E;&#x22;Mandriva&#x27;s
libtool causes &#x22;make install&#x22; of xine-lib-1.1-hg to fail&#x22;&#x3C;/a&#x3E;. I actually
had to build the Mandriva libtool several times to find the offending
downstream patch, and libtool&#x27;s &#x22;./bootstrap&#x22; script was so slow that
I could finish running &#x22;make&#x22; and &#x22;make install&#x22; in xine-lib while waiting
for it to finish. And it says a lot because xine uses GNU Autohell
which slows down the build process considerably. Eventually, I found the
offending patch after several hours, and I wouldn&#x27;t have finished on time if I 
didn&#x27;t cancel the &#x22;make check&#x22; test in the .rpm.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Autohell must die!
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>rants</category>
<category>cmake</category>
<category>build</category>
<category>autohell</category>
<category>gnu</category>
<category>escape</category>
<category>rant</category>
<category>make</category>
<category>autotools</category>
<comments>http://community.livejournal.com/shlomif_tech/44103.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/44103.html</guid>
<pubDate>Sun, 31 Jan 2010 12:45:57 GMT</pubDate>
</item>
<item>
<title>Project Euler Problem #10 in Haskell, Perl and C</title>
<link>http://community.livejournal.com/shlomif_tech/44006.html</link>
<description>&#x3C;p&#x3E;
zerothorder told 
&#x3C;a href=&#x22;http://zerothorder.blogspot.com/2009/11/after-drinking-functional-immutable-and.html&#x22;&#x3E;how 
he found a solution for Project Euler&#x27;s Problem 10 in Haskell&#x3C;/a&#x3E;. The 
problem is &#x22;Find the sum of all primes less than 2,000,000&#x22;. It is given
here below:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
primes :: [Integer]
primes = 2 : filter isPrime [3, 5 ..]
    where
        -- only check divisibility of the numbers less than the square root of n
        isPrime n = all (not . divides n) $ takeWhile (\p -&#x26;gt; p*p &#x26;lt;= n) primes
        divides n p = n `mod` p == 0
 
result = sum $ takeWhile (&#x26;lt; 2000000) primes
 
main = do putStrLn( show result )
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
He says &#x22;If this doesn&#x27;t give you a nerdgasm, I don&#x27;t know what will.&#x22;. The
problem is that this nerdgasm will last a long time. Benchmarking this
program gives that 20 iterations of it run at 310 seconds - less
than - about 15 seconds each (on my Pentium 4 2.4GHz machine running
Mandriva Linux Cooker). So next I tried a better Haskell
implmenetation that I recalled from a thread I started in the Haskell Caf&#xE9;
mailing list about implementing
&#x3C;a href=&#x22;http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes&#x22;&#x3E;a sieve of
Eratosthenes in Haskell&#x3C;/a&#x3E;:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
import Data.Int

primes :: Int64 -&#x26;gt; [Int64]

primes how_much = sieve [2..how_much] where
         sieve (p:x) = 
             p : (if p &#x26;lt;= mybound
                 then sieve (remove (p*p) x)
                 else x) where
             remove what (a:as) | what &#x26;gt; how_much = (a:as)
                                | a &#x26;lt; what = a:(remove what as)
                                | a == what = (remove (what+step) as)
                                | a &#x26;gt; what = a:(remove (what+step) as)
             remove what [] = []
             step = (if (p == 2) then p else (2*p)) 
         sieve [] = []
         mybound = ceiling(sqrt(fromIntegral how_much))

--main = print (length (primes 1000000))
main = print (sum (primes 2000000))
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
This does not involve costly operations such as modulo or division
and 20 iterations of it run at 135 wallclocks seconds - over two times faster
than zeroth&#x27;s Haskell version.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Now how about Perl? Since Perl has assignment, we have the advantage that
we can create a vector of bits that we will mark with the primes by iterating
over all numbers up to the root of the limit. Here is the code:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
#!/usr/bin/perl

use strict;
use warnings;

use Math::BigInt lib =&#x26;gt; &#x26;#39;GMP&#x26;#39;;

my $limit = 2_000_000;

my $primes_bitmask = &#x26;quot;&#x26;quot;;

my $loop_to = int(sqrt($limit));
my $sum = 0;
my $total_sum = Math::BigInt-&#x26;gt;new(&#x26;#39;0&#x26;#39;);

for my $p (2 .. $loop_to)
{
    if (vec($primes_bitmask, $p, 1) == 0)
    {
        $sum += $p;

        my $i = $p * $p;

        while ($i &#x26;lt; $limit)
        {
            vec($primes_bitmask, $i, 1) = 1;
        }
        continue
        {
            $i += $p;
        }

    }
}

for my $p ($loop_to .. $limit)
{
    if (vec($primes_bitmask, $p, 1) == 0)
    {
        if (($sum += $p) &#x26;gt; (1 &#x26;lt;&#x26;lt; 30))
        {
            $total_sum += $sum;
            $sum = 0;
        }
    }
}

$total_sum += $sum;
print &#x26;quot;$total_sum\n&#x26;quot;;
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
20 runs of it run at 95 walclock seconds - even faster than the Haskell
version. But it gets better. Since all the primes we encounter greater than
2 are not even, we can create a map of their pseduo-halves and conserve on
memory and iterations. This is the Perl version:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
#!/usr/bin/perl

use strict;
use warnings;

use Math::BigInt lib =&#x26;gt; &#x26;#39;GMP&#x26;#39;;

my $limit = 2_000_000;

my $primes_bitmask = &#x26;quot;&#x26;quot;;

my $loop_to = (int(sqrt($limit)))&#x26;gt;&#x26;gt;1;
my $half_limit = ($limit-1)&#x26;gt;&#x26;gt;1;

my $sum = 0+2;
my $total_sum = Math::BigInt-&#x26;gt;new(&#x26;#39;0&#x26;#39;);

for my $half (1 .. $loop_to)
{
    if (vec($primes_bitmask, $half, 1) == 0)
    {
        my $p = (($half&#x26;lt;&#x26;lt;1)+1);
        $sum += $p;

        my $i = ($p * $p)&#x26;gt;&#x26;gt;1;

        while ($i &#x26;lt; $limit)
        {
            vec($primes_bitmask, $i, 1) = 1;
        }
        continue
        {
            $i += $p;
        }

    }
}


for my $half ($loop_to .. $half_limit)
{
    if (vec($primes_bitmask, $half, 1) == 0)
    {
        if (($sum += (($half&#x26;lt;&#x26;lt;1)+1)) &#x26;gt; (1 &#x26;lt;&#x26;lt; 30))
        {
            $total_sum += $sum;
            $sum = 0;
        }
    }
}

$total_sum += $sum;
print &#x26;quot;$total_sum\n&#x26;quot;;
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
Running this 20 times takes 73 wallclock seconds, close to half that of my
Haskell version.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Then I wondered how long C will take. Here is a C implementation without
the halving:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
#include &#x26;lt;string.h&#x26;gt;
#include &#x26;lt;math.h&#x26;gt;
#include &#x26;lt;stdint.h&#x26;gt;
#include &#x26;lt;stdio.h&#x26;gt;

#define limit 2000000
int8_t bitmask[(limit+1)/8];

int main(int argc, char * argv[])
{
    int p, i;
    int mark_limit;
    long long sum = 0;

    memset(bitmask, &#x26;#39;\0&#x26;#39;, sizeof(bitmask));
    mark_limit = (int)sqrt(limit);
    
    for (p=2 ; p &#x26;lt;= mark_limit ; p++)
    {
        if (! ( bitmask[p&#x26;gt;&#x26;gt;3]&#x26;amp;(1 &#x26;lt;&#x26;lt; (p&#x26;amp;(8-1))) ) )
        {
            /* It is a prime. */
            sum += p;
            for (i=p*p;i&#x26;lt;=limit;i+=p)
            {
                bitmask[i&#x26;gt;&#x26;gt;3] |= (1 &#x26;lt;&#x26;lt; (i&#x26;amp;(8-1)));
            }
        }
    }
    for (; p &#x26;lt;= limit; p++)
    {
        if (! ( bitmask[p&#x26;gt;&#x26;gt;3]&#x26;amp;(1 &#x26;lt;&#x26;lt; (p&#x26;amp;(8-1))) ) )
        {
            sum += p;
        }
    }

    printf(&#x26;quot;%lli\n&#x26;quot;, sum);

    return 0;
}
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
This was too fast to measure with 20 runs alone, so 500 runs of it took 15
seconds, two or three orders of magnitude faster than the fastest Haskell
or Perl versions. But naturally, we can apply the halving paradigm there too:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
#include &#x26;lt;string.h&#x26;gt;
#include &#x26;lt;math.h&#x26;gt;
#include &#x26;lt;stdint.h&#x26;gt;
#include &#x26;lt;stdio.h&#x26;gt;

#define limit 2000000
int8_t bitmask[(limit+1)/8/2];

int main(int argc, char * argv[])
{
    int half, p, i;
    int half_limit;
    int loop_to;
    long long sum = 0 + 2;

    memset(bitmask, &#x26;#39;\0&#x26;#39;, sizeof(bitmask));

    loop_to=(((int)(sqrt(limit)))&#x26;gt;&#x26;gt;1);
    half_limit = (limit-1)&#x26;gt;&#x26;gt;1;
    
    for (half=1 ; half &#x26;lt;= loop_to ; half++)
    {
        if (! ( bitmask[half&#x26;gt;&#x26;gt;3]&#x26;amp;(1 &#x26;lt;&#x26;lt; (half&#x26;amp;(8-1))) ) )
        {
            /* It is a prime. */
            p = (half &#x26;lt;&#x26;lt; 1)+1;
            sum += p;
            for (i = ((p*p)&#x26;gt;&#x26;gt;1) ; i &#x26;lt; half_limit ; i+=p )
            {
                bitmask[i&#x26;gt;&#x26;gt;3] |= (1 &#x26;lt;&#x26;lt; (i&#x26;amp;(8-1)));
            }
        }
    }

    for( ; half &#x26;lt; half_limit ; half++)
    {
        if (! ( bitmask[half&#x26;gt;&#x26;gt;3]&#x26;amp;(1 &#x26;lt;&#x26;lt; (half&#x26;amp;(8-1))) ) )
        {
            sum += (half&#x26;lt;&#x26;lt;1)+1;
        }
    }

    printf(&#x26;quot;%lli\n&#x26;quot;, sum);

    return 0;
}
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
500 runs of it take 10 wallclock seconds - 54.35 times per second,
and 50% better than the previous C version. And I still haven&#x27;t applied
platform-specific gcc optimisations. 
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I should also note that the executables generated by ghc are extremely
large in comparison to their C ones:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
$ ls -l c_* haskell_*
-rwxr-xr-x 1 shlomi shlomi   6082 2009-12-04 07:46 c_mine
-rwxr-xr-x 1 shlomi shlomi   6103 2009-12-04 07:46 c_mine_half
-rwxr-xr-x 1 shlomi shlomi   6092 2009-12-04 07:46 c_mine_micro_opt
-rwxr-xr-x 1 shlomi shlomi 796825 2009-12-04 07:56 haskell_mine
-rwxr-xr-x 1 shlomi shlomi 571717 2009-12-04 07:46 haskell_zeroth
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
&#x3C;tt&#x3E;c_mine_half&#x3C;/tt&#x3E; is less than 1% the size of &#x3C;tt&#x3E;haskell_mine&#x3C;/tt&#x3E; (and
runs faster). When talking about this to other people, they said that Haskell
has a very optimised primes sequence generator, which I can try using (which
should be over 3 times as fast), and that it has two kinds of integers, which
the other type is faster, and that it has a better way to emulate assignment.
But the bottom line is that the na&#xEF;ve and intuitive way to write such
programs in Haskell is under-performant, even in comparison to Perl, and 100
or 1,000 times as much in comparison to C.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I&#x27;ve written this as a separate post and not as a comment to the original
blog post because I&#x27;m very limited with the markup in the commenting there
(I&#x27;m going to post a comment there with a link to this blog post, though). 
I should note that you can find all the code I mentioned inside 
&#x3C;a href=&#x22;http://github.com/shlomif/Project-Euler-Problem-10-Comparison&#x22;&#x3E;a
dedicated Github repository&#x3C;/a&#x3E;, and you can experiment with it further.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>problem</category>
<category>summary</category>
<category>primes</category>
<category>project</category>
<category>optimize</category>
<category>optimise</category>
<category>optimization</category>
<category>c</category>
<category>haskell</category>
<category>perl</category>
<category>10</category>
<category>speed</category>
<category>optimisation</category>
<category>euler</category>
<comments>http://community.livejournal.com/shlomif_tech/44006.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/44006.html</guid>
<pubDate>Sat, 30 Jan 2010 12:50:07 GMT</pubDate>
</item>
</channel>
</rss>