<?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>Yet Another [À Compléter] &#187; C#</title>
	<atom:link href="http://blog.neteril.org/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.neteril.org</link>
	<description>Random thoughts of Jérémie Laval</description>
	<lastBuildDate>Wed, 24 Aug 2011 17:43:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>DBus Explorer 0.4 Christmas release</title>
		<link>http://blog.neteril.org/2008/12/28/dbus-explorer-04-christmas-release/</link>
		<comments>http://blog.neteril.org/2008/12/28/dbus-explorer-04-christmas-release/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 16:51:28 +0000</pubDate>
		<dc:creator>Jérémie Laval</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[DBus Explorer]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[dbus]]></category>
		<category><![CDATA[managed dbus]]></category>

		<guid isPermaLink="false">http://garuma.wordpress.com/?p=351</guid>
		<description><![CDATA[<p>Finally after months of postponing the 0.4 release of D-Bus Explorer I managed to get it out as a Christmas/New Year present :-) . For the impatient you will find download link <a href="http://www.ndesk.org/DBusExplorer">at the usual place</a>.</p>

<p>For those who doesn't know what D-Bus Explorer is, it's a little tool I wrote up a long time ago which allows to browse D-Bus bus services and services' API. It's similar in concept to dbus-viewer or DFeet with extra feature which make it sweet when you work with C# and Managed D-Bus.</p>

<p>For instance when you want to know the signature of a method/event/property it's both shown with D-Bus own syntax and C# syntax. In this release this mechanism is extensible to other language though only C# is provided at the moment.</p>

<a href="http://garuma.files.wordpress.com/2008/12/2008-12-27-215012_802x625_shot1.png"><img class="aligncenter size-medium wp-image-354" title="2008-12-27-215012_802x625_shot1" src="http://garuma.wordpress.com/files/2008/12/2008-12-27-215012_802x625_shot1.png?w=300" alt="2008-12-27-215012_802x625_shot1" width="300" height="233" /></a>

<p>Coming to this release is also a C# generator which will create the necessary interface definition for use with Managed D-Bus. Simply right-click on the path / interface you want to use in your program and save it somewhere. Again this is extensible to other language.</p>

<a href="http://garuma.files.wordpress.com/2008/12/2008-12-27-215639_802x625_shot3.png"><img class="aligncenter size-medium wp-image-355" title="2008-12-27-215639_802x625_shot3" src="http://garuma.wordpress.com/files/2008/12/2008-12-27-215639_802x625_shot3.png?w=300" alt="2008-12-27-215639_802x625_shot3" width="300" height="233" /></a>

<p>In other news, the interface is now fully tabbed to let you browse different API at the same time.</p>

<a href="http://garuma.files.wordpress.com/2008/12/2008-12-28-174241_802x625_shot4.png"><img class="aligncenter size-medium wp-image-357" title="2008-12-28-174241_802x625_shot4" src="http://garuma.wordpress.com/files/2008/12/2008-12-28-174241_802x625_shot4.png?w=300" alt="2008-12-28-174241_802x625_shot4" width="300" height="233" /></a>

<p>Happy D-Bus hacking !</p>]]></description>
			<content:encoded><![CDATA[<p>Finally after months of postponing the 0.4 release of D-Bus Explorer I managed to get it out as a Christmas/New Year present <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  . For the impatient you will find download link <a href="http://www.ndesk.org/DBusExplorer">at the usual place</a>.</p>
<p>For those who doesn&#8217;t know what D-Bus Explorer is, it&#8217;s a little tool I wrote up a long time ago which allows to browse D-Bus bus services and services&#8217; API. It&#8217;s similar in concept to dbus-viewer or DFeet with extra feature which make it sweet when you work with C# and Managed D-Bus.</p>
<p>For instance when you want to know the signature of a method/event/property it&#8217;s both shown with D-Bus own syntax and C# syntax. In this release this mechanism is extensible to other language though only C# is provided at the moment.</p>
<p><a href="http://garuma.files.wordpress.com/2008/12/2008-12-27-215012_802x625_shot1.png"><img class="aligncenter size-medium wp-image-354" title="2008-12-27-215012_802x625_shot1" src="http://garuma.files.wordpress.com/2008/12/2008-12-27-215012_802x625_shot1.png?w=300" alt="2008-12-27-215012_802x625_shot1" width="300" height="233" /></a></p>
<p>Coming to this release is also a C# generator which will create the necessary interface definition for use with Managed D-Bus. Simply right-click on the path / interface you want to use in your program and save it somewhere. Again this is extensible to other language.</p>
<p><a href="http://garuma.files.wordpress.com/2008/12/2008-12-27-215639_802x625_shot3.png"><img class="aligncenter size-medium wp-image-355" title="2008-12-27-215639_802x625_shot3" src="http://garuma.files.wordpress.com/2008/12/2008-12-27-215639_802x625_shot3.png?w=300" alt="2008-12-27-215639_802x625_shot3" width="300" height="233" /></a></p>
<p>In other news, the interface is now fully tabbed to let you browse different API at the same time.</p>
<p><a href="http://garuma.files.wordpress.com/2008/12/2008-12-28-174241_802x625_shot4.png"><img class="aligncenter size-medium wp-image-357" title="2008-12-28-174241_802x625_shot4" src="http://garuma.files.wordpress.com/2008/12/2008-12-28-174241_802x625_shot4.png?w=300" alt="2008-12-28-174241_802x625_shot4" width="300" height="233" /></a></p>
<p>Happy D-Bus hacking !</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.neteril.org/2008/12/28/dbus-explorer-04-christmas-release/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Parallel goodness</title>
		<link>http://blog.neteril.org/2008/07/02/parallel-goodness/</link>
		<comments>http://blog.neteril.org/2008/07/02/parallel-goodness/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 16:18:41 +0000</pubDate>
		<dc:creator>Jérémie Laval</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Google Summer of Code 2008]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[parallelfx]]></category>

		<guid isPermaLink="false">http://garuma.wordpress.com/?p=202</guid>
		<description><![CDATA[I think I pretty much arrived to the point where my work is starting to get useful. With yesterday basic Tasks implementation and today Parallel.For work I was able to run a parallelized version of Luke&#8217;s C# RayTracer. There was already a version using ParallelFx in the CTP samples but I preferred to made my [...]]]></description>
			<content:encoded><![CDATA[<p>I think I pretty much arrived to the point where my work is starting to get useful. With yesterday basic Tasks implementation and today Parallel.For work I was able to run a parallelized version of <a href="http://blogs.msdn.com/lukeh/archive/2007/04/03/a-ray-tracer-in-c-3-0.aspx">Luke&#8217;s C# RayTracer</a>. There was already a version using ParallelFx in the CTP samples but I preferred to made my custom, simpler one :</p>
<p><a href="http://garuma.files.wordpress.com/2008/07/capture-raytracer.png"><img src="http://garuma.files.wordpress.com/2008/07/capture-raytracer.png?w=290" alt="" width="290" height="300" class="aligncenter size-medium wp-image-204" /></a></p>
<p>After some micro-benchmarking on my <a href="http://monoport.com/25060">dual-core system</a> the overall speed improvement is around 42%. Deductively it should be 50% but due to the work-stealing algorithm overhead it&#8217;s a little less. Still it&#8217;s a good improvement over the classic and synchronous version.</p>
<p>Like the folks at the ParallelFx blog <a href="http://blogs.msdn.com/pfxteam/archive/2008/06/04/8573863.aspx">did</a> I added some color mask to show which thread was doing the work :</p>
<p><a href="http://garuma.files.wordpress.com/2008/07/capture-ray-tracer.png"><img src="http://garuma.files.wordpress.com/2008/07/capture-ray-tracer.png?w=290" alt="" width="290" height="300" class="aligncenter size-medium wp-image-203" /></a></p>
<p>As we can see the work is almost homogeneous between each of the processor. The small delta is explained by the fact that while one of the thread is in the middle of queuing all the work, the other is already processing it.</p>
<p>The code for the parallel ray tracer is here : <a href="http://monoport.com/25053">http://monoport.com/25053</a>. If you want to test it out grab a copy of the source <a href="http://code.google.com/p/mono-soc-2008/source/checkout">from here</a> in addition (warning : it&#8217;s probably full of bugs and won&#8217;t work on your system <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ). Run the program with <code>--thread-mask</code> for the color mask.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.neteril.org/2008/07/02/parallel-goodness/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Beware of double.Parse()</title>
		<link>http://blog.neteril.org/2008/05/28/beware-of-doubleparse/</link>
		<comments>http://blog.neteril.org/2008/05/28/beware-of-doubleparse/#comments</comments>
		<pubDate>Wed, 28 May 2008 11:05:35 +0000</pubDate>
		<dc:creator>Jérémie Laval</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Monodevelop]]></category>
		<category><![CDATA[double]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[parsing]]></category>

		<guid isPermaLink="false">http://garuma.wordpress.com/?p=187</guid>
		<description><![CDATA[Some svn up ago, Monodevelop started to throw strange exceptions at my face about Format error occuring when parsing a string with double.Parse(). This was triggered in various places ranging from startup, project opening, file opening or application unloading. At the time I hadn&#8217;t bothered tracking down the issue but last Monday I decided to [...]]]></description>
			<content:encoded><![CDATA[<p>Some <code>svn up</code> ago, Monodevelop started to throw strange exceptions at my face about Format error occuring when parsing a string with <code>double.Parse()</code>. This was triggered in various places ranging from startup, project opening, file opening or application unloading. At the time I hadn&#8217;t bothered tracking down the issue but last Monday I decided to investigate it. Turned out that double.Parse was throwing a FormatException about &#8216;.&#8217; (like in &laquo;&nbsp;12.68&#8243;) which was considered unknown.</p>
<p>After poking and modifying some stuff in Double.cs the problem was remaining. So, I made a really simple test case that I pasted below :</p>
<pre class="brush: csharp; title: ; notranslate">using System;

class DoubleFormatTestCase
{
  public static void Main()
  {
	Console.WriteLine(double.Parse(&quot;12.68&quot;));
  }
}</pre>
<p>Compiling it and running it on my machine threw the same exception that in Monodevelop. I admit this puzzled me completely as I was thinking that, programming language speaking, floating numbers were always represented like this in their textual form.</p>
<p>After asking in #mono, yakeen suggested replacing the simple double.Parse(string) with double.Parse(string, CultureInfo) like this :
<pre class="brush: csharp; title: ; notranslate">using System;
using System.Globalization;
class DoubleFormatTestCase
{
  public static void Main()
  {
	Console.WriteLine(double.Parse(&quot;12.68&quot;,
                    CultureInfo.InvariantCulture.NumberFormat));
  }
} </pre>
<p>And if you try this code it should work no matter your platform or your language.</p>
<p>Why that ? Because as you should know (and as I should have remembered <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ) .NET/Mono enforces that things like string comparisons, DateTime handling or long.Parse (in our case) are made according to the user culture. Indeed, here in France, when we write floating numbers, we use &#8216;,&#8217; and not &#8216;.&#8217; to separate the integer and floating part. This syntax difference explained why long.Parse(string) was borking on my system.</p>
<p>You can also re-run the first test like this : <code>LANG=en_EN mono DoubleFormatTestCase.exe</code>. Normally it should run without problem.</p>
<p>The moral of the story : always use <code>double.Parse(string, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);</code> instead of <code>double.Parse(string)</code> when doing conversion between string and double in a persistent way (configuration files, intern calculations) and only use the latter when you have to exchange with the user.</p>
<p>Btw, with big kudos to yakeen, I submitted a patch to Monodevelop to correct the problem. It should be available soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.neteril.org/2008/05/28/beware-of-doubleparse/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CoverFlow finalized</title>
		<link>http://blog.neteril.org/2008/05/20/coverflow-finalized/</link>
		<comments>http://blog.neteril.org/2008/05/20/coverflow-finalized/#comments</comments>
		<pubDate>Tue, 20 May 2008 18:49:13 +0000</pubDate>
		<dc:creator>Jérémie Laval</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[School]]></category>
		<category><![CDATA[coverflow]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://garuma.wordpress.com/?p=183</guid>
		<description><![CDATA[Maybe some folks remember the CoverFlow GTK# widget I talked about a while ago. I had left it in an undetermined state but today I managed to clean it and make it the work the way I intended. For the little background, I want to use that widget as part of a presentation I will [...]]]></description>
			<content:encoded><![CDATA[<p>Maybe some folks remember the CoverFlow GTK# widget I talked about <a href="http://garuma.wordpress.com/2007/11/22/coverflowwidget-or-how-to-make-horrible-code-when-you-are-sick/">a while ago</a>. I had left it in an undetermined state but today I managed to clean it and make it the work the way I intended.</p>
<p>For the little background, I want to use that widget as part of a presentation I will make at school, in two weeks, on creating C# softwares on Linux with <a href="http://www.mono-project.com">Mono</a>. During the presentation, I will make attendees do a simple app which ask, via a GTK# GUI, some informations about an artist, do a query on <a href="http://musicbrainz.org/">musicbrainz</a>, parse the reply and, finally, display the cover art of the artist&#8217;s albums. That&#8217;s why I thought coding a CoverFlow widget would provide a more aesthetic look than a bare Image widget (and, at a same time, allow me to practice graphic programming <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ).</p>
<p>Anyway, for the technical side the code doesn&#8217;t do too fancy things. For a start it&#8217;s not even accelerated or OpenGL-enabled (would be fun to do a Clutter port), it&#8217;s just good-old-gdk and System.Drawing operations on bitmaps with a DrawingArea. There is no animation too, it would probably flicker too much and eat CPU which isn&#8217;t the purpose. Finally I used the traditional way of manipulating pixel, no pointer black magic in the code.</p>
<p>I will post the code somewhere tomorrow or later but, in the meantime, here is a screenshot showing <a href="http://en.wikipedia.org/wiki/Nightwish">Nightwish</a> (\o/) discography :</p>
<p align="center"><a href="http://garuma.files.wordpress.com/2008/05/cover-flow-finish.png"><img src="http://garuma.files.wordpress.com/2008/05/cover-flow-finish.png?w=300" alt="" width="300" height="162" class="aligncenter size-medium wp-image-184" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.neteril.org/2008/05/20/coverflow-finalized/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C# vs. Python</title>
		<link>http://blog.neteril.org/2008/02/12/c-vs-python/</link>
		<comments>http://blog.neteril.org/2008/02/12/c-vs-python/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 12:36:04 +0000</pubDate>
		<dc:creator>Jérémie Laval</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://garuma.wordpress.com/?p=143</guid>
		<description><![CDATA[That post isn&#8217;t a in-depth comparison of the two languages because it would require lot of time and, in the end, I don&#8217;t find that sort of thing particularly pertinent. It&#8217;s just a side-by-side presentation of the same script, written in both languages, assorted with my &#171;&#160;it&#8217;s just my opinion&#160;&#187;-type of comments. Without further introduction, [...]]]></description>
			<content:encoded><![CDATA[<p>That post isn&#8217;t a in-depth comparison of the two languages because it would require lot of time and, in the end, I don&#8217;t find that sort of thing particularly pertinent. It&#8217;s just a side-by-side presentation of the same script, written in both languages, assorted with my &laquo;&nbsp;it&#8217;s just my opinion&nbsp;&raquo;-type of comments.</p>
<p>Without further introduction, here is the Python version :</p>
<pre class="brush: python; title: ; notranslate">#!/usr/bin/env python

import dbus, gobject, dbus.glib

NICK = &quot;Kiri&quot;
CHAN = &quot;#riverotte&quot;

bus = dbus.SessionBus()

obj = bus.get_object(&quot;im.pidgin.purple.PurpleService&quot;, &quot;/im/pidgin/purple/PurpleObject&quot;)
purple = dbus.Interface(obj, &quot;im.pidgin.purple.PurpleInterface&quot;)

obj = bus.get_object (&quot;org.xchat.service&quot;, &quot;/org/xchat/Remote&quot;)
xchat = dbus.Interface(obj, &quot;org.xchat.plugin&quot;)

away = False

def statuschangementCallback(acctID, old, new):
	global away
	cur_status = purple.PurpleSavedstatusGetCurrent()
	message = purple.PurpleSavedstatusGetMessage(cur_status)

	if (purple.PurpleSavedstatusIsIdleaway() == 1):
		message = &quot;aw&quot;

	message = message.replace(&quot; &quot;, &quot;_&quot;)
	if (len(message) &gt; 8):
		return
	serv_id = xchat.FindContext(&quot;&quot;, CHAN)
	xchat.SetContext(serv_id)
	xchat.Command(&quot;nick &quot;+NICK+&quot;`&quot;+message)
	if (purple.PurpleSavedstatusGetType(cur_status) == 5):
		xchat.Command(&quot;away&quot;)
		away = True
	elif (away):
		xchat.Command(&quot;back&quot;)
		away = False

bus.add_signal_receiver(statuschangementCallback, dbus_interface=&quot;im.pidgin.purple.PurpleInterface&quot;, signal_name=&quot;AccountStatusChanged&quot;)

gobject.MainLoop().run()</pre>
<p>And here is the C# version :</p>
<p>using System;<br />
using GLib;<br />
using NDesk.DBus;</p>
<p>[Interface("im.pidgin.purple.PurpleInterface")]<br />
public interface PurpleInterface<br />
{<br />
	int PurpleSavedstatusIsIdleaway();<br />
	int PurpleSavedstatusGetCurrent();<br />
	string PurpleSavedstatusGetMessage(int status);<br />
	int PurpleSavedstatusGetType(int status);<br />
	event StatusChangedEventHandler AccountStatusChanged;<br />
}</p>
<p>[Interface("org.xchat.plugin")]<br />
public interface XChatInterface<br />
{<br />
	uint FindContext(string serv, string channel);<br />
	void SetContext(uint cont);<br />
	void Command(string cmd);<br />
}</p>
<p>public delegate void StatusChangedEventHandler();</p>
<p>class Plugin<br />
{<br />
	const string Nick = &laquo;&nbsp;Kiri&nbsp;&raquo;;<br />
	const string Chan = &laquo;&nbsp;#riverotte&nbsp;&raquo;;</p>
<p>	static bool away;</p>
<p>	public static void Main()<br />
	{<br />
		MainLoop ml = new MainLoop();<br />
		BusG.Init();</p>
<p>		XChatInterface xchat = Bus.Session.GetObject<xchatInterface>(&laquo;&nbsp;org.xchat.service&nbsp;&raquo;, new ObjectPath(&laquo;&nbsp;/org/xchat/Remote&nbsp;&raquo;));<br />
		PurpleInterface purple = Bus.Session.GetObject
<purpleInterface>(&laquo;&nbsp;im.pidgin.purple.PurpleService&nbsp;&raquo;, new ObjectPath(&laquo;&nbsp;/im/pidgin/purple/PurpleObject&nbsp;&raquo;));</p>
<p>		purple.AccountStatusChanged += delegate {<br />
			int cur_status = purple.PurpleSavedstatusGetCurrent();<br />
			string message = purple.PurpleSavedstatusGetMessage(cur_status);</p>
<p>			if (purple.PurpleSavedstatusIsIdleaway() == 1) {<br />
				message = &laquo;&nbsp;aw&nbsp;&raquo;;<br />
			}</p>
<p>			message = message.Replace(&nbsp;&raquo; &laquo;&nbsp;, &laquo;&nbsp;_&nbsp;&raquo;);<br />
			if (message.Length > <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> 				return;</p>
<p>			xchat.SetContext(xchat.FindContext(&laquo;&nbsp;&nbsp;&raquo;, Chan));<br />
			xchat.Command(&laquo;&nbsp;nick &nbsp;&raquo; + Nick + &laquo;&nbsp;`&nbsp;&raquo; + message);</p>
<p>			if (purple.PurpleSavedstatusGetType(cur_status) == 5) {<br />
				xchat.Command(&laquo;&nbsp;away&nbsp;&raquo;);<br />
				away = true;<br />
			} else if (away) {<br />
				xchat.Command(&laquo;&nbsp;back&nbsp;&raquo;);<br />
				away = false;<br />
			}<br />
		};</p>
<p>		ml.Run();<br />
	}<br />
}</p>
<h2>Preliminary</h2>
<p>First of all, one may find that the Python code is shorter. But if you remove the boilerplate code (the interfaces and delegate), which could be both autogenerated with a future release of <a href="http://www.ndesk.org/DBusExplorer">D-Bus Explorer</a> anyway (ad inside <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ), the overhead is about 3-4 lines ({ } included). So no real advantage there.</p>
<h2>Readability != Conciseness</h2>
<p>Now for readability. Python has always been praised for being concise and all. Why do I say &#8216;concise&#8217; there ? Because IMHO conciseness and readability aren&#8217;t the same things at all.</p>
<p>When friends show me a OCaml sexy hack, the first thing I reply is &laquo;&nbsp;and what does it do ?&nbsp;&raquo;. Don&#8217;t mistake me, I don&#8217;t use OCaml that much and sure these things come with habit, but nonetheless, I&#8217;m not completely alien to the programming style and, even with that knowledge, I can&#8217;t tell what a &laquo;&nbsp;concise&nbsp;&raquo; 20 lines OCaml program do. You can call me dumbass but I&#8217;m pretty sure I&#8217;m not the only one in this case. Anyway, all of this to illustrate that, at least for some people (which I&#8217;m part of), these two concepts of readability and conciseness are not equivalent.</p>
<p>Returning to our matter, I think the previous story illustrate the case of the C# example. Indeed, it may not be shorter at first sight but (and I&#8217;m convinced about that) even if you never programmed in C#, you know, with a quick glance, <strong>what</strong> it does. Verbosity is not a bad thing if it&#8217;s not extreme (read, VB). Complain about that in comments, with arguments, if you disagree.</p>
<p>Of course, it can hold true for the Python snippet too. This first part was just to clear the idea that conciseness ⇔ readability.</p>
<h2>Tackling the binding problems</h2>
<p>Now there is another important aspect to take care (in my sense) : <em>language integration</em>. I won&#8217;t talk about the &#8216;global away&#8217; line and the inherent block semantic which I find strange in a &laquo;&nbsp;Python is the C programmer best friend&nbsp;&raquo; context as it&#8217;s more a personal preference. However, since we are talking about C, I just can&#8217;t see the design difference between the Python snippet and an equivalent C one coded with libdbus so what&#8217;s the advantage to use Python over C for D-Bus ? In fact, what I want to point out is that having binding is good and all, but, IMHO, having <b>integrated</b> binding is better. What do I mean by integrated ? Well, look at the C# code and you will see several things which make Managed D-Bus &laquo;&nbsp;integrated&nbsp;&raquo; compared to dbus-python :</p>
<ul>
<li>Real polymorphism with interface and genericity (What GetObject is doing ? I don&#8217;t care, I have my interface definition for reference purpose).</li>
<li>No dbus.Interface, everything is handled thanks to attribute and reflection.</li>
<li>Integrated events, not a silly bus.add_signal_receiver() C-ism.</li>
</ul>
<p>All of that allow D-Bus specific calls to blend more nicely in the rest of the application. To the contrary, I often see Python scripts which look more like a patchwork of different paradigm and convention style.</p>
<p>Having an interface-based way to access DBus&#8217; methods also provides type safety (provided that you don&#8217;t <a href="http://www.natulte.net/index.php/blog/524">fight with your keyboard</a> or that you use the kind of autogenerating tool I described before) and I&#8217;m pretty sure your computer <a href="http://xkcd.com/371/">who-doesn&#8217;t-like-runtime-error</a> will also be happier. And with a tool like <a href="http://www.ndesk.org/DBusExplorer">D-Bus Explorer</a> you don&#8217;t have to search tons of docs for type informations (still ad inside).</p>
<p>This last point is more debatable since it touches the more general philosophy of dynamic typing against static typing. My general stance on that is that, even if dynamic typing simplifies the process of writing the first code, it&#8217;s very damageable at the end for several points (which are also valid in our test case) :</p>
<ul>
<li>Type information is &laquo;&nbsp;volatile&nbsp;&raquo; meaning that, even if you know what that function of yours is supposed to return when you write it down, chances are that you will have to re-read the whole thing (or check the doc, or take a look at the unit testsn or something else time-consuming) later to remember what it does because, well, time and coffee do their job. Whereas in static typing langage, if the API is well made and if you have some sort of auto-completion, you can pretty most always deduce things from the full prototype.</li>
<li>Continuing from point 1, it&#8217;s even worse for those guys who have to understand what you did before writing their own code.</li>
<li>It&#8217;s not robust by default : you have to write unit tests to make sure no one is going to screw that part of the code with type mismatch (who said shortness ?).</li>
</ul>
<h2>Conclusion</h2>
<p>So, to conclude, even if this post looks like a monologue against Python, it&#8217;s not. I understand Python advantages over traditional typed language and, as the first script shows, I even use it to test my ideas. What I wanted to highlight is that I consider Python *not* suited to large applications where several people have to collaborate (especially if there are no strong policy or rigor inside the team). Python as a powerful Bash replacement, yes. Python as a nice framework for testing and prototyping ideas, good, why not. Python as en embeddable scripting language, sure, it&#8217;s made for that in a sense.  But Python for a large and maintainable application ? No, not for me.</p>
<p>NB: this post is what some might call a (badly hidden) troll. Instead of that, I would like to present this post as an invitation to discuss in comments, so feel free to drop your thoughts.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.neteril.org/2008/02/12/c-vs-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Could C++ have at least a good point ?</title>
		<link>http://blog.neteril.org/2007/09/26/could-c-have-at-least-a-good-point/</link>
		<comments>http://blog.neteril.org/2007/09/26/could-c-have-at-least-a-good-point/#comments</comments>
		<pubDate>Wed, 26 Sep 2007 19:12:07 +0000</pubDate>
		<dc:creator>Jérémie Laval</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[difference]]></category>
		<category><![CDATA[functionnal]]></category>
		<category><![CDATA[imperative]]></category>

		<guid isPermaLink="false">http://garuma.wordpress.com/2007/09/26/could-c-have-at-least-a-good-point/</guid>
		<description><![CDATA[(I&#8217;m taking risks with such a title ) During yesterday computer science practical session (just think of the most hellish thing you have ever done), I was wandering lazily in the program list of the computer where I was supposed to do Excel stuff (actually I had pretty most finished and I wasn&#8217;t really in [...]]]></description>
			<content:encoded><![CDATA[<p>(I&#8217;m taking risks with such a title <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  )</p>
<p>During yesterday computer science practical session (just think of the most hellish thing you have ever done), I was wandering lazily in the program list of the computer where I was supposed to do Excel stuff (actually I had pretty most finished and I wasn&#8217;t really in the mood to do extra work), when I found an antique DevC++ installation in one of the menu. Launching the thing I started to do a calculator (yes, after VBA almost anything else to program sounds interesting) when I remembered the use of the <code>const</code> keyword applied to functions and methods which (C++ purists correct me if I&#8217;m wrong) compiler-check that the code inside the function/method doesn&#8217;t modify both the parameters or the internal class state.</p>
<p>After thinking about it I thought : &laquo;&nbsp;Hey actually that&#8217;s a nice idea&nbsp;&raquo; and indeed it somehow lessens what the functional enthusiasts may call one of the &#8216;imperative nightmare&#8217;, namely, the imperative&#8217;s side-effects :</p>
<blockquote><p>&laquo;&nbsp;Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions <strong>and avoids state and mutable data</strong>. It emphasizes the application of functions, <strong>in contrast</strong> with the imperative programming style <strong>that emphasizes changes in state.</strong>&laquo;&nbsp;.<br />
 Wikipédia, <a href="http://en.wikipedia.org/wiki/Functional_programming">Functional programming</a></p></blockquote>
<p>This feature is particularly important in the today context where search for performance leads to parallel programming, a field <a href="http://en.wikipedia.org/wiki/Erlang_%28programming_language%29">where functional language excels</a> by using this feature that imply that every function calls are independent from the execution context of the program.</p>
<p>IMHO this could proves to be a good feature in C# : a compiler-enforced mean to behave in a (mimicked) functional way with readonly access to fields and parameters and, thus, both no pollution of the others class&#8217; methods call and the absence of locks which would allow, for example, auto-parallelism by the runtime. Especially when C# tends to get more and more functional concepts integrated both in the core language and in the class library.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.neteril.org/2007/09/26/could-c-have-at-least-a-good-point/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

