<?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>weblob.net</title>
	<atom:link href="http://www.weblob.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weblob.net</link>
	<description>World WiSe Web</description>
	<lastBuildDate>Mon, 23 Apr 2012 14:03:59 +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>Haxe 2.09 &#8211; WWX 2012</title>
		<link>http://www.weblob.net/2012/haxe-2-09-wwx-2012/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=haxe-2-09-wwx-2012</link>
		<comments>http://www.weblob.net/2012/haxe-2-09-wwx-2012/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 14:03:59 +0000</pubDate>
		<dc:creator>franco</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[wwx]]></category>

		<guid isPermaLink="false">http://www.weblob.net/?p=83</guid>
		<description><![CDATA[It was really a great pleasure to attend the WWX 2012 in Paris. The talks were extremely interesting and they really showed how much the community is growing. Several factors are contributing to that growth and I am pretty sure &#8230;<p class="read-more"><a href="http://www.weblob.net/2012/haxe-2-09-wwx-2012/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>It was really a great pleasure to attend the <a href="http://wwx.haxe.org/">WWX 2012 in Paris</a>. The talks were extremely interesting and they really showed how much the community is growing. Several factors are contributing to that growth and I am pretty sure that one of these is the amazing development that <a href="http://www.haxenme.org/">NME</a> is living and the features that it offers in the mobile department.</p>
<p>The conference was also an occasion for announcements like the new formal spelling of &#8220;Haxe&#8221; (no more &#8220;haXe&#8221;). And of course the new <a href="http://haxe.org/download">Haxe 2.09</a> that is, in my opinion, one of the best releases ever. Here is my 2 cents about why I like this release so much.</p>
<h2>Haxe compiler service</h2>
<p>The idea of the Haxe compiler service is really simple. Instead of restarting the compilation process (and the compiler boot strap) on each execution, the compiler is always active in a service waiting for some code to be compiled. It go further than that (otherwise the difference in performances would be minimal), it also keeps cached in memory the intermediate states of the compilation updating only the portions that are subjects to modifications.</p>
<p>My personal benchamarks show the following (after the first run):</p>
<table>
<tbody>
<tr>
<th>project</th>
<th>standard compilation</th>
<th>compilation service</th>
</tr>
<tr>
<td>utest test cases (neko)</td>
<td>310ms (w/o generation 210ms)</td>
<td>110s (w/o generation 10ms)</td>
</tr>
<tr>
<td>ReportGrid charts (js)</td>
<td>720ms (w/o generation 590ms)</td>
<td>490s (w/o generation 360ms)</td>
</tr>
</tbody>
</table>
<p>Since the compiler was already very fast, what really makes this feature stand out is that it accelerates auto-completion through <a href="http://ncannasse.fr/blog/haxe_completion">-display</a> considerably. I&#8217;ve not tested it myself but Nicolas claims x10 faster performances. FlashDevelop is the only IDE so far having adopted this feature transparently but it is not yet in an official build. You can still use it by launching the service this way:</p>
<pre>haxe --wait 888</pre>
<p>(add <code>-v</code> if you want more detailed information)</p>
<p>And compile you project this way:</p>
<pre>haxe --connect 888 build.hxml</pre>
<p>Of course you can customize the host/port number and the .hxml file.</p>
<h2>JS Improvements</h2>
<p>The first most impressive improvement in the JavaScript target is certainly the introduction of <code>--js-modern</code> and the consequent removal of <code>--js-namespace</code>. The new command option enclose the generated code into a closure that prevent the pollution of the global object with all the types defined in your application. Beside that, it adds the <a href="http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/">&#8220;strict mode&#8221;</a> directive that can potentially enhance performances in some JavaScript contexts. Also the way that fields are now written in the generated output are more human friendly than before.<br />
Besides the new output works wonder with <a href="https://developers.google.com/closure/compiler/">Google Closure Compiler</a>:</p>
<table>
<tbody>
<tr>
<th>project</th>
<th>plain</th>
<th>DCE</th>
<th>DCE + Closure Compiler</th>
</tr>
<tr>
<td>ReportGrid charts</td>
<td>918kb</td>
<td>748kb</td>
<td>569kb</td>
</tr>
<tr>
<td>ReportGrid charts w/ &#8211;js-modern</td>
<td>924kb</td>
<td>755kb</td>
<td>483kb</td>
</tr>
</tbody>
</table>
<p>Then there is the new <code>-debug</code> implementation. What it does is mapping the source Haxe code to the JavaScript output using a <a href="http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/">source mapping</a> file. In the browsers that support this very new feature (Chrome so far) you will be able to debug your application directly in Haxe instead of in JavaScript. That means being able to set breakpoints, inspect variable values and call stacks directly in the Haxe code.</p>
<h2>revamped Dead Code Elimination (DCE)</h2>
<p>My first implementation of DCE had issues under certain conditions. Nicolas took over and revamped it completely making it a lot, lot better.<br />
Using DCE you always have to use some care preventing that portions of the code you are using in your app are not removed by accident. For example if you create an instance by using reflection and the class name, then DCE is probably going to remove that class entirely since its typing is never encountered in the code flow. To avoid that to happen you must use <code>@:expose</code> meta tag at either the type level or at the method level.</p>
<h2>Anonymous Objects</h2>
<p>The anonymous objects have seen two major improvements, the first is the possibility to use quoted fields to be able to use special characters in your field name and the addition of the optional fields.<br />
The first is very important because now you can simply copy and paste some Json object in your code without having to worry about stripping the quotes. To access the fields with special characters you still need to use reflection.<br />
The optional fields are really powerful for &#8220;option objects&#8221; (pretty common in the JS world) where you want to be able to define a set of key/value pairs without the need of specifying all of them.<br />
Note that this feature only applies to constant struct, for that reason you can do this:</p>
<pre>// assuming that the type of the argument of 'create' is : { ?x : Int, ?y : Int, ?r : Int }
 create({ x : 10, y : 7, r : 4 });
 create({ x : 20, r : 5 });
 create({});</pre>
<p>but you cannot do this:</p>
<pre>var options = opt(); // where opt is a function returning { x : 20, r : 5 };
create(options); // doesn't compile because not all the fields of options match the signature of the options argument</pre>
<h2>Unification of Classes</h2>
<p>When Haxe was really young there was only one platform (neko) that was capable of accessing the system platform. With the proliferation of the new targets and the expanded possibilities to use the existing ones in different contexts, more and more implementations of the same functionalities have been spreaded over different package names (mainly neko, php and cpp). In Haxe 3 the platform specific API for these will be gone and they will be unified; in 2.09 the types have been already moved to their final destination but shortcuts were left so that the existing code doesn&#8217;t break.<br />
The modules affected by these changes are:</p>
<pre>Sys (was neko.Sys/php.Sys/cpp.Sys)
sys.FileStat
sys.FileSystem
sys.db.*
sys.io.*
sys.net.*</pre>
<p>In <a href="https://github.com/fponticelli/thx">thx</a> there were already shortcuts to avoid platform specific packages and I guess I will have to remove them now.</p>
<h2>Std.format</h2>
<p>This tiny macro is a huge time saver that allows you to simplify things like this:</p>
<pre>var s = "Hi "+name+" "+lastname+", your score is "+score;</pre>
<p>to this:</p>
<pre>var s = Std.format("Hi $name $lastname, your score is $score");</pre>
<p>A lot more readable and starting with Haxe 3 it will be applied automatically to all the string definitions compacting the above to:</p>
<pre>var s = "Hi $name $lastname, your score is $score";</pre>
<p>You can use any Haxe expression inside the string, but if it is more complex than a simple identifier you will have to use the curly brackets format:</p>
<pre>Std.format("list length: ${list.length}")</pre>
<h2>std package for root package</h2>
<p>In rare occasions you might have experienced conflicts between types with the same name but that existed in the root package and in a sub-package. Suppose that you have a class <code>def.Type</code> referenced in your code and in the same code you want also to use the type <code>Type</code>. The only way to make that happen would be to create a typedef alias to Type but now you can instead just use <code>std.Type</code>.</p>
<h2>haxe.Utf8</h2>
<p>For performance reasons the <code>String</code> type is mapped directly to the native implementation of each target platform. The biggest implication of this choice is that the <code>length</code> property and the <code>substr()</code> method can return different results depending on the support of the UTF8 encoding in the targets. With haxe.Utf8 you can reliably obtain a consistent behavior cross-platform.</p>
<p>I have not covered all <a href="http://code.google.com/p/haxe/source/browse/trunk/doc/CHANGES.txt#13">changes</a> in the new release but only those that make me particularly happy <img src='http://www.weblob.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblob.net/2012/haxe-2-09-wwx-2012/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Vector Graphics in the Browser &#8211; WWX 2012</title>
		<link>http://www.weblob.net/2012/vector-graphics-in-the-browser-wwx-2012/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=vector-graphics-in-the-browser-wwx-2012</link>
		<comments>http://www.weblob.net/2012/vector-graphics-in-the-browser-wwx-2012/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 14:20:56 +0000</pubDate>
		<dc:creator>franco</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dhx]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[thx]]></category>
		<category><![CDATA[wwx]]></category>

		<guid isPermaLink="false">http://www.weblob.net/?p=79</guid>
		<description><![CDATA[I have uploaded my slides (PDF) and the samples from the presentation: bubbles (source) B-Chart (source) &#8230; and remember, circles are bad! The libraries presented are dhx and thx.]]></description>
			<content:encoded><![CDATA[<p>I have uploaded <a href="http://www.weblob.net/demo/wwx2012/slides/">my slides</a> (<a title="WWX Conference Slides in PDF Format" href="http://www.weblob.net/demo/wwx2012/wwx 2012.pdf">PDF</a>) and the samples from the presentation:</p>
<ul>
<li><a href="http://www.weblob.net/demo/wwx2012/bubbles/">bubbles</a> (<a href="http://www.weblob.net/demo/wwx2012/bubbles.zip">source</a>)</li>
<li><a href="http://www.weblob.net/demo/wwx2012/bchart/">B-Chart</a> (<a href="http://www.weblob.net/demo/wwx2012/bchart.zip">source</a>)</li>
</ul>
<p>&#8230; and remember, circles are bad!</p>
<p>The libraries presented are <a href="https://github.com/fponticelli/dhx">dhx</a> and <a href="https://github.com/fponticelli/thx">thx</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblob.net/2012/vector-graphics-in-the-browser-wwx-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>thx: error</title>
		<link>http://www.weblob.net/2011/thx-error/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=thx-error</link>
		<comments>http://www.weblob.net/2011/thx-error/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 23:05:46 +0000</pubDate>
		<dc:creator>franco</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[thx]]></category>

		<guid isPermaLink="false">http://www.weblob.net/?p=73</guid>
		<description><![CDATA[The thx.error package contains a bunch of classes to manage errors in your applications. The base class is Error and is a lightweight container for error messages. The nice thing about it is that it separates the message itself from &#8230;<p class="read-more"><a href="http://www.weblob.net/2011/thx-error/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>The <code>thx.error</code> package contains a bunch of classes to manage errors in your applications. The base class is <code>Error</code> and is a lightweight container for error messages. The nice thing about it is that it separates the message itself from its parameters allowing to format it in a meaningful way:</p>
<pre class="code haxe">
var error = new Error("invalid import {0:C}", 0.123);
trace(error);
// trace results is: invalid import $0.12
</pre>
<p>If you provide the needed infrastructure you can also use an instance of <code>ITranslation</code> to deliver your messages:</p>
<pre class="code haxe">
// Translated Error
var translator = new DictionaryTranslation(ItIT.culture);
translator.addSingular("invalid import {0:C}", "importo invalido {0:C}");
trace(error.translate(translator));
// trace result is: importo invalido € 0,12
</pre>
<p>I often use to mark my abstract methods so that at least at runtime I have a feedback that the implementation is missing and I do that using the <code>AbstractMethod</code> error class (the <code>NotImplemented</code> error class is functionally equivalent but has a different semantic).</p>
<pre class="code haxe">
// AbstractMethod / NotImplemented
// in a real world context this will be an instance method and not an inline function

function notImplemented() throw new NotImplemented();
try
{
	notImplemented();
} catch (e : Dynamic) {
	trace(e);
}
</pre>
<p>The nice thing is that I don&#8217;t have to type any message into the constructor because all the info I need are already in there; this is the trace:</p>
<pre class="code haxe">
method Main.notImplemented() needs to be implemented
</pre>
<p>Finally the <code>NullArgument</code> error class has a couple of static constructors that helps me check for null arguments. Using macros the argument name is extracted so that you don&#8217;t need to type it as a string; that spares you some typing but better yet avoids annoying and error prone repetitions.</p>
<pre class="code haxe">
// NullArgument
function toUpperCase(text : String)
{
	NullArgument.throwIfNull(text);
	return text.toUpperCase();
}

try
{
	toUpperCase(null);
} catch(e : Dynamic)
{
	trace(e);
}
// trace result is: invalid null argument 'text' for method Main.toUpperCase()
</pre>
<p>The <code>NullArgument.throwIfNullOrEmpty</code> works similarly but also test for emptiness &#8230; this works on <code>String</code>s, <code>List</code>s, <code>Array</code>s (length) and objects (no fields). Note that the type discovery is made at compile time and not at runtime:</p>
<pre class="code haxe">
// null or empty
function pop(arr : Array<String>) : String
{
	NullArgument.throwIfNullOrEmpty(arr);
	return arr.pop();
}

try
{
	pop([]);
} catch(e : Dynamic)
{
	trace(e);
}

// trace result is: invalid null or empty argument 'arr' for method Main.pop()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.weblob.net/2011/thx-error/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>thx: parsing dates</title>
		<link>http://www.weblob.net/2011/thx-parsing-dates/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=thx-parsing-dates</link>
		<comments>http://www.weblob.net/2011/thx-parsing-dates/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 15:30:33 +0000</pubDate>
		<dc:creator>franco</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[thx]]></category>

		<guid isPermaLink="false">http://www.weblob.net/?p=65</guid>
		<description><![CDATA[One of the latest additions to thx is thx.dates.DateParser. It is obviously a date parser, the nice thing about it is that it tries to be fuzzy and to extract a date whenever possible. You can try it yourself here: &#8230;<p class="read-more"><a href="http://www.weblob.net/2011/thx-parsing-dates/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>One of the latest additions to thx is thx.dates.DateParser. It is obviously a date parser, the nice thing about it is that it tries to be fuzzy and to extract a date whenever possible. You can try it yourself here:</p>
<input id="date" type="text" placeholder="type a date expression" />
<div id="processed"></div>
<link href="http://www.weblob.net/demo/thx/dateparser/style.css" type="text/css" rel="stylesheet" />
<script src="http://www.weblob.net/demo/thx/dateparser/thxdateparser.js" type="text/javascript"></script></p>
<p>Examples of expressions:</p>
<ul>
<li>today</li>
<li>now</li>
<li>tomorrow</li>
<li>next april</li>
<li>last sunday</li>
<li>three weeks ago plus 5 minutes</li>
<li>tomorrow in the evening</li>
<li>6/27</li>
<li>27/6</li>
</ul>
<p>To produce this tiny demo you just need a bunch of lines of code:</p>
<pre class="code haxe">import thx.date.DateParser;
import thx.js.Dom;
import js.Dom;
class Main
{
  static function main()
  {
    Dom.select("#date").onNode("keyup", function(n : HtmlDom, _) {
      var t : Text = cast n;
      var result = try {
        Dates.format(DateParser.parse(t.value), "DT");
      } catch (e : Dynamic) {
        Std.string(e);
      }
      Dom.select("#processed")
        .html().string(result);
    });
  }
}</pre>
<p>Surely the expression grammar can be improved but it works for my needs right now and it is already very flexible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblob.net/2011/thx-parsing-dates/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>thx: basics</title>
		<link>http://www.weblob.net/2011/thx-basics/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=thx-basics</link>
		<comments>http://www.weblob.net/2011/thx-basics/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 16:00:27 +0000</pubDate>
		<dc:creator>franco</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.weblob.net/?p=60</guid>
		<description><![CDATA[In this post I continue to describe the basic functionalities of thx. I&#8217;ve decided to put those classes directly in the root because that make them extremely accessible and cases for name conflicts are really low. Having them in the &#8230;<p class="read-more"><a href="http://www.weblob.net/2011/thx-basics/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>In this post I continue to describe the basic functionalities of <a title="thx project page" href="http://code.google.com/p/thx-core/">thx</a>. I&#8217;ve decided to put those classes directly in the root because that make them extremely accessible and cases for name conflicts are really low. Having them in the root is perfect if you don&#8217;t want to &#8220;waste&#8221; a line of code for importing a class that you will use just once. For example I always do stuff like:</p>
<pre class="code haxe">var values = Ints.range(10);</pre>
<p>If you work a lot with math algorithms, the Ints and Floats classes can really make your life easier. Let&#8217;s see some examples:</p>
<pre class="code haxe">trace(Ints.range(3)); // -&gt; [0,1,2]
trace(Ints.range(7, 10)); // -&gt; [7,8,9]
trace(Ints.range(0, 10, 2)); // -&gt; [0,2,4,6,8]
trace(Floats.range(0, 10, 2.5)); // -&gt; [0,2.5,5,7.5]</pre>
<p>I build parsers, encoders and decoders quite often and if that happen to you too you will probably appreciate <code>Ints.canParse(mystring)</code> and <code>Ints.parse</code>. They are really simple functions but help a lot rationalizing your code. The same functions exist in <code>Floats</code>, <code>Dates</code> and <code>Bools</code> (remember that the helper class has the same name as the class it extends but pluralized). The other said of the coin is <code>Ints.format()</code> which convert the value into its string representation. The format function accept formatting options and optionally the reference to a Culture instance (the default one is used if omitted).</p>
<p>Interpolate is also present in most of the basic types. It is really handy for transitions and you can also specify the equation you want to use (default is a linear equation); you can find more pre-cooked equations in <code>thx.math.Equations</code>). So you can interpolate on Strings, Floats, Values, Dates, Arrays and Dynamics &#8230; pretty wide options. Where you find the &#8220;interpolate&#8221; method, usually you find <code>interpolatef</code> too. It works the same but returns a function that takes a float as argument so that you can reuse the same settings over and over. You may wonder what does it mean that you can interpolate over a <code>String</code> or<br />
<code>Dynamic</code>, but it is easy said. <code>Strings.interpolate</code> extracts the floats/integers values from a pair of strings and interpolate those values. <code>Dynamics.interpolate</code> detects the runtime type of the range values and use the function from the corresponding type; if the values do not match a type with a known interpolator an exception is thrown (instance of thx.error.Error).</p>
<p>One of the function I use a lot for debugging is <code>Dynamics.string()</code> that takes any object and transform it into a nicely formatted string. It is surely heavier than <code>Std.string()</code> but it also tries to give a more complete representation of the value passed. Let&#8217;s compare both:</p>
<pre class="code haxe">var o = [{
	name : "John Doe",
	birthdate : Date.fromString("1972-07-05"),
	score : 7777.7,
	contacts : {
			emails : [
			{ type : "personal", email : "john@example.com" },
			{ type : "work", email : "jd@example.com" }
		]
	}
}, {
	name : "Jane Doe",
	birthdate : Date.fromString("1974-06-09"),
	score : 77777.7,
		contacts : {
			emails : [
			{ type : "personal", email : "jane@example.com" }
		]
	}
}];

trace(Std.string(o));
trace(Dynamics.string(o));</pre>
<p>The first trace returns (newline added by hand):</p>
<pre class="code haxe">[{
  name : John Doe,
  birthdate : 1972-07-05 00:00:00,
  score : 7777.7,
  contacts : {
    emails : [{
      type : &lt;...&gt;, email : &lt;...&gt; },{
      type : &lt;...&gt;, email : &lt;...&gt; }] } },{
  name : Jane Doe,
  birthdate : 1974-06-09 00:00:00,
  score : 77777.7,
  contacts : {
    emails : [{
      type : &lt;...&gt;,
      email : &lt;...&gt; }] } }]</pre>
<p>So you may notice that at some level of recursion the contents are simply striped off; this makes sense in most occasions but I like to have the option to display everything if I have to. This is the output of the second trace (again, newlines added by hand):</p>
<pre class="code haxe">[{
  name : "John Doe",
  birthdate : Wednesday, July 05, 1972,
  score : 7,777.70,
  contacts : {
    emails : [{
      type : "personal",
      email : "john@example.com"}, {
      type : "work", email : "jd@example.com"}]}}, {
  name : "Jane Doe",
  birthdate : Sunday, June 09, 1974,
  score : 77,777.70,
  contacts : {
    emails : [{
      type : "personal",
      email : "jane@example.com"}]}}]</pre>
<p>So, what are the differences?</p>
<ul>
<li>Strings are quoted (this is handy for guessing the type by just looking at the dump).</li>
<li>Dates and numbers are formatted.</li>
<li>The whole graph is shown.</li>
</ul>
<p>That&#8217;s all for now <img src='http://www.weblob.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblob.net/2011/thx-basics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>thx : Arrays</title>
		<link>http://www.weblob.net/2011/thx-arrays/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=thx-arrays</link>
		<comments>http://www.weblob.net/2011/thx-arrays/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 15:00:49 +0000</pubDate>
		<dc:creator>franco</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[thx]]></category>

		<guid isPermaLink="false">http://www.weblob.net/?p=50</guid>
		<description><![CDATA[In thx there are many helper methods. The convention is that if a class is not meant to be instantiated and its only purpose is to add functionalities to other types than it will be named after the type it &#8230;<p class="read-more"><a href="http://www.weblob.net/2011/thx-arrays/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>In <a title="thx project page" href="http://code.google.com/p/thx-core/">thx</a> there are many helper methods. The convention is that if a class is not meant to be instantiated and its only purpose is to add functionalities to other types than it will be named after the type it enhances but in the plural form. So it is now pretty obvious that <a href="http://code.google.com/p/thx-core/source/browse/src/Arrays.hx">Arrays</a> is a helper class for the <code>Array</code> type as <a href="http://code.google.com/p/thx-core/source/browse/src/Strings.hx">Strings</a> is a helper class for <code>String</code>.</p>
<p>So far I am really focused to add (and to improve) features and I am not really worry about file size or performances. Some of the helper classes are pretty dense and refers to other dense definitions which can add some weight to your output. This issue will be addressed at some point by improving thx compatibility with haxe DCE (Dead Code Elimination) or maybe splitting the classes.</p>
<p>Back on the post topic, I&#8217;d like to introduce a few of the options you can find in <code>Arrays</code>. So I assume for the following examples that <code>using Arrays;</code> is always in place since that makes the programmer life even easier.</p>
<p><code>Arrays</code> adds some functions to enhance method chaining, for example you can write:</p>
<pre class="code haxe">var arr = [].add(1).add(2).addIf(value &gt; 2, 3).remove(2);</pre>
<p>Many methods in <code>Arrays</code> derive from the <code>Lambda</code> class found in the <code>std</code> library but tend to be more flexible and the definitions are also repeated in Iterators and Iterables to make your life easier. Whenever is possible <code>inline</code> is used to prevent adding a new level of indirection. Note that if a method returns a list, it always returns an <code>Array</code>, even if you are using the <code>Iterator</code> or <code>Iterable</code> type. Arrays are pretty fast on all the platforms and are a lot more flexible than the iterators.</p>
<pre class="code haxe">// Ints.range(10) returns an array of int from 0 to 9
var arr = Ints.range(10)
  .filter(function(d) return 0 == d % 2)
  .map(function(d,i) return d*d);
// arr is [0,4,16,36,64]</pre>
<p>Since <a title="hxculture project page" href="http://code.google.com/p/hxculture/">hxculture</a> has been included inside thx, you can format many types (and Array is not an exception) to string in a localized fashion. So far you can use 2 formats with array <code>J</code> for &#8220;join&#8221; and <code>C</code> for &#8220;count&#8221;.</p>
<pre class="code haxe">trace(arr);  //  [0,4,16,36,64]
trace(arr.format("J")); // 0, 4, 16, 36, 64
// the first parameter is for the format of each individual value
trace(arr.format("J", ["D"]));  //  0.00, 4.00, 16.00, 36.00, 64.00
// the second parameter is for empty array
trace([].format("J", ["D", "-"]));  //  -
// the third parameter is the separator
trace(arr.format("J", ["D", "-", "; "]));  //  0.00; 4.00; 16.00; 36.00; 64.00
// the fourth parameter is the max number of elements to display
trace(arr.format("J", ["D", "-", "; ", "3"]));  //  0.00; 4.00; 16.00 ...
// the fifth parameter is for the remaining elements after max
trace(arr.format("J", ["D", "-", "; ", "3", " and more"]));  //  0.00; 4.00; 16.00 and more

trace(arr.format("C"));  //  5</pre>
<p>You can also create a format function using <code>var f = Arrays.formatf("J", ["D"]);</code> and after that <code>f([1,2,3]);</code></p>
<p>Functions like <code>.all()</code>/<code>.any()</code> permits to check if all or at least one of the elements of the array matches a certain rule. The rest of the functions in <code>Arrays</code> are pretty obvious to catch but if you have any doubt I will be glad to five more insights.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblob.net/2011/thx-arrays/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>thx: color</title>
		<link>http://www.weblob.net/2011/thx-color/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=thx-color</link>
		<comments>http://www.weblob.net/2011/thx-color/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 00:18:21 +0000</pubDate>
		<dc:creator>franco</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[thx]]></category>

		<guid isPermaLink="false">http://www.weblob.net/?p=47</guid>
		<description><![CDATA[thx is really growing fast and since it is not yet documented I want to start giving users some hints on the classes included. The thx.color package is the first set of features I will introduce since the API is &#8230;<p class="read-more"><a href="http://www.weblob.net/2011/thx-color/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p><a title="thx project page" href="http://code.google.com/p/thx-core/">thx</a> is really growing fast and since it is not yet documented I want to start giving users some hints on the classes included.</p>
<p>The <a href="http://code.google.com/p/thx-core/source/browse/#hg%2Fsrc%2Fthx%2Fcolor">thx.color</a> package is the first set of features I will introduce since the API is pretty stable and I use it a lot.</p>
<p>Creating a color from its channels is really easy:</p>
<pre class="code haxe">var color = new Rgb(255, 0, 0); // RGB values are integers from 0 to 255</pre>
<p>Of course you can use alternatives to create a Rgb color:</p>
<pre class="code haxe">color = Rgb.fromInt(0xFF000);</pre>
<p>or</p>
<pre class="code haxe">color = Rgb.fromFloats(1.0, 0.0, 0.0);</pre>
<p>&#8230; but if you are as lazy as I am you can use:</p>
<pre class="code haxe">color = NamedColors.red;</pre>
<p>or even</p>
<pre class="code haxe">color = Colors.parse("red");</pre>
<p>Note that <code>Colors.parse()</code> will try everything to find a matching color, infact you can pass a:</p>
<ul>
<li>color name, as defined in NamedColors; names with spaces are accepted aswell (ei: &#8220;<code>dark sea green</code>&#8220;)</li>
<li>css color: <code>#ff0000</code></li>
<li>rgb definition: <code>rgb(255,0,1)</code></li>
<li>hsl definition:<code> hsl(0,1,0.5)</code></li>
<li>cmyk definition: <code>cmyk(0,1,1,0)</code></li>
</ul>
<p>Other than Rgb you can define colors in the following colorspaces: <code>Hsl</code>, <code>Grey</code>, <code>Cmyk</code></p>
<p>I find Hsl particularly useful when you want to create smooth interpolations:</p>
<pre class="code haxe">using thx.colors.Hsl;
// ...
var midcolor = Hsl.interpolate(NamedColors.red.toHsl(), NamedColors.blue.toHsl(), 0.5);</pre>
<p>If you want to recycle the interpolation and generate an array of colors you can use:</p>
<pre class="code haxe">using Arrays;using thx.colors.Hsl;
// ...
var f = Hsl.interpolatef(NamedColors.red.toHsl(), NamedColors.blue.toHsl()),	len = 10;
var colors = Ints.range(len).map(function(_, i) return f(i / (len-1)));</pre>
<p>The interpolate/interpolatef methods in <code>Colors</code> will do the same but starting from string definitions.</p>
<p>This can be very handy when you want to interpolate a CSS color. The <code>Rgb.contrast</code>/<code>constrastBW</code> methods are also pretty useful. The former will try to find a pastel color that contrasts with the passed one while the latter will always return white or black. The algorithm of <code>contrastBW</code> uses the grey equivalent of the passed color to estabilish the better contrast for the human vision.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblob.net/2011/thx-color/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ufront/uform/thx demo from haxecon 2011</title>
		<link>http://www.weblob.net/2011/ufrontuformthx-demo-from-haxecon2011/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ufrontuformthx-demo-from-haxecon2011</link>
		<comments>http://www.weblob.net/2011/ufrontuformthx-demo-from-haxecon2011/#comments</comments>
		<pubDate>Sat, 28 May 2011 21:42:11 +0000</pubDate>
		<dc:creator>franco</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[haxecon]]></category>
		<category><![CDATA[thx]]></category>
		<category><![CDATA[uform]]></category>
		<category><![CDATA[ufront]]></category>

		<guid isPermaLink="false">http://www.weblob.net/?p=37</guid>
		<description><![CDATA[Eventually I&#8217;ve found the time to put everything together and here come my demos from haxecon 2011. You can play with it live or you can download the project and compile/run it on your machine. To compile the project you &#8230;<p class="read-more"><a href="http://www.weblob.net/2011/ufrontuformthx-demo-from-haxecon2011/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Eventually I&#8217;ve found the time to put everything together and here come my demos from haxecon 2011.</p>
<p>You can play with it <a title="haxecon demo application" href="http://www.weblob.net/sample/haxecon2011/">live</a> or you can <a href="http://www.weblob.net/wp-content/uploads/2011/05/haxecon.demo_.zip">download the project</a> and compile/run it on your machine.</p>
<p>To compile the project you must have installed through <a href="http://lib.haxe.org/">haxelib</a> the following libraries (be sure you are using the correct version because the API will probably change before the 1.0 release):</p>
<ul>
<li><a title="thx project page" href="http://code.google.com/p/thx-core/">thx</a> (v.0.2.0)</li>
<li><a title="hxevents project page" href="http://code.google.com/p/hxevents/">hxevents</a> (v.0.3.3)</li>
<li><a title="ufront project page" href="http://lib.haxe.org/p/ufront">ufront</a> (v.0.1.2)</li>
<li><a title="erazor project page" href="http://lib.haxe.org/p/erazor">erazor</a> (v.0.1.1)</li>
<li><a title="hscript project page" href="http://lib.haxe.org/p/hscript">hscript</a> (v.1.6)</li>
</ul>
<p>Note that <a title="uform project page" href="http://code.google.com/p/uform/">uform</a> is included in the project and you don&#8217;t need to install anything for it.</p>
<p>To run the example on your machine you will probably have to tweak a couple of things:</p>
<ul>
<li><strong>Main.hx</strong>: if you use mod_rewrite you will have to create your .htaccess file and change the parameter in the Config constructor from &#8220;false&#8221; to &#8220;true&#8221;. Also, if you run the demo from a subfolder different then demo you will have to change that parameter too; if you plan to run in root just put &#8220;/&#8221; in the path argument.</li>
<li><strong>demo/Config.hx</strong>: Change your connection settings for your Mysql database and be sure to create a table in the DB with the structure described in the same file.</li>
</ul>
<p>The project is divided into 3 separate projects:</p>
<ul>
<li>web-pages (both php and neko), use the haxecon.php.hxml or haxecon.neko.hxml to compile</li>
<li>colors example page (js), compile using haxecon.d3colors.hxml</li>
<li>d3.js port examples (js), compile using haxecon.d3examples.hxml</li>
</ul>
<p>The <a title="demo from haxecon 2011" href="http://www.weblob.net/sample/haxecon2011/">live demo</a> on this website is running on neko which is way faster than the php version.</p>
<p><a href="http://www.weblob.net/wp-content/uploads/2011/05/haxecon-demo-screenshot.png"><img class="alignnone size-medium wp-image-39" title="haxecon demo screenshot" src="http://www.weblob.net/wp-content/uploads/2011/05/haxecon-demo-screenshot-300x181.png" alt="" width="300" height="181" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblob.net/2011/ufrontuformthx-demo-from-haxecon2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>haxecon 2011</title>
		<link>http://www.weblob.net/2011/haxecon-2011/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=haxecon-2011</link>
		<comments>http://www.weblob.net/2011/haxecon-2011/#comments</comments>
		<pubDate>Mon, 16 May 2011 13:37:50 +0000</pubDate>
		<dc:creator>franco</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.weblob.net/?p=29</guid>
		<description><![CDATA[The haxecon 2011 has been an amazing experience. Finally giving faces to many haXe users has been incredible. I attach here my slides in case someone is interested. I&#8217;ve just release on haxelib thx, ufront and erazor. uform will have &#8230;<p class="read-more"><a href="http://www.weblob.net/2011/haxecon-2011/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.haxecon.com/" target="_blank">haxecon 2011</a> has been an amazing experience. Finally giving faces to many haXe users has been incredible.<br />
I attach here my <a href="http://www.weblob.net/wp-content/uploads/2011/05/slides.pdf">slides</a> in case someone is interested. I&#8217;ve just release on haxelib <a href="http://lib.haxe.org/p/thx" target="_blank">thx</a>, <a href="http://lib.haxe.org/p/ufront" target="_blank">ufront</a> and <a href="http://lib.haxe.org/p/erazor" target="_blank">erazor</a>. <a href="http://code.google.com/p/uform/" target="_blank">uform</a> will have to wait because it is still moving too fast (or too slow, it is really a matter of points of view).</p>
<p>I will also attach the code of my demo soon enough.</p>
<p><a href="http://www.weblob.net/wp-content/uploads/2011/05/haxecon_sortie.jpg"><img class="alignnone size-large wp-image-30" title="haxecon sortie by some anonymous french guy" src="http://www.weblob.net/wp-content/uploads/2011/05/haxecon_sortie-1024x476.jpg" alt="" width="620" height="288" /></a></p>
<p>p.s. Wow &#8230; a post after more than one year.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblob.net/2011/haxecon-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Friend types are slow &#8230; really?</title>
		<link>http://www.weblob.net/2010/friend-types-are-slow-really/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=friend-types-are-slow-really</link>
		<comments>http://www.weblob.net/2010/friend-types-are-slow-really/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 18:55:39 +0000</pubDate>
		<dc:creator>franco</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[avm2]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://localhost/weblob/?p=18</guid>
		<description><![CDATA[If you followed the post about friend types or the discussion about that topic on the haXe mailing list started by Michael Baczynski, you may believe that friend types can be slow. This is true (we are talking about targeting flash 9 here) &#8230;<p class="read-more"><a href="http://www.weblob.net/2010/friend-types-are-slow-really/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>If you followed the post about <a href="http://www.weblob.net/2009/08/friendly-types-haxe">friend types</a> or the discussion about that topic on the <a href="http://haxe.markmail.org/search/?q=friend%20syntax%20with%20typedefs#query:friend%20syntax%20with%20typedefs+page:1+mid:52aiyh5if4k5wbc6+state:results">haXe mailing list</a> started by <a href="http://lab.polygonal.de/">Michael Baczynski</a>, you may believe that friend types can be slow. This is true (we are talking about targeting flash 9 here) if you use a temporary variable to &#8220;cast&#8221; the friend instance, but there is a workaround for that.</p>
<p>So suppose you have this class:</p>
<pre>class Test
{
  var value : Int; // this is the private field we want to expose as friend
  public function new() {
    value = 1;
  }
}</pre>
<p>The friend type is:</p>
<pre>typedef TestFriend = {
  private var value : Int;
}</pre>
<p>So what are your options?</p>
<p>The simple one:</p>
<pre>var test = new Test();
var friend : TestFriend = test;
var v = friend.value;</pre>
<p>This is not fast because test needs to be converted to a dynamic type to be used like that. Here is the alternative, first create an utility method as such:</p>
<pre>class TestUtil {
  public static inline function getValue(t : TestFriend) {
    return t.value;
  }
}</pre>
<p>Then use it:</p>
<pre>var test = new Test();
var v = TestUtil.getValue(test);</pre>
<p>Does it perform better? A lot (even faster that untyped). Is it type safe? Sure &#8230; no need for untyped.</p>
<p>Using &#8220;using&#8221; makes it even nicer:</p>
<pre>using TestUtil;
// ...
var test = new Test();
var v = test.getValue();</pre>
<p>About perfomances, I&#8217;ve made a test on 2.000.000 iterations (average on 5 cycles) and here are the results:</p>
<ul>
<li>using a <strong>temp var</strong> (reassigned on each iteration): <strong>reference time</strong> (454.0 ms)</li>
<li>using a <strong>temp var</strong> (assigned once): <strong>14% faster</strong> (397.8 ms)</li>
<li><strong>untyped</strong>: <strong>46% faster</strong> (310.6 ms)</li>
<li>using the <strong>static getValue()</strong> function: <strong>50% faster</strong> (301.8 ms)</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblob.net/2010/friend-types-are-slow-really/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

