<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-3870801931584460413</atom:id><lastBuildDate>Sun, 27 Dec 2009 00:06:46 +0000</lastBuildDate><title>On Software and Languages</title><description>Speaking up from the Telco ghetto... (on C++, Java, Perl, Python, Haskell?, Erlang??, Systems and Processes)</description><link>http://ib-krajewski.blogspot.com/</link><managingEditor>noreply@blogger.com (Marek Krj)</managingEditor><generator>Blogger</generator><openSearch:totalResults>48</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-7481825544492963345</guid><pubDate>Mon, 21 Dec 2009 08:56:00 +0000</pubDate><atom:updated>2009-12-21T04:15:09.175-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>misc</category><category domain='http://www.blogger.com/atom/ns#'>Java</category><category domain='http://www.blogger.com/atom/ns#'>C++</category><title>Local language trends 2009</title><description>&lt;p&gt;&lt;/p&gt;I just had a look on the statistics pages on our local IT freelancer website (&lt;a href="http://www.freelancermap.de/"&gt;http://www.freelancermap.de/&lt;/a&gt;) and found the results pretty interesting. First let have a look at the languages which are most popular in the freelancer projects. The picture below shows the languages, the &lt;strong&gt;&lt;span style="color:#3366ff;"&gt;supply&lt;/span&gt;&lt;/strong&gt; of programmers (the &lt;strong&gt;&lt;span style="color:#3366ff;"&gt;blue bar&lt;/span&gt;&lt;/strong&gt;) and the &lt;strong&gt;&lt;span style="color:#ff0000;"&gt;demand&lt;/span&gt;&lt;/strong&gt; in projects (the&lt;strong&gt;&lt;span style="color:#ff0000;"&gt; red bar&lt;/span&gt;&lt;/strong&gt;).&lt;br /&gt;&lt;br /&gt;As it seems, here in Germany there are only two serious languages: &lt;em&gt;C/C++&lt;/em&gt; and &lt;em&gt;Java&lt;/em&gt;. Well, ok, &lt;em&gt;Visual Basic&lt;/em&gt; and &lt;em&gt;C#&lt;/em&gt; are sough after rather strongly (&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;red bars&lt;/span&gt;&lt;/strong&gt;), but there seems to bee too little supply. Is that the fear of a vendor lock-in or is it just because Microsoft is considered evil that the programmers don't like &lt;em&gt;.NET&lt;/em&gt;? The same case of too little supply for &lt;em&gt;PHP&lt;/em&gt;, but here I must mention that the hourly rates for &lt;em&gt;PHP&lt;/em&gt; tend to be rather low - &lt;em&gt;PHP&lt;/em&gt; still considered a hacker language?&lt;br /&gt;&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5417649859246294194" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 476px; CURSOR: hand; HEIGHT: 285px; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_79IsVE3vX_Y/Sy9b19HSBLI/AAAAAAAAAFs/-FSgoaKJOIs/s400/programmierspachen+12.2009.bmp" border="0" /&gt;&lt;br /&gt;And now look at the last but one language wit a longwinded German name I won't retype here (too lazy). In fact it's not a language of its own, but rather denotes "all the other ones in there", which include everything fancy (or just plain old). You see there is too much supply, the IT managers seem to be more conservative than programmers, no surprise here.&lt;br /&gt;&lt;br /&gt;Which leaves us with &lt;em&gt;C/C++&lt;/em&gt; and &lt;em&gt;Java&lt;/em&gt;. &lt;em&gt;Java&lt;/em&gt; is unmistakably the 500 pound gorilla here, but it hopelessly over-supplied (&lt;strong&gt;&lt;span style="color:#3366ff;"&gt;blue bar&lt;/span&gt;&lt;/strong&gt;)! For&lt;em&gt; C/C++&lt;/em&gt; the situation isn't so dramatic, an I'm glad I specialize in &lt;em&gt;C++&lt;/em&gt;!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The proposed course of action here:&lt;/strong&gt; go away from &lt;em&gt;Java&lt;/em&gt; (or well, from everything else for that matter) and start on &lt;em&gt;.NET&lt;/em&gt;!&lt;br /&gt;&lt;br /&gt;Now the overview of technologies in the freelancer projects:&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img id="BLOGGER_PHOTO_ID_5417655388170195378" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 498px; CURSOR: hand; HEIGHT: 287px; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_79IsVE3vX_Y/Sy9g3x9dkbI/AAAAAAAAAF0/2uowaJSap-U/s400/technologies+2009.bmp" border="0" /&gt;&lt;/p&gt;&lt;p&gt;Software development comes first (sitll a little place for more work -&lt;strong&gt;&lt;span style="color:#cc0000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;red bar&lt;/span&gt;&lt;/strong&gt;!), then system management (puse service and support), however the suply is much too big (&lt;strong&gt;&lt;span style="color:#3366ff;"&gt;blue bar&lt;/span&gt;&lt;/strong&gt;)! It's just as bad as for SAP programming - in the past the eternal cash cow with the ridiculously high hourly wages, now it's a real "problem child" - the market seems to be breaking down. Banking crisis anyone? For Web development and "graphics, content and media" there's much too much demand, just like in the PHP case above. Then the ominous field "IT consulting", where I don't have any idea wht it is, sorry, no comments there :-/. One interesting filed is "Executive consulting" with so much demand and so little supply, maybe everyone is jst too shy to position theirself in that niche?&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;The proposed course of action here&lt;/strong&gt;: either stay with software development or move into "Executive consulting"! &lt;/p&gt;&lt;p&gt;Having said that: &lt;strong&gt;&lt;span style="color:#009900;"&gt;Merry&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Christmas&lt;/span&gt; &lt;span style="color:#009900;"&gt;you&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;all&lt;/span&gt;!&lt;/strong&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-7481825544492963345?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/12/local-language-trends-2009.html</link><author>noreply@blogger.com (Marek Krj)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_79IsVE3vX_Y/Sy9b19HSBLI/AAAAAAAAAFs/-FSgoaKJOIs/s72-c/programmierspachen+12.2009.bmp' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-735207385071851953</guid><pubDate>Tue, 24 Nov 2009 16:23:00 +0000</pubDate><atom:updated>2009-12-14T00:33:50.381-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Java</category><title>More about Java Closures</title><description>&lt;p&gt;&lt;/p&gt;Surprize, surprize! Hear, hear! &lt;blockquote&gt;&lt;em&gt;One year ago, Mark Reinhold, Principal Engineer at Sun Microsystems, announced At the Devoxx conference in Antwerp, Belgium that the next major release of Java, JDK 7, would&lt;strong&gt; not include closures&lt;/strong&gt;. At the same conference this year, however, Reinhold announced in a surprise turn around the Java&lt;strong&gt; would be getting closures after all in JDK 7&lt;/strong&gt;&lt;/em&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;a href="#ref1"&gt;*&lt;/a&gt;&lt;/blockquote&gt;&lt;p&gt;More specifically, they adopt the &lt;em&gt;BGGA&lt;/em&gt; proposal (look &lt;a href="http://ib-krajewski.blogspot.com/2009/10/javas-closures-debate-for-c-eyes.html"&gt;here&lt;/a&gt;) but &lt;strong&gt;without&lt;/strong&gt; the &lt;em&gt;non-local return&lt;/em&gt; (look &lt;a href="http://ib-krajewski.blogspot.com/2009/10/javas-closures-debate-for-c-eyes.html"&gt;here&lt;/a&gt;) &lt;em&gt;and control invocation statements&lt;/em&gt;. This leaves Java without any destructor or C# style &lt;em&gt;using&lt;/em&gt; statements support!&lt;br /&gt;&lt;br /&gt;What can I say? I can only reinstate what I said in my previous post: comparing to the development of the C# language (look here &lt;a href="#ref2"&gt;**&lt;/a&gt; for an interesting inteview about LINQ and its supporting language features) the Java language looks increasingly mouldy (ouch!!!).&lt;br /&gt;&lt;br /&gt;But maybe I'm mistaken? maybe there will be some support for modern ressource management in Java but it's decoupled from the closure proposal? Let's hope so.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Update:&lt;/span&gt;&lt;/strong&gt; well, I didn't hope in vain, there will be a feature for this: Automatic Ressource Management (see &lt;a href="http://code.joejag.com/2009/new-language-features-in-java-7/"&gt;here&lt;/a&gt;)!!! Moreover, we'll got a little bit of type inference for the right hand generic expressions with &lt;em&gt;new&lt;/em&gt; (as Google Collections provides it) with a "diamond" operator (?) &amp;lt;&amp;gt;, and strings in the switch statement (as in &lt;em&gt;Groovy&lt;/em&gt;). &lt;strong&gt;All in all you cannot complain&lt;/strong&gt;, I'd say, and some bloggers (ehm...) shouldn't be too quick to bash Java 7!&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;&lt;a name="ref1"&gt;*&lt;/a&gt; I found the news here: &lt;a href="http://www.artima.com/forums/flat.jsp?forum=276&amp;amp;thread=274496"&gt;http://www.artima.com/forums/flat.jsp?forum=276&amp;amp;thread=274496&lt;/a&gt;&lt;br /&gt;&lt;a name="ref2"&gt;**&lt;/a&gt; &lt;a href="http://www.infoq.com/interviews/LINQ-Erik-Meijer"&gt;http://www.infoq.com/interviews/LINQ-Erik-Meijer&lt;/a&gt;, BTW I found an interesting quote of general interest there: &lt;/p&gt;&lt;blockquote&gt;&lt;em&gt;Actually, if you look at where I'm going, &lt;strong&gt;I'm getting more and more into old school object orientation with interfaces and so on, going away from functional programming. &lt;/strong&gt;If you are passing a high order function you are passing one thing, one closure. If you're passing an interface or a class, you are passing many because you are passing a whole V table. These can all be recursive and so on. I'm rediscovering object oriented programming and I feel that maybe I wasted some of my time doing functional programming and missed out on objects.&lt;/em&gt;&lt;/blockquote&gt;&lt;p&gt;You see, it's not only the functional programminch which is gonna be the Big Next Thing! I think that we cannot just condemn OO and go all for the functional. OO has its merits when structuring code, and a hybrid OO/functional approach seems to be a good thing to me! &lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-735207385071851953?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/11/more-about-java-closures.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-2615814880097962593</guid><pubDate>Thu, 12 Nov 2009 07:36:00 +0000</pubDate><atom:updated>2009-11-11T23:57:08.919-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>misc</category><title>Songs in code</title><description>&lt;p&gt;&lt;/p&gt;Won't explain what &lt;a href="http://twitter.com/search?q=songsincode#search?q=songsincode"&gt;they&lt;/a&gt; are, because it's obvious. These two made me laugh:&lt;br /&gt;&lt;br /&gt;Bob Marley's (and Groovy's): &lt;pre&gt;  4.times{&lt;br /&gt;  !woman == !cry&lt;br /&gt;  }&lt;/pre&gt;and REM's (and SQL's): &lt;pre&gt;  DROP TABLE MyReligion&lt;/pre&gt;but normally they are boring, uninspired or plainly wrong, like this one:&lt;pre&gt;  while(young)&lt;br /&gt;  {} &lt;span style="color:#33cc00;"&gt;// loops forever&lt;/span&gt;&lt;/pre&gt;Come on, the whole thing is that &lt;em&gt;young&lt;/em&gt; is a volatile variable, which will somehow, sometimes be set to &lt;em&gt;false&lt;/em&gt;! ;-)&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-2615814880097962593?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/11/songs-in-code.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-8850633943384280247</guid><pubDate>Fri, 30 Oct 2009 16:29:00 +0000</pubDate><atom:updated>2009-11-08T11:42:05.142-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Java</category><title>Java's Closures Debate for C++ Eyes</title><description>&lt;p&gt;&lt;/p&gt;&lt;br /&gt;Years ago Sun described Microsoft's delegate extension proposal for Java as:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;Many of the advantages claimed for Visual J++ delegates -- type safety, object orientation, and ease of component interconnection -- are simply consequences of the security or flexibility of the Java object model.&lt;br /&gt;....&lt;br /&gt;Bound method references are simply unnecessary. They are not part of the Java programming language, and are thus not accepted by compliant compilers. Moreover, they detract from the simplicity and unity of the Java language.&lt;a href="#ref1"&gt;*&lt;/a&gt;&lt;/em&gt; &lt;/blockquote&gt;&lt;p&gt;blah, blah, blah, marketing drivel! I don't know what is more annoying here: &lt;strong&gt;1.&lt;/strong&gt; the object-oriented orthodoxy, or&lt;strong&gt; &lt;/strong&gt;&lt;strong&gt;2.&lt;/strong&gt; the complacency that "we know it all better! Be that as it may, but now James Gosling (Mr Java himself) says he'd always &lt;a href="http://blogs.sun.com/jag/entry/closures"&gt;wanted closures&lt;/a&gt; instead of anonymous inner classes in Java, and there is not one, but whole 3 (!!!) proposals how to include functions as first class citiciens of the Java language! So much for the "simply unnessary" argument...&lt;br /&gt;&lt;br /&gt;And there is considerable controversy around the very idea of closures, somehow similiar to the C++ debate around Concepts we discuseed recently, deeming it unnecessary and "too complicated". As we are lucky to get lambda functions in C++0x and don't complain the least, the debate in Java community made me curious. &lt;strong&gt;Come on, why not to have closures?&lt;/strong&gt; Even C# has some!&lt;br /&gt;&lt;br /&gt;So what is a closure? For the sake of this blog entry it is something like a lambda function in C++ (or Python or Groovy), i.e. an anonymous, freestanding function: &lt;/p&gt;&lt;pre&gt;  auto print = [] (int x) { cout &amp;lt;&amp;lt; x; }&lt;/pre&gt;Now let's do it in Java.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. Proposals&lt;/h2&gt;&lt;p&gt;So let's have a look at the three proposals.&lt;a href="#ref2"&gt;**&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;a) BGGA&lt;/strong&gt; (Bracha, Gafter, Gosling, Ahé)&lt;br /&gt;&lt;br /&gt;This is the most ambitious proposal. It introduces a new type into the language: a function type, and a totally new notation for it. This notation remainds me of Haskell's or of the lambda calculus types. &lt;/p&gt;&lt;blockquote&gt;&lt;em&gt;{T =&amp;gt; U}&lt;/em&gt; for a function from T to U&lt;br /&gt;&lt;em&gt;{T =&amp;gt; U =&amp;gt; V}&lt;/em&gt; (or is it&lt;em&gt; {T,U =&amp;gt; V}&lt;/em&gt;?) for a function from T and U to V &lt;/blockquote&gt;I think this notation is one of the purposes why many in the Javaland doesn't like this proposal a bit. The second one will be surely the nonlocal control statements (returns, breaks etc). Come again, non-what? Well, it means that for example the return statement doesn't return from the closure but from the scope which invoked the closure! They don't bind to the closure but to the environment! Why should that be good for? Wait till next section for expanation, dear reader.&lt;br /&gt;&lt;br /&gt;An usage example: &lt;pre&gt;  {Integer =&amp;gt; void} print = { Integer x =&amp;gt; System.out.println(x); }&lt;/pre&gt;&lt;strong&gt;b) CICE&lt;/strong&gt; (Concise Instance Creation Expressions)&lt;br /&gt;&lt;br /&gt;This is the simplest of the three proposals. Basically it's only a syntactic sugar for defining anonymous classes on the run, nothing more. No first class functions! No obscure functional programming theory!&lt;br /&gt;&lt;br /&gt;An usage example:&lt;br /&gt;&lt;pre&gt;  public interface IPrint { public void invoke(Integer x);} &lt;span style="color:#33cc00;"&gt;// exacltly 1 method!&lt;/span&gt;&lt;br /&gt;  IPrint print = IPrint(Integer x) { System.out.println(x); }&lt;/pre&gt;It's the simplest of the proposals, but for my mind, the most annoying one: you have always to refer back to some interface definition, and it sucks!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;c) FCM&lt;/strong&gt; (First Class Methods)&lt;br /&gt;&lt;br /&gt;This is a kind of middle ground between the previous two: it introduces first class functions, but doesen't have the nonlocal binding for closures return statement and the irritatinmg lambda-type notation.&lt;br /&gt;&lt;br /&gt;An usage example:&lt;br /&gt;&lt;pre&gt;  #(void(Integer)) print = #(Integer x) { System.out.println(x); }&lt;/pre&gt;From all the three syntactically I like the BGGA proposal the best, as you can just write your code in a familiar code-block manner, without the FCM's hash or CICE's interface tag.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;2. The Debate&lt;/h2&gt;&lt;p&gt;To put it mildly, sometimes I find the debate somehow childish. Here the typical arguments:&lt;a href="#ref3"&gt;***&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;strong&gt;&lt;em&gt;pro:&lt;/em&gt;&lt;/strong&gt; If the don't implement closures, I'll never code any line of Java an will go to Scala&lt;br /&gt;&lt;em&gt;&lt;strong&gt;con:&lt;/strong&gt;&lt;/em&gt; If they implement the closures, I'll just break down and cry... I cannot change to any other language, but I'll hate you all for that! &lt;/blockquote&gt;Come on people! It's just a language feature! And you don't have to use it at all if you don't like it. Beside this, it's not the developers that choose languages, it's the managers! If they can be convinced that a language offers some substantial benefits, it will be adopted. But not because you like Scala or something else better!&lt;br /&gt;&lt;br /&gt;Will the closures make Java too complicated? Would they really&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;"...complicate the language beyond normal usability: mainstream programmers will turn away from Java, so the argument goes, and move on to simpler programming languages&lt;br /&gt;...&lt;br /&gt;Java will turn into a guru language used only by experts in niche areas&lt;/em&gt;"&lt;a href="#ref2"&gt;**&lt;/a&gt;?&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;So tell me which the simpler languages for the JVM are! I can see none (nonscripting one) which would be simpler. Guru language? Are you kidding me? The closures are an attempt to make Java less verbose, so everyone should be happy. So why the fear? &lt;/p&gt;&lt;p&gt;One (non PC) answer might be, that the "too complicated" camp is perfectly happy with the language as it is now, doesn't mind the lack of elegance, and don't want learn new mechanisms. &lt;strong&gt;And maybe there is some point where there are to much mechanisms&lt;/strong&gt; (or paradigms) in the language? Me, as a C++ guy, I'm accustomed to the "multiparadigm design", as C++ is a real behemot in that respect. I just try not to think about the mechanisms I'm not using now. &lt;/p&gt;&lt;p&gt;Maybe in Javaland this isn't so simple, as the programmers were lectured for years that there is only one paradigm in the world: the object oriented one. This would explain why some people think that the addition of generics stressed the complexity of language to the limits (the other explanation is the design choices for backward compatibility, in particular the wildcards).&lt;br /&gt;So it seems to be either the the irritation caused the generics or the unusual nonlocal returns in BGGA which provoked the strong feelings, dont you think?&lt;/p&gt;&lt;h2&gt;3. Discussion&lt;/h2&gt;&lt;br /&gt;But let's get more technical: &lt;strong&gt;why do we need closures in Java?&lt;/strong&gt; The answer is probably: because Ruby has got it! The Java community seems still to be in a collective Ruby trauma, and emulating Ruby features is a good enough reason in itself. As they used to say behind the Iron Curtain: to learn form Ruby is to learn how to win! So now, just as in Ruby (or Groovy and C# for that count) we'll be able to write in Java:&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;  Utils.forEach(names, { Integer x =&amp;gt; System.out.println(x); }); &lt;span style="color:#33cc00;"&gt;// BGGA&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;So, that's kind what we've always had in C++ with STL and lambda libraries.&lt;br /&gt;&lt;br /&gt;But that's not all there is! In each of the three above proposals there is a second part, which allows some kind of finer-grained resource management, i.e. a kind of &lt;a href="http://ib-krajewski.blogspot.com/2008/12/do-we-need-constructors.html"&gt;"destructors for the modern times"&lt;/a&gt;. I can only say "finally", because Java's resource management is just a big pain in the rear.&lt;br /&gt;&lt;br /&gt;BGGA tries to achieve this goal by nonlocal control statements mentioned above, which will then allow to implement the &lt;a href="http://ib-krajewski.blogspot.com/2008/12/do-we-need-constructors.html"&gt;"execute around"&lt;/a&gt; pattern as so called "control abstractions"&lt;a href="#ref2"&gt;**&lt;/a&gt; , but are somehow not very intuitive. In the BGGA proposal the keyword &lt;em&gt;this&lt;/em&gt; will be lexically bound and will &lt;strong&gt;automatically refer to an instance of the enclosing type&lt;/strong&gt; in which the closure is defined. For me, Groovy solves the problem of nonlocal bindings somehow clearer - introducing two members for a closure: &lt;em&gt;owner&lt;/em&gt; (refering to the enclosing object) and &lt;em&gt;delegate&lt;/em&gt; (defining the lexical binding). In tis way wee can always explicitely say what type of lexical binding we need, the default value of &lt;em&gt;delegate&lt;/em&gt; being &lt;em&gt;owner&lt;/em&gt;!&lt;br /&gt;&lt;br /&gt;The other proposals try to address the same question as well: CICE by &lt;a href="http://docs.google.com/View?docid=dffxznxr_1nmsqkz"&gt;ARM&lt;/a&gt; (Automatic Resource Management Blocks - a special type of block where a dispose method will be automatically applied when leaving it) and FCM by &lt;a href="http://docs.google.com/View?docid=ddhp95vd_8f8zkn3"&gt;JCA&lt;/a&gt; (Java Control Abstractions - this one is more like the "execute around" pattern mentioned above, and requires nonlocal lexical bindings as BGGA does).&lt;br /&gt;&lt;br /&gt;At this point &lt;strong&gt;let us try to draw some conclusions&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Firstly&lt;/strong&gt;: with C# having the lambdas in its 3.0 version&lt;a href="#ref4"&gt;****&lt;/a&gt;, and C++0x having lambdas and the auto specifier, leaving closures out of Java 7 would let Java looking pretty old in comparison!&lt;br /&gt;&lt;br /&gt;But don't despair, there is a library solution out there (&lt;a href="http://code.google.com/p/lambdaj/"&gt;http://code.google.com/p/lambdaj/&lt;/a&gt;). Maybe a library solution will be suffiecient in this case? I don't know, the syntax doesn't look very intuitive, but it's probably the best you can get.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Secondly&lt;/strong&gt;: what I find the most instructive lesson here is however, that we can see that &lt;strong&gt;the old notion of destructor isn't so old-fashioned after all!&lt;/strong&gt; C# has meanwhile its &lt;em&gt;using&lt;/em&gt; statement and Java deserves (and needs) some destructor-like mechanism as well! So much for the (former) "modern languages".&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;&lt;a name="ref1"&gt;*&lt;/a&gt; form SUN's rebuttal of delegates - &lt;a href="http://java.sun.com/docs/white/delegates.html"&gt;http://java.sun.com/docs/white/delegates.html&lt;/a&gt;, where they claim that delegates (i.e. C# equivalent of C++ member function pointers) are bad, because the anonymous classes can do all the same ans are object oriented too! A typical case ob the object-craze of the nineties IMHO&lt;br /&gt;&lt;br /&gt;&lt;a name="ref2"&gt;**&lt;/a&gt; I will only skim the surface here, as my aim is only the look-and-feel. If you need more information a good place to start is: &lt;a href="http://www.javaworld.com/javaworld/jw-06-2008/jw-06-closures.html"&gt;http://www.javaworld.com/javaworld/jw-06-2008/jw-06-closures.html&lt;/a&gt; &lt;em&gt;("Understanding the closures debate - Does Java need closures? Three proposals compared"&lt;/em&gt;, by Klaus Kreft and Angelika Langer, JavaWorld.com, 06/17/08)&lt;br /&gt;&lt;br /&gt;&lt;a name="ref3"&gt;***&lt;/a&gt; rephrased ;-U from the discussion here - &lt;a href="http://infinitescale.blogspot.com/2007/12/bgga-closures-end-of-many-java-careers.html"&gt;http://infinitescale.blogspot.com/2007/12/bgga-closures-end-of-many-java-careers.html&lt;/a&gt;, but seen in that form on other places in the Web&lt;br /&gt;&lt;br /&gt;&lt;a name="ref4"&gt;****&lt;/a&gt; Let us digress a little: in C# we'd define the above lambda like that: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;  Function&amp;lt;int, void&amp;gt; p = name =&amp;gt; Console.WriteLine(name);&lt;/pre&gt;or use it directly like that: &lt;pre&gt;  names.FindAll(name =&amp;gt; name != "Marek")&lt;br /&gt;       .ForEach(name =&amp;gt; Console.WriteLine(name));&lt;/pre&gt;&lt;p&gt;Note that in C++ the lambdas aren't templates (they are monomorphic, i.e. we must define the argument types) but in C# they are! To achieve the same in C++ you have to use a template lambda library. &lt;/p&gt;&lt;p&gt;I mean the C# language is looking increasingly cool, perhaps I should learn it, as everybody can program Java these days???&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-8850633943384280247?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/10/javas-closures-debate-for-c-eyes.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>18</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-1072959027103826050</guid><pubDate>Thu, 27 Aug 2009 10:52:00 +0000</pubDate><atom:updated>2009-10-09T08:17:50.919-07:00</atom:updated><title>Tony Hoare and the meaning of life (well, almost...)</title><description>&lt;p&gt;&lt;/p&gt;You know, I was always &lt;a href="http://ib-krajewski.blogspot.com/2008/05/why-is-software-engineering-not.html"&gt;wondering&lt;/a&gt; about programming - is it an art, a craft, or is it an engineering discipline? Some crazy hackers maintain it be an art, more down-to-earth types oscillate between craft and engineering.&lt;br /&gt;&lt;br /&gt;My personal feeling was that it couldn't be engineering - I missed the scientific part of it, it was too "soft". For me software engineering appeared rather to be a set of rules of thumb for organizing our mental work (functions, classes, modules...), something from the realm of cognitive science perhaps :-). For example I couldn't take my multithreading program and &lt;strong&gt;prove it not to deadlock&lt;/strong&gt; in a future (i.e not yet written, but planned) installment of this blog...&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. The presentation &lt;/h2&gt;&lt;p&gt;And then, some months ago, I came across that presentation&lt;a href="#ref_1"&gt;*&lt;/a&gt; given on &lt;em&gt;QCon 2009 Conference&lt;/em&gt; by Sir C.A.R. Hoare (aka Tony Hoare of the &lt;em&gt;Hoare logic&lt;/em&gt;, &lt;em&gt;Quicksort&lt;/em&gt;, and &lt;em&gt;CSP&lt;/em&gt; fame) about relationships between programming and computer science.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;Computer Science is about how programs run and how correct programs can be constructed &lt;/em&gt;&lt;a href="#ref_1"&gt;&lt;em&gt;*&lt;/em&gt;&lt;/a&gt; &lt;/blockquote&gt;By the way, I used to dislike the all-present video presentations, which seem to be replacing the old-fashioned articles as programmer's information source of choice. Well, to put it frankly, I &lt;strong&gt;hated&lt;/strong&gt; &lt;strong&gt;them&lt;/strong&gt;! Instead of beeing able to quickly scoop the essentials and then read the article if it'd interest me, I'm now forced to hear for hours to some uninspiring presentations and often to &lt;strong&gt;some really horrible accents to boot,&lt;/strong&gt; as to discover that in the end only the title of the video was interesting!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_79IsVE3vX_Y/SkYlyabQ_DI/AAAAAAAAAFU/WoVNwyU_Xbo/s1600-h/THoare.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5352006755193781298" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 101px; CURSOR: hand; HEIGHT: 107px" alt="" src="http://2.bp.blogspot.com/_79IsVE3vX_Y/SkYlyabQ_DI/AAAAAAAAAFU/WoVNwyU_Xbo/s320/THoare.jpg" border="4" /&gt;&lt;/a&gt;But on the other side, with the video presentations I'm no able to hear people like Linus Thorvald&lt;a href="#ref_2"&gt;**&lt;/a&gt; and Tony Hoare in person, and it proved to be very rewarding to me in both cases. Watching Tony Hoare was a great pleasure - &lt;strong&gt;he's a wonderfully gentle and good humored old man, I'd say my idol of sorts&lt;/strong&gt;. And as he's got his first degree in philosophy, so he's bound to have some interesting insights in the question at hand.&lt;br /&gt;&lt;br /&gt;His answer is both simple and compelling (I'm rephrasing it here):&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;Software Engineering is an engineering discipline because it uses Computer Science, and Computer Science is a science because its results are exploited and confirmed by software products!&lt;/em&gt;&lt;a href="#ref_1"&gt;&lt;em&gt;*&lt;/em&gt;&lt;/a&gt;&lt;em&gt; &lt;/em&gt;&lt;/blockquote&gt;Sounds at first rather convincing, doesn't it? But wait, for a philosophy major, isn't he overlooking something? &lt;p&gt;&lt;/p&gt;&lt;h2&gt;2. Circulus Vitiosus?&lt;/h2&gt;&lt;p&gt;Well, embarassingly, it's looking suspiciously similiar to a &lt;a href="http://en.wikipedia.org/wiki/Begging_the_question"&gt;circular argument &lt;/a&gt;, right? For SW Engineering gets justified by the CS but the CS is justified by SW Engineering? It certainly appeared like this to me at the first glance So let us have a closer look at it: &lt;blockquote&gt;science is: &lt;em&gt;"the systematic study of the structure and behaviour of the physical world, especially by watching, measuring and doing experiments, and the development of theories to describe the results of these activities "&lt;a href="#ref_3"&gt;***&lt;/a&gt; &lt;/em&gt;&lt;/blockquote&gt;Does this apply here? Well, maybe, if for "physical world" we substitute the human-built things like hardware and binaries. But wait, don't we rather work with mental constructs instead (you know, languages, functions, classes)? Well, yes, but they are models, like math is a model in civil engineering. In the end it's all about how the binary runs!&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;engineering is: &lt;em&gt;"to design and build something using scientific principles"&lt;a href="#ref_3"&gt;***&lt;/a&gt; &lt;/em&gt;&lt;/blockquote&gt;This one seems to fit perfectly. So both parts of the argument are corrct, but it is a circular one? Let it translate it form English into the language of logic: &lt;blockquote&gt;&lt;em&gt;(&lt;strong&gt;CS&lt;/strong&gt; usedIn &lt;strong&gt;SWEng&lt;/strong&gt; =&gt; &lt;strong&gt;SWEng&lt;/strong&gt; is &lt;strong&gt;Eng&lt;/strong&gt;) and (&lt;strong&gt;CS&lt;/strong&gt; usedIn &lt;strong&gt;SWEng&lt;/strong&gt; =&gt; &lt;strong&gt;CS&lt;/strong&gt; is &lt;strong&gt;Sc&lt;/strong&gt;)&lt;/em&gt;&lt;/blockquote&gt;You see it's not really circular, as it's two separate propositions, and they are just rephrasing the two above definitions (check it!). Because science is defined as a special, rigorous kind of examination of the physical world, and engineering uses science when dealing with this world directly! But wait again, it's not said that we are allowed to use only scince in engineering, or ist it? &lt;p&gt;&lt;/p&gt;&lt;h2&gt;3. The Engineer an the Scientist &lt;/h2&gt;&lt;p&gt;This leads us to another interesting aspect of that presentation, which was the comparison between science and engineering, and how they relate to each other. Somehow explaining the above realtionship (I must paraphrase again):&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;so it's first:&lt;/strong&gt;&lt;br /&gt;scientists are interested in pure truths, i.e. programs which doesn't have errors, while an engineer must compromise, i.e. live with programs that have got some errors,&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;&lt;em&gt;&lt;strong&gt;and second:&lt;br /&gt;&lt;/strong&gt;scientists are interested in certainity, while an engineer lives in incertanity, must take risks and perform risk management,&lt;br /&gt;&lt;/em&gt;&lt;strong&gt;&lt;br /&gt;&lt;em&gt;and thus:&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;scientists should be women, engineers should be men (Yes, he really made this little joke:) &lt;/em&gt;&lt;/blockquote&gt;&lt;p&gt;There are several other comparisions along these lines in the presentation, and furthermore, even a gradation between the two extremes like applied scientist or scientific engineer are introduced. So there is (almost) a continuum of positions between the two extremes of pure CS scientist an a common hacker. &lt;/p&gt;&lt;p&gt;And that fact harbors &lt;strong&gt;some kind of consolation&lt;/strong&gt;, particularly if I'm in a very pedestrian project and must do the most boring things. Just remember, you can always move up the ladder, and use more science, more absolute truths, and thus (as the ancients believed) come in contact with more beauty. An that's maybe the ultimate &lt;em&gt;"consolatio philosophiae“&lt;/em&gt;, or do you think this is an exaggeration on my part? &lt;p&gt;&lt;/p&gt;--&lt;br /&gt;&lt;a name="ref_1"&gt;&lt;/a&gt;* all citations are not original but rephrased by yours truly, so if they are wrong it's my fault! Original source: Tony Hoare, &lt;em&gt;"The Science of Computing and the Engineering of Software",&lt;/em&gt; QCon Conference, Jun 11, 2009 , London: &lt;a href="http://www.infoq.com/presentations/tony-hoare-computing-engineering"&gt;http://www.infoq.com/presentations/tony-hoare-computing-engineering&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="ref_2"&gt;&lt;/a&gt;** for example this presentation by Linus was fun: &lt;a href="http://www.youtube.com/watch?v=4XpnKHJAok8&amp;amp;feature=player_embedded"&gt;http://www.youtube.com/watch?v=4XpnKHJAok8&amp;amp;feature=player_embedded&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="ref_3"&gt;&lt;/a&gt;*** the definitions are taken from &lt;em&gt;"Cambridge Advanced Learner's Dictionary",&lt;/em&gt; as I was looking for simplicity: &lt;a href="http://dictionary.cambridge.org/"&gt;http://dictionary.cambridge.org/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-1072959027103826050?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/08/tony-hoare-and-meaning-of-life-well.html</link><author>noreply@blogger.com (Marek Krj)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_79IsVE3vX_Y/SkYlyabQ_DI/AAAAAAAAAFU/WoVNwyU_Xbo/s72-c/THoare.jpg' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-7774980874085542426</guid><pubDate>Tue, 28 Jul 2009 14:16:00 +0000</pubDate><atom:updated>2009-09-01T02:31:57.783-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>software engineering</category><category domain='http://www.blogger.com/atom/ns#'>C++</category><title>Two C++ curiosities with a deeper meaning</title><description>&lt;p&gt;Lately, I was quite surprised by two things in the realm of programming, both of them C++ related. &lt;strong&gt;The first one is the new attribute syntax&lt;/strong&gt; for C++09*, which I curiously failed to notice in the new standard proposal as I first had &lt;a href="http://ib-krajewski.blogspot.com/2009/01/ive-read-on-my-local-german-c-forum.html"&gt;a look&lt;/a&gt; at it.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. The first one&lt;/h2&gt;&lt;br /&gt;What are attributes? No, they aren't class data members with a convenient access syntax in this case (like Groovy's &lt;em&gt;attribute&lt;/em&gt; syntax - or was it Python?).&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;I personally only knew attributes as an ugly Microsoft Windows COM-specific hack, by virtue of which you can inject COM related information into C++ code. Look at this example:&lt;/p&gt;&lt;pre&gt;  #define _ATL_ATTRIBUTES 1&lt;br /&gt;  #include &amp;lt;atlbase.h&amp;gt;&lt;br /&gt;  #include &amp;lt;atlcom.h&amp;gt;&lt;br /&gt;  #include &amp;lt;string.h&amp;gt;&lt;br /&gt;  #include &amp;lt;comdef.h&amp;gt;&lt;/pre&gt;&lt;pre&gt;  &lt;span style="color:#3366ff;"&gt;[module(name="test")];&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;  &lt;span style="color:#3366ff;"&gt;[ object, uuid("00000000-0000-0000-0000-000000000001"), library_block ]&lt;/span&gt;&lt;br /&gt;  __interface IFace&lt;br /&gt;  {&lt;br /&gt;     &lt;span style="color:#3366ff;"&gt;[ id(0) ]&lt;/span&gt; int int_data;&lt;br /&gt;     &lt;span style="color:#3366ff;"&gt;[ id(5) ]&lt;/span&gt; BSTR bstr_data;&lt;br /&gt;  };&lt;/pre&gt;&lt;pre&gt;  &lt;span style="color:#3366ff;"&gt;[ coclass, uuid("00000000-0000-0000-0000-000000000002") ]&lt;/span&gt;&lt;br /&gt;  class MyClass : public IFace&lt;br /&gt;  {&lt;br /&gt;  private:&lt;br /&gt;    int m_i;&lt;br /&gt;    BSTR m_bstr;&lt;/pre&gt;&lt;pre&gt;  public:&lt;br /&gt;    MyClass();&lt;br /&gt;    ~MyClass()&lt;/pre&gt;&lt;pre&gt;    int get_int_data();&lt;br /&gt;    void put_int_data(int _i);&lt;br /&gt;    BSTR get_bstr_data();&lt;br /&gt;    void put_bstr_data(BSTR bstr);&lt;br /&gt;  };&lt;/pre&gt;Doesn't it send shivers down your spine? You might say I'm not consequent, because I just lashed out on excessive XML configuration files (&lt;a href="http://ib-krajewski.blogspot.com/2009/04/from-dll-to-xml-hell.html"&gt;here&lt;/a&gt;), but when presented with the alternative, I don't like it either! And now, there are annotations in Java too, doing a similiar thing... What I can say, I was growing up with the classical paradigm of the standalone programm using external functionality through libraries. But nowadays you don't program just for the machine or the OS, you program for same giant framework! Did you hear the phrase &lt;em&gt;"programming by bulldozer"?&lt;/em&gt; &lt;strong&gt;And to my mind there's no satisfactory model of how to do this!&lt;/strong&gt; For me both the configuration file madness and mixing code with meta information are both somehow unsatisfactory. Look at this example &lt;em&gt;JBoss Seam&lt;/em&gt; action class:&lt;br /&gt;&lt;pre&gt;  &lt;span style="color:#3366ff;"&gt;@Stateless@Name("manager")&lt;/span&gt;&lt;br /&gt;  public class ManagerAction implements Manager {&lt;br /&gt;      &lt;span style="color:#3366ff;"&gt;@In @Out&lt;/span&gt; private Person person;&lt;br /&gt;      &lt;span style="color:#3366ff;"&gt;@Out&lt;/span&gt; private List&amp;lt;Person&amp;gt; fans;&lt;br /&gt;   }&lt;/pre&gt;Well, what do you think, does it look OK? We have (nearly) POJOs here (i.e. no framework class derivation) which is the Holy Grail in Java programming lately, but the code is littered with annotations. To me they are no better than the old C++ event macros used in some very old Windows frameworks!&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now the question arises: is that a cognitive bias caused by the preceeding simple (and thus elegant) programming model? Remember, even &lt;a href="http://en.wikipedia.org/wiki/Herb_Sutter"&gt;Herb Sutter&lt;/a&gt;, when charged with the task of making &lt;em&gt;.NET&lt;/em&gt; programming possible with C++, didn't embrace the traditional program + library model! He rather created a language extension, the &lt;em&gt;C++/CLI&lt;/em&gt; langauge dialect. Maybe he was constrained to do so by his commision of getting &lt;em&gt;Managed C++&lt;/em&gt; up to speed, but on the other side, in the design paper he argued it's the natural way and compliant with the spirit of C++. Personally I didn't like this language extension a bit, opting for a carefully designed library or framework oriented solution, but maybe it's simply not possible???&lt;/p&gt;&lt;p&gt;Sorry, I digressed. So back to the subject! &lt;/p&gt;The second species of attributes I knew were the Gnu attributes, looking like that:&lt;br /&gt;&lt;pre&gt;  void kill(int) &lt;span style="color:#3366ff;"&gt;__attribute__((__noreturn__))&lt;/span&gt;; &lt;span style="color:#009900;"&gt;//GCC specific&lt;/span&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;/pre&gt;but I never used them either, because I thought they were only of any use with som Gnu-specific langauge extensions, which is always avoided like the plague. And do you know how the new standard compliant attributes look like now? Look (&lt;em&gt;"C++09 Working Draft n2798"&lt;/em&gt;, &lt;em&gt;10.2008&lt;/em&gt;, Chap. 7.6.):&lt;br /&gt;&lt;pre&gt;  class C&lt;br /&gt;  {&lt;br /&gt;    virtual void f &lt;span style="color:#3366ff;"&gt;[[final]] &lt;/span&gt;();&lt;br /&gt;  };&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;It's a crossbred of Microsoft an Gnu annotations, isn't it?&lt;/strong&gt; That's why everyone is happy, and why the syntax is really ugly. And do you know what? There are a fistful of annotations defined in the standard (but vendors are allowed to add new ones) and one of them is, you guess it, &lt;em&gt;final&lt;/em&gt;! Could someone tell me why should this one be an annotation and not a keyword - is it supposed to be matter in specific environments? Or are we making the way clear for vendor specific language extension? So maybe the whole annotation thing is in there to placate the major vendors: Microsoft and Gnu? Because as I got it (correct me please if I'm wrong!) &lt;strong&gt;there isn't a mechanism to plug in an attribute processor&lt;/strong&gt; as in Microsoft COM-attributes or Java's annotations, so the whole construct is aimed at the compiler writers.&lt;/p&gt;&lt;p&gt;Summing up: first, Java annotation syntax, as seen in the &lt;em&gt;Seam&lt;/em&gt; example above, seems to be more pleasing to the eyes, and second, I didn't really grasp the need for standardized annotations, except for vendor's conveniency.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;2. The second one&lt;/h2&gt;&lt;p&gt;The second curious thing I stumbled upon &lt;strong&gt;is the removal of Concepts&lt;/strong&gt; (or should say of the "Concepts" concept?) from the C++09 standard proposal. As I read**, it was the standard library where the Concepts were first removed from. Come again? As I had &lt;a href="http://ib-krajewski.blogspot.com/2009/01/ive-read-on-my-local-german-c-forum.html"&gt;a look&lt;/a&gt; at the draft, all the std library chapters were strewn with concepts, every one of them in pretty blue (or was is green?) colour.&lt;br /&gt;&lt;br /&gt;And wasn't the Concepts supposed to be the best thing since sliced bread? I mean not for me, as I had a look at it one, and didn't want to learn it (in patricular the whole &lt;em&gt;concept_map&lt;/em&gt; stuff!!!), but for the compiler writers - they could at last avoid the horrendous error messages for type errors in the template instatiations. Beside of that, it was Bjarne's pet project, and I thought that all Bjarne's PhD and post-doc students were working at it!&lt;/p&gt;&lt;p&gt;And now, out of the blue, the whole feature was cancelled! So maybe there's a limit to the pushing of the type system? C++ is a relentless type-monster already, and sometimes programming it feel like writing a mathematical proof to me. Thus building another level of type definitions on top of the generic meta types is maybe too much of the good thing. But, OK, the idea is not to take out the "duck typing" altogether from the templates, but to strike a delicate balance: add an minimum of concept decalarations and get the best error messages and type security possible. Is that task simply to complicated and too big or is it only the current design of the mechanism which is flawed?&lt;/p&gt;&lt;p&gt;As Bjarne said in the paper which finally did the deathly blow to the Concepts***:&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;Concepts were meant to &lt;strong&gt;make generic programming easier as well as safer&lt;/strong&gt;. It is part of a whole collection of features aimed at simplifying GP, together with template aliases, auto, decltype, lambdas, etc. However, "concepts" is a complex mechanism and its language-technical complexity seems to be leaking into user code. By "language-technical complexity" I mean complexity arising from the need of compiler/linker technology rather than complexity from the solution to a problem itself (the algorithm).&lt;br /&gt;&lt;br /&gt;My particular concern is that in the case of concept maps, in the name of safety &lt;strong&gt;we have made templates harder to use. &lt;/strong&gt;We require programmers to name many entities that would better be left unnamed, cause excess rigidity in code and encourage a mindset in programmers that will lead to either a decrease in generic programming (in favor of less appropriate techniques) or to concepts not being used (where they would be useful). We have &lt;strong&gt;overreacted&lt;/strong&gt; to the problems of structural typing. ***&lt;/em&gt;&lt;/blockquote&gt;This means that exaclty what I wasn't willing to learn leaked out into the user space! Bjarne made a series of proposals how to avoid it, but my general feeling after having read the paper was that the concept's design is somehow flawed, and cannot be fixed by some quick workarounds. So it's no wonder that the commitee had to make a tough decision. And that after years of work! And nobody have seen it coming all these years? Don't you think it's unacanny - how little we can do as to design a complicated language feature and to avoid mistakes? Or maybe we see here how badly the standardisation process is working. These problems were there for a much longer time and nobody said a word! Because of lack of time, because of politics, or simply because noone really understood that topic? So it had to be the creato of C++ himself to blow the whistle: &lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;em&gt;The use of concepts&lt;strong&gt; is supposed to help people&lt;/strong&gt; write and use a wide range of templates. The current definition of concept maps and the philosophy that seems to go with them &lt;strong&gt;makes it harder.&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Addressing this is important. I suspect that the alternative is widespread disuse of concepts and libraries using concepts.&lt;strong&gt; &lt;/strong&gt;I would consider that a major failure of C++0x. ***&lt;/em&gt;&lt;/blockquote&gt;&lt;p&gt;I'd say he killed his pet project out of sense of responsibility.&lt;/p&gt;&lt;p&gt;And where is the promised deeper meaning? As I said previously: there's maybe a limit to the type system. Because for me it felt sometimes like constructing inaccessible cardinals on top if the regular ones (&lt;a href="http://en.wikipedia.org/wiki/Regular_cardinal"&gt;wiki&lt;/a&gt;) in the set theory - just very, very subtle. And maybe the horrendous error messages for templates are just the proverbial price of the (type) freedom, and we have better to pay it? When you read Bjarne's article*** you see, that the gratest problems are encountered in sublassing and conversions - so C++ is much more "modern" a language than most of us would like to believe, &lt;strong&gt;as it allows us so much of the type freedom using the type system itself to achieve it!&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And maybe the design problem relatively simple to solve, but &lt;strong&gt;the archaic linker technology we inherited from C is simply too old&lt;/strong&gt; for that? As it reads: &lt;blockquote&gt;&lt;em&gt;"... complexity arising from the need of compiler/linker technology rather than complexity from the solution to a problem itself (the algorithm)"***&lt;/em&gt;&lt;/blockquote&gt;---&lt;br /&gt;* Danny Kalev &lt;em&gt;"Introducing Attributes", &lt;/em&gt;&lt;a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;amp;seqNum=440"&gt;http://www.informit.com/guides/content.aspx?g=cplusplus&amp;amp;seqNum=440&lt;/a&gt;&lt;br /&gt;** Danny Kalev &lt;em&gt;"The Removal of Concepts From C++0x",&lt;/em&gt; &lt;a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;amp;seqNum=441"&gt;http://www.informit.com/guides/content.aspx?g=cplusplus&amp;amp;seqNum=441&lt;/a&gt;&lt;br /&gt;*** Bjarne Stroustrup &lt;em&gt;"Simplifying the use of concepts"&lt;/em&gt;, 2009-06-21, &lt;a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2906.pdf"&gt;http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2906.pdf&lt;/a&gt; &lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-7774980874085542426?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/07/two-c-curiosities-with-deeper-meaning.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>5</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-4619346420649647229</guid><pubDate>Sat, 27 Jun 2009 13:58:00 +0000</pubDate><atom:updated>2009-08-31T03:55:00.045-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>C++</category><category domain='http://www.blogger.com/atom/ns#'>OO</category><title>For German Speakers only...</title><description>&lt;p&gt;&lt;/p&gt;Hi everyone! As it comes, I stumbled recently upon an interesting C++ website, which I quite enjoyed, and even happened to learn something new in the process! Its address is:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.kharchi.eu/wiki/doku.php?id=cpp:start"&gt;http://www.kharchi.eu/wiki/doku.php?id=cpp:start&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I particularly liked the coverage of some more modern topics liker my favourite theme of Web programming in C++, embedded C++ scripting, or the string tutorial covering conversions between different encodings (and not to forget the link to the Pirates Party :)). Don't get me wrong, it's not the uber C++ webpage, but it's a cute, interesting little thing!&lt;br /&gt;&lt;br /&gt;Unfortunatlely it's all in German :-((. Good for me (see, learning languages pays off sometimes), bad luck for the rest of you. So if you're speaking German, have a look at it!&lt;br /&gt;&lt;br /&gt;Speaking about languages, there's a little story as a goodie: on some project several years ago I had to update an open source tool for copying entire websites. It was thousands and thousands lines of plain, spaghetti-style C code. As this wouldn't be bad enough, all the comments that were there weren't in English, no, &lt;strong&gt;they were all in French!!!&lt;/strong&gt; Hadn't I learnt some French for my holidays, I couldn't possibly have this assignment finished! Without comments the code was absolutely incomprehensible! However it worked fine, &lt;strong&gt;even if it wasn't any OO or structured programming thing. &lt;/strong&gt;Why? For all we know it shouldn't ;-))). &lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-4619346420649647229?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/06/for-german-speakers-only.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-3258416785269826120</guid><pubDate>Thu, 28 May 2009 12:31:00 +0000</pubDate><atom:updated>2009-10-14T01:11:12.349-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>shell</category><title>Windows not so bad after all?</title><description>&lt;p&gt;&lt;/p&gt;This post is for my distinguished hacker colleague &lt;strong&gt;Stefan Z.&lt;/strong&gt; Do you remember how we were always complaining that you cannot do any serious development on Windows, as the following standard Unix command line isn't posible?&lt;pre&gt;    cat out.txt | grep ERROR&lt;/pre&gt;Well, as I'm doing Windows programming now, I recently found out that it's possible after all! Incredible but true! Hovever the syntax is somehow different:&lt;br /&gt;&lt;pre&gt;    type out.txt | findstr ERROR&lt;/pre&gt;On things like that I see how fast the time is passing! A couple of years before, I'd never believe that Windows would ever catch on. I think, the tide change came with XP. &lt;p&gt;But wait, it comes even better! Here's a script for checking if a process is running and killing it if so:&lt;/p&gt;&lt;pre&gt;   tasklist /FI "IMAGENAME eq myProcess.exe" | findstr myProcess.exe&lt;br /&gt;   if ERRORLEVEL 1 GOTO next&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;   echo "-- kill running myProcess"&lt;br /&gt;   taskkill /F /IM myProcess.exe&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt; next:&lt;br /&gt;   echo "-- starting the XXX process"&lt;br /&gt;&lt;/pre&gt;Even a sleep is possible (athough it's arguably very ugly):&lt;pre&gt;    @ping 127.0.0.1 -n 2 -w 1000 &gt; nul&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;And &lt;a href="http://blogs.techrepublic.com.com/itdojo/?p=947&amp;amp;tag=nl.e101"&gt;here&lt;/a&gt; (in the IT-Dojo) you can see that the Windows command promtp has some interesting history mechanisms!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-3258416785269826120?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/05/windows-not-so-bad-after-all.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-8787738731653239243</guid><pubDate>Tue, 19 May 2009 10:02:00 +0000</pubDate><atom:updated>2009-05-28T07:05:47.997-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Java</category><category domain='http://www.blogger.com/atom/ns#'>SQL</category><title>Two Java Collection Utilities</title><description>&lt;p&gt;&lt;/p&gt;Lately I stumbled upon two iteresting Java libraries which add search capabilities to Java collections: one adding SQL search and another adding XPath search syntax to an existing collection. I think it's cool - you can &lt;strong&gt;take a collection of Java objects and treat it in a high level way&lt;/strong&gt;! I suppose they are implemented using introspection.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The first one&lt;/strong&gt; is called &lt;em&gt;JoSQL&lt;/em&gt; (&lt;a href="http://josql.sourceforge.net/index.html"&gt;http://josql.sourceforge.net/index.html&lt;/a&gt;) and can be used like this: &lt;pre&gt;try {&lt;br /&gt;    Query q = new Query ();&lt;br /&gt;    q.parse(&lt;br /&gt;        &lt;span style="color:#009900;"&gt;"SELECT *"&lt;/span&gt; +&lt;br /&gt;        "&lt;span style="color:#009900;"&gt;FROM java.lang.String "&lt;/span&gt; +&lt;br /&gt;        &lt;span style="color:#009900;"&gt;"WHERE length &amp;lt;= :stringSize "&lt;/span&gt; +&lt;br /&gt;        &lt;span style="color:#009900;"&gt;"AND toString LIKE '%e%' "&lt;/span&gt; +&lt;br /&gt;        &lt;span style="color:#009900;"&gt;"ORDER BY length DESC"&lt;/span&gt;);&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    q.setVariable ("stringSize", "5");&lt;br /&gt;    List&amp;lt;String&amp;gt; names = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;    String[] n = {&lt;br /&gt;        "alpha", "beta", "gamma", "delta", "epsilon", "zeta", "pi", "chi"&lt;br /&gt;    };&lt;br /&gt;    Collections.addAll(names, n);&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    QueryResults qres = q.execute(names);&lt;br /&gt;    List res = qres.getResults();&lt;br /&gt;}&lt;br /&gt;catch(Exception e) ...&lt;br /&gt;&lt;/pre&gt;Here I got { &lt;em&gt;"beta", "delta", "epsilon"&lt;/em&gt; } as result. The only problem I can see as far is that the library doesn't use generics. The other one is the somehow unintuitive way it's treating the "SELECT *" query. Nomally the JoSQL library treats a collection of Java objects as a table which columns are formed by the values returned by the class' methods. However, in case of a "SELECT *" query, we won't get all of the object's attributes, but just the whole object as it is. On the other side, it's the equivalent, isn't it.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The second one&lt;/strong&gt; is called &lt;em&gt;jXPath (&lt;a href="http://commons.apache.org/jxpath/"&gt;http://commons.apache.org/jxpath/&lt;/a&gt;),&lt;/em&gt; and is part of the Apache project. You can use it like that:&lt;pre&gt;    JXPathContext context = JXPathContext.newContext(employees);&lt;br /&gt;&lt;br /&gt;    Employee emp =&lt;br /&gt;       (Employee)context.getValue(&lt;span style="color:#009900;"&gt;"/employees[name='Susan' and age=27]"&lt;/span&gt;);&lt;/pre&gt;Pretty nifty, isn't it? But while SQL query syntax seemed obvious to me, the XPath search expressions seems plain ugly and non-intuitive. I don't know both SQL and X-Path very good, but I find myself always forgetting pretty everything about XPath while SQL gets stuck. Maybe because XPath is too low-level an too much a hack?&lt;br /&gt;&lt;br /&gt;You can read in many blogs that the above libraries are pretty the same, but in reality, the XPath query syntax is better for hierarchical data, somehow like that: &lt;pre&gt;    Employee emp =&lt;br /&gt;        (Employee)context.getValue(&lt;span style="color:#009900;"&gt;"/departments/employees[name='Johnny']"&lt;/span&gt;);&lt;/pre&gt;I assume you can do the equivalent in JoSQL, but you'd like to use joins, an that isn't that convenient for simple hierarchical structures like that above. So, in the end, maybe the XPath isn't so bad after all?&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-8787738731653239243?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/05/two-java-collection-utilities.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-5147223979862345848</guid><pubDate>Wed, 29 Apr 2009 20:22:00 +0000</pubDate><atom:updated>2009-09-01T02:37:36.775-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>XML</category><title>From DLL- to XML-hell</title><description>&lt;p&gt;&lt;/p&gt;This is one of the original articles I wanted to write when I &lt;a href="http://ib-krajewski.blogspot.com/2007/10/some-plans-or-whats-to-be-expected.html"&gt;started this blog&lt;/a&gt;. Well, it's taken some time, it's a little outdated now, but at last I've kept my promise (or rather one of them) !&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. The Lament&lt;/h2&gt;&lt;br /&gt;As I switched from C++ to Java in some previous project I thought I plunged directly from the DLL- to the XML-hell! Well, not exacltly (as I didn't programm under Windows in the preceeding project) but a little hyperbole makes a good start! The XML part of the title however, is true. The very first thing I noticed, was the ubiquitous XML - you had to use it for compilation (&lt;em&gt;Ant&lt;/em&gt; scripts), you had to use it for for deployment (&lt;em&gt;web.xml&lt;/em&gt;), you had to use it for your application (&lt;em&gt;struts2.xml&lt;/em&gt;, &lt;em&gt;spring.xml, log4j.xml&lt;/em&gt;).&lt;br /&gt;&lt;br /&gt;The most annoying part of this was the change from makefiles to &lt;em&gt;Ant&lt;/em&gt; scripts: so much superfluous verbiage! Look, compare the &lt;em&gt;Ant&lt;/em&gt; script with the equivalent Ant-builder script in Groovy, taken from the &lt;em&gt;"Groovy in Action"&lt;/em&gt; book, first the XML file:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;project name="prepareBookDirs" default="copy"&amp;gt;&lt;br /&gt;  &amp;lt;property name="target.dir" value=&lt;span style="color:#009900;"&gt;"target"&lt;/span&gt;/&amp;gt;&lt;br /&gt;  &amp;lt;property name="chapters.dir" value=&lt;span style="color:#009900;"&gt;"chapters"&lt;/span&gt;/&amp;gt;&lt;br /&gt;  &amp;lt;target name="copy"&amp;gt;&lt;br /&gt;    &amp;lt;delete dir="${target.dir}" /&amp;gt;&lt;br /&gt;    &amp;lt;copy todir="${target.dir}"&amp;gt;&lt;br /&gt;      &amp;lt;fileset dir="${chapters.dir}"&lt;br /&gt;        includes=&lt;span style="color:#009900;"&gt;"*.doc"&lt;/span&gt;&lt;br /&gt;        excludes=&lt;span style="color:#009900;"&gt;"~*"&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;/copy&amp;gt;&lt;br /&gt;  &amp;lt;/target&amp;gt;&lt;br /&gt;&amp;lt;/project&amp;gt;&lt;/pre&gt;Then the builder script:&lt;br /&gt;&lt;pre&gt;  TARGET_DIR = &lt;span style="color:#009900;"&gt;'target'&lt;/span&gt;&lt;br /&gt;  CHAPTERS_DIR = &lt;span style="color:#009900;"&gt;'chapters'&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;  ant = new AntBuilder()&lt;br /&gt;  ant.delete(dir:TARGET_DIR)&lt;br /&gt;  ant.copy(todir:TARGET_DIR){&lt;br /&gt;      fileset(dir:CHAPTERS_DIR, includes:&lt;span style="color:#009900;"&gt;'*.doc'&lt;/span&gt;, excludes:&lt;span style="color:#009900;"&gt;'~*'&lt;/span&gt;)&lt;br /&gt;  }&lt;/pre&gt;&lt;p&gt;Well, that's at least readable (and writeable), and it states exactly what you want! When I see such a comparison I think that the XML code should be used only as &lt;em&gt;Ant&lt;/em&gt;-internal, assembly-code level data representation! You could maybe find it interesting that even the creator of Ant himself admitted that using XML was &lt;em&gt;"probably an error"&lt;/em&gt;*.&lt;br /&gt;&lt;br /&gt;The second problem was that, (as another programmer put it):&lt;/p&gt;&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;Developers from other languages often find Java's over-reliance on XML configuration annoying.&lt;/strong&gt; We use so much configuration outside of the language because configuration in Java is painful and tedious. We do configuration in XML rather than properties because...well, because overuse of XML in Java is a fad.**&lt;/em&gt;&lt;/blockquote&gt;&lt;p&gt;I can only confirm this. You can get a feel of how much of XML "code" was needed in a Java web application I was then writing from the following (addmittedly pretty old) table*** :&lt;/p&gt;&lt;pre&gt;&lt;strong&gt;     Metric               Java +              Ruby +&lt;br /&gt;                     Spring/Hibernate         Rails &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;  Time to market     4 months, approx.      4 nights,&lt;br /&gt;                      20 hours/week       5 hours/night&lt;br /&gt;  Lines of code          3,293                1,164&lt;br /&gt;&lt;span style="color:#009900;"&gt;  Lines of config        1,161                113&lt;/span&gt;&lt;br /&gt;  Number of classes/     62/549               55/126&lt;br /&gt;  methods                  &lt;/pre&gt;&lt;p&gt;Do you see? The configuration, it's 30% of the code (!!!), and that's 10 times more than was needed in Rails! That's &lt;em&gt;some&lt;/em&gt; dependency! By the way, note that Rails needs &lt;em&gt;only&lt;/em&gt; 3 times less code that Java, despite the fact that Java libraries can be sometimes pretty low level!&lt;/p&gt;&lt;p&gt;Now, for me the &lt;a href="http://en.wikipedia.org/wiki/Spring_Framework"&gt;&lt;em&gt;Spring 2&lt;/em&gt;&lt;/a&gt; platform was somehow an apogeum of the XML overdependency - the endless configuration files weren't even human readable, you should better use a graphical &lt;em&gt;Eclipse&lt;/em&gt; plugin:&lt;/p&gt;&lt;p&gt;&lt;img id="BLOGGER_PHOTO_ID_5330223269693360498" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 237px; TEXT-ALIGN: center" alt="" src="http://1.bp.blogspot.com/_79IsVE3vX_Y/SfjB0rOYCXI/AAAAAAAAAFM/0b09FHHTXjg/s320/BeansGraph+.png" border="0" /&gt;&lt;/p&gt;&lt;p&gt;to edit the wirings. That's like you need something like UML to tame the complexity of the XML files (and of &lt;em&gt;Spring&lt;/em&gt;'s configuration of course):&lt;br /&gt;&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5330222623645798578" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 239px; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_79IsVE3vX_Y/SfjBPEgokLI/AAAAAAAAAFE/sedw89BEdeo/s320/BeansGraph.png" border="0" /&gt;&lt;br /&gt;A rhetoric question: isn't it too much of a good thing for something as simple as configuration files? I found the &lt;em&gt;Spring-2 MVC&lt;/em&gt; (Spring's web GUI application framework) particularly bad in that respect. Comparing it to the &lt;em&gt;Struts 2&lt;/em&gt; configuration, I had an impression that every obvious fact must be expressed in XML, and &lt;strong&gt;that there's no defaults altogether:&lt;/strong&gt; &lt;/p&gt;&lt;pre&gt;&amp;lt;bean name="userListController"&lt;br /&gt;    class="de.ib-krajewski.myApp.UserListController"&amp;gt;&lt;br /&gt;    &amp;lt;property name="&lt;span style="color:#009900;"&gt;userListManager&lt;/span&gt;"&amp;gt;&lt;br /&gt;        &amp;lt;ref bean="&lt;span style="color:#009900;"&gt;userListManager&lt;/span&gt;" /&amp;gt;&lt;br /&gt;    &amp;lt;/property&amp;gt;&lt;br /&gt;    ....&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&amp;lt;bean id="&lt;span style="color:#009900;"&gt;userListManager&lt;/span&gt;"&lt;br /&gt;    class="de.ib-krajewski.myApp.&lt;span style="color:#009900;"&gt;UserListManager&lt;/span&gt;" /&amp;gt;&lt;/pre&gt;&lt;p&gt;and so on, and on, and on.&lt;br /&gt;&lt;br /&gt;But wait, it comes even better: some people are so enamoured with XML that they are using it as a programming language****, either doing patterns with &lt;em&gt;Spring&lt;/em&gt; and XML configuration files, or even inventing an XML-based programming language and writing its interpterer in XSLT (I'm not joking!).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;A word of caution:&lt;/strong&gt; Java community noticed the problem and is trying to reduce the amount of XML needed. Unfortunately, I haven't got any hard numbers, but each new release of a Java framework seems to claim a &lt;em&gt;"reduced XML config file size" - t&lt;/em&gt;ake for example &lt;em&gt;Spring MVC v.3&lt;/em&gt;. However, as the DLL hell is still a reality despite of Microsoft's efforts and the introduction of manifests (&lt;a href="http://ib-krajewski.blogspot.com/2008/11/letter-from-dll-hell-msvc60dll-and.html"&gt;really, look here!&lt;/a&gt;), equally, for my mind the overdependence on XML won't vanish overnight from the Java world - it's at its core! &lt;/p&gt;&lt;h2&gt;2. The Analysis&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;2.1 XML data&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Why are we all using XML? The received standard answer is: because it's a portable, human-readable, standardized data format with a very good tool support!&lt;br /&gt;&lt;br /&gt;So why does it all feel so wrong? The first reason I see is that XML is too low level for human consumption. It's claiming to be human-readable while it's only human-tolerable - see the Groovy AntBuilder example above. There are tons and tons of verbiage (although that's something a Java programmer will be rather accustomed to ;-)) which is what machines need, &lt;strong&gt;but it's not how human mind is working&lt;/strong&gt;. It needs high level descriptions because it's only all to easy distracted by unneeded details.&lt;br /&gt;&lt;br /&gt;When I recall my own config file implementations of yore, I conclude that I never needed more constructs than single config values ans lists of them. And I never needed hierarchical config data for my systems. So if people are using XML for configuration,&lt;strong&gt; they are maybe after something more than pure config settings, &lt;/strong&gt;maybe they are looking for a scripting solution for the application (as mentioned in*) along the lines of the late &lt;em&gt;Tcl&lt;/em&gt;? But with &lt;em&gt;Tcl&lt;/em&gt; the model was entirely different: the &lt;em&gt;Tcl&lt;/em&gt; scipts glueing together passive modules of code, whereas now, the modules are active and &lt;strong&gt;use XML as a database of sorts&lt;/strong&gt;... So is it that at last? People using XML data as a poor man's, read only database? It's a good, ad-hoc solution, and you can emulate hierarchical, network and OO databases without much of a hassle, can't you? So people are using XML as a kind of qiuck and dirty hack, and hacks aren't normally very pretty ;-).&lt;/p&gt;&lt;p&gt;&lt;strong&gt;2.2 XML in Java&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;The second part of the question is:&lt;/span&gt; why are we using so much XML in Java? The answer is probably that we need XML config files to increase modularity an require the loose coupling of our systems. The Spring framework allows us to pull the parts of the system together at the startup or run-time, and that's supposedly a good thing, isn't it. &lt;/p&gt;&lt;p&gt;Coming to this part of the question: &lt;strong&gt;I think that the loose coupling thing is overrated&lt;/strong&gt;. As Nicolai Yossutis said in his book about SOA (we &lt;a href="http://ib-krajewski.blogspot.com/2008/01/soa-in-practice-yams.html"&gt;reported ;-)&lt;/a&gt;): &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;"...loose coupling has its price, and it's the complexity." &lt;/em&gt;&lt;br /&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;So firstly, a little bit of coupling isn't that bad if it decreases complexity and increases readability of code! To my mind, it's a classical tradeoff, but as some developers are only too prone to introduce tight coupling all over the place, the received wisdom is to avoid the coupling at every price! But be honest, you can't decouple everything, if the parts are ment to be working together! Secondly, I thing that the &lt;a href="http://www.martinfowler.com/articles/injection.html"&gt;&lt;em&gt;"inversion of control"&lt;/em&gt;&lt;/a&gt; pattern is a bit of overkill too. &lt;/p&gt;&lt;p&gt;Personally, I'd like to glue together the parts of the system directly in code, so that I can see how my software is composed, and that in my source code - it should be the sole point of reference! Thus I like much more the approach &lt;em&gt;Guice&lt;/em&gt; or &lt;em&gt;Seam&lt;/em&gt; are taking (and nowadays the &lt;em&gt;Spring&lt;/em&gt; framework itself) - that of annotations. At last we have the relevant information where it belongs - in code! The problem here is, that the annotations aren't really code, they are metadata, and I don't like the idea of using metadata where you could do things directly by using some API. But hey, that's probably the way we are doing such things in Java...&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;3. A Summary&lt;/h2&gt;&lt;p&gt;That's what I wanted to write approximately 2 years ago. Meanwhile I use XML everywhere in my architectures and designs, mainly &lt;strong&gt;because it excludes any discussions about formats!&lt;/strong&gt; No one has ever said anything against XML! &lt;/p&gt;&lt;p&gt;But programming it (in C++ and &lt;em&gt;Qt&lt;/em&gt;) is a real pain - I first tried DOM, than SAX - and it was an even greater mess (well, there's a C++ &lt;a href="http://en.wikipedia.org/wiki/XML_data_binding"&gt;data binding&lt;/a&gt; implementation á la Java's &lt;em&gt;Apache XMLBeans&lt;/em&gt; but it's not used at my client's :-((). XPath's selectors are supposed to be better, but &lt;em&gt;Qt&lt;/em&gt; doesn't have it by now. The good thing is, everyone will think&lt;strong&gt; &lt;/strong&gt;the system is &lt;em&gt;sooo cool&lt;/em&gt; because it uses XML,&lt;strong&gt; and I have to make my users happy!&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;PS:&lt;/strong&gt; And you know what? The new &lt;em&gt;&lt;a href="http://static.springsource.org/s2-dmserver/2.0.x/user-guide/htmlsingle/user-guide.html"&gt;dm&lt;/a&gt; &lt;/em&gt;application server by SpringSource uses JSON for configuration files!!! I told you so ;-)&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;* &lt;em&gt;"The creator of Ant excercising hit own daemons"&lt;/em&gt;, this article was originally stored under &lt;a href="http://x180.net/Articles/Java/AntAndXML.html"&gt;http://x180.net/Articles/Java/AntAndXML.html&lt;/a&gt;, but this link seems to be dead, so I'll host it on my website for a while (hope it's OK...): &lt;a href="http://www.ib-krajewski.de/misc/ant-retrospect.html"&gt;http://www.ib-krajewski.de/misc/ant-retrospect.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;** as a matter of fact, he's a Ruby programmer too, so he isn't &lt;em&gt;that&lt;/em&gt; unpartial: &lt;a href="http://www.brainbell.com/tutorials/java/About_Ruby.htm"&gt;http://www.brainbell.com/tutorials/java/About_Ruby.htm&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;***taken from the book &lt;em&gt;"Beyond Java"&lt;/em&gt; by Bruce Tate: &lt;a href="http://commons.oreilly.com/wiki/index.php/Beyond_Java/Ruby_on_Rails"&gt;http://commons.oreilly.com/wiki/index.php/Beyond_Java/Ruby_on_Rails&lt;/a&gt;, unfortunately the original link stated there isn't working: Justin Gehtland, Weblogs for Relevance, LLC (April 2005); &lt;a class="external free" title="http://www.relevancellc.com/blogs" href="http://www.relevancellc.com/blogs" rel="nofollow"&gt;http://www.relevancellc.com/blogs&lt;/a&gt;. &lt;em&gt;"I *heart* rails; Some Numbers at Last."&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;**** &lt;em&gt;"Wiring The Observer Pattern with Spring":&lt;/em&gt; &lt;a href="http://www.theserverside.com/tt/articles/content/SpringLoadedObserverPattern/article.html"&gt;http://www.theserverside.com/tt/articles/content/SpringLoadedObserverPattern/article.html&lt;/a&gt;, and "&lt;em&gt;XSL Transformations. A delivery medium for executable content over the Internet&lt;/em&gt;" in DDJ from April 05, 2007: &lt;a href="http://www.ddj.com/architect/198800555"&gt;http://www.ddj.com/architect/198800555&lt;/a&gt; . I cite from the latter:&lt;br /&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;em&gt;XIM is an XML-based programming language with imperative control features, such as assignment and loops, and an interpreter written in XSLT. XIM programs can thus be packaged with an XIM processor (as an XSLT stylesheet) and sent to the client for execution.&lt;/em&gt;&lt;/blockquote&gt;See, I wasn't joking...&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-5147223979862345848?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/04/from-dll-to-xml-hell.html</link><author>noreply@blogger.com (Marek Krj)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_79IsVE3vX_Y/SfjB0rOYCXI/AAAAAAAAAFM/0b09FHHTXjg/s72-c/BeansGraph+.png' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-5132085552792956908</guid><pubDate>Sat, 04 Apr 2009 19:09:00 +0000</pubDate><atom:updated>2009-10-05T23:22:34.049-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>distributed computing</category><category domain='http://www.blogger.com/atom/ns#'>SQL</category><title>Some distributed computing news: cuddly elephans, pigs, nymphs and couch computing</title><description>&lt;p&gt;&lt;/p&gt;As I did some distributed computing research in my previous life, and then tried to get involved with Google, I'm still somehow interested in the subject. If you are into distributed computing, you'd know that &lt;span style="color:#009900;"&gt;Google&lt;/span&gt; is using a distributed C++ system called MapReduce* for indexing of the crawled webpages. It happens that there's an open-source Java implemenation of Google's system (based on published Google's research papers) called &lt;a href="http://hadoop.apache.org/"&gt;Hadoop&lt;/a&gt; . Up to now I didn't know about any serious usage of Hadoop in big distributed systems, but as it comes, I learned that &lt;span style="color:#009900;"&gt;Yahoo!&lt;/span&gt; is using Hadoop internally** for spam detection!&lt;br /&gt;&lt;br /&gt;Yahoo's researchers have also designed a new language called &lt;em&gt;PIG Latin (?!)&lt;/em&gt;*** for distributed programming on the Hadoop platform. The idea is rather an interesting one: they pointed out that the existing way of writing programs for the mapper and reducer part of a distributed application is too low-level and not reusable, but somehow familiar to programmers. In contrast, a declarative language like SQL poses some problems, so the paradigm there is completely diffrent:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;At the same time, the transformations carried out in each step are fairly high-level, e.g.,filltering, grouping, and aggregation, much like in SQL. The use of such high-level primitives &lt;strong&gt;renders low-level manipulations (as required in map-reduce) unnecessary&lt;/strong&gt;.&lt;br /&gt;...&lt;/em&gt;&lt;br /&gt;&lt;em&gt;To experienced system programmers, this method is much more appealing than encoding their task as an SQL query, &lt;strong&gt;and then coercing the system to choose the desired plan through optimizer hints&lt;/strong&gt;.&lt;/em&gt;&lt;/blockquote&gt;So it provides a middle ground, where we can avoid SQL and write down the computation steps, but can do that at higher level!&lt;br /&gt;&lt;br /&gt;Unsuprisingly, &lt;span style="color:#009900;"&gt;Microsoft&lt;/span&gt; already has a &lt;strong&gt;proprietary&lt;/strong&gt; &lt;strong&gt;distributed computing platform&lt;/strong&gt; called &lt;a href="http://research.microsoft.com/en-us/projects/Dryad/"&gt;Dryad&lt;/a&gt;, which tries to do something like this as well, but is using C# and LINQ (i.e. an SQL-like query language):&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;a href="http://research.microsoft.com/en-us/projects/dryadlinq/default.aspx" target="_self"&gt;&lt;em&gt;DryadLINQ&lt;/em&gt;&lt;/a&gt;&lt;em&gt; generates Dryad computations from the &lt;/em&gt;&lt;a href="http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx"&gt;&lt;em&gt;LINQ&lt;/em&gt;&lt;/a&gt;&lt;em&gt; Language-Integrated Query extensions to C#.&lt;/em&gt; &lt;/blockquote&gt;&lt;p&gt;But I don't know how much this is a research project and if it's really used internally. On the other side, Microsoft recently aquired a search company called &lt;a href="http://www.powerset.com/"&gt;Powerset&lt;/a&gt;, which is using Hadoop at its core, and as the gossip runs, should be used to bring Microsoft's LiveSearch up to speed.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#009900;"&gt;Facebook&lt;/span&gt;, in their turn, are using Hadoop, &lt;strong&gt;but added a Business Intelligence tool&lt;/strong&gt; called &lt;a href="http://hadoop.apache.org/hive/"&gt;Hive&lt;/a&gt; (now released as open source!) on top of it. It uses an SQL-like query language, as BI-users understand it best. Beneath the surface Hive leverages Hadoop and translates SQL-like imperatives into MapReduce jobs.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_79IsVE3vX_Y/Sewn300VbvI/AAAAAAAAAE8/3g6_FVuOkMg/s1600-h/hadoop-logo.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5326676299296894706" style="FLOAT: right; MARGIN: 0px 0px 10px 10px; WIDTH: 300px; CURSOR: hand; HEIGHT: 71px" alt="" src="http://3.bp.blogspot.com/_79IsVE3vX_Y/Sewn300VbvI/AAAAAAAAAE8/3g6_FVuOkMg/s320/hadoop-logo.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Not bad, cuddly elephant! It seems everyone is loving you!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Accidentally, when speaking about SQL and non-SQL: there's a&lt;strong&gt; non-SQL database by Apache&lt;/strong&gt; called &lt;a href="http://couchdb.apache.org/"&gt;Couch DB&lt;/a&gt;. It is written in Erlang (we reported already**** ;-)) and implements a distributed document database. It's designed for lock-free concurrency using Erlang's "share-nothing" philosophy. To my mind it resembles Linus' Thorvalds&lt;em&gt; git&lt;/em&gt; source configuration system, as it holds all the versions of documents determining the "winner" to be visible in defined views. Hear, hear! Erlang's alive, distributing and kicking!&lt;br /&gt;&lt;br /&gt;Another thing worth noticing is that's not only SQL anymore, there are attempts to do things differently, athough others are sticking with the ol 'n reliable. Paradigm change on its way? It's interesting times I think.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;PS &lt;/span&gt;(6 Okt. 2009):&lt;/strong&gt; Look, look, now even the &lt;span style="color:#009900;"&gt;Big Blue&lt;/span&gt; has jumped the wagon too! They offer the M2 enterprise data analysis platform, based on Hadoop and using PIG. See: &lt;a href="http://www.sdtimes.com/link/33808"&gt;http://www.sdtimes.com/link/33808&lt;/a&gt;. So it seems Hadoop is definitely mainstream and business analyst thingie now, and as such it has lost much of its appeal, as far as I'm concerned.&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* Jeffrey Dean, Sanjay Ghemawat: &lt;em&gt;"MapReduce: Simplified Data Processing on Large Clusters"&lt;/em&gt;, OSDI 2004, &lt;a href="http://labs.google.com/papers/mapreduce.html"&gt;http://labs.google.com/papers/mapreduce.html&lt;/a&gt;&lt;br /&gt;** unfortunately it's a two-parts video: &lt;a href="http://developer.yahoo.net/blogs/hadoop/2009/03/using_hadoop_to_fight_spam_-_part_1.html"&gt;http://developer.yahoo.net/blogs/hadoop/2009/03/using_hadoop_to_fight_spam_-_part_1.html&lt;/a&gt;&lt;br /&gt;*** Christopher Olston et al: &lt;em&gt;"Pig Latin: A Not-So-Foreign Language for Data Processing"&lt;/em&gt;, SIGMOD 2008, &lt;a href="http://www.cs.cmu.edu/~olston/publications/sigmod08.pdf"&gt;http://www.cs.cmu.edu/~olston/publications/sigmod08.pdf&lt;/a&gt;&lt;br /&gt;**** &lt;a href="http://ib-krajewski.blogspot.com/2007/08/erlangs-change-of-fortunes.html"&gt;http://ib-krajewski.blogspot.com/2007/08/erlangs-change-of-fortunes.html&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-5132085552792956908?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/04/some-distributed-computing-news-cuddly.html</link><author>noreply@blogger.com (Marek Krj)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_79IsVE3vX_Y/Sewn300VbvI/AAAAAAAAAE8/3g6_FVuOkMg/s72-c/hadoop-logo.jpg' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-830265476823376730</guid><pubDate>Mon, 30 Mar 2009 08:06:00 +0000</pubDate><atom:updated>2009-03-30T03:35:45.514-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Java</category><category domain='http://www.blogger.com/atom/ns#'>C++</category><category domain='http://www.blogger.com/atom/ns#'>OO</category><title>One cute microdesign example and some thoughts on language design.</title><description>&lt;p&gt;&lt;/p&gt;This time I'll begin with a citation of another blogger*:&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;I made the switch from C++, I'd wished that Java allowed operator overloading (i.e. custom implementations of operators such as '+', or the array brackets). However, some argue that this feature adds to the complexity of C++ with little advantage, and that there is no need to pass this complexity on to the Java language. &lt;strong&gt;Someone who never coded in C++ would more than likely agree with that.&lt;/strong&gt;&lt;/em&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/blockquote&gt;OK, someone who never coded C++ won't understand that, and will take the argument about the undue complexity as received wisdom. So let's show you a little piece of design, a microdesign actually, so you can (maybe) appreciate the feature. If you're a Python/Perl/Groovy (or C++ for that matter!) programmer, I must apologise, but maybe you'll find this small example nonetheless instructive.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. A piece of microdesign&lt;/h2&gt;&lt;p&gt;It's a piece of code from my old project I wrote several years ago. I wanted a class for interthread and interprocess messages (you know, for my favourite pattern: share-nothing, message-passing actors). I wanted to be able to construct a message using parameters of the constructor like this:&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;    AbstractData notif;&lt;br /&gt;    SocketMsg msg(DispInterface::crReqNotifType, &amp;amp;notif, father);&lt;br /&gt;&lt;/pre&gt;And then simply send the formatted message as binary data: &lt;pre&gt;    m_connSocket.send(msg, msg.buffsize())&lt;/pre&gt;On the other side, I wanted to receive the binary data from socket directly into the message object, which would then parse it and provide high level access to the received data, just like:&lt;br /&gt;&lt;pre&gt;    SocketMsg msg; &lt;span style="color:#009900;"&gt;// empty&lt;/span&gt;&lt;br /&gt;    if(!m_connSock.receive(msg.writebuff(), msg.buffsize()))&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color:#009900;"&gt;// if too much errors, better bail out here!&lt;/span&gt;&lt;br /&gt;        TRACE_AND_CONT("Cannot read from socket in an FD event handler!",&lt;br /&gt;                       E_ID_Q3A_SOCK_ERR); &lt;span style="color:#009900;"&gt;// try to escalate&lt;/span&gt;&lt;br /&gt;        return;&lt;br /&gt;    }&lt;/pre&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// look what message received&lt;/span&gt;&lt;br /&gt;    if(msg.getType() == cmdOkMsgType)&lt;br /&gt;        handleCmdResp(msg.getAbstrData());&lt;/pre&gt;Pretty high level, eh? Just hide away all that low level data parsing and formatting and use the message!&lt;br /&gt;&lt;br /&gt;It's design on its lowest level, you cannot possibly make a smaller piece of meaningful design, but I liked that piece! Now a question for the astute reader: what pattern is that? Proxy, bridge or a facade? Or a builder maybe? Perhaps none? Well, I don't think in pattrens, I think in abstractions: what I needed was an abstraction of a self-formatting message. Don't you like it too? Unfortunately, you need some operator overloading magic to do this. Look at the following class:&lt;br /&gt;&lt;pre&gt;class SocketMsg&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;    SocketMsg(int type, AbstractData* message, DsetId dsetId = nillDsetId,&lt;br /&gt;              int cmdId = 0, int userCode = 0);&lt;br /&gt;    &lt;span style="color:#ff9900;"&gt;... etc&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// conversions&lt;/span&gt;&lt;br /&gt;    operator const char*() const { return m_charRepr; };&lt;br /&gt;    inline SocketMsgBufferProxy writebuff(); &lt;span style="color:#009900;"&gt;// see inline section&lt;/span&gt; &lt;/pre&gt;&lt;pre&gt;private:&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// buffer&lt;/span&gt;&lt;br /&gt;    static const int c_buffsize = sizeof(SocketMsgStruct) + 1;&lt;br /&gt;    char m_buff[c_buffsize];&lt;/pre&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// decoded data: don't remove in case we use different encoding!&lt;/span&gt;&lt;br /&gt;    AbstractData* m_data;&lt;br /&gt;    int m_type;&lt;br /&gt;    DsetId m_dsetId;&lt;br /&gt;    int m_cmdId;&lt;br /&gt;    int m_userCode; &lt;/pre&gt;&lt;pre&gt;    friend class SocketMsgBufferProxy;&lt;br /&gt;};&lt;/pre&gt;&lt;p&gt;You can see in the above definition that the class has a buffer for the coded binary message and several fields for the decoded message values. In the char array context, it exports its internal message buffer for reading (through the &lt;span style="font-family:courier new;"&gt;operator const char*()&lt;/span&gt;) so the socket's send function can read the raw data from there. In the other direction, i.e. for receiving data into the internal buffer a different mechanism is used: we are returning a &lt;em&gt;SocketMsgBufferProxy&lt;/em&gt; object (this time through the &lt;span style="font-family:courier new;"&gt;writebuff()&lt;/span&gt; function) , which is defined as follows:&lt;/p&gt;&lt;pre&gt;class SocketMsgBufferProxy&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;    SocketMsgBufferProxy(SocketMsg* sm) : m_sm(sm) {};&lt;br /&gt;    operator char*();&lt;br /&gt;    ~SocketMsgBufferProxy();&lt;br /&gt;private:&lt;br /&gt;    SocketMsg* m_sm;&lt;br /&gt;}&lt;/pre&gt;What it that proxy object doing? It's forwarding the address of the internal raw data buffer and revealing it through the &lt;span style="font-family:courier new;"&gt;operator const char*() &lt;/span&gt;again. As a matter of fact I could offer an even cleaner interface: &lt;pre&gt;    m_connSock.receive(msg, msg.buffsize())&lt;/pre&gt;So why didn't I simply expose the internal buffer with the char* conversion operator and introduced a &lt;em&gt;SocketMsgBufferProxy&lt;/em&gt; object inbetween? Simply because of the &lt;em&gt;SocketMsgBufferProxy&lt;/em&gt;'s destructor. When its destructor is invoked, it rescans the raw contents of the receive buffer so after the &lt;span style="font-family:courier new;"&gt;receive()&lt;/span&gt; line of code is finished, the message object is parsed and ready! Of course there is another possibility to achieve this: lazy parsing, but I was somehow more excited with that cool proxy object automatically coming inbetween and doing all the work! I'm only a human too and sometimes looking for the unusual...&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;2. And now some more general discussion&lt;/h2&gt;&lt;br /&gt;So as you can see, the operator overloading is a pretty useful little feature. So why didn't the designers of Java include it into the language definition? My opinion is that they overreacted. I can still remember the times of the &lt;strong&gt;“object craze”&lt;/strong&gt; when everybody tried to be object oriented without knowing what that really was, and to use every single feature C++ offered without thinking if it's needed or not for the particular problem at hand. That was somehow similar to the &lt;strong&gt;“patterns craze”&lt;/strong&gt; I can see even today: people asking me &lt;em&gt;“so what pattern could I use here?”&lt;/em&gt; - you don't need a pattern here, you need a solution of the programming problem, or do you want just a cool name to stick it on your code? But more about that in future entry.&lt;br /&gt;&lt;br /&gt;You wouldn't believe how stupid the people got with the operator overloading, maybe it was something like the ”powder rush” of the skiers, an incredible infatuation with the until-then unheard-of possibilities! You must consider that a fresh-made C++ programmer came from a much smaller language (namely C) and normally didn't have exposure to any higher level language concepts form Smalltalk, Lisp or Simula. So the Java designers simply thought &lt;em&gt;“Hey folks, it's time to cool down!”&lt;/em&gt; and banned the feature. To my mind, a fatal case of underestimation of people's capabilities and of patronizing. Because the result of it is that &lt;em&gt;“you cannot do any magic in Java!”&lt;/em&gt; (well, actually you can with introspection and bytecode insertion, but only so much, and that's simply not enough). Look at the following citation**:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;In fact, I'd say that many of today's current hot trends in programming are a direct result of a backlash *against* everything that Java has come to represent: Lengthy code and slow development being the first and foremost on the list. In Java you generally need hundreds of lines of code to do what modern scripting languages do in dozens (or less).&lt;br /&gt;...&lt;br /&gt;So what's the solution? Well, this is the problem. People have been tinkering with Java for years now, and there's still no hope in sight. There's &lt;strong&gt;something about the Java culture which just seems to encourage obtuse solutions over simplicity&lt;/strong&gt;. As a Java developer, I was always so amazed at how difficult it was to use the standard Java Class Libraries for day-to-day tasks.&lt;/em&gt;&lt;/blockquote&gt;And you know what? My pet idea is, &lt;strong&gt;that the reason why Java code is so dull and repetitive&lt;/strong&gt; (and that the Java culture is, ehm..., you've just read it...)&lt;strong&gt; is the lack of operator overloading!&lt;/strong&gt; You think I'm overly generalizing now? Well, the fact is, you simply cannot hide the gory details as conveniently as I was able to do it in the &lt;em&gt;SocketMsg&lt;/em&gt; class! The best indication that the people in Javaland are thinking the same, is the Groovy JVM programming language: it has the operator overloading at its core, and is capable of doing things you wouldn't dream possible in Java. Well, that's no virtue in and by itself, but as result it gives you much leaner code! And we all need it: less code!&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;3. Now something even more general&lt;/h2&gt;&lt;br /&gt;When am already at it, Java programmers I met wouldn't understand the idea of the h-files (aka include files) too. Why are they needed for Heaven's sake? Isn't it an awful bore? I admit that the origin of the h-files lies in the limitations of the early C compilers, but with C++ it gained another significance: a “table of content” of the code proper. I give the word to another man from Java(FX)land***:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;From my experience with C++ and Java, having method bodies in the class declaration &lt;strong&gt;clutters it with a mass of implementation details which is detrimental to getting an overview &lt;/strong&gt;of the actual relationships and operations embodied by the class. It was for this reason that I decided to define the bodies of class operations and functions outside the class declaration.&lt;/em&gt;&lt;/blockquote&gt;Exactly what I think! You need an overview for the class, so you don't have to skip every one int and bool declaration until your head gets dizzy. You'll retort that this will be done with Javadoc comments. Well... The Javadocs... It's quite a theme of its own. Let me give only a small example here: if I've already written the function declaration like:&lt;pre&gt;    void sendMessage(SocketMsg&amp;amp; msg, Receiver dest);&lt;/pre&gt;why should I repeat all this in a trivial Javadoc header? Is it "don't repeat yourself" or what? Don't get me wrong, I wouldn't check in any uncommented code, but I don't use them in (C++) header files - they only clutter up and make the definitions unreadable! For me they are well suited as implementation descriptions. And seconly, you have to run the javadoc tool first, you cannot just have a quick glance at the code! I must admit, sometimes I'm annoyed about having to edit the h-files, but when I'm reading the code afterwards, I'm happy I did that. Pretty non-progressive, isn't it? &lt;p&gt;&lt;/p&gt;&lt;h2&gt;4. Summing up&lt;/h2&gt;&lt;p&gt;Maybe you'll say that it's not ethical to lambast a slightly ageing, slightly demodée, mainstream language, and that all is only too well known for several years now, &lt;strong&gt;but hey, it's just what I always thought!&lt;/strong&gt; And like with my other favourite subjects (Agile, XML, Python, patterns), it simply takes time till I write it down, and it's no so insightful then, sorry...&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;* &lt;a href="http://www.ddj.com/blog/javablog/archives/2007/08/java_and_potato.html"&gt;http://www.ddj.com/blog/javablog/archives/2007/08/java_and_potato.html&lt;/a&gt;&lt;br /&gt;** &lt;a href="http://www.russellbeattie.com/blog/java-needs-an-overhaul"&gt;http://www.russellbeattie.com/blog/java-needs-an-overhaul&lt;/a&gt;&lt;br /&gt;*** Chris Oliver, Creator of &lt;em&gt;JavaFX&lt;/em&gt;, in his presentation about &lt;em&gt;JavaFX:&lt;/em&gt; &lt;a href="http://jazoon.com/jazoon07/en/conference/presentationdetails.html"&gt;http://jazoon.com/jazoon07/en/conference/presentationdetails.html&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-830265476823376730?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/03/one-cute-microdesign-example-and-some.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-6590446349965494586</guid><pubDate>Sat, 21 Feb 2009 15:40:00 +0000</pubDate><atom:updated>2009-03-11T04:57:28.671-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>multithreading</category><title>Fibers, at last!</title><description>&lt;p&gt;&lt;/p&gt;As I'm recently doing Windows programming again after some 10 years of a pause, I keep learning about new things. One of them are fibers. Come again? What's that??&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;A fiber, as the name implies, is a piece of a thread. More precisely, a fiber is a unit of execution within a thread that can be scheduled by the application rather than by the kernel. *&lt;/em&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;So fibers are just user space threads, aka cooperative multitasking, which I knew since the stone-age DOS times and which weren't supposed to be cool at all!&lt;/p&gt;&lt;p&gt;&lt;img id="BLOGGER_PHOTO_ID_5311840919307593682" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 230px; TEXT-ALIGN: center" alt="" src="http://4.bp.blogspot.com/_79IsVE3vX_Y/SbdzLDq2p9I/AAAAAAAAAE0/Er_GKrP8YYM/s320/Silk-Winding.png" border="0" /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;It were native kernel threads which were supposed to be cool back then! But I must admit that in the past as I was working with cooperative multitasking in a rather big, multithreading system, I was quite happy with it! &lt;strong&gt;It gave a nice, predicatble feel to the system&lt;/strong&gt;; you just new at what times what threads are supposed to run! The sole problem was (of course) that a long running user task couls block all the system. But then we moved on to native threads and I forgot about cooperative multitasking.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;But something has changed since then: first, as it was already said, Windows has got it, although allegedly only as a good-enough implementation to support the SQL-Server (fibers have severe restrictions on the kinds of Win32 API’s they can call!). Second, &lt;em&gt;Oracle 10g&lt;/em&gt; has got it too, I cite**:&lt;/p&gt;&lt;blockquote&gt;&lt;em&gt;Fiber model support&lt;br /&gt;- An extension of the thread support already in place since Oracle7. Users may now run the database in fiber mode, which employs Oracle-scheduled fibers instead of O/S scheduled threads.&lt;br /&gt;- For CPU intensive apps, &lt;strong&gt;this will provide a performance boost&lt;/strong&gt; and reduce CPU utilization.&lt;/em&gt;&lt;/blockquote&gt;&lt;p&gt;Moreover, recently I discovered a fiber library for &lt;em&gt;Windows XP&lt;/em&gt; to remedy the unsufficient native Windows fibers support named &lt;strong&gt;FiberPool&lt;/strong&gt;***. And then there are &lt;strong&gt;Green Threads&lt;/strong&gt; (user space level, cooperative multitasking threads) in Java's JVM for some time now! The recent&lt;em&gt; Windows 7 beta&lt;/em&gt; has introduced User Mode Scheduled Threads (&lt;strong&gt;UMS Threads&lt;/strong&gt;)**** , which are like Win32 Fibers, as they can be scheduled by hand, but are backed by real bona-fide kernel level threads! Sounds rather interesting!&lt;/p&gt;&lt;p&gt;So at last it's the old, good cooperative mutitasking rediscovered? There's a growing evidence! Will be the ol' good times of DSET maybe back then Stefan?&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* &lt;a class="v1" target="_new"&gt;Johnson M. Hart&lt;/a&gt;: &lt;em&gt;Windows System Programming Third Edition&lt;/em&gt;, Addison Wesley 2004&lt;br /&gt;** &lt;a href="http://download.oracle.com/owsf_2003/40171_colello.ppt"&gt;http://download.oracle.com/owsf_2003/40171_colello.ppt&lt;/a&gt;&lt;br /&gt;***&lt;a href="http://www.fiberpool.de/en/research.html"&gt;http://www.fiberpool.de/en/research.html&lt;/a&gt;&lt;br /&gt;**** &lt;a href="http://blogs.msdn.com/nativeconcurrency/archive/2009/02/04/concurrency-runtime-and-windows-7.aspx"&gt;http://blogs.msdn.com/nativeconcurrency/archive/2009/02/04/concurrency-runtime-and-windows-7.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-6590446349965494586?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/02/fibers-at-last.html</link><author>noreply@blogger.com (Marek Krj)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_79IsVE3vX_Y/SbdzLDq2p9I/AAAAAAAAAE0/Er_GKrP8YYM/s72-c/Silk-Winding.png' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-4457588877567592514</guid><pubDate>Wed, 18 Feb 2009 12:24:00 +0000</pubDate><atom:updated>2009-10-07T06:42:22.323-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>C++</category><category domain='http://www.blogger.com/atom/ns#'>servlets</category><title>C++ Server Pages</title><description>&lt;p&gt;&lt;/p&gt;&lt;p&gt;In my prevoius blogs I wondered if there is/could be a C++ implementation of the Java's Servlet interface(s)*, and recently a friendly fellow blogger** pointed out to me that there already is one, viz the &lt;em&gt;&lt;span style="color:#009900;"&gt;CPPSERV&lt;/span&gt;&lt;/em&gt;: &lt;a href="http://www.total-knowledge.com/progs/cppserv/"&gt;http://www.total-knowledge.com/progs/cppserv/&lt;/a&gt;! &lt;/p&gt;&lt;p&gt;&lt;a href="http://4.bp.blogspot.com/_79IsVE3vX_Y/SaK7Iwcw0LI/AAAAAAAAAEk/aGSEiv7BtS0/s1600-h/cppservlogo.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5306009070114754738" style="MARGIN: 10px 10px 10px 0px; WIDTH: 74px; CURSOR: hand; HEIGHT: 81px" alt="" src="http://4.bp.blogspot.com/_79IsVE3vX_Y/SaK7Iwcw0LI/AAAAAAAAAEk/aGSEiv7BtS0/s200/cppservlogo.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Can you see C++ it its logo? &lt;/p&gt;&lt;p&gt;I cite*: &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;CPPSERV is a web application server&lt;/strong&gt; that provides Servlet-like API and JSP-like functionality to C++ programmers.&lt;br /&gt;...&lt;br /&gt;&lt;strong&gt;CSP (C++ Server pages), the JSP equivalent for CPPSERV&lt;/strong&gt;, are currently implemented as a precompiler that converts CSP source to C++ source of a servlet, which, in turn needs to be compiled into CPPSERV servlet&lt;/em&gt;.&lt;br /&gt;...&lt;br /&gt;&lt;em&gt;Current CSP implementation supports basic parsing, as well as compile-time taglibs.&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Well, that's it! Or perhaps not? What we have is the equivalent of the Java's JSPs, which generally suck, and standing alone are too week a framework for serious work. But hey, &lt;strong&gt;it's not that bad, as we have got some choices: &lt;/strong&gt;the &lt;em&gt;CPPSERV&lt;/em&gt; for the oldskool JSP-like programming, the late &lt;em&gt;Bobcat&lt;/em&gt; for more of the same, or the &lt;em&gt;Wt&lt;/em&gt; framework*** for more modern, &lt;em&gt;GWT&lt;/em&gt;-like work! &lt;/p&gt;&lt;p&gt;And with some discipline (I mean the model 1 ;-))) servlets, do you remember???) it's possible to get working application in C++ quickly! And all that Java frameworks out there are only trying to hide the JSP processing model, and they aren't that beautiful themselves. So for smaller things a JSP-like solution will be probably sufficient, and for more modern applications (including &lt;em&gt;AJAX&lt;/em&gt; support) I'd choose the &lt;em&gt;Wt&lt;/em&gt; framework.&lt;/p&gt;&lt;p&gt;There remains the question of the OO-Relational mapping, an the creators of &lt;em&gt;CPPSERV&lt;/em&gt; suggest using their &lt;em&gt;SPTK&lt;/em&gt; classes****, but it seems to be only a JDBC-like DB access layer. I suppose, I'd rather take Qt's DB classes for that, but on the other side, they are somehow heavyweight. But the OO-Relational thing for C++ is a different question in itself. But JDBC style access isn't &lt;em&gt;that &lt;/em&gt;horrible either, and in a whole I think there are some viable options for C++ web applications out there! &lt;/p&gt;&lt;p&gt;Now I guess, I should try out the 2 frameworks, but ... ehm ... you know, so little time, so many books...&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;PS&lt;/span&gt; (07 Oct. 2009):&lt;/strong&gt; meanwhile I have detected two another C++ and C "Servlets". Well they aren't really Servlets, but are rather one step back on the evolutionary path, and are somehow JSP-equivalent. The first of them is named &lt;a href="http://koanlogic.com/klone/tut.html"&gt;KLone&lt;/a&gt; and allows you to include C scripts in the HTML page in the exact JSP manner. The other is &lt;a href="http://trustleap.com/"&gt;GWAN&lt;/a&gt; - it's free and it allows you to write "servlet" scripts in C, which will be executed by the server and generate the HTML output - so in this case we are almost there, except for the very limited set of functions you can use in the script. Nonetheless, very interesting!&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;* see: &lt;a href="http://ib-krajewski.blogspot.com/2008/10/c-servlets-again.html"&gt;http://ib-krajewski.blogspot.com/2008/10/c-servlets-again.html&lt;/a&gt;&lt;br /&gt;** &lt;a href="http://www.blogger.com/profile/13381726511364305841"&gt;Gavino&lt;/a&gt;, unfortunately his profile isn't available :-(((, but nonetheless, thanks bloke!&lt;br /&gt;*** The Wt-framework ("witty" - &lt;a href="http://www.webtoolkit.eu/wt/"&gt;http://www.webtoolkit.eu/wt/&lt;/a&gt;)&lt;br /&gt;**** SPTK: mainly a GUI framework, but it has some DB access support as well: &lt;a href="http://www.sptk.net/index.php"&gt;http://www.sptk.net/index.php&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-4457588877567592514?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/02/c-server-pages.html</link><author>noreply@blogger.com (Marek Krj)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_79IsVE3vX_Y/SaK7Iwcw0LI/AAAAAAAAAEk/aGSEiv7BtS0/s72-c/cppservlogo.png' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-2721713454827245943</guid><pubDate>Wed, 28 Jan 2009 07:32:00 +0000</pubDate><atom:updated>2009-03-12T02:00:53.194-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>multithreading</category><category domain='http://www.blogger.com/atom/ns#'>C++</category><title>Reading the new C++ Standard</title><description>&lt;p&gt;&lt;/p&gt;&lt;p&gt;Recently I've read on my local German C++ forum* that's there was a new draft document for C++09 Standard** and immediately I rushed out to read it. I mean, something tangible at last! Well, actually it wasn't really a read, but rather a very superficial skimming-over. There are good reviews of C++09 on the Web***, so I didn't actually want to read it in depth, &lt;strong&gt;but rather to get an overall impression of the changes: just how it all would feel like&lt;/strong&gt; in &lt;em&gt;C++0x: x &amp;lt; a&lt;/em&gt;. &lt;/p&gt;&lt;p&gt;And guess what? It was last year in &lt;em&gt;November (sic!!!)&lt;/em&gt; when I read it and then wrote some things up :-(((. Somehow I'm too busy with my current project! Of course I'd like to read the proposal in depth and analyze it here thoroughly, but alas, it's not possible. So let's start with just few of my very personal impressions:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;1. Ranges and initializers&lt;/h3&gt;&lt;br /&gt;What I perhaps liked best of the new features! Now I can write things like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    map&amp;lt;&lt;span style="color:#009900;"&gt;type-expr&lt;/span&gt;&amp;gt; m = {{}, {}, {}};&lt;br /&gt;    int a[] = {1};&lt;br /&gt;    vector&amp;lt;&lt;span style="color:#009900;"&gt;type-expr&lt;/span&gt;&amp;gt; v = { a, b, c };&lt;br /&gt;    SomeClass obj({ a, b, c, d });&lt;/pre&gt;and that for any class I want! How is that done? You have to implement the &lt;span style="font-family:courier new;"&gt;initializer_list&lt;/span&gt; constructor for your class! Wow, it feels just (like) &lt;em&gt;Groovy&lt;/em&gt; to me :-). &lt;strong&gt;A great improvement over the oldskool tricks&lt;/strong&gt; used to force initialization where it wasn't possible by the language definition!&lt;br /&gt;&lt;br /&gt;A realated feature I liked are ranges:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    for(int&amp;amp; x: array)&lt;br /&gt;    {&lt;br /&gt;        x = 0; &lt;span style="color:#009900;"&gt;// for example!&lt;/span&gt;&lt;br /&gt;    }&lt;/pre&gt;This is accomplished internally by a &lt;span style="font-family:courier new;"&gt;Range&lt;&gt;&lt;/span&gt; class being internally instantiated with the array instance: &lt;span style="font-family:courier new;"&gt;Range&lt;&lt;span style="color:#009900;"&gt;type-expr&lt;/span&gt;&gt;(array).&lt;/span&gt; It gives you a nice, scripting language like feeling when iterating; I mean, even Java's got it, and the &lt;em&gt;boost::FOREACH&lt;/em&gt; macro was in my personal opinion rather an ugly hack than anything else!&lt;br /&gt;&lt;br /&gt;When talking about ranges: actually I was expecting that the ranges will be included for the STL algorithms, so we don't have to write the annoing:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;    find(v.begin(), v.end(), not_zero());&lt;/pre&gt;each time. I was quite positive that we'll going to have something like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    find(v, not_zero());&lt;/pre&gt;as an overload of the traditional STL signature using the new &lt;span style="font-family:courier new;"&gt;Range&lt;&gt;&lt;/span&gt; class (there is a &lt;span style="font-family:courier new;"&gt;boost::range&lt;/span&gt; library after all!), so I must say &lt;strong&gt;I'm a bit disappointed here&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;2. Some nice utilities I found&lt;/h3&gt;&lt;br /&gt;There were suprisingly large number of small interesting things to be discovered, like:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;error support: &lt;span style="font-family:courier new;"&gt;error_code, system_error - &lt;/span&gt;well, I can definitely use some of it!&lt;br /&gt;&lt;/li&gt;&lt;li&gt;compile time (i.e. template) rational arithmetic - suprise! BTW do we really need it?&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new;"&gt;clock&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;time_point&lt;/span&gt; classes - useful!&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new;"&gt;stoi&lt;/span&gt;: string to int conversion - a suprise!, so don't we take the road of &lt;span style="font-family:courier new;"&gt;lexical_cast&lt;&gt;&lt;/span&gt; as I was expecting all the time?&lt;br /&gt;&lt;/li&gt;&lt;li&gt;alignment control - at last I can say what the aligment is and not the machine! Will then the machines revolt?&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new;"&gt;unique_ptr - &lt;/span&gt;just what we need most often, or &lt;em&gt;auto_ptr&lt;/em&gt; fixed!&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new;"&gt;addressof - &lt;/span&gt;even if the actual &lt;em&gt;&amp;amp; &lt;/em&gt;operator is overloaded!&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new;"&gt;reference_closure&lt;/span&gt; as &lt;span style="font-family:courier new;"&gt;Callable &lt;/span&gt;- what was that again??? But I wrote it up in my original notes, so it must be something funny!&lt;br /&gt;&lt;/li&gt;&lt;li&gt;delegating constructors - we can reuse one constructor in another one, like in this example from the draft document:&lt;pre&gt;  struct C {&lt;br /&gt;      C(int){}     &lt;span style="color:#009900;"&gt;// 1: non-delegating constructor&lt;/span&gt;&lt;br /&gt;      C(): C(42){} &lt;span style="color:#009900;"&gt;// 2: delegates to 1&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new;"&gt;nullptr&lt;/span&gt; as a keyword - no more the annoing &lt;em&gt;&lt;span style="font-family:courier new;"&gt;(XXX*)0&lt;/span&gt;&lt;/em&gt; casts!&lt;/li&gt;&lt;/ul&gt;I liked these little things, and there is probably more like that to be discovered. It's refreshing to see that the smaller problems of day-to-day programming are addressed too!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;3. Some expected things&lt;/h3&gt;&lt;br /&gt;As expected we've got the hash tables at last, as actually the whole &lt;em&gt;TR.1&lt;/em&gt; stuff like regular expressions, type traits for templates, tuples, general binders and function objects, is in there too. Plus the move constructors and rvalue references.&lt;br /&gt;&lt;br /&gt;Moreover the &lt;span style="font-family:courier new;"&gt;auto&lt;/span&gt; keyword and the &lt;em&gt;lambda&lt;/em&gt; functions are there, so now we can write&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    auto iter = m.begin();&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// and not&lt;/span&gt;&lt;br /&gt;    map&amp;lt;string,string&amp;gt;::const_iterator iter = m.begin();&lt;/pre&gt;at last! Just think how many keystrokes/copy and pastes it will save!&lt;br /&gt;&lt;br /&gt;Speaking of lambdas - as I read it, there isn't one example of a lambda function in the draft! And moreover, in &lt;em&gt;"Chap. 14.3.1 Template type arguments"&lt;/em&gt; there's something missing: namely the old restictions about the non-global linkage of the template parameters! This means, I can write a functor in local scope and pass it to the STL algorithm like that:&lt;br /&gt;&lt;pre&gt;    void XXX::someFunc()&lt;br /&gt;    {&lt;br /&gt;        struct my_not_zero {&lt;br /&gt;            bool operator() (const X&amp;amp; p) { return p != 0; }&lt;br /&gt;        };&lt;br /&gt;&lt;br /&gt;        &lt;span style="color:#009900;"&gt;// use the local functor &lt;/span&gt;&lt;br /&gt;        find(v.begin(), v.end(), my_not_zero());&lt;br /&gt;        &lt;span style="color:#009900;"&gt;// OR use a lambda function:&lt;/span&gt;&lt;br /&gt;        find(v.begin(), v.end(), [] (const X&amp;amp; p) -&gt; bool { return p != 0 });&lt;br /&gt;    }&lt;/pre&gt;I'd say, what was the reason for lambdas again (at least for me)? To be able write a functor which doesn't have to have global linkage! Are lambdas obsolete then? Well, both yes and no. Just look at the code example above, writing a local functor still requires quite a lot of plumbing, and a lambda expression is somehow more terse (we could even spare the return type of bool in our example!). IMHO both of them are not wholly satisfactory. Using a lambda library solution I could write it in a much more terse way:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// OR using my pocket lambda library&lt;/span&gt;:&lt;br /&gt;    find(v.begin(), v.end(), _$1 != 0 });&lt;br /&gt;&lt;/pre&gt;Another expected (and somehow dreaded) new thing are the &lt;strong&gt;Concepts&lt;/strong&gt;. I must say thery are everywhere in the standard library section, like in this new &lt;span style="font-family:courier new;"&gt;std::list&lt;/span&gt; move constructor:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    &lt;span style="color:#ff6600;"&gt;requires AllocatableElement&amp;lt;Alloc, T, T&amp;amp;&amp;amp;&amp;gt;&lt;/span&gt; list(list&amp;amp;&amp;amp; x);&lt;/pre&gt;I mean, now the standard library header files will get even less readable, but the compiler errors will be (hopefully) more so. So I'm in two minds about this feature: isn't it too much of the type system? What about the duck typing in templates? Are we giving it up? For me it was a very nice feature. I guess it won't come that bad, and the templates without Concepts will be working as before but are Concepts only for compiler support or are we supposed to use meta-typing everywhere?&lt;br /&gt;&lt;br /&gt;The next expected thing, which however deserves its own section is:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;4. Multithreading support&lt;/h3&gt;&lt;p&gt;Sorry, I didn't read it yet... It's two whole chapters (29 and 30) ant they aren't exactly short.&lt;br /&gt;&lt;br /&gt;But instead it started me thinkig: how was I writing multithreading applications before there was the C++ memory model defined? How on earth was this possible? Well, it was all vendor (i.e. compiler) specific. When a compiler supported the POSIX thread library (&lt;em&gt;pthreads&lt;/em&gt;) for example, it would pose some memory fences around the pthread calls****. It would treat some pieces of code in a special way - just like in Java's &lt;em&gt;String &lt;/em&gt;magic. The local static initializes would be automatically guarded by locks (Gnu compiler) or maybe not (Sun compiler). The &lt;span style="font-family:courier new;"&gt;volatile&lt;/span&gt; keyword would be given an extra visibility guarantee (Microsoft compiler). And I never initialized global static variables out of the multithreading part of the program, only in the main thread portion. An the best of it is, that all these techniques wasn't guaranteed to work****! But hey, the 1st Java memory model wa buggy too, wasn't it?&lt;br /&gt;&lt;br /&gt;Now it's all supposed to be portable.&lt;br /&gt;&lt;br /&gt;One thing which &lt;strong&gt;I did read up&lt;/strong&gt; (however on the Web and not in the proposal itself), and what was a littel unexpected for me, is about the &lt;span style="font-family:courier new;"&gt;volatile&lt;/span&gt; keyword. The proposal didn't stengthen the volatile keyword in the way it's been done in Java or C#. I suppose that out of the reasons of backward compatibility with C's &lt;span style="font-family:courier new;"&gt;volatile&lt;/span&gt; remained only a compiler (dis)optimisation directive, while for the visibility guarantees between threads we are supposed to use the &lt;span style="font-family:courier new;"&gt;atomic&lt;&gt;&lt;/span&gt; library! &lt;/p&gt;&lt;p&gt;How will the old programs using volatile for visiblity between threads be running now? Are they broken? I suppose so, they probably must be rewritten using the &lt;span style="font-family:courier new;"&gt;atomic&lt;&gt;&lt;/span&gt; types.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;5. Summing things up&lt;/h3&gt;&lt;p&gt;My impression so far is, that there are many small things you wouldn't expect, and that they are fun! I was expecting the big new chunks of functionality to be added (and they were added indeed) to be the most impressive ones, but it's rather the small things which make the difference. Look at that code snippet in the new, cool layout style (which I picked up in this Ferbruary's issue of the MSDN Magazine) :&lt;pre&gt;    for_each(values.begin(), values.end(), [](int&amp;amp; value)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color:#009900;"&gt;// now we can nest STL at last! (or can we???)&lt;/span&gt;&lt;br /&gt;        for_each(value.begin(), value.end, DoSomething);&lt;br /&gt;    });&lt;/pre&gt;I'd dare to say &lt;strong&gt;that C++ seems to have put away its 90-ties image,&lt;/strong&gt; as it allows to write programs more in style of the scripting languages than the old and venerable K&amp;amp;R C! I can only add &lt;em&gt;"at last"&lt;/em&gt; and &lt;em&gt;"Amen".&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* Thanks &lt;a href="https://www.xing.com/profile/Jens_Weller8"&gt;Jens&lt;/a&gt;!&lt;br /&gt;** Herb Sutter's announcement and some discussion with the inevitable C++ bashing: &lt;a href="http://herbsutter.wordpress.com/2008/10/28/september-2008-iso-c-standards-meeting-the-draft-has-landed-and-a-new-convener/"&gt;http://herbsutter.wordpress.com/2008/10/28/september-2008-iso-c-standards-meeting-the-draft-has-landed-and-a-new-convener/&lt;/a&gt;, the Draft document itself is here: &lt;a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf"&gt;http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf&lt;/a&gt;&lt;br /&gt;*** like the article in the Wikipedia, which I found to be surprisingly good: &lt;a href="http://en.wikipedia.org/wiki/C%2B%2B0x"&gt;http://en.wikipedia.org/wiki/C%2B%2B0x&lt;/a&gt;&lt;br /&gt;**** Hans Boehm: &lt;em&gt;"Threads cannot be implemented as a library"&lt;/em&gt; Technical Report HPL-2004-209, HP Laboratories Palo Alto, 2004, &lt;a href="http://www.hpl.hp.com/techreports/2004/HPL-2004-209.pdf"&gt;http://www.hpl.hp.com/techreports/2004/HPL-2004-209.pdf&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-2721713454827245943?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2009/01/ive-read-on-my-local-german-c-forum.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-5302008647317752688</guid><pubDate>Thu, 11 Dec 2008 08:01:00 +0000</pubDate><atom:updated>2009-02-21T08:45:47.256-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Java</category><category domain='http://www.blogger.com/atom/ns#'>Groovy</category><category domain='http://www.blogger.com/atom/ns#'>C++</category><title>Do we need destructors?</title><description>&lt;p&gt;&lt;/p&gt;This post is for my honoured, old-time, old-skool hacker colleague &lt;strong&gt;Stefan Z&lt;/strong&gt;. As we were discussing the new and (then) hot Java language, we couldn't accept that it didn't have destructors. I cite Stefan:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;The constructor/destructor pair is an incredibly powerful concept!&lt;/em&gt;&lt;/blockquote&gt;Well, you can't have everything: either we support garbage collection or destructors, isn't it? But it just one more point where Java sucks: the ugly &lt;em&gt;try/finally&lt;/em&gt; block and then the explicit &lt;em&gt;close()&lt;/em&gt; call like in the following code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    BufferedReader reader =&lt;br /&gt;            new BufferedReader(new FileReader(aFileName));&lt;br /&gt;&lt;br /&gt;    try {&lt;br /&gt;      String line = null;&lt;br /&gt;      while ( (line = reader.readLine()) != null ) {&lt;br /&gt;        &lt;span style="color:#009900;"&gt;// process the line...&lt;/span&gt;&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;    finally {&lt;br /&gt;      reader.close();&lt;br /&gt;    }&lt;/pre&gt;Ugly? You bet! And what I really don't like is that you cannot hide all the required handling in a library! In C++ you'd just write:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    ifstream f(aFileName);&lt;br /&gt;    string line;&lt;br /&gt;&lt;br /&gt;    while(f)&lt;br /&gt;    {&lt;br /&gt;      getline(f, line);&lt;br /&gt;      &lt;span style="color:#009900;"&gt;// process the line...&lt;/span&gt;&lt;br /&gt;    }    &lt;/pre&gt;That's all, &lt;strong&gt;the plumbing is hidden&lt;/strong&gt; &lt;strong&gt;in the destructor*&lt;/strong&gt; and it is there automatically! It's the reason why Stefan called this concept an &lt;em&gt;"incredibly powerful"&lt;/em&gt; one. But that powerful concept can cause problems in a multithreading and garbage-collected environment. As a matter of fact, a recent C++ standard proposal for the multithreading execution model opted for removing destructors from the language (!!!), or at least for not executing the static destructors in a multithreading setting! Of course, it's a shortcut in order to solve a rather complicated problem, but you get the idea, right?&lt;br /&gt;&lt;br /&gt;So maybe the destructors are a little bit outdated, what do you think Stefan? All the more was I pleased as I recently stumbled on a Smalltalk pattern &lt;strong&gt;called &lt;em&gt;"Execute Around Method"&lt;/em&gt; pattern**&lt;/strong&gt; (to be true, I don't do any Smalltalk and have seen it in some Groovy example code). It's another possiblity to hide the plumbing in the library: you just define a static method doing all the dirty work and accepting your "payload" code - just like in an IP packet: we have the framing and the payload, and the user is only delivering the payload! Well, an example explains it best:&lt;br /&gt;&lt;pre&gt;    def static use(closure)&lt;br /&gt;    {&lt;br /&gt;      def r = new Resource()&lt;br /&gt;      try&lt;br /&gt;      {&lt;br /&gt;        r.open()&lt;br /&gt;        closure(r)&lt;br /&gt;      }&lt;br /&gt;      finally&lt;br /&gt;      {&lt;br /&gt;        r.close()&lt;br /&gt;      }&lt;br /&gt;    }&lt;/pre&gt;The &lt;em&gt;closure&lt;/em&gt; parameter stands for our "payload" code. This code is the hidden in the library. An application of this is the following Groovy code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    new FileReader(aFileName).withReader&lt;br /&gt;    { reader -&gt;&lt;br /&gt;        reader.readLine(line)&lt;br /&gt;        &lt;span style="color:#009900;"&gt;// process the line...&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// no need to close()!!!&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;We create a new reader, give it to the static &lt;em&gt;withReader()&lt;/em&gt; library method, and provide a "code block" (as you'd call it in Perl) for execution. This code block (called closure in Groovy) gets as the parameter the ressource which will be closed at the end, just like the &lt;em&gt;use()&lt;/em&gt; method shown above!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;A destructor for the modern times!&lt;/strong&gt; So the &lt;em&gt;"incredibly powerful"&lt;/em&gt; idea can be saved?&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* this is called a RAII-pattern in C++, see: &lt;a href="http://www.hackcraft.net/raii/"&gt;http://www.hackcraft.net/raii/&lt;/a&gt;&lt;br /&gt;** Kent Beck: "&lt;em&gt;Smalltalk Best Practice Patterns",&lt;/em&gt; Prentice Hall, Englewood Cliffs, NJ, 1996.&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-5302008647317752688?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2008/12/do-we-need-constructors.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-1298428911258670764</guid><pubDate>Thu, 27 Nov 2008 07:26:00 +0000</pubDate><atom:updated>2009-02-21T08:46:34.832-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SW processes</category><category domain='http://www.blogger.com/atom/ns#'>C++</category><category domain='http://www.blogger.com/atom/ns#'>OO</category><title>C vs C++ and some celebrity gossiping</title><description>&lt;p&gt;&lt;/p&gt;Every time I read a post of &lt;a href="http://www.youtube.com/watch?v=4XpnKHJAok8"&gt;Linus "Linux" Torvalds&lt;/a&gt; I can't help thinking "what a smug, assumptuous, &lt;em&gt;xxx-yyy-zzz&lt;/em&gt;!". Well, I don't know the man personally, but I certainly wouldn't like to have him as my boss in any project, betcha! The first quote is a couple of years old (I cite from memory as I cannot find it anymore) and was a reply to some proposal Linus didn't like :&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;....go and play in your little world...&lt;/em&gt;&lt;/blockquote&gt;It looks innoculous enough here and now, but in the context it was realy ugly. And now, for some time everyone seems to feel obliged to speak about Linus' C++-hating post*, so I had a look at it myself. OK, nothing changed, it goes in the same vein:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;*YOU* are full of bullshit.&lt;/em&gt; ...... &lt;em&gt;is likely a programmer that I really *would* prefer to piss off, so that he doesn't come and screw up any project I'm involved with.&lt;/em&gt; ...&lt;em&gt;... the end result is a horrible and unmaintainable mess. But I'm sure you'd like it more than git.&lt;/em&gt; &lt;/blockquote&gt;... etc, etc, etc. OK, maybe it's only his personal creative writing coach who's to be blamed, or perhaps it's the macho Linux kernel developer culture? But, aside of personal dislike, what the man says got a bell ringing with me. Why? Read on:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;C++ leads to really really bad design choices&lt;/strong&gt;. You invariably start using the "nice" library features of the language like STL and Boost and other total and utter crap, that may "help" you program, but causes: &lt;ul&gt;&lt;li&gt;infinite amounts of pain when they don't work (and anybody who tells me that STL and especially Boost &lt;strong&gt;are stable and portable is just so full of BS&lt;/strong&gt; that it's not even funny)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;inefficient abstracted programming models where two years down the road &lt;strong&gt;you notice that some abstraction wasn't very efficient&lt;/strong&gt;, but now all your code depends on all the nice object models around it, and you cannot fix it without rewriting your app. &lt;/li&gt;&lt;/ul&gt;&lt;le&gt;In other words, the only way to do good, efficient, and system-level and portable C&lt;strong&gt;++&lt;/strong&gt; ends up to limit yourself to all the things that are basically available in C. &lt;/em&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/blockquote&gt;Whoa, that man is really hardcore! What he's actually saying is: don't trust any code you didn't write by yourself! And on a higher level: any abstraction we are using is a trap, lulling us in a false sense of security. And more: &lt;strong&gt;we can really build big, fast, complex systems without using OO abstractions&lt;/strong&gt;!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Didn't I feel the same before?&lt;/strong&gt; That for the efficient, near system level code we can take C, and that all the fancy object thing, where the is better done in Ruby or (even) Java? So no place for C++ here? Take Wireshark protocol analyzer as example?&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Gossiping&lt;/h3&gt;Well, the story doesn't end here. First, there are some entertaining comments on digg**. My favourites are:&lt;br /&gt;&lt;em&gt;&lt;br /&gt;&lt;/em&gt;&lt;ul&gt;&lt;li&gt;&lt;em&gt;Linus codes a kernel for a living, so its not that surprising that he hates C++.&lt;br /&gt;&lt;/em&gt;&lt;/li&gt;&lt;li&gt;&lt;em&gt;Linus is an *****, he lives here in Beaverton and the man has a big ego for someone nobody outside of the Linux community cares about.&lt;br /&gt;&lt;/em&gt;&lt;/li&gt;&lt;li&gt;&lt;em&gt;Ok... Who cares if Linus Torvalds hates C++. I don't really give a damn.&lt;br /&gt;&lt;/em&gt;&lt;/li&gt;&lt;li&gt;&lt;em&gt;another episode of "I am Linus and hate everything"&lt;/em&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;em&gt;funny that linus prefers kde when it is programmed in C++&lt;br /&gt;&lt;/em&gt;&lt;/li&gt;&lt;li&gt;&lt;em&gt;Personally I've evolved thinking in OO abstractions, so working with C++ is much more natural for me than C. Does that mean I'm a crappy programmer? Only Linux Torvals knows&lt;/em&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;em&gt;The STL is the biggest piece of crap I've seen in 40 years of programming. It's a graduate students project to prove one can write a totally orthogonal, yet totally inefficient, impossible to maintain, piece of crud.&lt;/em&gt;&lt;/li&gt;&lt;/ul&gt;Well, as it seems, first: people aren't taking Linus such seriously, and second: STL ist the culprit!&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Living in the past?&lt;/h3&gt;So, as to begin with something, what's the matter with STL? As we are &lt;strong&gt;gossiping&lt;/strong&gt; in this installment, it's perfectly fine for me to say that the &lt;em&gt;prevalent opinion&lt;/em&gt; on the Web (for example ***) is that Linus is referring to a problem from the past (around 2001 or so), when he's speaking abot the non-portability of C++. At that time the support for the C++ standard, and especially tempaltes, was very unconsistet across the compilers, and so the STL implementations could be nonportable between compilers! But nowadays even &lt;em&gt;Visual C++&lt;/em&gt; is quite up to speed here!&lt;br /&gt;&lt;br /&gt;Then the inefficiency allegation. I don't even want to discuss it here, because it's so old (back in time to 1998 or so). There's long refutation along classical lines from that time to be found****, if only not very entertaining, and a shorter one*****, from a practitioner's point of view - &lt;a href="http://www.informit.com/store/product.aspx?isbn=0321321928"&gt;Steven Dewhurst&lt;/a&gt; actually wrote low level code with C++ and templates:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;Just to annoy people like Linus,&lt;/strong&gt; I've also used typelist meta-algorithms to generate exception handlers with identical efficiency to hand-coded C. In a number of recent talks given at the Embedded Systems conferences, I've shown that commonly-criticized C++ language features can significantly outperform the C analogs.&lt;br /&gt;&lt;/em&gt;&lt;/blockquote&gt;&lt;h3&gt;Who's incompetent?&lt;/h3&gt;Next comes the critique that C++ tends to attract substandard programmers, and that:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;... &lt;strong&gt;limiting your project to C means that people don't screw that up&lt;/strong&gt;, and also means that you get a lot of programmers that do actually understand low-level issues and don't screw things up with any idiotic "object model" crap.&lt;/em&gt;&lt;/blockquote&gt;The first thought that comes to mind is Linus' "software Darwinism": in 2000 he lambasted people wanting a debugger in the Linux kernel. His argument was: I don't need any sissy that needs a debugger! I want people who understand the code as a whole! Any higher level abstraction or language (i.e. STL or C++) will make you a wimp and not careful enough!&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;The fact is, that is *exactly* the kinds of things that C excels at. &lt;strong&gt;Not just as a language, but as a required *mentality*.&lt;/strong&gt; One of the great strengths of C is that it doesn't make you think of your program as anything high-level...&lt;/em&gt;&lt;/blockquote&gt;But isn't this just another management whip for the programmers to keep them under pressure, so they are more obedient? A manager's trick? The &lt;strong&gt;Linus' software management process&lt;/strong&gt;? I'm most hardcore of you all, so I'm the overlord ;-). In that light Linus' diatribes are only politics: he's defending the status quo.&lt;br /&gt;&lt;br /&gt;There's also a diffrent response to the "substandard programmers" reproach I must mention here. &lt;a href="http://www.informit.com/store/product.aspx?isbn=0321321928"&gt;Steven Dewhurst&lt;/a&gt; broght in the point, that for a C programmer C++ is so complex because there are alien idioms, methodologies, tricks, and so on*****. You would be tempted to say it's to difficult for the average C coder, but there's something else! C++ isn't just C, it only happens to be backwards compatible! When you switch from C to Common Lisp you won't be an expert instantly, but the C folks assume they can just come and start programming C++. And then they cry that it's too difficult and complex.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Summary&lt;/h3&gt;This time there's no summary. I was just gossiping...&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* Linus original post (admittedly taken out of context!): &lt;a href="http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918"&gt;http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918&lt;/a&gt;, but I must admit, when he's speaking, he does make a much better impression!&lt;br /&gt;** Digg gossiping: &lt;a href="http://digg.com/linux_unix/Linus_Torvalds_hates_C"&gt;http://digg.com/linux_unix/Linus_Torvalds_hates_C&lt;/a&gt;&lt;br /&gt;*** Hacker News discussion: &lt;a href="http://news.ycombinator.com/item?id=51451"&gt;http://news.ycombinator.com/item?id=51451&lt;/a&gt;&lt;br /&gt;**** A typical reply: &lt;a href="http://warp.povusers.org/OpenLetters/ResponseToTorvalds.html"&gt;http://warp.povusers.org/OpenLetters/ResponseToTorvalds.html&lt;/a&gt;&lt;br /&gt;***** Steven Dewhurst's reply: &lt;a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;amp;seqNum=411"&gt;http://www.informit.com/guides/content.aspx?g=cplusplus&amp;amp;seqNum=411&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-1298428911258670764?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2008/11/c-vs-c-and-some-celebrity-gossiping.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>5</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-8759849630219260471</guid><pubDate>Wed, 19 Nov 2008 08:23:00 +0000</pubDate><atom:updated>2008-12-15T07:33:38.482-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>windows</category><category domain='http://www.blogger.com/atom/ns#'>Qt</category><title>A letter from DLL hell: msvc60.dll and msvcr80.dll</title><description>&lt;p&gt;&lt;span style="color:#009900;"&gt;&lt;strong&gt;This is only a short technical note&lt;/strong&gt;&lt;/span&gt; - for those who (like me) first check the Internet for solution to weird programming questions!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;The Problem:&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Locally everything worked fine: I could install my old (VC++ 6.0) Windows application and start it without a hitch. But at client's site (1000s of miles away) Windows refused to start as it couldn't find the&lt;em&gt;&lt;strong&gt; msvcr80.dll&lt;/strong&gt;&lt;/em&gt; library.&lt;br /&gt;&lt;br /&gt;What the heck, I link against&lt;strong&gt;&lt;em&gt; msvc60.dll&lt;/em&gt;&lt;/strong&gt; but Windows complains about &lt;strong&gt;&lt;em&gt;msvcr80.dll&lt;/em&gt; which I don't use, don't link, and don't need???&lt;/strong&gt; &lt;strong&gt;I that black magic? Help!!!&lt;/strong&gt; That was the problem I was fighting for the best part of one of last weeks. Welcome in the manifest/DLL hell. Well, I tried first to reproduce this locally: it didn't work (i.e. it did work ;-))) on my develpoment&lt;em&gt; Widows XP&lt;/em&gt; machine, as well as a freshly installed&lt;em&gt; Windows Server 2003 Std. Edition (SP2)&lt;/em&gt;, a running &lt;em&gt;Windows Server 2003 Web Edition (SP1)&lt;/em&gt;, and it always worked! No probs at all when starting the app! &lt;/p&gt;&lt;p&gt;At the client there was the &lt;em&gt;Windows Server 2003 Web Edition (SP2), &lt;/em&gt;with "nothing installed" (as asserted by my colleague at the client' s site) except for our product and Oracle! What's going on? There are no dependencies to msvcr80.dll in my code (I checked with the &lt;a href="http://www.dependencywalker.com/"&gt;Dependency Walker&lt;/a&gt;) and the installation worked for years before I made that last bugfix! &lt;/p&gt;&lt;p&gt;In the last attempt to reproduce the error I found a running installation of &lt;em&gt;Windows Server 2003 Web Edition (SP2)&lt;/em&gt; at my client's company local site and could at last see it with my own eyes:&lt;span style="color:#009900;"&gt; "Cannot start application, msvcr80.dll not found".&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;The Solution:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;It's elementary: if there's no static dependency, ther must be a dynamic one! The &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx"&gt;Process Explorer &lt;/a&gt;has shown, that the process has really tried to load the msvcr80.dll! &lt;strong&gt;How?&lt;/strong&gt; Through the Qt plugin mechanism: &lt;blockquote&gt;&lt;em&gt;"Qt applications automatically know which plugins are available, because plugins are stored in the standard plugin subdirectories. Because of this applications don't require any code to find and load plugins, since Qt handles them automatically.&lt;br /&gt;&lt;br /&gt;The default directory for plugins is QTDIR/plugins*, with each type of plugin in a subdirectory for that type, e.g. styles..."&lt;/em&gt; &lt;/blockquote&gt;&lt;p&gt;Although I used the &lt;span style="color:#009900;"&gt;Qt version 3&lt;/span&gt;, this generic mechanism pulled in all the plugins found, which were OK, except for the styles plugin&lt;em&gt; qtdotnet2.dll&lt;/em&gt;. Because of course &lt;em&gt;"nothing else installed"&lt;/em&gt; wasn't true: the Base package of my client was there, and it had various plugins installed, including the culprit: qtdotnet2.dll, which was written for &lt;span style="color:#009900;"&gt;Qt version 4&lt;/span&gt; and pulled in the Visual C++ 2005 runtime support! &lt;/p&gt;&lt;p&gt;---&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-8759849630219260471?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2008/11/letter-from-dll-hell-msvc60dll-and.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-4513946346506388855</guid><pubDate>Sat, 25 Oct 2008 20:54:00 +0000</pubDate><atom:updated>2009-02-21T08:46:08.471-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>distributed computing</category><category domain='http://www.blogger.com/atom/ns#'>Erlang</category><category domain='http://www.blogger.com/atom/ns#'>Python</category><title>Erlang and Map-Reduce</title><description>&lt;p&gt;&lt;/p&gt;I was a fan of Google's Map-Reduce for a quite long time, as I was first doing my PhD research in distributed systems and then was working in some high-availability projects, so such interest emerged somehow naturally.&lt;br /&gt;&lt;br /&gt;Their (i.e. Google's) achievements quite impressed me: first the whole infrastructure (lot of C++ coding - they simple wrote their own filesystem and database!!!), but equally the level of abstraction used when working with distributed data. I wrote about the superiority of that model over the SOA model before, although the SOA model is probably the best you can achieve in a heterogenous environment (and I was probably wrong there...).&lt;br /&gt;&lt;br /&gt;So every time I see a map-reduce implementation I can't help reading about it: &lt;em&gt;Hadoop&lt;/em&gt; is the most known open source implementation, but there's the &lt;em&gt;QtConcurrent::mappedReduced&lt;/em&gt; algorithm in the new Qt 4.5* as well. You see, the idea seems to be catching on.&lt;br /&gt;&lt;br /&gt;Now to the news: there is a Map-Reduce implementation in Erlang (!!!)** which runs Python scripts (!!!) and it's called &lt;strong&gt;&lt;em&gt;Disco&lt;/em&gt;&lt;/strong&gt;***! And if you don't have a massive parallel cluster at home, you can run it in the Amazon's &lt;em&gt;Elastic Computing Cloud&lt;/em&gt;! I don't like Nokia very much, but I must admit that this one is rather cool: &lt;strong&gt;you simply write scripts to manipulate your data, much in the vein of UNIX shell programming, only infinitely scalable&lt;/strong&gt;! And we know that scripting languages are much better for data manipulations than Java or C++. According to its homepage, Disco is quite a success too:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;This far Disco has been succesfully used, for instance, in parsing and reformatting data, data clustering, probabilistic modelling, data mining, full-text indexing, and log analysis with hundreds of gigabytes of real-world data. ***&lt;br /&gt;&lt;/em&gt;&lt;/blockquote&gt;Wow! I like te idea of Erlang and Python working unisono!&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* Qt 4.5 docs: &lt;a href="http://doc.trolltech.com/main-snapshot/threads.html#qtconcurrent"&gt;http://doc.trolltech.com/main-snapshot/threads.html#qtconcurrent&lt;/a&gt;&lt;br /&gt;** a small itroduction to Erlang: &lt;a href="http://ib-krajewski.blogspot.com/2007/08/erlangs-change-of-fortunes.html"&gt;http://ib-krajewski.blogspot.com/2007/08/erlangs-change-of-fortunes.html&lt;/a&gt;&lt;br /&gt;*** Disco's homepage: &lt;a href="http://discoproject.org/"&gt;http://discoproject.org/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-4513946346506388855?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2008/10/erlang-and-map-reduce.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>3</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-2996392714347967893</guid><pubDate>Tue, 07 Oct 2008 11:47:00 +0000</pubDate><atom:updated>2009-02-21T08:46:57.379-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>C++</category><category domain='http://www.blogger.com/atom/ns#'>servlets</category><title>C++ servlets - again</title><description>&lt;p&gt;&lt;/p&gt;It looks like it's getting to be a new hobby of mine: collecting C++ web application frameworks. After the first one* (a simple HTTP server and session classes) and the modern one (&lt;em&gt;Wt&lt;/em&gt; aka witty)**, now the "missing link" was found: the classic Java-like Servlet container implementation in C++! This was made possible by a friendly fellow blogger &lt;a href="http://www.blogger.com/profile/01661872353574105253"&gt;Eduardo Zea&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Eduado was kind enough to give me a link to the DDJ article describing such an implementation by Rogue Wave named &lt;strong&gt;Bobcat&lt;/strong&gt;***. It's quite old (by SW-industry standards) and the link to evaluation downloads doesn't work anymore, so I think, it didn't quite catch on. But it's another one in my collection! So the actual counters are &lt;em&gt;C++=3&lt;/em&gt;, &lt;em&gt;Java=googol.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;PS:&lt;/strong&gt; To be more precise, Bobcat functionality is now part of the &lt;em&gt;Hydra Express&lt;/em&gt;****, a Rogue Wave's SOA publishing framework. So are we all going SOAP?&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* see: &lt;a href="http://ib-krajewski.blogspot.com/2007/09/servlets-in-c.html"&gt;http://ib-krajewski.blogspot.com/2007/09/servlets-in-c.html&lt;/a&gt;&lt;br /&gt;** The Wt-framework: &lt;a href="http://www.webtoolkit.eu/wt/"&gt;http://www.webtoolkit.eu/wt/&lt;/a&gt;&lt;br /&gt;*** John Hinke, &lt;em&gt;Implementing C++ Servlet Containers,&lt;/em&gt; April 01, 2002: &lt;a href="http://www.ddj.com/184405023"&gt;http://www.ddj.com/184405023&lt;/a&gt;&lt;br /&gt;**** &lt;a href="http://www.roguewave.com/blog/so-what-is-it-with-rogue-wave-and-xml-soa/"&gt;http://www.roguewave.com/blog/so-what-is-it-with-rogue-wave-and-xml-soa/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-2996392714347967893?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2008/10/c-servlets-again.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-176294107655529443</guid><pubDate>Mon, 29 Sep 2008 10:03:00 +0000</pubDate><atom:updated>2009-02-21T08:47:39.691-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>software engineering</category><category domain='http://www.blogger.com/atom/ns#'>C++</category><title>Beautiful code</title><description>&lt;p&gt;&lt;/p&gt;What is beatiful code? The shortest answer (which I've read somewhere but can't remember where) is:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;&lt;strong&gt;we all know what "ugly code" is:&lt;/strong&gt; code that someone else wrote...&lt;/i&gt;&lt;/blockquote&gt;But beautiful code? Isn't it in the eye of the beholder? Well, for me, beautiful equals readable. You have to see on the first sight what the overall idea of the piece of code is. On the other side, the idea itself might be crap (!!!) but then we should ask the next question: what is a beautiful design/architecture?&lt;br /&gt;&lt;br /&gt;I, for my side, am thus a proponent of writing aesthetically appealing code. And I'm not alone! Read this:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;Whether it is a natural occurrence, a quirk of human languages, or conditioning, most people find while (x==3) significantly simpler to read than while (3==x). Although neither is going to cause confusion, &lt;strong&gt;the latter tends to slow people down or interrupt their train of thought&lt;/strong&gt;. In this book, we have favored readability over safety—but our situation is somewhat different than that of normal development. You will have to decide for yourself which convention suits you and your team better. *&lt;/em&gt;&lt;br /&gt;&lt;/blockquote&gt;Here we've got it: the eternal problem with the coding guidelines forcing me to write a plug-ugly &lt;em&gt;(3==x)&lt;/em&gt;! The question is: &lt;strong&gt;should we write ugly code as to be on the safe side?&lt;/strong&gt; I admit, that I never wrote such an ignominious line of code in my life. You expect trouble? Nope! I've never had any problems at this point! Well, one single time I mistyped it, but found it out in an instant! In C++ you have to develop certain sensitivity for that construct, that's all.&lt;br /&gt;&lt;br /&gt;As for practical examples (instead of dull theoreticizing) - some time ago I asked myself: what is the most cool/beatiful piece of code you eve wrote, what would you show to others in order to impress them or to show them how crystal-clear ;-) your style is? As it was even before my lambda library, and only had plain production code on my disposal, I settled on the following piece: &lt;pre&gt;&lt;span style="color:#009900;"&gt;/*------------------------------------------------------------------------*/ /**&lt;br /&gt;* @brief      configDelta&lt;br /&gt;* @descr&lt;br /&gt;*     This function compares two configurations and returns the differences.&lt;br /&gt;*&lt;br /&gt;* @param[in]  other - the other configuration&lt;br /&gt;* @param[in]  scope - what delta requested: all the new entries, all the deleted&lt;br /&gt;*                     entries, or all changes altogether?&lt;br /&gt;* @param[out] delta - the calculated diffrence&lt;br /&gt;*&lt;br /&gt;* @note       Assumption: both configurations must be sorted!!!&lt;br /&gt;*///---------------------------------------------------------------------------&amp;gt;&lt;/span&gt;&lt;br /&gt;void SimpleCfgFile::configDelta(const SimpleCfgFile&amp;amp; other, CfgDelta scope,&lt;br /&gt;                                vector&amp;lt;string*&amp;gt;&amp;amp; delta) const&lt;br /&gt;{&lt;br /&gt;    TRACE_FUNC("SimpleCfgFile::configDelta");&lt;br /&gt;    delta.clear();&lt;br /&gt;&lt;br /&gt;    switch(scope)&lt;br /&gt;    {&lt;br /&gt;        case addedDelta:&lt;br /&gt;            TRACE_DEBUG("addedDelta");&lt;br /&gt;            &lt;span style="color:#009900;"&gt;// all in this but not in other&lt;/span&gt;&lt;span style="color:#009900;"&gt;:&lt;/span&gt;&lt;br /&gt;            set_difference(begin(), end(),&lt;br /&gt;                           other.begin(), other.end(),&lt;br /&gt;                           inserter(delta, delta.begin()),&lt;br /&gt;                           less_then_deref&amp;lt;string*&amp;gt;());&lt;br /&gt;            break;&lt;br /&gt;&lt;br /&gt;        case removedDelta:&lt;br /&gt;            TRACE_DEBUG("removedDelta");&lt;br /&gt;            &lt;span style="color:#009900;"&gt;// all in other but not in this:&lt;/span&gt;&lt;br /&gt;            set_difference(other.begin(), other.end(),&lt;br /&gt;                           begin(), end(),&lt;br /&gt;                           inserter(delta, delta.begin()),&lt;br /&gt;                           less_then_deref&amp;lt;string*&amp;gt;());&lt;br /&gt;            break;&lt;br /&gt;&lt;br /&gt;        case completeDelta:&lt;br /&gt;            TRACE_DEBUG("completeDelta");&lt;br /&gt;            &lt;span style="color:#009900;"&gt;// all in this but not in other + in other and not this:&lt;/span&gt;&lt;br /&gt;            set_symmetric_difference(begin(), end(),&lt;br /&gt;                                     other.begin(), other.end(),&lt;br /&gt;                                     inserter(delta, delta.begin()),&lt;br /&gt;                                     less_then_deref&amp;lt;string*&amp;gt;());&lt;br /&gt;            break;&lt;br /&gt;&lt;br /&gt;        default:&lt;br /&gt;            TRACE_ERR("Unknown scope requested for configuration delta!!!");&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    TRACE_VALUE(delta.size());&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;You see, it's not a rocket science. What I liked in this piece of code was it's conciseness, readibility and (though it's of no real importance for workings of the code) its symmetry. And moreover, I was amazed how a judicious usage of the standard library simplified the task which at first seemed to be rather a daunting one!&lt;br /&gt;&lt;br /&gt;An lastly, it's an illustration for the fact that you don't have to use a lambda library to obtain a clear code: I just wrote the following trivial functor:&lt;br /&gt;&lt;pre&gt;  template &amp;lt;class T&amp;gt; struct less_then_deref : binary_function&amp;lt;T,T,bool&amp;gt;&lt;br /&gt;  {&lt;br /&gt;      &lt;span style="color:#009900;"&gt;// OPEN TODO ---&amp;gt; constraint: isPtrType(T)...&lt;/span&gt;&lt;br /&gt;      bool operator() (const T&amp;amp; x, const T&amp;amp; y) const { return *x &amp;lt; *y; }&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;instead of the lambda expression &lt;em&gt;(*$1 &amp;lt; *$2)&lt;/em&gt; and it is still readable. Or even more readable by using a telling name?&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* taken from the following book: &lt;em&gt;Groovy in Action&lt;/em&gt;, Dierk König et al., Manning 2007, page 157-158&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-176294107655529443?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2008/09/beautiful-code.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-4718725880623557102</guid><pubDate>Wed, 17 Sep 2008 12:00:00 +0000</pubDate><atom:updated>2009-02-21T08:48:08.780-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Java</category><category domain='http://www.blogger.com/atom/ns#'>J2EE</category><category domain='http://www.blogger.com/atom/ns#'>Google</category><title>Google's technology stack</title><description>&lt;p&gt;&lt;/p&gt;Well, I said I wouldn't write any knee-jerk reaction posts on this blog, only well thoght-through, throughly researched, and insightful entries. Certainly, I have some entries I should be rather working on, like mutithreading testing or lock-free synchronization... But I must admit, that was a bit over-optimistic, as you'll see in a second...&lt;br /&gt;&lt;br /&gt;Recently, I stumbled across this one:&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;Google has recently launched the Google App Engine. From an Java enterprise developers point of view it is shamelessly easy to use, deploy, etc. Well, unfortunately it only takes Python apps for now, but it is stated that there will be more languages supported in the future.&lt;strong&gt; But it’s Google again putting its finger into the Java EE wound&lt;/strong&gt; (first GWT with webapps, then Android shaking the Java ME world, and now App Engine showing how runtimes should look like).*&lt;/em&gt;&lt;/blockquote&gt;I blogged before about the "Google phone", which came out not as a phone, but as an SDK (BTW: do you want to make your 1st milion? Take part in the Android Developer Challenge, no kidding!). The local german &lt;em&gt;"Java Magazin"&lt;/em&gt; published on this ocasion (i.e Android's release) an editorial, accusing Google of attacking Sun, Java, splitting the Javaland and whatever. What the fuss?&lt;br /&gt;&lt;br /&gt;I cite Wkipedia**:&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;Dalvik is often referred to as a Java Virtual Machine, but this is not strictly accurate, as the bytecode on which it operates is not Java bytecode. Instead, a tool named dx, included in the Android SDK, transforms the Java Class files of Java classes compiled by a regular Java compiler into another class file format (the .dex format).&lt;/em&gt;&lt;/blockquote&gt;So you are writng Java code, but it's not running on the JVM! Is that forbidden?&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;"...some have related Dalvik to Microsoft's JVM and the lawsuit that Sun filed against Microsoft, wondering if a similar thing might happen with Google, while others have pointed out that Google is not claiming that Dalvik is a Java implementation, whereas Microsoft was."***&lt;/em&gt;&lt;/blockquote&gt;I don't know. But I think it shouldn't be!&lt;br /&gt;&lt;br /&gt;Now for the Google App Engine. As I had a look at it some time ago, it didn't ring a bell with me. I rather though about it as of another grid computing offering, like Amazon's Elastic Cloud: just write your app locally and ther throw it on the grid and it will scale automatically with your needs. But when a Java person sees this, it sees Java technology attacked. The same for GWT: it is JSF as it should always has been. But come on, you are still writing your programms in Java, the difference is that the ideas don't come from Sun! I'd rather say &lt;strong&gt;Google is giving a second life to Java by providing new ways for using it.&lt;/strong&gt; I wouldn't have though that 5 years ago, when they were essentially a C++/Pythonn shop!&lt;br /&gt;&lt;br /&gt;Additionally, I can't help feeling that the Java poeople are thinking in an "imperialistic" way: boasting about their superiority, but on the other side always suspicious that someone may have try to challenge their (self proclaimed) supremacy. Like the late USSR...&lt;br /&gt;&lt;br /&gt;But on the other side, when you look at Google, you could be tempted to think, that they are writing everything new: newly they published an own C++ test framework**** and an own (C++) transfer data encoding****, just as example. So maybe it's not an assault on Java iteself, but&lt;strong&gt; just a manifestation of the "Not Invented Here" syndrome?&lt;/strong&gt; Now, the employees must do something in their 20% project-free time, so they programm every conceivable thing anew (and better?).&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* &lt;a href="http://adminsight.de/2008/05/05/springsource-announces-an-application-plattform/"&gt;http://adminsight.de/2008/05/05/springsource-announces-an-application-plattform/&lt;/a&gt;&lt;br /&gt;** &lt;a href="http://en.wikipedia.org/wiki/Dalvik_virtual_machine"&gt;http://en.wikipedia.org/wiki/Dalvik_virtual_machine&lt;/a&gt;&lt;br /&gt;*** &lt;a href="http://www.infoq.com/news/2007/11/dalvik"&gt;http://www.infoq.com/news/2007/11/dalvik&lt;/a&gt;&lt;br /&gt;**** Google test framework: &lt;a href="http://code.google.com/p/googletest/wiki/GoogleTestPrimer"&gt;http://code.google.com/p/googletest/wiki/GoogleTestPrimer&lt;/a&gt;, Google transfer encoding: &lt;a href="http://code.google.com/apis/protocolbuffers/docs/overview.html"&gt;http://code.google.com/apis/protocolbuffers/docs/overview.html&lt;/a&gt;, and now they even wrote their own browser: Google Chrome (ok, you knew that already...)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-4718725880623557102?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2008/09/googles-technology-stack.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-6523889957327908512</guid><pubDate>Wed, 27 Aug 2008 20:30:00 +0000</pubDate><atom:updated>2009-02-21T08:48:40.494-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Java</category><category domain='http://www.blogger.com/atom/ns#'>C++</category><title>The end of dumbing-down of programming?</title><description>&lt;p&gt;&lt;/p&gt;Times are changing. Definitely. Think about this little story: do you remember what Java's USP was at the beginning? Yes, the garbage collection, and yes, the JVM portability. But the main thing was it's philosophy of not allowing bad programmers to make bad mistakes. We don't have pointers, we don't have operator overloading, we don't have multiple inheritance, our core classes are final... As one person expressed it at that time: &lt;i&gt;"...they gave me a paper hammer instead of a real one so I can't hit my fingers!"&lt;/i&gt; And that's the reason why i din't like it, didn't really want to use it, and consequently missed out on a cash-cow :-(.*&lt;br /&gt;&lt;br /&gt;But yesterday, I read this on the InfoQ**:&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;... And it is true, my experience weaves that out too: you can create environment really restricted just to keep bad developers out of trouble, but these restricted environments harm the productivity of your best programmers. Basically what you do is: &lt;b&gt;you are not speeding up your bad developers and you are slowing down your best developers&lt;/b&gt; and that's why our productivity stinks in software right now, but the attitude is changing around.&lt;br /&gt;&lt;/em&gt;&lt;/blockquote&gt;I've read similar complaints before, but as it seems, after the Ruby-shock (RoR faster than Struts and 10x mote productive) such opinion is somehow fashionable and even almost mainstream today.&lt;br /&gt;&lt;br /&gt;What do you say? Isn't that &lt;b&gt;the old C++ philosophy we are returning to?&lt;/b&gt; I cite Bjarne***: &lt;blockquote&gt;&lt;em&gt;Kierkegaard was a strong proponent for the individual against "the crowd" and has some serious discussion of the importance of aesthetics and ethical behavior. I couldn't point to a specific language feature [....] but he is one of the roots &lt;b&gt;of my reluctance to eliminate "expert level" features, to abolish "misuses", and to limit features &lt;/b&gt;to support only uses that I know to be useful.&lt;/em&gt;&lt;/blockquote&gt;---&lt;br /&gt;* The language was just plain uninteresting to me, and I didn't see its real merits at the time. Maybe I didn't want to see them?&lt;br /&gt;** &lt;a href="http://www.infoq.com/interviews/Languages-Platforms-Neal-Ford"&gt;http://www.infoq.com/interviews/Languages-Platforms-Neal-Ford&lt;/a&gt;&lt;br /&gt;*** &lt;a href="http://technologyreview.com/Infotech/17831/page3/"&gt;http://technologyreview.com/Infotech/17831/page3/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;PS:&lt;/strong&gt; BTW, concerning the &lt;em&gt;"Java is the next Cobol"&lt;/em&gt; thing, there was a discussion on some German Java forum here, where I argued with 2 arguments, but as I see now, I (and everyone else) missed the most important one. Namely: Java &lt;em&gt;is&lt;/em&gt; the new Cobol, as it's mainly used in corprate and business settings (like Cobol was). The solution is simple, isn't it?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-6523889957327908512?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2008/08/end-of-dumbing-down-of-programming.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-6997310083301352782</guid><pubDate>Wed, 09 Jul 2008 21:16:00 +0000</pubDate><atom:updated>2009-02-21T08:54:24.710-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>C++</category><title>C++ pocket lambda library, the last</title><description>&lt;p&gt;&lt;/p&gt;So, this will be definitely the last part! I promise! I planned this to be a three part series, and see how it has grown. But let's go down to the business: in the previous installments we achieved the following:&lt;br /&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// part 1: basics&lt;/span&gt;&lt;br /&gt;    find_if(vec.begin(), vec.end(),  _$1 &amp;lt;= 10);&lt;br /&gt;    transform(vec.begin(), vec.end(), vec1.begin(), _$1*2);&lt;br /&gt;    sort(vp.begin(), vp.end(), *_$1 &amp;lt;= *_$2);&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// part 2: function applications&lt;/span&gt;&lt;br /&gt;    for_each(vec.begin(), vec.end(), bind(sinus, _$1*(pi/180.0)) );&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// part 2a: member access&lt;/span&gt;&lt;br /&gt;    find_if(vecx.begin(), vecx.end(),  _$1-&amp;gt;*(&amp;amp;XXX::getValue) &amp;lt;= 2);&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// part 3: output&lt;/span&gt;&lt;br /&gt;   for_each(vec.begin(), vec.end(), cout &amp;lt;&amp;lt; delay("---") &amp;lt;&amp;lt; _$1 &amp;lt;&amp;lt; delay("\n"));&lt;br /&gt;&lt;/pre&gt;You can see, we had defined a kind of a custom (if not too counter-intuitive) mini-language for the lambda expessions. As each language has to be learnt, we'd like it to be kept simple! So I have only one more thing to add, namely:&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. Control structures&lt;/h2&gt;&lt;br /&gt;This is really fun, because it's not difficult at all and it let us define very cute lamdbas indeed. The entire code, as it stands in the library, is like that:&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;    // if_then&lt;br /&gt;    //  ---&lt;/span&gt;&lt;br /&gt;    template &amp;lt;class S, class T&amp;gt; void eval_then_expr(S&amp;amp; e, T&amp;amp; t) { e(); }&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;    // helper: Assgn needs the iterator for: if_then(_$1==0, _$1=44)&lt;br /&gt;    // --- OPEN, TODO: make general for e.g.: if_then(_$1&amp;gt;=3, cout &amp;lt;&amp;lt; _$1)&lt;br /&gt;    // --&lt;/span&gt;&lt;br /&gt;    template &amp;lt;class T&amp;gt; void eval_then_expr(Assgn&amp;lt;T&amp;gt;&amp;amp; e, T&amp;amp; t) { e(t); }&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;    template&amp;lt;class S, class T&amp;gt; struct IfThen  : public lambda_expr {&lt;br /&gt;        S if_expr;&lt;br /&gt;        T then_expr;&lt;br /&gt;        IfThen(S s, T t) : if_expr(s), then_expr(t) {}&lt;br /&gt;        template &amp;lt;class U&amp;gt;&lt;br /&gt;            &lt;span style="color:#009900;"&gt;// OPEN, TODO: check if then_expr needs the val argument!&lt;/span&gt;&lt;br /&gt;            bool operator()(U&amp;amp; val) { if(if_expr(val))&lt;br /&gt;                                          eval_then_expr(then_expr, val); }&lt;br /&gt;    };&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;    template &amp;lt;class S, class T&amp;gt;&lt;br /&gt;        IfThen&amp;lt;S, T&amp;gt; if_then(S s, T t) { return IfThen&amp;lt;S, T&amp;gt;(s, t); }&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// t.b.c....&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;you see, there are some TODOs, which we'll discuss in the due time, but the technique is &lt;strong&gt;simple&lt;/strong&gt;: first we store the &lt;em&gt;if_expr&lt;/em&gt; and the &lt;em&gt;then_expr&lt;/em&gt; (as functors), and when the &lt;em&gt;IfThen&lt;/em&gt; functor is evaluated, we just evaluate the sub-functors, and make the then_expr dependant on the value of the &lt;em&gt;if_expr&lt;/em&gt;. I didn't think myself this would be so simple! As this isn't a ready library, but rather an exploration of some possibilities in code, ther are a lot of open ends here. First, we probably don't need the val parameter in the function call operator. Second, if the &lt;em&gt;then_expr&lt;/em&gt; needs the iterator (i.e. &lt;em&gt;_$1&lt;/em&gt;), I currently just hacked in only the overload for the assignment. This must be extended with some general forwarder mechamism. But even with this rudimentary support, we can do this now:&lt;br /&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// count occurences&lt;/span&gt;&lt;br /&gt;    for_each(vec.begin(), vec.end(), if_then(_$1 == 1, globvar(yyy_ctr)++));&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// replace values&lt;/span&gt;&lt;br /&gt;    for_each(vec.begin(), vec.end(), if_then(_$1 == 1, _$1 = 9));&lt;br /&gt;&lt;/pre&gt;I think it's pretty useful. Other possible control structures? Well, I think they are possible, but not so useful: a loop, a switch? I don't think that it would be good design. What we really would need sometimes, is rather a possiblility to nest STL algorithms than to use a loop functor. But it's not difficult, maybe something along the lines of:&lt;br /&gt;&lt;pre&gt;    template &amp;lt;class U&amp;gt;&lt;br /&gt;        bool operator()(U&amp;amp; val) { auto it = val.begin(); &lt;span style="color:#009900;"&gt;// C++Ox&lt;/span&gt;&lt;br /&gt;                                  for(it != val-&amp;gt;end(); it++)&lt;br /&gt;                                      eval_loop_body(loop_body, it); }&lt;br /&gt;&lt;/pre&gt;would do, and then we could process a container of containers:&lt;br /&gt;&lt;pre&gt;    for_each(cc.begin(), cc.end(), loop_all(cout &amp;lt;&amp;lt; _$1));&lt;br /&gt;&lt;/pre&gt;and perhaps even to extend it like that:&lt;br /&gt;&lt;pre&gt;    for_each(cc.begin(), cc.end(), loop_some(_$2 &amp;lt; 1, cout &amp;lt;&amp;lt; _$1));&lt;br /&gt;    for_each(cc.begin(), cc.end(), loop_counted(10, cout &amp;lt;&amp;lt; _$1));&lt;br /&gt;&lt;/pre&gt;But do we need it? I think it's more a gimmick that an useful feature, because it's not orthogonal: you have a host of special &lt;em&gt;loop_xxx&lt;/em&gt; lambdas instead of a single mechanism. What do you think?&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;2. Summing this all up&lt;/h2&gt;&lt;br /&gt;In conclusion? There are 2 conlusions:&lt;br /&gt;&lt;br /&gt;1. lambda library is cool, all this stuff is cool, I'm cool.&lt;br /&gt;&lt;br /&gt;2. Frankly, isn't that all just appalling? All that effort and what we got is an unnatural syntax! And it's not transparent: for each new combination of operators I've got to write new code in the library (or almost)! Makes you think of Phillip Greenspun's Tenth Rule of Programming: &lt;i&gt;"Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp."&lt;/i&gt; &lt;b&gt;Please Mr. Stroustrup, why don't we have lambda-expressions as core language feature in C++???&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Actually, as the things are, it seems like we are going to have lambda functions in the new C++0x standard*! For me, they look like Groovy lambdas (or are they really Ruby's ???), compare**:&lt;br /&gt;&lt;pre&gt;&lt;strong&gt;Groovy:&lt;/strong&gt; myMap.each { key, value -&amp;gt; println "$key =&amp;gt; $value" }&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;C++0x:&lt;/strong&gt; for_each(a.begin(), a.end(), &amp;lt;&amp;gt; (int x) -&amp;gt; int { return sum += x; } );&lt;br /&gt;       &lt;span style="color:#009900;"&gt;// or, equivalently, but not much Groovy-like:&lt;/span&gt;&lt;br /&gt;       for_each(a.begin(), a.end(), &amp;lt;&amp;gt;(int x) { return sum += x; } );&lt;br /&gt;&lt;/pre&gt;Should we rejoice then? The proposal paper itself lists the problems with lambda expressions:&lt;br /&gt;&lt;br /&gt;1. lambda-libraries may render simpler code in basic cases, compare:&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// lambda lib.&lt;/span&gt;&lt;br /&gt;    os &amp;lt;&amp;lt; _$1&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// lambda expr.&lt;/span&gt;&lt;br /&gt;    &amp;lt;&amp;gt; (int i) extern(os) { os &amp;lt;&amp;lt; i; }&lt;br /&gt;&lt;/pre&gt;You see, we need the old, ugly, annoying type specifications again! An we've just started to ejoy the typeless (ehm, generic...) programming in C++! Isn't that what the whole template thing is for! This leads immediately to the second problem:&lt;/blockquote&gt;2. there are no polymorfic lambda functions!!!&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;The proposal doesn't allow us to write templated, polymorfic lambda function (i.e. ones with implicit type recognition), as it would clash with the concepts feature. More specific, it wouldn't exaclty clash and explode, but rather the concepts couldn't guarantee the correct type checking in this case. So bye bye type freedom? Do we alway have to use the annoying explicite typing? Imagine a lambda function working with an iterator on a list of strings, an then write this type expicitely as input parameter. Ghastly! When you are using a lambda library solution, you'll simply write &lt;em&gt;_$&lt;/em&gt;1, and that's it! In such a case, the whole point of the lambda expression, its conciseness, goes down the drain. I can write a standalone functor as well.&lt;/blockquote&gt;&lt;strong&gt;Summing up:&lt;/strong&gt; if have only a simple thing to do, a lambda library solution is simpler. But if there is some more work to do, and we don't have elaborate type specifications for input parameters, the lambda expression solution has clearly an edge, as we don't have to learn a new, special-purpose mini-language, but can just use the standard C++ syntax.&lt;br /&gt;&lt;br /&gt;As it seems none of the solutions is optimal: do we need both of them?. And I can say I'm rather not pleased, although the situation here is definitely better than in Python.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;3. Personal note&lt;/h2&gt;&lt;br /&gt;In the past I thought (or rather believed) that you could &lt;strong&gt;just do everything in C++ with libraries, operator overloading and template tricks&lt;/strong&gt;. But I guess I was just dazzled by the template syntax ;-). After this series I think there are limits to the flexibility of C++ which can be only worked around with ugly syntax (or macros).&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* as in the last "State of C++ Evolution" document they are on the list of the features which are definitely planned to be included, see: "State of C++ Evolution (between Portland and Oxford 2007 Meetings)" of Dec.01.2007 - &lt;a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2142.html"&gt;http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2142.html&lt;/a&gt;&lt;br /&gt;** C++0x lambda expressions proposal - &lt;a href="http://www.research.att.com/~bs/N1968-lambda-expressions.pdf"&gt;http://www.research.att.com/~bs/N1968-lambda-expressions.pdf&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-6997310083301352782?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2008/07/c-pocket-lambda-library-last.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3870801931584460413.post-4000154837178929040</guid><pubDate>Wed, 25 Jun 2008 08:35:00 +0000</pubDate><atom:updated>2009-02-21T08:49:11.466-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Qt</category><category domain='http://www.blogger.com/atom/ns#'>C++</category><category domain='http://www.blogger.com/atom/ns#'>OO</category><title>The future of C++</title><description>&lt;p&gt;&lt;/p&gt;In my recent blog entry* I complained about not exactly knowing where C++ is heading, what features will C++0x contain when it finally appears, and if we'll need to switch to hex as in C++0a ;-). Then I read some interviews with Bjarne Stroustrup** and the things became clearer.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. The process&lt;/h2&gt;&lt;br /&gt;The first ambiguity I addressed, was the problem of the very loooong time which C++ needs when acquiring new features, and hinted at the lack of corporate backing. Bjarne on that**: &lt;blockquote&gt;&lt;em&gt;BS: The progress on standard libraries has not been what I hoped for. ... We will not get ... I had hoped for much more, but the committee has so few resources and absolutely no funding for library development.&lt;br /&gt;&lt;/em&gt;&lt;/blockquote&gt;and: &lt;blockquote&gt;&lt;em&gt;BS: There is no shortage of good ideas in the committee or of good libraries in the wider C++ community. &lt;strong&gt;There are, however, severe limits to what a group of volunteers working without funding can do&lt;/strong&gt;. What I expect to miss most will be thread pools and the file system library. However, please note that the work will proceed beyond '09 and that many libraries are already available; for example see what boost.org has to offer.&lt;/em&gt;&lt;/blockquote&gt;So that's pretty clear, the industry isn't backing C++ anymore, and the ISO beaurocracy isn't helping here. Java's JSP is definitely more lightweight. Python hasn't a commitee. IBM, Sun (and Google?) are massively backing Java. Previously Google was a stronghold of C++ (MapReduce, BigTable, BigFile), but lately Java seems to take over, in the real "weed language" manner.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;2. The features&lt;/h2&gt;&lt;br /&gt;The second of my questions was the extent of new features which will make it into new standard, beacuse this was a constant source of confusion: thousands of proposals, each in a different state of progress, constantly wandering between approved, considered, considered strongly, considered not so strongly, not considered, demised, etc ;-). Now the new feature scope seems to stabilize at last. Bjarne again**: &lt;blockquote&gt;&lt;em&gt;BS: I do — based on existing work and votes — expect to get:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Libraries&lt;/b&gt;&lt;br /&gt;- Threads&lt;br /&gt;- Regular expressions&lt;br /&gt;- Hash tables&lt;br /&gt;- Smart pointers&lt;br /&gt;- Many improvements for containers&lt;br /&gt;- Quite a bit support for new libraries&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Language&lt;/b&gt;&lt;br /&gt;- A memory model supporting modern machine architectures&lt;br /&gt;- Thread local storage&lt;br /&gt;- Atomic types&lt;br /&gt;- Rvalue references&lt;br /&gt;- Static assertions&lt;br /&gt;- Template aliases&lt;br /&gt;- Variadic templates&lt;br /&gt;- Strongly typed enums&lt;br /&gt;- constexpr: Generalized constant expressions&lt;br /&gt;- Control of alignment&lt;br /&gt;- Delegating constructors&lt;br /&gt;- Inheriting constructors&lt;br /&gt;- auto: Deducing variable types from initializers&lt;br /&gt;- Control of defaults&lt;br /&gt;- nullptr: A name for the null pointer&lt;br /&gt;- initializer lists and uniform initialization syntax and semantics&lt;br /&gt;- concepts (a type system for template arguments)&lt;br /&gt;- a range-based for loop&lt;br /&gt;- raw string literals&lt;br /&gt;- UTF8 literals&lt;br /&gt;- Lambda functions&lt;br /&gt;&lt;/em&gt;&lt;/blockquote&gt;The most important feature (IMHO) is**: &lt;blockquote&gt;&lt;em&gt;BS: The new memory model and a task library was voted into C++0x in Kona. That provides a firm basis for share-memory multiprocessing as is essential for multicores.&lt;/em&gt;&lt;br /&gt;&lt;/blockquote&gt;and, of course, the auto keyword and lambdas!&lt;br /&gt;&lt;br /&gt;Maybe more important is &lt;strong&gt;what won't be there&lt;/strong&gt;**: &lt;blockquote&gt;&lt;em&gt;BS: The progress on standard libraries has not been what I hoped for. .... We will not get the networking library, the date and time library, or the file system library. These will wait until a second library TR. I had hoped for much more, ...&lt;br /&gt;BS: ... What I expect to miss most will be thread pools and the file system library. However, please note that the work will proceed beyond '09 ...&lt;/em&gt;&lt;br /&gt;&lt;/blockquote&gt;But an important change of working style will take place:** &lt;blockquote&gt;&lt;em&gt;... Fortunately, the committee has decided to try for more and smaller increments. For example, C++0x (whether that'll be C++09 or C++10) will have only the preparations for programmer-controlled garbage collection and lightweight concurrency, whereas we hope for the full-blown facilities in C++12 (or C++13).&lt;/em&gt;&lt;br /&gt;&lt;/blockquote&gt;and we may expect a host of new extensions in the future!&lt;br /&gt;&lt;br /&gt;On the other hand, at least when the multithreading is concerned, there are independent libraries available, and they offer some rather high level concepts! Take for example the latest Trolltech's &lt;em&gt;Qt 4.5&lt;/em&gt; framework***, which implements futures, automatic scaling for multicore, has a MapReduce implementation plus concurrent mapping and filtering algorithms. It's just like Java 7's &lt;em&gt;fork-join&lt;/em&gt; framework* and the &lt;em&gt;ParallelArray&lt;/em&gt; class. Bravo! Other library with high level threading support are of course the Intel's &lt;em&gt;Thread Building Blocks&lt;/em&gt;, it's not bad either! At this point we don't need a standard document, as it seems.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;3. The prospects&lt;/h2&gt;&lt;br /&gt;At last, let's pose a more general question: what kind of language wants C++ to be? In the past Bjarne Stroustrup maintained that C++ should be a &lt;em&gt;"general purpose programming language".&lt;/em&gt; Contrast this with the statements from the last interviews**: &lt;blockquote&gt;&lt;em&gt;JB: You are looking at making C++ better for systems programming in C++0x as I understand it, is that correct? ...&lt;br /&gt;&lt;br /&gt;BS: Correct. The most direct answer involves features that directly support systems programming, such as thread local storage and atomic types.&lt;br /&gt;&lt;br /&gt;JB: C++ is often used in embedded systems, including those where safety and security are top priorities. What are your favorite examples and why do you think C++ is an ideal language for embedded systems especially where safety is a concern, aside from easy low-level machine access?&lt;br /&gt;&lt;br /&gt;BS: Yes, and I find many of those applications quite exciting.&lt;/em&gt;&lt;br /&gt;&lt;/blockquote&gt;For my taste, Bjarne thinks clearly that C++ is an system and embedded programming language: e.g. he expressed his fondness for robotics systems before. That's bad news, because I don't really like embedded programming and automotive :-(((. On the other hand, system programming is quite exciting for me, provided I haven't to fiddle about low level data structures too much.&lt;br /&gt;&lt;br /&gt;Allow me a question in this context: for me OO programming is about hiding low level details, seeing the bigger picture. &lt;strong&gt;If the strengths of the language lie in the hardware access then maybe it's not so useful for OO programming?&lt;/strong&gt; We can use C for low level programming (like Wireshark's code does, and it's not a toy system) and do OO in Java or Python? So where's the place for C++ then?&lt;br /&gt;&lt;br /&gt;But maybe the future will be totally diffrent? &lt;strong&gt;Maybe we won't be programming C++ anymore but rather the Qt platform&lt;/strong&gt;, which only happens to be written in C++? This would be akin to the Java platform: because C++ doesn't provide a standard ABI, many comapnies are using Qt as to assure the portability of their code between operating systems (among others my current client). Interestingly, not only in GUI applications, abut also in general purpose programming! But what about the (maybe only preconceived) imcompatibility with the standard library, which I bemoaned in one of my previous entries? If I can give faith to Danny Kalev's words****: &lt;blockquote&gt;&lt;em&gt;And in other news, Nokia completed its acquisition of Trolltech last week.&lt;br /&gt;...&lt;br /&gt;Qt is currently used in Skype, Google Earth, and Adobe Photoshop Elements.&lt;br /&gt;....&lt;br /&gt;After Nokia's acquisition, it seems that Qt will be modified to support Symbian and other mobile environments, or at least POSIX libraries &lt;strong&gt;and better support for mainstream C++.&lt;br /&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/blockquote&gt;then it seems that not only yours truly is having that impression, and that there will be a remedy soon!&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;* Language trends and waiting blues: &lt;a href="http://ib-krajewski.blogspot.com/2008/04/language-trends-and-waiting-blues.html"&gt;http://ib-krajewski.blogspot.com/2008/04/language-trends-and-waiting-blues.html&lt;/a&gt;&lt;br /&gt;** An Interview with Bjarne Stroustrup: &lt;a href="http://www.ddj.com/cpp/207000124"&gt;http://www.ddj.com/cpp/207000124&lt;/a&gt; (but&lt;br /&gt;also &lt;a href="http://www.informit.com/articles/article.aspx?p=1192024"&gt;http://www.informit.com/articles/article.aspx?p=1192024&lt;/a&gt; , although I don't quote it here)&lt;br /&gt;*** &lt;a href="http://labs.trolltech.com/page/Projects/Threads/QtConcurrent"&gt;http://labs.trolltech.com/page/Projects/Threads/QtConcurrent&lt;/a&gt;&lt;br /&gt;**** C++ Reference Guide: &lt;a href="http://www.informit.com/guides/guide.aspx?g=cplusplus"&gt;http://www.informit.com/guides/guide.aspx?g=cplusplus&lt;/a&gt; (Notes on 25th of June)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-4000154837178929040?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ib-krajewski.blogspot.com/2008/06/future-of-c.html</link><author>noreply@blogger.com (Marek Krj)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></item></channel></rss>