<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3870801931584460413</id><updated>2012-01-30T15:42:58.505-08:00</updated><category term='Unix'/><category term='Python'/><category term='Go'/><category term='JSP'/><category term='SQL'/><category term='REST'/><category term='Javascript'/><category term='patterns'/><category term='security'/><category term='Clojure'/><category term='multithreading'/><category term='XML'/><category term='Perl'/><category term='SW processes'/><category term='OO'/><category term='Java'/><category term='SOA'/><category term='distributed computing'/><category term='Google'/><category term='Groovy'/><category term='misc'/><category term='private'/><category term='C++'/><category term='Haskell'/><category term='BEA'/><category term='Scala'/><category term='iPhone'/><category term='HA'/><category term='Agile'/><category term='MDD'/><category term='shell'/><category term='servlets'/><category term='software engineering'/><category term='Cocoa'/><category term='Qt'/><category term='design'/><category term='windows'/><category term='web sevices'/><category term='J2EE'/><category term='Boost'/><category term='estimation'/><category term='Erlang'/><title type='text'>On Software and Languages</title><subtitle type='html'>Speaking up from the Telco ghetto... (on C++, Java, Perl, Python, Haskell?, Erlang??, Systems and Processes)</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>69</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-7184263314491413319</id><published>2012-01-22T11:25:00.000-08:00</published><updated>2012-01-22T11:38:31.491-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><title type='text'>Static vs Dynamic Debate Decided</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;span lang="DE"&gt;As I said, it's decided (at least for me) now!&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span lang="DE"&gt;&lt;/span&gt;&lt;br /&gt;A couple of years ago it became fashionable to be ecstatic about dynamic (i.e. dynamically typed*, aka scripting) languages, this sentiment is maybe best exposed by Steve Yegge &lt;a href="http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html"&gt;here&lt;/a&gt;. People started to talk about &lt;i&gt;"freedom languages"&lt;/i&gt;, and it all started getting rather emotional. Like in this tweet:&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;"Strong types are the hobnailed boot of the Enterprise Man on the neck of the &lt;b&gt;Agile Code Poet&lt;/b&gt;"&amp;nbsp;&lt;/i&gt; &lt;a href="http://goo.gl/aeEcn"&gt;http://goo.gl/aeEcn &lt;/a&gt;&lt;/blockquote&gt;It is understandable as an aftershock of the J2EE meltdown by Ruby and Rails, but I was always rather suspicious with that. I was always rather suspicious because of the following gut feeling -&lt;b&gt; why should I throw away things which can possibly help me?&lt;/b&gt; If you are skiing, you know that: you were falling and you'll fall, the question is only when (hope not in an icy couloire or over a cliff...). It's the same in programming; &lt;b&gt;you will fall.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;1. Theory&amp;nbsp;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://upload.wikimedia.org/wikipedia/commons/8/8b/Coq_plus_comm_screenshot.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="235" src="http://upload.wikimedia.org/wikipedia/commons/8/8b/Coq_plus_comm_screenshot.jpg" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;A proof written as a functional program (&lt;a href="http://www.google.de/imgres?imgurl=http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Coq_plus_comm_screenshot.jpg/300px-Coq_plus_comm_screenshot.jpg&amp;amp;imgrefurl=http://en.wikipedia.org/wiki/Curry%25E2%2580%2593Howard_correspondence&amp;amp;usg=__XWqhCdcMZtz232zCjL5kqnlUWc0=&amp;amp;h=223&amp;amp;w=300&amp;amp;sz=20&amp;amp;hl=de&amp;amp;start=0&amp;amp;sig2=U4yDkrlq2iXYwRSBzpflSg&amp;amp;zoom=1&amp;amp;tbnid=8A241rdkH4XhOM:&amp;amp;tbnh=164&amp;amp;tbnw=220&amp;amp;ei=UnHuTrzjNYP64QSKms2-BQ&amp;amp;prev=/search%3Fq%3DCurry-Howard%2Bisomorphism%26hl%3Dde%26biw%3D1078%26bih%3D864%26tbm%3Disch&amp;amp;itbs=1&amp;amp;iact=hc&amp;amp;vpx=546&amp;amp;vpy=426&amp;amp;dur=8864&amp;amp;hovh=178&amp;amp;hovw=240&amp;amp;tx=171&amp;amp;ty=149&amp;amp;sig=107852662001591128774&amp;amp;page=1&amp;amp;ndsp=23&amp;amp;ved=1t:429,r:20,s:0&amp;amp;biw=1078&amp;amp;bih=864" target="_blank"&gt;Wikimedia&lt;/a&gt;)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;As at that time I was interested in mathematical logic and automatic theorem proving, I happened to know about the &lt;a href="http://www.amazon.com/Lectures-Curry-Howard-Isomorphism-Foundations-Mathematics/dp/0444520775?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=btl&amp;amp;camp=213689&amp;amp;creative=392969" target="_blank"&gt;Curry-Howard isomorphism&lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0444520775" style="border: medium none ! important; margin: 0px ! important; padding: 0px ! important;" width="1" /&gt;. It roughly states that a proof in &lt;i&gt;intuitionistic &lt;/i&gt;logic has its equivalent type expression and vice versa. So if type system is equivalent to a (constructive) proofs of correctness, that's cannot be bad. We are getting some limited guarantees from the compiler (because the type system doesn't describe all of the program's behaviour) and that's one thing less we have to worry about!&lt;br /&gt;&lt;br /&gt;Well, OK, maybe that's all theoretical babbling -&amp;nbsp; who knows if all that logic/foundational thing in mathematic isn't contradiction-free? And even if it's not, it's maybe not that relevant in practice...&lt;br /&gt;&lt;br /&gt;Because when confronted with such a question (i.e. what about the correctness guarantees), the standard answer was:&lt;i&gt; "You gotta write more tests!"&lt;/i&gt; or "&lt;i&gt;Strong Testing not Strong Typing&lt;/i&gt;"**. And because tests are a good thing, you cannot say if that maybe could be true... &lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;2. Own Experiences&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So let me share some of my own experiences with dynamic typing.&lt;br /&gt;&lt;a href="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=bil&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=1558607013" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=bil&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=1558607013" style="border: medium none ! important; margin-top: 0px ! important; padding: 0px ! important;" width="1" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.amazon.com/Higher-Order-Perl-Transforming-Programs/dp/1558607013?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=bil&amp;amp;camp=213689&amp;amp;creative=392969" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;" target="_blank"&gt;&lt;img alt="Higher-Order Perl: Transforming Programs with Programs" src="http://ws.amazon.com/widgets/q?MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL160_&amp;amp;ASIN=1558607013&amp;amp;tag=wwwibkrajewsk-20" /&gt;&lt;/a&gt;A couple of years ago, as I read the excellent &lt;i&gt;"Higher Order Perl&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=bil&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=1558607013" style="border: medium none ! important; margin: 0px ! important; padding: 0px ! important;" width="1" /&gt;"&lt;/i&gt; &lt;a href="http://www.amazon.com/Higher-Order-Perl-Transforming-Programs/dp/1558607013?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=btl&amp;amp;camp=213689&amp;amp;creative=392969" target="_blank"&gt;book &lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=1558607013" style="border: medium none ! important; margin: 0px ! important; padding: 0px ! important;" width="1" /&gt;&amp;nbsp;and I got through the first and middle chapters and the code was understandable and clear. &lt;br /&gt;&lt;br /&gt;At this point it's maybe appropriate to give the book some praise, as it's well written, and shows an uknown side of Perl - it's functional self. As the title reveals, the book is about functional programming in... Perl! Yes, that's possible, it even seems to match the language rather well. Of course the language wasn't designed for that, and you will miss&amp;nbsp; all the compiler support and type inference of OCAML but then, Perl isn't statically typed, OK? The only fly in the oinment is that Perl isn't fashionable for quite a couple of years yet...&lt;br /&gt;&lt;br /&gt;But I'm digressing here, so back to the main theme: at first it wasn't aproblem that you don't know the types of the parameters in Perl. It's all convention, you have to retrieve the parameters from the &lt;i&gt;argv &lt;/i&gt;and use them according to their type like that:&lt;br /&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp; my($top, $code) = @_;&amp;nbsp;&lt;span style="color: #38761d;"&gt; &lt;span style="color: #6aa84f;"&gt;# @_ is Perl's argv!&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;So all the type information is so to say in the code that uses it later on. But in the last chapter, when the author is developing a linear equation DSL-based drawing system I sometimes got lost in code. I simply didn't know what the input is, and what the function will be doing with it.&lt;b&gt; How I wished I could see the parameter types in the function declarations!&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Another example: if you are writing Python code using a library you  aren't that accustomed to, and you don't want first to read the  domcumentation for an hour or so, but just quickly code something small  you need just now, you'll very likely just to get a bunch of runtime  exceptions and have to guess what is exactly going on now. What is the  exact type the library is expecting here? I did everything right, didn't  I? Nope, you didn't. Please look up the docs.&lt;br /&gt;&lt;br /&gt;So AFAIC, the types are for human understanding, even if you don't need the type checking guarantees of the compiler. So common sense dictataes using it - you know 80% (my wild guess here) of programming is maintenance, the code is written once and read 1000 times, and so on. We all know these old programming adages, and they don't just apply to telling variable names and insightful commens. Type information is in my eyes another part of writing understandable (as opposed to "genius"-) code.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;3. Other people's experiences&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;OK, I'm not that much experienced in dynamic languages, so maybe I've got the wrong impression, or didn't understand something correctly, or maybe I'm just not clever enough? &lt;br /&gt;&lt;br /&gt;But then, when I started reading the &lt;i&gt;"Beginning Scala" &lt;/i&gt;&lt;a href="http://www.amazon.com/Beginning-Scala-Experts-Voice-Source/dp/1430219890?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=btl&amp;amp;camp=213689&amp;amp;creative=392969" target="_blank"&gt;book &lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=1430219890" style="border: medium none ! important; margin: 0px ! important; padding: 0px ! important;" width="1" /&gt;(well, I didnt't finish reading it in the end because I got bored, but that's another story...) the following lines struck me:&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;As my Ruby and Rails projects grew beyond a few thousand lines of code and as I added team members to my projects, the challenges of dynamic languages became apparent. We were spending more than half our coding time writing tests, &lt;b&gt;and much of the productivity &lt;/b&gt;&lt;/i&gt;&lt;i&gt;&lt;b&gt;gains we saw were lost in test writing&lt;/b&gt;. Most of the tests would have been unnecessary &lt;/i&gt;&lt;i&gt;in Java because most of them were geared toward making sure that we’d updated the &lt;/i&gt;&lt;i&gt;callers &lt;b&gt;when we refactored code by changing method names &lt;/b&gt;or parameter counts.&lt;/i&gt;&lt;/blockquote&gt;As you see, that practical experiences are rather confirming my assertions about static typing: &lt;b&gt;a)&lt;/b&gt; why write test which can be (kind of) automatically generated by compiler, and: &lt;b&gt;b) &lt;/b&gt;why not let automatically document and check the interfaces?&lt;br /&gt;&lt;br /&gt;But there's another angle on that problem which I didn't think of:&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;Also, &lt;/i&gt;&lt;i&gt;I found that working on teams where there were mind melds between two to four team &lt;/i&gt;&lt;i&gt;members, things went well in Ruby, &lt;b&gt;but as we tried to bring new members&lt;/b&gt; onto the team, the &lt;/i&gt;&lt;i&gt;mental connections were hard to transmit to new team members.&lt;/i&gt;&lt;/blockquote&gt;This goes more into the psychology of programming on the first sight, and maybe it's a cultural thing altogether, but it relates a little with: &lt;b&gt;c) &lt;/b&gt;why not document the interfaces as you are writting code to make obvious things obvious? I mean, if the interfaces are better described then maybe the new team memebers will absorb the knowledege better? &lt;br /&gt;&lt;br /&gt;Another Ruby guy tried the &lt;a href="http://ib-krajewski.blogspot.com/2011/10/what-i-did-like-about-go.html"&gt;Go &lt;/a&gt;language and wrote an interesting post about &lt;a href="http://seanerussell.blogspot.com/2011/06/more-golang-adventures.html"&gt;his experiences&lt;/a&gt; with static (although implicit) typing he encountered in Golang:&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;I  guarantee that no matter how much I look at the Ruby code, if it runs for any  length of time I'll eventually encounter a typing error because of a bug in the code…&lt;/i&gt;&lt;/blockquote&gt;Ok, the same old story about interface documentation and checking as above. But read on, ther's more to come:&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;I've learned that I vastly prefer the cost of slower development  time to &lt;b&gt;gain reliability and safety, as long as the cost isn't too high.&lt;/b&gt; Haskell is even safer, but it pushes the boundaries of &lt;b&gt;how much pain I'm willing to endure&lt;/b&gt; trying to get code to pass through the type checker&lt;/i&gt;&lt;/blockquote&gt;Here he's making a good point, kind of reiterating my main argument: there's a trade-off between the developer time neede to type a piece of code and it's reliability. In the past we opted for ease of construction, but if we can have the realiability for very small additional cost? With type inference we hit a sweet spot here!****&lt;br /&gt;&lt;br /&gt;So it's decided, there are real problems with dynamic typing in real-world projects, and static typing can help out here. Why would anyone want to use a dynamic language (beside for scripting some small pieces of code) then?&lt;br /&gt;&lt;br /&gt;But wait, what about Clojure? I like this language... and I'm somehow in 2 minds here - the reason says ML but the heart says Lisp. So is this an emotional thing in the end? But in business you have to follow the path of reason, not coolness, to deliver results to your clients. And there aren't that much Lisp projects out there... So the decision isn't difficult: I'll opt for statically typed languages in general, but when offered a Clojure project (which will happen very seldom I guess) I'll jump to it! Don't you think it's a good tradeoff?&lt;/div&gt;&lt;br /&gt;&lt;span lang="DE" style="font-size: large;"&gt;Goodie:&lt;/span&gt;&lt;br /&gt;&lt;span lang="DE"&gt; &lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: inherit;"&gt;&lt;b&gt;PS:&lt;/b&gt; do you remember pre-ANSI C? Probably not, but &lt;b&gt;it wasn't type safe&lt;/b&gt;: &lt;/div&gt;&lt;blockquote&gt;&lt;div style="font-family: inherit;"&gt;&lt;i&gt;Within the function, the declaration of a is visible, so the compiler knows it's a char*. For a call, the compiler doesn't know what type of argument the function expects, so it's up to the caller to pass the right type. It's similar to what happens with printf-like functions.***&amp;nbsp;&lt;/i&gt;&lt;/div&gt;&lt;/blockquote&gt;Here an example for those not remembering the "stone-age": &lt;br /&gt;&lt;blockquote&gt;&lt;div style="font-family: inherit;"&gt;&lt;i&gt; &lt;/i&gt;&lt;/div&gt;&lt;div style="color: #666666; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;int&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #666666; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;ParseGLFunc (interp, argc, argv, nArg) &lt;/span&gt;&lt;/div&gt;&lt;div style="color: #666666; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Tcl_Interp *interp; &lt;/span&gt;&lt;/div&gt;&lt;div style="color: #666666; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int argc; &lt;/span&gt;&lt;/div&gt;&lt;div style="color: #666666; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *argv []; &lt;/span&gt;&lt;/div&gt;&lt;div style="color: #666666; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int *nArg; &lt;/span&gt;&lt;/div&gt;&lt;div style="color: #666666; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;{ &lt;/span&gt;&lt;/div&gt;&lt;div style="color: #666666; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;--&lt;br /&gt;&lt;div style="font-family: inherit;"&gt;* I'm sure you know it aleady, but statically typed means for a programming language to check the types at compile time whereas dynamically typed means checking of type correctness at runtime.&lt;br /&gt;** An article by Bruce Eckel:&lt;a href="https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk&amp;amp;pli=1"&gt; &lt;/a&gt;&lt;i&gt;&lt;a href="https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk&amp;amp;pli=1"&gt;"Strong Typing vs. Strong Testing&lt;/a&gt;"&lt;/i&gt;&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;*** found it here: &lt;i&gt;&lt;a href="http://www.44342.com/c-f846-t24629-p1.htm" target="_blank"&gt;"pre-ansi declarations&lt;/a&gt;"&lt;/i&gt;&lt;br /&gt;&lt;i&gt;**** here I&amp;nbsp;&lt;/i&gt; must admit that I'm just impressed with the ML family of languages&lt;i&gt; &lt;/i&gt;(i.e.&lt;i&gt; OCAML, F#&lt;/i&gt; and well,&lt;i&gt; Haskell &lt;/i&gt;too) and the automatic type deduction the compiler is doing! The code is  just flowing from your fingers as in Python or Ruby, but it's type  checked!&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;/div&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-7184263314491413319?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/7184263314491413319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=7184263314491413319' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7184263314491413319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7184263314491413319'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2012/01/static-vs-dynamic-debate-decided.html' title='Static vs Dynamic Debate Decided'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-1801839781168191353</id><published>2012-01-11T12:50:00.000-08:00</published><updated>2012-01-11T12:58:02.508-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='windows'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>ASSERT(AfxGetThread() == NULL) with VisualStudio 2010, or the DLL-hell, revamped</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class="separator" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Ci7C7B4RCzs/TwI_NvarOqI/AAAAAAAAAHw/NWWXITVCfnY/s1600/dll-hell.gif" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320px" src="http://4.bp.blogspot.com/-Ci7C7B4RCzs/TwI_NvarOqI/AAAAAAAAAHw/NWWXITVCfnY/s320/dll-hell.gif" width="320px" /&gt;&lt;/a&gt;&lt;/div&gt;Everybody thinks DLL-hell is a thing of the past. Me included: &lt;em&gt;&lt;span style="color: blue;"&gt;#WTF&lt;/span&gt;&lt;/em&gt;, just start the Dependency Walker, look what libraries got loaded, correct it and be happy*. Not so, with the advent of Visual Studio 2010 everything got a bit more complicated!&lt;br /&gt;&lt;br /&gt;Let me describe the problem which I encountered working in a project for one of my customers. Let's start with a...&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Disclaimer:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This is only a short technical note - for those who (like me) first check the Internet for solution to weird programming questions!&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The Problem:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;is maybe best described by this desperate &lt;a href="http://us.generation-nt.com/assert-error-help-13852702.html" target="_blank"&gt;post&lt;/a&gt;:&lt;/div&gt;&lt;blockquote&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;i&gt;Hi all,&lt;/i&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;i&gt;I have a question to solve, the situation is I use a exe to load a dll(MFC regular dll),but &lt;b&gt;when I use LoadLibrary() to load the d&lt;/b&gt;ll and in the &lt;b&gt;constructor of the object whose base class is CWinApp in the dll&lt;/b&gt;, It have a assert error, and the code line is ASSERT (AfxGetThread() == NULL).Is there anyone have the similar situation with me and have thoughts about it can tell me ,we can talk about it.&lt;/i&gt;&lt;/div&gt;&lt;i&gt;thanks in advance.&lt;/i&gt;&lt;/blockquote&gt;Well, the same happened to me when I was porting a C++ application&amp;nbsp;from Visual Studio 2008 to VS 2010. To be honest, the situation was a little more complicated: a mixed mode C++/C# program using C++/CLI as a glue. But back to the problem: the standard explanation for that ASSERT is that you have &lt;strong&gt;forgotten to include the &lt;i&gt;AFX_MANAGE_STATE&lt;/i&gt; macro&lt;/strong&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt; (Reason 1)&lt;/span&gt;&lt;/em&gt; in exported DLL functions as described &lt;a href="http://pinyotae.blogspot.com/2010/02/building-and-debugging-tips-in-visual-c.html." target="_blank"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Sadly, this wasn't my problem. It applies to non-MFC DLLs only**, which mine wasn't, so the whole module state management business should be cared automatically in DLL initalization code the linker is generating. This again is controlled by &lt;i&gt;#define&lt;/i&gt; macros used whith the compiler (like &lt;i&gt;_USRDLL, _AFXDLL&lt;/i&gt; and their hellish likes). So maybe this could be the reason? Nope, everything was correct :-(.&lt;br /&gt;&lt;br /&gt;After more web-searching and finding only tons of happless cries for help I stumbled upon the 2nd &lt;a href="http://www.pcreview.co.uk/forums/assertion-cwinapp-cwinapp-afxgetthread-null-t2277687.html" target="_blank"&gt;useful link&lt;/a&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;i&gt;Sounds like you have two or more CWinApp objects, and they're using the &lt;/i&gt;&lt;i&gt;same AfxGetThread data. I suppose this could happen if your libraries are &lt;/i&gt;&lt;i&gt;linking to different versions of MFC, including &lt;strong&gt;mixing of debug and release &lt;/strong&gt;&lt;/i&gt;&lt;i&gt;&lt;strong&gt;versions&lt;/strong&gt;. You might use Dependency Walker (depends.exe) to determine the &lt;/i&gt;&lt;i&gt;DLLs you link to implicitly, or the Sysinternals Process Explorer to &lt;/i&gt;&lt;i&gt;determine the DLLs you're using at runtime&lt;/i&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;Well, that sounds interesting, mybe I've mixed debug&amp;nbsp;and release DLLs? Nope (although I made that error later on,&amp;nbsp;so it's&amp;nbsp;&lt;strong&gt;defintely a good point to keep in mind &lt;/strong&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;(Reason 2)&lt;/span&gt;&lt;/em&gt;). What could it possibly be then???&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;b&gt;The Solution:&lt;/b&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;The solution is more complicated, but somehow both typical and symptomatic for real-life nontrivial system using Microsoft technology... As my client had a really old codebase growing steadily with the years, all possible Microsoft technologies could be found there; beginning with plain old DLL, through MFC-based ones, further using C++/CLI and at last arriving at C# and .NET. This last&amp;nbsp;one was burdened with a constraint: we had to use .NET v.2.0. The problem is, that Visual Studio 2010 doesn't suppport .NET 2.0! Because of time shortage they decided that only .NET 4.0 will be supported out of the box, and that the 2008 VS-compiler will be inegrated in Visual Studio 2010 to be used for older .NET versions. &lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;a href="http://4.bp.blogspot.com/-Ci7C7B4RCzs/TwI_NvarOqI/AAAAAAAAAHw/NWWXITVCfnY/s1600/dll-hell.gif" imageanchor="1" style="clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-Ci7C7B4RCzs/TwI_NvarOqI/AAAAAAAAAHw/NWWXITVCfnY/s1600/dll-hell.gif" /&gt;&lt;/a&gt;Well, in itself it wouldn't pose any problems, if there wouldn't be the C++/CLI code which we used as glue between pure&amp;nbsp;C++ MFC and the newer C# parts. It has to be compiled for the .NET 2.0 as well, thus should use the 2008 VS-compiler. But&amp;nbsp;it is put in a DLL which int turn is loaded by a traditional&amp;nbsp;C++/MFC one (created with&amp;nbsp; 2010 VS-compiler!). See it? Two different compilers, 2 diffrent runtimes, 2 CWinApp objects as in &lt;em&gt;&lt;span style="font-size: x-small;"&gt;(Reason 2)&lt;/span&gt;&lt;/em&gt;&amp;nbsp;(or maybe the loader gets misleaded, I'm not sure about it).&amp;nbsp;In any case, Visual &lt;strong&gt;Studio 2010 is forcing us to use 2 compilers in one application here&lt;/strong&gt; &lt;em&gt;&lt;span style="font-size: x-small;"&gt;(Reason 3).&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;b&gt;The Mores:&lt;/b&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;I'm not sure about that one. How about this: stay away from MFC and use Qt? Or: don't migrate your code to VisualStudio 2010 (as it's rather slow to boot)? You're damned if you have to be backwards compatible?&amp;nbsp;&lt;/div&gt;--&lt;br /&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;* see &lt;a href="http://ib-krajewski.blogspot.com/2008/11/letter-from-dll-hell-msvc60dll-and.html"&gt;here&lt;/a&gt;&amp;nbsp; for author's previous letter from DLL-hell&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;** more hellish details: 3 kinds of DLLs you can use on Windows: &lt;em&gt;... &lt;span style="font-size: x-small;"&gt;TODO: link (but that's just plain boring!)&lt;/span&gt;&lt;/em&gt;&lt;/div&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-1801839781168191353?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/1801839781168191353/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=1801839781168191353' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1801839781168191353'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1801839781168191353'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2012/01/assertafxgetthread-null-with.html' title='ASSERT(AfxGetThread() == NULL) with VisualStudio 2010, or the DLL-hell, revamped'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-Ci7C7B4RCzs/TwI_NvarOqI/AAAAAAAAAHw/NWWXITVCfnY/s72-c/dll-hell.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-1721940429860698397</id><published>2011-12-15T14:19:00.000-08:00</published><updated>2011-12-15T14:22:12.490-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>DSLs not so pointless?</title><content type='html'>&lt;p&gt;&lt;/p&gt;... or: busting myths and fallacies, this time - the DSL-s!&lt;br /&gt;&lt;br /&gt;Until recently I'd only sneer at the idea of DSL's: what the&lt;i&gt; @!%*&lt;/i&gt;, either we have a soild API for developers, or a specialized higher level language for the specific task. And the higher level language best shouldn't be&amp;nbsp; done at all, because the non-technical user just wants a smooth GUI to click his requests together! So spare your DSL hype on me, go and find another gullible middle management person. &lt;br /&gt;&lt;br /&gt;But then I read the following &lt;a href="http://jkarlsson.com/blog/2010/02/16/igloo-constraint-based-unit-testing-in-c/%20"&gt;passage&lt;/a&gt; and the fallacy behind this reasoning became apparent to me:&lt;blockquote&gt;&lt;i&gt;In other environments I could write tests together with the product owner. Together, we could create and discuss tests that expressed what we wanted our code to do without getting buried in the details. The tests I wrote in C++ were quite unreadable for a non-C++ developer.&lt;/i&gt;&lt;/blockquote&gt;What was my error? DSL isn't meant as a programming language, neither for the developer, nor for the notechnical user - it is meant to document things!&lt;br /&gt;&lt;br /&gt;Look at the following &lt;a href="http://jkarlsson.com/blog/2011/01/02/tdd-kata-the-game-of-life-now-in-c/"&gt;example&lt;/a&gt; of a &lt;b&gt;testing DSL&lt;/b&gt; in C++:&lt;a href="http://jkarlsson.com/blog/2011/01/02/tdd-kata-the-game-of-life-now-in-c/"&gt;&lt;/a&gt;&lt;pre&gt;&lt;b&gt;  &lt;/b&gt;#include &amp;lt;igloo.h&amp;gt;  &lt;span style="color: #6aa84f;"&gt;// testing framework*&lt;/span&gt;&lt;br /&gt;  #include &amp;lt;cell.h&amp;gt;   &lt;span style="color: #6aa84f;"&gt;// tested class&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;  using namespace igloo;&lt;br /&gt;&lt;br /&gt;  Describe(A_Cell)&lt;br /&gt;  {&lt;br /&gt;      It(should_have_coordinates)&lt;br /&gt;      {&lt;br /&gt;          Cell cell(3,4);&lt;br /&gt;          Assert::That(cell.getX(), Equals(3));&lt;br /&gt;          Assert::That(cell.getY(), Equals(4));&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      It(can_detect_if_its_a_neighbour)&lt;br /&gt;      {&lt;br /&gt;          Cell cell(1,5);&lt;br /&gt;          Cell neighb(2,4);&lt;br /&gt;&lt;br /&gt;          Assert::That(cell.isNeighbourTo(neighb), IsTrue());&lt;br /&gt;      }&lt;br /&gt;  };&lt;/pre&gt;You must say it's a &lt;b&gt;piece of C++ code** you could show to anyone&lt;/b&gt; and discuss it as a kind of formal spec. You and your partner don't have to learn Z or some other specialized notation. What both of you know already is just enough to bridge the gap. And it's cool code as well!&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;* see: &lt;a href="http://igloo-testing.org/"&gt;http://igloo-testing.org/ &lt;/a&gt;&lt;br /&gt;** it's not a joke, all this is possible in C++&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-1721940429860698397?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/1721940429860698397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=1721940429860698397' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1721940429860698397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1721940429860698397'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2011/12/dsls-not-so-pointless.html' title='DSLs not so pointless?'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-7242571212017377796</id><published>2011-11-11T02:15:00.000-08:00</published><updated>2012-01-11T13:03:26.931-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Go'/><title type='text'>Geeky Halloween costumes...</title><content type='html'>&lt;p&gt;&lt;/p&gt;Matching nicely my last post abot the Go language: dress up as a programming language mascot:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-_LT12eYgAbY/TrxkJFQY3bI/AAAAAAAAADw/fWCHEytwdec/s1600/costume.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320px" src="http://3.bp.blogspot.com/-_LT12eYgAbY/TrxkJFQY3bI/AAAAAAAAADw/fWCHEytwdec/s320/costume.jpg" width="296px" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;(as appeared in&amp;nbsp; &lt;a href="http://blog.golang.org/2011/11/go-programming-language-turns-two.html"&gt;Golang blog&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;Any other languages to follow? For Perl it's simple (a camel), for OCAML too (a supercharged camel), but what about C++? Or Assembler? &lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;PS: My favourite C++ pic is this: &lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-0oVCH3_UNK8/Tw34wz-ULsI/AAAAAAAAAH8/y91Yr1KNNDQ/s1600/cpp.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200px" src="http://3.bp.blogspot.com/-0oVCH3_UNK8/Tw34wz-ULsI/AAAAAAAAAH8/y91Yr1KNNDQ/s200/cpp.gif" width="200px" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;. But you really can't dress up like that, can you?&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-7242571212017377796?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/7242571212017377796/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=7242571212017377796' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7242571212017377796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7242571212017377796'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2011/11/geeky-halloween-costumes.html' title='Geeky Halloween costumes...'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-_LT12eYgAbY/TrxkJFQY3bI/AAAAAAAAADw/fWCHEytwdec/s72-c/costume.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-4580653029009710393</id><published>2011-10-25T05:07:00.000-07:00</published><updated>2011-10-25T05:18:58.535-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Go'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>What I did like about Go.</title><content type='html'>&lt;pre&gt;&lt;/pre&gt;&lt;div style="border: currentColor;"&gt;&lt;a href="http://2.bp.blogspot.com/-CFOvSeGQcvI/TpnL0Nqx2DI/AAAAAAAAAHM/7LqHA7vwHUU/s1600/golang.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" oda="true" src="http://2.bp.blogspot.com/-CFOvSeGQcvI/TpnL0Nqx2DI/AAAAAAAAAHM/7LqHA7vwHUU/s1600/golang.png" /&gt;&lt;/a&gt;Last week&amp;nbsp;I've read the &lt;i&gt;"Learning Go"&lt;/i&gt; &lt;a href="http://groups.google.com/group/golang-nuts/browse_thread/thread/f164fe79e1b8ee89"&gt;book&lt;/a&gt;. I did that by sheer coincidence: it happened that I had the (free) book loaded on my eBook reader and just&amp;nbsp;looked for light but interesting read. Why not an intro to a new programming language? So I started to with it and I didn't regret my decision. It was an entertaining and interesting lecture. I'd like to describe here what I liked about the language. &lt;br /&gt;&lt;br /&gt;See, normally reviewers concetrate on &lt;b&gt;what they didn't like&lt;/b&gt; in a language, but I think that's way too easy! The things we don't like are most probably the things we aren't accustomed with, and with some experience they wouldn't annoy us any more. So don't gripe, just be easy on Go!&lt;/div&gt;&lt;div style="border: currentColor;"&gt;&lt;br /&gt;As I learned from the book, Plan 9 project*, the (supposed to be)&amp;nbsp;successor of Unix, included a language called &lt;i&gt;Limbo&lt;/i&gt; which was a lot like Go already, which built on an earlier langauge called &lt;i&gt;Newsqueak&lt;/i&gt;.&amp;nbsp;So surprisingly, there's a lot of history showing up here!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/-WIZ4-SSksy4/TpnL5k0Ru9I/AAAAAAAAAHU/mWy0y0BBbAc/s1600/golang1.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" oda="true" src="http://3.bp.blogspot.com/-WIZ4-SSksy4/TpnL5k0Ru9I/AAAAAAAAAHU/mWy0y0BBbAc/s1600/golang1.jpg" /&gt;&lt;/a&gt;Go itself is like it's mascot (look to the right!): small and quick. It's compiled and&amp;nbsp;statically typed but does type deduction (like OCAML or Haskell).&amp;nbsp;It main claim to fame are (beside garbage collection) &lt;b&gt;goroutines&lt;/b&gt; and &lt;b&gt;channels&lt;/b&gt;, but I have too little experience with them, so I'd rather concentrate on basic day to day traits of the language. I mean, the small things are the things that annoy us the most, and should a language will be anoying, it will screw them. Additionally, this way we can somehow transmit the "feel" of the language. &lt;br /&gt;&lt;br /&gt;So let's start with:&lt;/div&gt;&lt;br /&gt;&lt;b&gt;1. multiple assignement&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;...a la Python:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  &lt;/b&gt;x, y := 11, 12&lt;br /&gt;  _, y := 22, 23&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see the &lt;strong&gt;semicolons are not needed too&lt;/strong&gt;&amp;nbsp;-&amp;nbsp;gives you a nice Python&amp;nbsp;/ F# / Clojure feeling!&lt;br /&gt;If you have mutliple assignament, you get multiple&amp;nbsp;return values&amp;nbsp;for free, as in the following function**:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  func&lt;/b&gt; Write(file *File, b []&lt;b&gt;byte&lt;/b&gt;)(&lt;b&gt;int&lt;/b&gt;, Error)&lt;/pre&gt;See? You just specify the returns in parens after the parameters. And that leads us to the next goodie connected to the multiple assignment: &lt;br /&gt;&lt;br /&gt;&lt;b&gt;1a. the ok-idiom&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;it goes like that:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  if&lt;/b&gt; ok, x = foobar(y); ok {&lt;br /&gt;    &lt;span style="color: #6aa84f;"&gt;// do sth&lt;/span&gt;&lt;br /&gt;    ...&lt;br /&gt;  }&lt;/pre&gt;So no more &lt;i&gt;&lt;b&gt;if&lt;/b&gt;(foo() == -1)!&lt;/i&gt; Instead you can write:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  if&lt;/b&gt; nr, err = write(f, buf); err == nil {&lt;br /&gt;    &lt;span style="color: #6aa84f;"&gt;// do sth&lt;/span&gt;&lt;br /&gt;    ...&lt;br /&gt;  }  &lt;/pre&gt;You can assign and test a value inside of the "if "clause. Additionally the parens can be omitted too&amp;nbsp;with "if"&amp;nbsp;- more Python / F# feeling! Nice, isnt it?&lt;br /&gt;&lt;br /&gt;&lt;b&gt;2. named return parameters&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;We can assign names the return parameters:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  func &lt;/b&gt;write(file *File, b []&lt;b&gt;byte&lt;/b&gt;)(n &lt;b&gt;int&lt;/b&gt;, err Error){&lt;br /&gt;    ...&lt;br /&gt;    &lt;br /&gt;    &lt;b&gt;return&lt;/b&gt;&lt;br /&gt;  }&lt;/pre&gt;When we name the returns, the compiler will initialize them with defaults (i.e. their zero-values)! We can eithet&lt;strong&gt; &lt;/strong&gt;refer to them inside of the function (!!)&amp;nbsp;or even omit them from the return statement, and then they will be used &lt;strong&gt;automatically with the initialized values&lt;/strong&gt;. One thing less to worry about.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;3. maps (and strings)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;They are part of the language and not in&amp;nbsp;the library. I wish they'll be that way in C++ too. Come on, D has done that!. Add this to the {} initalization syntax and you can write (almost LISP, Python or Perl style)***:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  var &lt;/b&gt;opmap = &lt;b&gt;map&lt;/b&gt;[&lt;b&gt;int&lt;/b&gt;]&lt;b&gt;string&lt;/b&gt;{&lt;br /&gt;    ADD: ”+”,&lt;br /&gt;    SUB: ”-”,&lt;br /&gt;    MUL: ”*”,&lt;br /&gt;    DIV: ”/”,&lt;br /&gt;  }&lt;/pre&gt;Well, speaking frankly, the {}&amp;nbsp;initialization is possible in C++ too, alas only as of C++11.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;4. defer for destructors&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;You can define Deferred actions, i.e. actions which are executed on the end of scope only:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  &lt;/b&gt;file.Open(”filename.in”)&lt;br /&gt;  &lt;b&gt;defer &lt;/b&gt;file.Close()&lt;/pre&gt;It's a nice replacement for destructors (see my previous post &lt;a href="http://ib-krajewski.blogspot.com/2008/12/do-we-need-constructors.html"&gt;here&lt;/a&gt;). And it looks better that some "using" constructs from&amp;nbsp; other languages.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;5. duck typing&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Go has duck typing, but it's not C++ type of template duck typing. You don't have to mention a specific interface (yes, Go has a notion of interfaces!), it suffices to implement them ***:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  type &lt;/b&gt;I &lt;b&gt;interface &lt;/b&gt;{&lt;br /&gt;    Get() int&lt;br /&gt;    Put(int)&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;And then you just implement the required functions for a data type (see note ** below), and it will automaticall comply with the interface&lt;em&gt; I&lt;/em&gt;:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  type &lt;/b&gt;S &lt;b&gt;struct &lt;/b&gt;{ i &lt;b&gt;int &lt;/b&gt;}&lt;br /&gt;  &lt;b&gt;func &lt;/b&gt;(p *S) Get() &lt;b&gt;int &lt;/b&gt;{ return p.i }&lt;br /&gt;  &lt;b&gt;func &lt;/b&gt;(p *S) Put(v &lt;b&gt;int&lt;/b&gt;) { p.i = v }&lt;br /&gt;&lt;/pre&gt;like that:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  func &lt;/b&gt;f(p I) { p.Put(1) }&lt;br /&gt;  &lt;b&gt;var &lt;/b&gt;s S &lt;br /&gt;  f(&amp;amp;s)&lt;br /&gt;&lt;/pre&gt;OK, so whats the difference to C++ type duck typing? C++&amp;nbsp;doesn't&amp;nbsp;care about types: a template with two parameters simply takes two things, and then tests if they have the methods the template code requires:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  template &lt;/b&gt;&amp;lt;&lt;b&gt;type &lt;/b&gt;T&amp;gt; void foo(T&amp;amp; t)&lt;br /&gt;  {&lt;br /&gt;    if(t.canBark()) t.bark();&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;How's that different from Go? C++ gets problems with overloading in that context: it sees only a function that takes 1 thing. A totally generic &lt;em&gt;thing&lt;/em&gt;! So you cannot define a second template with the same name and a different argument type, because at the definition level there aren't types, only &lt;em&gt;things&lt;/em&gt;! That's why there's no range or complete container overloads for SLT algorithms (see H.Sutter's &lt;a href="http://herbsutter.com/2011/10/07/why-no-container-based-algorithms/"&gt;blogpost&lt;/a&gt;). &lt;br /&gt;&lt;br /&gt;&lt;b&gt;6. generic switch&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Just like Groovy, Go has a very flexible switch statement:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  switch &lt;/b&gt;c {&lt;br /&gt;    &lt;b&gt;case &lt;/b&gt;’ ’, ’?’, ’&amp;amp;’, ’=’, ’#’, ’+’:   &lt;br /&gt;      &lt;b&gt;return &lt;/b&gt;true&lt;br /&gt;    &lt;b&gt;case &lt;/b&gt;c &amp;lt; 'a': fallthrough&lt;br /&gt;    &lt;b&gt;case &lt;/b&gt;c &amp;gt; 'A':&lt;br /&gt;      &lt;b&gt;return &lt;/b&gt;true&lt;br /&gt;    &lt;b&gt;default&lt;/b&gt;:&lt;br /&gt;      &lt;b&gt;return &lt;/b&gt;false&lt;br /&gt; }&lt;/pre&gt;I mean, ever language needs something like that: &lt;strong&gt;case switch for strings&lt;/strong&gt; and other types! And did you notice that fallthrogh must be stated explicitly? I like that.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;7. the go keyword.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I liked the idea of introducing the word "go" as keyword to start a parallel "goroutine":&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  int &lt;/b&gt;i&lt;br /&gt;  &lt;b&gt;go &lt;/b&gt;foobar(i)&lt;br /&gt;&lt;/pre&gt;I just find it funny :), that's all...&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Note:&lt;/span&gt;&lt;br /&gt;I admit, I didn't describe the features that make Go to stand out, only a couple of&amp;nbsp; those which particularly appealed to me. For more info on: function definitions, val notation, control structures, function literals (i.e. lambdas), goroutines, etc please read the book by yourself!&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* a note aside: as pointed out several times on the web, there's a notable similarity between the logos of Plan 9 and Go. BTW: don't you think they are cute?&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-eiSm-gNjyNg/TpyT81IepEI/AAAAAAAAAHc/XvDmumxHVwc/s1600/go+ang+plan9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-eiSm-gNjyNg/TpyT81IepEI/AAAAAAAAAHc/XvDmumxHVwc/s1600/go+ang+plan9.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;** more precise, you'd rather define a function like this:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  func&lt;/b&gt; (file *File) Write(b []&lt;b&gt;byte&lt;/b&gt;)(&lt;b&gt;int&lt;/b&gt;, Error) &lt;/pre&gt;i.e. a function working on the &lt;i&gt;File&lt;/i&gt; type, and invoke it like: &lt;br /&gt;&lt;pre&gt;&lt;b&gt;  &lt;/b&gt;nr, err = f.Write(buf)&lt;/pre&gt;But this is the part of the OO stuff so I skipped it in this post.&lt;br /&gt;&lt;br /&gt;*** code example from the &lt;em&gt;"Learning Go"&lt;/em&gt; &lt;a href="http://groups.google.com/group/golang-nuts/browse_thread/thread/f164fe79e1b8ee89"&gt;book&lt;/a&gt;. &lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-4580653029009710393?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/4580653029009710393/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=4580653029009710393' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4580653029009710393'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4580653029009710393'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2011/10/what-i-did-like-about-go.html' title='What I did like about Go.'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-CFOvSeGQcvI/TpnL0Nqx2DI/AAAAAAAAAHM/7LqHA7vwHUU/s72-c/golang.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-7178982662647483627</id><published>2011-06-26T15:26:00.000-07:00</published><updated>2012-01-11T12:06:15.509-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Scala'/><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><category scheme='http://www.blogger.com/atom/ns#' term='Go'/><category scheme='http://www.blogger.com/atom/ns#' term='Groovy'/><category scheme='http://www.blogger.com/atom/ns#' term='Clojure'/><title type='text'>2009 Languages Overload</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;img alt="" border="0" height="1px" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=bil&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0672329816" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px; padding-bottom: 0px! important; padding-left: 0px! important; padding-right: 0px! important; padding-top: 0px! important;" width="1px" /&gt;&lt;img alt="" border="0" height="1px" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=bil&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0981531644" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px; padding-bottom: 0px! important; padding-left: 0px! important; padding-right: 0px! important; padding-top: 0px! important;" width="1px" /&gt;&lt;br /&gt;&lt;div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;This year (or more to the point, that year, i.e. 2009) was for me a year of languages. Or maybe better, of languages overload! While I'm earning my bacon mainly with C++ (and a bit of Python), this year I had a look at a couple of new languages (adding to my last year's Groovy adventures) like: C# 3.0, Go, Scala, Clojure and even a bit of Haskell. In case of Haskell I'm feeling rather guilty, as I wanted to keep myself busy with Haskell this year but didn't manage more than some superficial reads about monads, and only becaue I needed to explain some Clojure code! Shame! &lt;/div&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;1. Java&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;But let me first comment on another language, which is ly dying these days: Java. Is it really dying? Looking at this post by &lt;a href="http://codemonkeyism.com/java-dead/"&gt;codemonkeyism&lt;/a&gt; you'd say so. Why don't we like Java anymore? Let me cite: &lt;/div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;i&gt;Inheritance: outside of frameworks, inheritance is inflexible, leads to tight &lt;/i&gt;&lt;/div&gt;&lt;i&gt;coupling and is plain bad. Composition is most often a better choice. As are &lt;/i&gt;&lt;br /&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;i&gt;mixins and traits &lt;/i&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;i&gt;Noisy syntax: Lately there has been the enlightenment that &lt;/i&gt;&lt;i&gt;too much noise in a language is a bad thing. Java is especially noisy in &lt;/i&gt;&lt;i&gt;closures (anonymous inner classes) and generics. &lt;/i&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;i&gt;Null / NPE: Null as the default for object references was a billion dollar mistake. An object should by default need a value. Otherwise NPEs will proliferate through your code. Newer languages prevent nulls or make the null behavior the non default one &lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;i&gt;List processing: As shown by functional languages, list processing should not be done &lt;/i&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;i&gt;in loops. ..&lt;/i&gt;&lt;i&gt;. Java should have native support for easy &lt;/i&gt;&lt;i&gt;list processing, not via the – best we have – constructs in Google Collections.&lt;/i&gt; &lt;/div&gt;&lt;/blockquote&gt;For me the 2nd problem is the worst, i.e. the noise. It's &lt;b&gt;appalling how much of the Java boilerplate can be thrown away &lt;/b&gt;- check this&amp;nbsp;&lt;a href="http://www.slideshare.net/paulk_asert/concurrency-with-gpars"&gt;presentation&lt;/a&gt;&amp;nbsp;to see how much can be done with&amp;nbsp;Groovy!&amp;nbsp;But each of the new languages does a pretty good job here. Well, to be true, my biggest problem wasn't stated above at all mentionae above - lack of operator overloading! Whatever, the fact is that there's a host of new languages out thre, and the times seem to be more exciting than ever since the 70-ties!&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;span style="font-size: large;"&gt;2. Scala&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;a href="http://www.amazon.com/Programming-Scala-Comprehensive-Step-Step/dp/0981531644?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=bil&amp;amp;camp=213689&amp;amp;creative=392969" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;" target="_blank"&gt;&lt;img alt="Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition" src="http://ws.amazon.com/widgets/q?MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL160_&amp;amp;ASIN=0981531644&amp;amp;tag=wwwibkrajewsk-20" /&gt;&lt;/a&gt;Scala seems to be a la&lt;img alt="" border="0" height="1px" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=bil&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=1934356336" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px; padding-bottom: 0px! important; padding-left: 0px! important; padding-right: 0px! important; padding-top: 0px! important;" width="1px" /&gt;nguage having every single feature from any language known to man. The overall impression was: OK, I know that one from ... One single feature I liked is the solution to the multiple inheritance conundrum (you know, the &lt;i&gt;Deadly Diamond of Death&lt;/i&gt;) by linearization of the base classes. Clean, efficient, impressive! From the above list it's solving the Null/NPE, noise and inheritance problems. But the syntax is ML derived! Hate it! if this is a Java replacement, why cannot we stay in the old good C-lands? Another problem with Scala is poor tool support: I wasn't able to get the Eclipse plugin running, despite applying various workarounds found on Scala's homepage&amp;nbsp;and upgrades of both the platform and the plugin. Even Martin Odersky (Scala's creator) is using Emacs for work!&lt;/div&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;On the other side, I think Groovy solves the list processing more elegantly, and it's DSL capabilites are more convincing too! &lt;i&gt;&lt;span style="font-size: x-small;"&gt;(example to come)&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;3. Clojure&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;a href="http://www.amazon.com/Programming-Clojure-Pragmatic-Programmers-Halloway/dp/1934356336?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=bil&amp;amp;camp=213689&amp;amp;creative=392969" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;" target="_blank"&gt;&lt;img alt="Programming Clojure (Pragmatic Programmers)" src="http://ws.amazon.com/widgets/q?MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL160_&amp;amp;ASIN=1934356336&amp;amp;tag=wwwibkrajewsk-20" /&gt;&lt;/a&gt;I like Clojure! I don't know why. It's not typesafe, has Lisp-y syntax and&amp;nbsp;very complicated&amp;nbsp;mechanism for integration of Java class libraries, but it is somehow elegant and minimalistic. It includes mutithreading primitives in the language definition and it tries to achieve good performance while staying immutable! &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;As I&amp;nbsp;watched &lt;a href="http://blip.tv/clojure/clojure-concurrency-819147"&gt;this presentation&lt;/a&gt; by Rich Hickey I noticed one important thing: he's an architect who was facing design problems in complex real life systems* (somehow like me, although I must admit that he's been exposed to more complexity than me) an tried to find a solution. And he really knows his stuff - all the conventional wisdom of software architecture! And Clojure (and Clojure's features) is an answer to these problems: it takes from LISP what seems suitable and isn't afraid to change it** otherwise.&lt;br /&gt;&lt;br /&gt;Contrast this with Scala - sometimes feeling like an academic exercise in trying implementing all the features known to man in a single programming language just to show that it can be done (caveat: totally subjective opinion here). Maybe this pragmatic legacy is one of reasons why I like Clojure much more then Scala.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;4. F# (and C#)&lt;/span&gt;&lt;br /&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;a href="http://www.amazon.com/3-0-Unleashed-NET-Framework-3-5/dp/0672329816?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=bil&amp;amp;camp=213689&amp;amp;creative=392969" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;" target="_blank"&gt;&lt;img alt="C# 3.0 Unleashed: With the .NET Framework 3.5" src="http://ws.amazon.com/widgets/q?MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL160_&amp;amp;ASIN=0672329816&amp;amp;tag=wwwibkrajewsk-20" /&gt;&lt;/a&gt;C# seems to be evolving very rapidly. From the ugly duckling it was a couple of years ago, it developed a respectable language with a decent amount of innovation. It has good lambda function support and the LINQ concept is rather interesting. I was surprised! &lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;F# in its turn seems to be syntax-wise another ML derived langage like Scala, but it's not so overloaded with features.&amp;nbsp;Sorry, I'm still not done with the &lt;a href="http://www.ctocorner.com/fsharp/book/"&gt;free F# book&lt;/a&gt;...&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;Some (for example Scala Lift's creator &lt;a href="http://goodstuff.im/functional-languages-will-rule-but-not-this-y"&gt;here&lt;/a&gt;) say that it could be the single one of functional languages to success in the mainstream!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;5. Go-lang&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;I didn't like it that much despite of its heritage. The obligatory, one and only true formatting rules, lack of subclassing... But on the other side, there is a CSP implementation on the language level! And as another programmer, who actually tried it out, stated &lt;a href="http://blog.kowalczyk.info/article/af1h/Experience-porting-4k-lines-of-C-code-to-go.html"&gt;here&lt;/a&gt;, it's much like writing in Python, only without&amp;nbsp;its excruciating slowness. So maybe I should switch from Python to Go? Google Application Engine supports it now!&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;em&gt;Update:&lt;/em&gt;&lt;/b&gt; in the meanwhile I managed to have a &lt;a href="http://ib-krajewski.blogspot.com/2011/10/what-i-did-like-about-go.html"&gt;look at Go&lt;/a&gt;!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;6. Summary&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;&lt;b&gt;Warning:&lt;/b&gt; You see, it's not the comprehensive comparision I wanted to write back in 2009/10, but before I ditch the project altogether, I'd rather write this stub and extend it when I find some time. But the summary is already complete now, so...&amp;nbsp;----&amp;gt;&lt;/i&gt;&lt;/blockquote&gt;As I said above, I'd use Scala as a "better Java" as to avoid Java verbosity, lack of operator overloading and multiple inheritance. I'd use Closure for the joy of if (pun intended), I'd like some of my clients to want me to use Go, but wouldn't propose it myself, and I probably won't use C# unless I switch to .NET which is rather unlikely. On the other side, I might install F# on my PC - just to play with it a little.&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;* according to &lt;a href="http://www.infoq.com/presentations/Simple-Made-Easy"&gt;InfoQ&lt;/a&gt; &lt;em&gt;"...Rich has worked on scheduling systems, broadcast automation, audio analysis and fingerprinting, database design, yield management, exit poll systems, and machine listening." &lt;/em&gt;&lt;br /&gt;&lt;br /&gt;** e.g. even the venerable parentheses!&lt;br /&gt;&lt;/div&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-7178982662647483627?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/7178982662647483627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=7178982662647483627' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7178982662647483627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7178982662647483627'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2011/06/2009-languages-overload.html' title='2009 Languages Overload'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-4936462985887915833</id><published>2011-06-26T13:16:00.000-07:00</published><updated>2011-06-26T13:18:27.352-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='private'/><title type='text'>Exegi Monumentum...</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;em&gt;"Exegi monumentum aeris perennis"&lt;/em&gt; I don't know why but this line is always coming to my mind when I'm thinking about my father, who deceased&amp;nbsp; more than 2 years ago. Just because he was fond of classical studies and Latin?&lt;br /&gt;&lt;br /&gt;He also cherished that other lines of poetry, in a language that you can't possibly know, but which, as I can assure you, are work of a genius (I cite form memory):&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;"Wsrod takich pol przed laty, nad brzegiem ruczaju, &lt;/em&gt;&lt;br /&gt;&lt;em&gt;na pagorku niewiekim, we brzozowym gaju, &lt;/em&gt;&lt;br /&gt;&lt;em&gt;stal dwor szlachecki, z drewna, lecz podmurowany, &lt;/em&gt;&lt;br /&gt;&lt;em&gt;swiecly sie z daleka jego biale sciany, &lt;/em&gt;&lt;br /&gt;&lt;em&gt;tym bielsze, ze odbite od ciemnej zieleni, &lt;/em&gt;&lt;br /&gt;&lt;em&gt;topoli, co go strzegly od wiatrow jesieni."&lt;/em&gt;&lt;/blockquote&gt;You're right, that's a single sentence. And he could recite one after another in the endless flow of the language. Yes, you are right, this is a hommage to my late father, which I'm writing 2 years too late. The first thing I'll always associate with him will be the classical poetry. The another one, linked via the above phrase of Horace, is a story of an interview and things which it revealed to me in retrospect.&lt;br /&gt;&lt;br /&gt;It was my school appointment to interview someone and&amp;nbsp;I choose my father. I remeber just a single question I asked: what do you want to be remembered for? The answer was somehow unexpected to me: he cited the line of&amp;nbsp; Horace, and said: I want to be remembered for the things I accomplish. And he did, he was working in local political bodies&amp;nbsp;and was involved in building roads and water lines in our rural neighbourhood.&lt;br /&gt;So when it came to finding a vocation, I wanted to build things! Not maths, physics, literature or music (things I was interested in), but engineering! &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;As for us in life there are 2 things which are worth of pursuing:&lt;/strong&gt;&amp;nbsp;for yourself,&amp;nbsp;trying to understand the great scheme of things in that world (for practically minded,&amp;nbsp;if you are&amp;nbsp;more ambitious it's&amp;nbsp;the universe then). But you owe&amp;nbsp;th the others, those&amp;nbsp;before you and&amp;nbsp;those to come,&amp;nbsp;to&amp;nbsp;keep the world running smoothly, and build new smootly running things to replace old ones.&lt;br /&gt;&lt;br /&gt;I think, that's my father's heritage. And that's why I cannot be a geek -&amp;nbsp;because I grew up listening to poetry, looking at nature of the rural coutryside and experiencing very practical achievements in very real world.&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-4936462985887915833?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/4936462985887915833/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=4936462985887915833' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4936462985887915833'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4936462985887915833'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2011/06/exegi-monumentum.html' title='Exegi Monumentum...'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-1410216783249774227</id><published>2011-06-06T06:41:00.000-07:00</published><updated>2011-06-08T00:01:39.000-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SW processes'/><category scheme='http://www.blogger.com/atom/ns#' term='Agile'/><title type='text'>Agile Rant Update</title><content type='html'>&lt;p&gt;&lt;/p&gt;After you've read my Agile &lt;a href="http://ib-krajewski.blogspot.com/2010/12/little-agile-nad-xp-rant.htm"&gt;rant&lt;/a&gt; you may have though: &lt;i&gt;"just another old-fashioned hacker who just doesn't get it..."&lt;/i&gt;. Fair enough, I'm myself not that sure if that what I'm saying isn't just result of lack of experience with Agile? Maybe with even more exposure all my reservations would vanish?&lt;br /&gt;&lt;br /&gt;So I'm happy to find out that there are other people thinking roughly along my lines. For example here: &lt;a href="http://links.techwebnewsletters.com/servlet/MailView?ms=MzYyNzA3NzIS1&amp;amp;r=MjIxNTU4NzIwNQS2&amp;amp;j=OTQyNjAzMTkS1&amp;amp;mt=1&amp;amp;rt=0" rel="nofollow"&gt;Agile Hokum&lt;/a&gt;, in DDJ reader mail. He (the reader)says exaclty what I said:&lt;br /&gt;&lt;blockquote style="font-family: inherit;"&gt;&lt;span style="color: black; font-size: small;"&gt;&lt;i&gt;But the "TDD corrupted by writing the tests after coding"&lt;b&gt; is about as extreme as the Taliban. &lt;/b&gt;Testing is good. Write them before, during, after, much after, etc., all have their place&lt;/i&gt;.&lt;/span&gt;&lt;/blockquote&gt;and doubts usefulness pair programming as well. The standard TDD answer of the expert goes than like that:&lt;br /&gt;&lt;blockquote&gt;&lt;div style="font-family: inherit;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;a href="http://1.bp.blogspot.com/-M4YShRFtjhc/TezVHjwJ_WI/AAAAAAAAAHI/oARF_Jjuuow/s1600/logo.agile.gif.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-M4YShRFtjhc/TezVHjwJ_WI/AAAAAAAAAHI/oARF_Jjuuow/s1600/logo.agile.gif.jpg" /&gt;&lt;/a&gt;&lt;i&gt;&lt;span style="color: black; font-size: small;"&gt; &lt;/span&gt;&lt;span style="color: black; font-family: arial; font-size: small;"&gt;I agree that tests written at anytime will generally have value. However, TDD was not designed as a way of validating code — plain unit testing will do that. &lt;/span&gt;&lt;/i&gt;&lt;span style="font-family: inherit; font-size: small;"&gt;&lt;i&gt;&lt;span style="color: black;"&gt; TDD is first and foremost a design practice. And so doing TDD by writing the tests after the code is simply a misunderstanding of what you’re actually doing.&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div style="font-family: inherit;"&gt;&lt;span style="color: black; font-size: small;"&gt; Well, that opinon is already dealt with in my &lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;a href="http://ib-krajewski.blogspot.com/2010/12/little-agile-nad-xp-rant.htm"&gt;Agile rant&lt;/a&gt;&lt;/span&gt;&lt;span style="color: black; font-size: small;"&gt;. But taking the simplistic road I'd &lt;/span&gt;&lt;span style="font-size: small;"&gt;just say that's the way it is handled in agile projects: not as a design &lt;/span&gt;&lt;span style="font-size: small;"&gt;technique &lt;/span&gt;&lt;span style="font-size: small;"&gt;but rather as a testing &lt;/span&gt;&lt;span style="font-size: small;"&gt;one. OK, here seems to be some confusion on the term itself: it's either Test Driven Development or Design...&lt;br /&gt;&lt;br /&gt;On the other side the author (i.e. the reader) openly admits that he's not an Agile practitioner, so that opinion doesn't give any earnest support for my criticism?&lt;/span&gt;.&lt;/div&gt;&lt;br /&gt;But look what an ex Googler says &lt;a href="http://rethrick.com/#unit-tests-false-idol"&gt;here&lt;/a&gt;:&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;This is not to say that all unit testing is bad--of course not. The dispatch logic in Guice Servlet and Sitebricks benefit from rigorous, modular unit tests. If you have ever used Gmail, Blogger, Google Apps, AdWords or Google Wave (all use Guice Servlet to dispatch requests) you have seen the benefits of this rigor first-hand. But take it from me, we could have &lt;b&gt;achieved the same level of confidence with a few well written unit tests and a battery of integration tests.&lt;/b&gt; And we'd have been in a much better position to improve the framework and add features quickly&lt;/i&gt;. &lt;/blockquote&gt;That strikes a chord with me, because it's exactly the way I tested my last system - a lot of integration and pre-integration tests, and a couple of unit tests for classes which couldn't be easily tested thorougly that way. Wouldn't that be allowed at your company? Because this isn't Agile?&lt;br /&gt;&lt;p&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-1410216783249774227?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/1410216783249774227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=1410216783249774227' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1410216783249774227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1410216783249774227'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2011/06/agile-rant-update.html' title='Agile Rant Update'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-M4YShRFtjhc/TezVHjwJ_WI/AAAAAAAAAHI/oARF_Jjuuow/s72-c/logo.agile.gif.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-3386170478945178499</id><published>2011-05-28T13:23:00.000-07:00</published><updated>2012-01-02T15:20:22.045-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Don't Decay your Arrays!</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;b&gt;OK, that's nothing new, the technique is old&lt;/b&gt;, will be obsolete soon with the new s&lt;i&gt;td::tr1::array&lt;/i&gt;, and why should we use naked arrays anyhow? But recently I  couldn't write it down as easily as I would like to, and as it's useful in the pre C++2011 code, why not discuss it shortly here?&lt;br /&gt;&lt;br /&gt;Imagine you have to implement a Netbios/SMB remote file access protocol. The problem we are faced with while doing this is trivial but important - we need to log different packet types, operation codes and command options for debugging. They are all defined as &lt;i&gt;integer &lt;/i&gt;type values and C++ doesn't (nor does any language I know) offer much support in that respect. So we define our own mini framework using macros. Don't panic, macros aren't that bad as they are told, and in our use case they are a perfect fit: translating between code (integer value) and strings (its descriptions). It's like &lt;i&gt;eval() &lt;/i&gt;but in the other direction :). And it is working like this:&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #6aa84f;"&gt;  // trace helper tables&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;  #define&lt;/span&gt; DEF_DESCRIPTION_ROW(a) {a, #a}&lt;br /&gt;  struct CmdNameEntry { int cmdId; string cmdName; };&lt;br /&gt;&lt;br /&gt;  const CmdNameEntry g_cmdNameTableNetbios[] = {&lt;br /&gt;      DEF_DESCRIPTION_ROW(SESS_MESSAGE),&lt;br /&gt;      DEF_DESCRIPTION_ROW(SESS_REQUEST),                             &lt;br /&gt;      ...&lt;br /&gt;  };&lt;br /&gt;  const CmdNameEntry g_cmdNameTableSmb[] = { &lt;br /&gt;      ...&lt;br /&gt;  };&lt;br /&gt;  const CmdNameEntry g_cmdNameTableTrans[] = { &lt;br /&gt;      ...&lt;br /&gt;  };&lt;br /&gt;  const CmdNameEntry g_cmdNameTableTrans2[] = {                 &lt;br /&gt;      ...&lt;br /&gt;  };    &lt;/pre&gt;Got it? We use C's stringize operator (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;, &amp;quot;Courier&amp;quot;, monospace;"&gt;#&lt;/span&gt;) to convert a constant's name to a string in compile time. You see, we need quite a couple of tables, and each of the tables has many entries (you have to believe me, Netbios &amp;amp; Co are rather a chatty bunch). &lt;b&gt;So why are we using naked arrays? &lt;/b&gt;Because the&lt;span style="font-family: &amp;quot;Courier New&amp;quot;, &amp;quot;Courier&amp;quot;, monospace;"&gt; std::vector &lt;/span&gt;class didn't have a convenient initializer before C++2011*, a shame! Alternatively you could copy the array's contents to a fresh vector just to pass it to futher processing, but how ugly is that?&lt;br /&gt;&lt;br /&gt;Now you'd need to write something like this to translate between integer codes and their descriptions: &lt;br /&gt;&lt;pre&gt;&lt;b&gt;  &lt;/b&gt;getCmd(g_cmdNameTableSmb, sizeof(g_cmdNameTableSmb)/sizeof(CmdNameEntry)),&lt;/pre&gt;because in C/C++ you cannot define a true function on arrays like this:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  &lt;/b&gt;getCmd(CmdNameEntry table[N]).&lt;/pre&gt;Well, it seems you can after all, but it's of no use anyway because (as you know) inside of the function&lt;b&gt; the array will decay to a pointer&lt;/b&gt; &lt;b&gt;and the size information will be lost.&lt;/b&gt; I don't know how other people may feel about it, but after some time I got pretty annoyed with that. Couldn't we wrap this in a macro, or even better, use some template trickery? Let's try and write a small utility:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  &lt;/b&gt;template&amp;lt;typename T, size_t N&amp;gt;&lt;br /&gt;    string SmbProtocol::getCmdName(int code, T(&amp;amp;table)[N], const char* errorStr)&lt;br /&gt;  {&lt;br /&gt;      for(size_t i = 0; &lt;span style="color: #cc0000;"&gt;i &amp;lt;&lt;/span&gt; &lt;b style="color: #cc0000;"&gt;N&lt;/b&gt;); i++) &lt;span style="color: #6aa84f;"&gt;// &amp;lt;- oops!!!&lt;/span&gt; &lt;span style="color: #6aa84f;"&gt;compile error!&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;typename n="" size_t="" t,=""&gt;      {&lt;br /&gt;          if(table[i].cmdId == code)&lt;br /&gt;              return table[i].cmdName;&lt;br /&gt;      }    &lt;br /&gt;      return errorStr;&lt;br /&gt;  }&lt;/typename&gt;&lt;/pre&gt;Uh-oh, that doesn't compile, but frankly, how should it?&lt;b&gt; &lt;i&gt;N&lt;/i&gt;&lt;/b&gt; isn't a runtime construct, it is type information, and it lives only at the compile time! What we need is something to translate between type and value, i.e. a bridge between compile and run time. It appears that's not so complicated as it sounds, just write**:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  &lt;/b&gt;namespace util&lt;br /&gt;  {&lt;br /&gt;  template&amp;lt;typename T, size_t N&amp;gt;&lt;br /&gt;    size_t array_size(T(&amp;amp;)[N]) { return N; }      &lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;As we are in a template, we can access the type information, and as we are a function, we can return a value. Bridge ready! Now we only need to replace the incorrect line with:&lt;br /&gt;&lt;pre&gt;&lt;b&gt;  &lt;/b&gt;for(size_t i = 0; i &amp;lt; util::array_size(table); i++)&lt;br /&gt;&lt;/pre&gt;and now we are ready to go: &lt;br /&gt;&lt;pre&gt;&lt;b&gt;  &lt;/b&gt;string SmbProtocol::getNetbiosCmdName(int code)&lt;br /&gt;  {&lt;br /&gt;      return getCmdName(code, g_cmdNameTableNetbios, "UNKNOWN_SESS_MSG");&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;Now we can define new description tables, forward them to functions using the pair of &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, &amp;quot;Courier&amp;quot;, monospace;"&gt;T(&amp;amp;table)[N]&lt;/span&gt;and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;, &amp;quot;Courier&amp;quot;, monospace;"&gt;util::array_size()&lt;/span&gt; and let our pre C++2011 code look a little more elegant.&lt;br /&gt;--&lt;br /&gt;* You can have a look at &lt;a href="http://ib-krajewski.blogspot.com/2009/01/ive-read-on-my-local-german-c-forum.html"&gt;this&lt;/a&gt; previous installment of this blog for the new C++0x initialization syntax . &lt;br /&gt;** if you wonder about the array parameter syntax look here for an explanation: &lt;a href="http://theotherbranch.wordpress.com/2011/08/24/template-parameter-deduction-from-array-dimensions/"&gt;template-parameter-deduction-from-array-dimensions&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-3386170478945178499?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/3386170478945178499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=3386170478945178499' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/3386170478945178499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/3386170478945178499'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2011/05/dont-decay-your-arrays.html' title='Don&apos;t Decay your Arrays!'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-6806854850766584311</id><published>2011-05-26T08:51:00.000-07:00</published><updated>2011-05-28T11:25:18.235-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><title type='text'>Bad Case of Code Reuse</title><content type='html'>&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-MqTYbLzQtyk/Td51zJinckI/AAAAAAAAAHE/UGHewBFCWP8/s1600/bug+1763.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-MqTYbLzQtyk/Td51zJinckI/AAAAAAAAAHE/UGHewBFCWP8/s200/bug+1763.jpg" width="195" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Bug story!&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;We all strive to write elegant, concise and clear code. One of the tenants of this pursit is the&amp;nbsp;"&lt;a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself"&gt;DRY&lt;/a&gt;" principle - don't repeat yourself! But as usual you shouldn't always follow a principle blindly. Take for example the following bug which caused&amp;nbsp;me some problems at customer's premises.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;I just extended the client library of&amp;nbsp;the system I was in charge of at that time to suppport parallel requests, as the legacy server code would would be too risky to be refactored. Why? Well, not everyone has the luxury to have (or even sometimes to be able to define) a comprehensive set of unit tests. In case of the legcy product there were none, and worse, the sheer number of possible inputs (any satellite data, corrupted or not) does not allow the system to be wholy tested! &lt;br /&gt;&lt;br /&gt;I decided to supervise long running tasks&amp;nbsp;and send a short running ones in parallel, so the concurrency level would be bounded by 2.&amp;nbsp; At two points in the code I have got to check if the next task is a long-runner or not: when a single new task is submitted for processing, an when I need a second, parallel task (which cannot be a long runner again!). As I (true to the agile) first wrote the new task submission code, I defined the:&lt;br /&gt;&lt;pre&gt;isLongrunner(filename)&lt;br /&gt;&lt;/pre&gt;method, which looked up if the input data file could be a potential long-runner.&amp;nbsp;This method was used to check if a newly arrived request should be run in parallet to the currently running one. Then the library was tested and the first version was finished.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;In the next test iteration I added&amp;nbsp;pulling of the&amp;nbsp;requests from the input queue when a short-runner&amp;nbsp;gets ready and the long-runner is still busy. So I had to check if a request sitting in the input queue were a short-runner. But wait, our requests are files, and we already have a method to check for it! DRY baby! Elegant code! I tested it locally, and then it was deployed to our customer on the other side of the globe, namely in Asia. Mission acomplished, no problems expected... You wish! Of course, in Asia the new client library didn't quite work as expected, and the problem that had to be corrected still showed up. Embarassement, client unhappy! After many calls and emails I had at last the logfiles with the error showing clearly up.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;What was the problem? In the parallel task submitting code&amp;nbsp;at the end of a short running request I DRY-reused the &lt;br /&gt;&lt;pre&gt;isLongrunner(filename)&lt;br /&gt;&lt;/pre&gt;method,&amp;nbsp;I should rather use:&lt;br /&gt;&lt;pre&gt;isLongrunnerSession(sessFilename)&lt;br /&gt;&lt;/pre&gt;What's the difference? Well, in my client library there is one: the filenames waiting in the input queue will be processed and can be renamed in some specific cases. The &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;isLongrunner()&lt;/span&gt; method will check the already processed filenames, as it's passed as paramether to the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;WorkerThread::process()&lt;/span&gt;&lt;span style="font-size: small;"&gt; &lt;/span&gt;method*. Unfortunately, in the second case, we are already in the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;process()&lt;/span&gt; method, and are looking directly into the input queue, where the raw file names are to be found! Bugger!&amp;nbsp;And the local test worked, because..., well I can't remember the reason now, probably I didn't test the interface variant (there are two, legacy and modern one - it's a real, living and growing system) the asian client was using. Ooops :( &lt;br /&gt;&lt;div&gt;&lt;/div&gt;So what do we learn from this story?&lt;br /&gt;&lt;ol&gt;&lt;li&gt;If I wasn't so obsessed with code elegance and DRY, I wouldn't be lured into bad reuse, and then the omission to test the right interface version wouldn't have such unpleasant consequences. &lt;/li&gt;&lt;li&gt;If I'd care about the naming of the methods and its parameters to the point of obsession, I wouldn't settle for the first name which somehow filled the bill. It was sloppy!&lt;/li&gt;&lt;/ol&gt;&amp;nbsp;So the advice is&amp;nbsp;&lt;b&gt;as with the optimization: first get the code right, that get it DRY!&lt;/b&gt; And sometimes the techniques we are eager to use are more of hindrance than of help in a subtle way.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;--&lt;br /&gt;*&lt;span style="font-size: small;"&gt; &lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;WorkerThread &lt;/span&gt;is a part of my portable (as it's Qt-based) worker library, maybe I'll find the time to blog about it. At least the title is already chosen: &lt;i&gt;"Are workers actors?"&lt;/i&gt;.&lt;br /&gt;&lt;p&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-6806854850766584311?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/6806854850766584311/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=6806854850766584311' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6806854850766584311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6806854850766584311'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2011/05/bad-case-of-code-reuse.html' title='Bad Case of Code Reuse'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-MqTYbLzQtyk/Td51zJinckI/AAAAAAAAAHE/UGHewBFCWP8/s72-c/bug+1763.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-6498411084210133700</id><published>2010-12-22T04:14:00.000-08:00</published><updated>2011-06-06T06:53:17.288-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SW processes'/><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><title type='text'>A Little Agile nad XP Rant</title><content type='html'>&lt;p&gt;&lt;/p&gt;The title of this blog is &lt;em&gt;"On Languages ... etc etc ...&amp;nbsp;Systems and Proceses"&lt;/em&gt;, but utill now I never said anything about processes (or did you think I meant UNIX processes?) so let us write something&amp;nbsp;about the latter now. As lately everybody seems to be happy with Agile/XP (like &lt;a href="http://cplusplus-soup.com/2010/12/14/agile-c-development/"&gt;here&lt;/a&gt;&amp;nbsp;and &lt;a href="http://codemonkeyism.com/developers-agile/"&gt;here&lt;/a&gt;), let's rant about that a little. So beware, it's (at least partially) a &lt;strong&gt;#RANT#, &lt;/strong&gt;so don't try to kill or evagelize me! &lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. The Gripes&lt;/h2&gt;&lt;br /&gt;The one single thing you encounter today in the process land is the Agile. Well, I have a few gripes with that, which I should have wrote up earlier (and I wanted to, really, for the last 3 years or so), but now the time has come. On the other side, now when Agile is mainstream, maybe my points aren't valid anymore? You know, "the normative force of the factual"* :(. Maybe, but&amp;nbsp;let us begin from the start of all that:&lt;br /&gt;&lt;br /&gt;As I read the &lt;em&gt;"Agile Manifesto"&lt;/em&gt; and the XP explanations some 10 years ago or so, I was just amazed. It was the liberation! And what I particularly liked were things like pair programming, test driven design, and iterative deleopment. But today I must realize that I was somehow mistaken - maybe did I get it all wrong? &lt;strong&gt;Somehow it's all different from what I imagined it'd be&lt;/strong&gt;, and I don't like it very much. Two examples:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;a) the pair programming&lt;/strong&gt; &lt;br /&gt;&lt;blockquote&gt;In my eyes it was all about two people caring about a piece of code, discussing its design, reviewing main rewrites, just because discussing something with another person can show you another perspective on the problem.&lt;br /&gt;&lt;br /&gt;And now? The reality? It is crazy, it's about keyboard swapping, and two people doing coding at the same time. For 15 minutes it's my keyboard, and then it's yours. Come on, are we in Henry Ford's car factory? Or were we supposed to be doing some creative work? &lt;strong&gt;&lt;span style="font-size: x-small;"&gt;#RANT#&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;But there are people who actually like that (&lt;a href="http://www.nytimes.com/2009/09/20/jobs/20pre.html?_r=2&amp;amp;8dpc"&gt;here&lt;/a&gt;, &lt;a href="http://blog.tridgell.net/?p=111"&gt;here&lt;/a&gt;) aren't they? I'd say this could work, but only if you are paired up with someone on your level. Not just another beginner guy with a big ego, thank you very much! Even then I find it to be an overkill, 2 people doing work of 1? Aren't there people able to be doing decent work by themselves anymore?&lt;span style="font-size: x-small;"&gt; &lt;strong&gt;#RANT#&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;strong&gt;b) test driven development/design (TDD)&lt;/strong&gt; &lt;br /&gt;&lt;blockquote&gt;I liked this idea very much. OK, I've only seldom written the tests before code myself, but there always have been tests for a new feature: either before I coded it or after that. Because really, that doesn't matter if you know what a feature you are going to implement.&lt;br /&gt;&lt;br /&gt;But now? The reality? You should always write tests first. Or you are not agile. And why that? It comes even better - TDD can mean test driven design! A good example of this was to find in a blog posting** of the venerable Uncle Bob where he develops a prime factorization algorithm by TDD, i.e. by writing a series of increasingly complicated tests and reworking the algorithm accordingly. That looks for me like crazy, groping in the dark for the right solution, excuse me?!&lt;span style="font-size: x-small;"&gt; &lt;strong&gt;#RANT#&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://upload.wikimedia.org/wikipedia/commons/f/f8/Blind_men_and_elephant3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="274" n4="true" src="http://upload.wikimedia.org/wikipedia/commons/f/f8/Blind_men_and_elephant3.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Why should we waste time and rework our solution on and on? The received answer is: because it results in &lt;em&gt;decoupled code&lt;/em&gt;. Come on, aren't there other ways to write decoupled code? Like old and unfashionable thinking about its design a little? &lt;strong&gt;&lt;span style="font-size: x-small;"&gt;#RANT#&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;h2&gt;2. Some Summary and More Gripes&lt;/h2&gt;&lt;br /&gt;So meanwhile the&lt;strong&gt; XP is for me not the freedom&lt;/strong&gt;, bur rather the next horsewhip of the pointy haired boss types. It's more about following the rules and&amp;nbsp;their &lt;a href="http://www.infoq.com/news/2007/10/religous-industry"&gt;religious&lt;/a&gt; observance than about anything else. As I read about XP/Agile first, I thought it was targeted at proficient developers, you know, at the responsible adults, which should be allowed to be adult and just do their job! But now I have more and more the impression that it's rather targeted at beginners. Obviously, they need clear rules and directions. So maybe it's about the overall prevalence (and importance) of beginners in our industry? &lt;br /&gt;&lt;br /&gt;Well, mabe (just maybe) I'm opposing the abovementioned XP principles because they introduce a process-like quality into XP, and I feel kind of betrayed now? It was supposed to be about freedom and interacting free individuals? Maybe it was&amp;nbsp;just an illusion, maybe&amp;nbsp;the recipe of Agile Manifesto was&amp;nbsp;too simple? &lt;br /&gt;&lt;br /&gt;In this&amp;nbsp;&lt;a href="http://gwaredd.blogspot.com/2010/02/game-development-in-post-agile-world.html"&gt;this&lt;/a&gt;&amp;nbsp;excellent post&amp;nbsp;about &lt;em&gt;"post agile" &lt;/em&gt;development &lt;a href="http://twitter.com/gwareddm"&gt;Gwaredd Mountain&lt;/a&gt; states that no methodology is pure "agile" or pure "process-oriented". Rather, each one of them contains "freedom" (agile) and "process" elements, as a mix of both is needed for the real world. So even the supposedly totally free XP has to have some emergency brakes. Well, so much for my illusions of a better world :(. Nonetheless, the emergency brakes are rather expensive, the double pair of eyes to watch over "Brownian motion" like TDD development? That's my private opinion, but arguably it's somehow taking things to the extreme.&lt;br /&gt;&lt;br /&gt;But there's 3rd problem, and it's not easily dismissed:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;d) evangelism&lt;/strong&gt;&lt;br /&gt;&lt;blockquote&gt;In the Agile world-view there's either agile or waterfall, stone age, and nuclear winter. A typical Twitter post says:&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;Agile change is change. Change is hard for people&lt;/em&gt;&lt;/blockquote&gt;thus, if you can't get enthusiastic about Agile it means that you are unreformable, and just can't see the light! I think the Agile trainer guild is responsible for that***. As their training courses target mainly the beginners, they must give them rules to be followed in each circumstances. But I cannot understand why this must be promulgated to the general public? You know, &lt;em&gt;"Only a Sith deals in absolutes", &lt;/em&gt;it's not a sign of wisdom do divide the world in the only right way and all the others! &lt;strong&gt;&lt;span style="font-size: x-small;"&gt;#RANT#&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Ok guys, you must earn a living, but doesn't engineering decency mean anything to you? Or can't you think for yourselfs and would rather become a follower? Silver bullet anyone? That irritates me, but at the same timee it's interesting - what could possibly be a result of a realy intensive full-night talk with an Agile trainer? &lt;strong&gt;&lt;span style="font-size: x-small;"&gt;#RANT#&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;It's a little known fact, but Dr. Royce's defining &lt;a href="http://www.valucon.de/documents/managing_softwareprojects.pdf"&gt;paper&lt;/a&gt;&amp;nbsp;for the waterfall process already contained iterations (see figures 3 and 4)! Agile is not that original, people were able to think and use common sense before that! &lt;strong&gt;&lt;span style="font-size: x-small;"&gt;#RANT#&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;h2&gt;3. So What Do I Think Myself?&lt;/h2&gt;&lt;br /&gt;You may ask, how should we develop software then? We're not supposed to go back to "cowboy coding" are we? Steve Yegge' &lt;a href="http://steve-yegge.blogspot.com/2006/09/good-agile-bad-agile_27.html"&gt;post&lt;/a&gt;&amp;nbsp;describes an alternative: the pretty informal Google development practices**** at that time and praises it as the solution. Well I must admit it does sound good, but then even Google wanted to introduce some process not a long time after that (&lt;a href="http://www.computer.org/portal/web/csdl/doi?doc=doi/10.1109/AGILE.2006.48"&gt;Shh, we are adding a process&lt;/a&gt;).&amp;nbsp;In that article&amp;nbsp;they describe how the Scrum process was introduced in the &lt;em&gt;AdSense&lt;/em&gt; project (if I'm not mistaken), however not a full embodiment of Scrum. But it seems that somehow for time critical, heavy-money projects you need some kind of a whip in the end... :(&lt;br /&gt;&lt;br /&gt;So what do we need a process for? Do we need it at all?&lt;br /&gt;&lt;br /&gt;First let me quote Aristotle (via Pragamtic Programmers &lt;a href="http://www.amazon.com/Practical-Guide-Successful-Software-Projects/dp/0974514047?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=btl&amp;amp;camp=213689&amp;amp;creative=392969" target="_blank"&gt;link&lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0974514047" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px; padding-bottom: 0px! important; padding-left: 0px! important; padding-right: 0px! important; padding-top: 0px! important;" width="1" /&gt;, and no, I don't read him in original...) - "&lt;em&gt;We are what we repeatedly do. Excellence, then, is not an act, but a habit."&lt;/em&gt; As I understand it, we have to&amp;nbsp;kind of &lt;strong&gt;design the things which we repeatedly do,&lt;/strong&gt; if we want to ge good at something. And that's a start of a process. &lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;a href="http://www.amazon.com/Staying-Alive-Avalanche-Terrain-Tremper/dp/0898868343?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=bil&amp;amp;camp=213689&amp;amp;creative=392969" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;" target="_blank"&gt;&lt;img alt="Staying Alive in Avalanche Terrain" src="http://ws.amazon.com/widgets/q?MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL160_&amp;amp;ASIN=0898868343&amp;amp;tag=wwwibkrajewsk-20" /&gt;&lt;/a&gt;The 2nd insight comes from the field of avalanche avoidance (because I'm somehow of an offpiste skier). What&amp;nbsp;the professionals always do, is to have a checklist in the car and to go through it every time they set off. Because people forget, people do make mistakes, and in that profession, when they do, it can cost them their life. That's a kind of process too - you won't believe that you could do a mistake, but in the grand scheme of things, you probably will. &lt;strong&gt;So you need some annoying routine&lt;/strong&gt;, even if you don't think so!&lt;/div&gt;&lt;br /&gt;So what would I take? A methodology I liked rather well was the "Tracer Bullet Development" from the abovementioned Pragmatic Programmers book. It's simple, it has a lot of common sense (what I seem to like more then religious fervor) and it goes along the lines of my own understanding of the agile development which I came to during the last 10 or so years. &lt;br /&gt;&lt;br /&gt;Because I'm not an enemy of agile. More than taht, I think it's somehow a necessity! In real life there's constant change, and the original design***** of a system cannot be sustained - either it will be dying or it must adapt! So for me, &lt;strong&gt;agile has got it right in its basic proposition&lt;/strong&gt; - you must always iterate. As the ancients used to say &lt;em&gt;"iterare necesse est, vivere non est necesse"&lt;/em&gt; :).&lt;br /&gt;&lt;br /&gt;And what about my Agile/XP gripes? Here I'm with Steve Yegge - there's "Agile" and "agile", Agile of the trainers and pointy-haired bosses, and agile of the pragmatics. And I'm with the latter.&lt;br /&gt;&lt;br /&gt;Waiting for your comments.&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* or &lt;em&gt;"die normative Kraft des Faktischen"&lt;/em&gt;, by Immanuel Kant. This means: all that is, is good ,because it is (i.e. exists) or&amp;nbsp;something like that.&lt;br /&gt;&lt;br /&gt;** sorry, the original blogpost I read is vanished, this one is the current version reworked as a Kata:&lt;br /&gt;&lt;a href="http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata"&gt;http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;*** Read&amp;nbsp;Steve Yegge's post&amp;nbsp;about the so called "Agile" experts: &lt;em&gt;"Good Agile, Bad Agile ",&lt;/em&gt; &lt;a href="http://steve-yegge.blogspot.com/2006/09/good-agile-bad-agile_27.html"&gt;http://steve-yegge.blogspot.com/2006/09/good-agile-bad-agile_27.html&lt;/a&gt;, or this one: &lt;em&gt;"Agile Ruined My Life"&lt;/em&gt;, &lt;a href="http://www.whattofix.com/blog/archives/2010/09/agile-ruined-my.php"&gt;http://www.whattofix.com/blog/archives/2010/09/agile-ruined-my.php&lt;/a&gt;&amp;nbsp;and look out for the &lt;strong&gt;Fraud&lt;/strong&gt; markers!&lt;br /&gt;&lt;br /&gt;**** BTW, as I was at Google's HQ in London once, this did just look like any anther SW outfit, maybe even a little like at NEC's HQ in Tokyo (sic!) - small desks (ok, not as small as in Japan), a big open space, no books articles on notes on the desks, just the programmer and the computer. I wasn't that impressed... Sorry, I digress, I know.&lt;br /&gt;&lt;br /&gt;***** For example, take this fascinating and/or terryfying&amp;nbsp;case of dying architecture (from this &lt;a href="http://www.amazon.com/Refactoring-Large-Software-Projects-Restructurings/dp/0470858923?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=btl&amp;amp;camp=213689&amp;amp;creative=392969" target="_blank"&gt;book&lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0470858923" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px; padding-bottom: 0px! important; padding-left: 0px! important; padding-right: 0px! important; padding-top: 0px! important;" width="1" /&gt;): &lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;Alas, everything started out so well! The concepts were clear-cut. The technical prototype was a success, the customer was thrilled and Gartner Group decided that the architecture was flawless. Then real life began to take its toll: the number of developers went up, the average qualification dropped, the architect always had other things on his plate – and time pressure increased.&lt;/em&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;em&gt;The consequence was that the architecture concepts were executed less and less consistently. Dependencies were in a tangle, performance dropped (too many client/server hops and too many single database queries), and originally small modifications turned into huge catastrophes. To a certain extent the architecture concepts were circumvented on purpose. For example, classes were instantiated via Reflection because the class was not accessible at compile-time.&lt;/em&gt;&lt;/blockquote&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-6498411084210133700?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/6498411084210133700/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=6498411084210133700' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6498411084210133700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6498411084210133700'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2010/12/little-agile-nad-xp-rant.html' title='A Little Agile nad XP Rant'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-7932983370004603077</id><published>2010-12-11T08:36:00.000-08:00</published><updated>2010-12-12T12:59:39.150-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><category scheme='http://www.blogger.com/atom/ns#' term='estimation'/><title type='text'>Some Observations on Software Estimation</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;span style="font-size: 78%;"&gt;&lt;span style="font-size: small;"&gt;In my prevoius post &lt;a href="http://ib-krajewski.blogspot.com/2010/06/software-estimation-and-re-reading.html"&gt;post&lt;/a&gt; in introduced the "real life factor" &lt;em&gt;f&lt;/em&gt;&lt;span style="font-size: 78%;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;rw&amp;nbsp;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;for software estimation, and&amp;nbsp;conjectured it to be as high as 3. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 78%;"&gt;&lt;span style="font-size: 78%;"&gt;&lt;span style="font-size: small;"&gt;I remebered that as I read James Iry's short &lt;a href="http://james-iry.blogspot.com/2010/10/how-to-estimate-software.html"&gt;blogpost&lt;/a&gt;. Let me quickly restate its contents. He recollects the course of a software project and the estimates at each point of its history. I summed that up and added the reason for each estimate failure:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color: blue;"&gt;             | Project | &lt;br /&gt;   Estimate  |  Phase  |   Error Reason &lt;br /&gt;  -----------+---------+-----------------&lt;br /&gt;    2 weeks  |    0%   |  initial guess&lt;br /&gt;             |         |  &lt;br /&gt;    4 weeks  |   50%   |  too optimistic!&lt;br /&gt;             |         |  &lt;br /&gt;    6 weeks  |   90%   |  hidden complexity&lt;br /&gt;             |         |  &lt;br /&gt;    8 weeks  |   99%   |  forgotten the tests,&lt;br /&gt;             |         |  docs and review&lt;br /&gt;             |         |  &lt;br /&gt;    8 weeks  |  100%   |  not really ready, but &lt;br /&gt;             |         |  has had enough!&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So there it is, when estimating we&amp;nbsp;are too optimistic from the start, and then we tend to forget a lot of things&amp;nbsp;.So using this error "model" the&amp;nbsp;real life factor would be &lt;em&gt;f&lt;span style="font-size: 78%;"&gt;&lt;span style="font-size: x-small;"&gt;rw=&lt;/span&gt;&lt;/span&gt;4&lt;/em&gt;! I'd say rather high. Maybe we need a better model? And what if we want to&amp;nbsp;be really careful?&lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;a href="http://www.amazon.com/Software-Estimation-Demystifying-Practices-Microsoft/dp/0735605351?ie=UTF8&amp;amp;tag=wwwibkrajewsk-20&amp;amp;link_code=bil&amp;amp;camp=213689&amp;amp;creative=392969" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;" target="_blank"&gt;&lt;img alt="Software Estimation: Demystifying the Black Art (Best Practices (Microsoft))" src="http://ws.amazon.com/widgets/q?MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL160_&amp;amp;ASIN=0735605351&amp;amp;tag=wwwibkrajewsk-20" /&gt;&lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=wwwibkrajewsk-20&amp;amp;l=bil&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0735605351" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px; padding-bottom: 0px !important; padding-left: 0px !important; padding-right: 0px !important; padding-top: 0px !important;" width="1" /&gt;&lt;br /&gt;&amp;nbsp;When speaking about serious software estimation you will usualy end up with the &lt;em&gt;"Demistyfying the Black Art"&lt;/em&gt; book (an excellent book indeed, read it!), and will probably learn and use the PERT technique, where you have to give 3 estimates: the best case, the normal case, and the worst case estimates. Then you take a formula and get the expected project duration.&lt;br /&gt;&lt;br /&gt;That's all very well and good, but when using this technique, we still tend to be overly optimistic and to forget a lot of things, exactly as in the above example!&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;The following &lt;a href="http://spin.atomicobject.com/2009/01/14/making-better-estimates-range-estimates"&gt;blogpost&lt;/a&gt;&amp;nbsp;hits the nail on the head:&lt;/div&gt;&lt;blockquote&gt;&lt;em&gt;Our experience has taught us that simply asking developers to make two estimates (“low” and “high”) doesn’t really result in much more information than a single point estimate. Developers tend to be optimistic when it comes to individual estimates. So without a little structure, the “low” estimate usually means the absolute smallest amount of time the task could take – an event with a very low probability of coming true. The “high” estimate means what it’s most likely to take to get done.&lt;/em&gt;&lt;/blockquote&gt;Given that data, let us do a smal, back of the envelope calculation for the probabilities of the 3 PERT estimates. Thus:&lt;br /&gt;&lt;pre&gt;&lt;span style="color: blue;"&gt;  low estimate =&amp;gt; rather improbable =&amp;gt; say 20% probability&lt;br /&gt;  high estimate =&amp;gt; most likely =&amp;gt; i.e. 50% probability&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;then&lt;br /&gt;&lt;pre&gt;&lt;span style="color: blue;"&gt;  medium estimate =&amp;gt; will lie inbetween =&amp;gt; ~30% probability&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;So the real life factor for the medium (i.e. realistic) here is &lt;em&gt;f&lt;/em&gt;&lt;span style="font-size: 78%;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;rw=&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;em&gt;3.3&lt;/em&gt;, not that different form the above, unscientific&amp;nbsp;guess!&amp;nbsp;PERT will correct this somehow, by not that much. So should we really always multiply our carefully crafted estimates by 3 (or 2), thus admitting that we cannot do it? That's scary.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But wait, we don't need 100% certainty, that would be sandbagging! Let us say, 80% is enough (see Pareto), but that's still 2,7 times the&amp;nbsp;our&amp;nbsp;"realistic" estimate or 1,6 times the "worst case estimate". I don't want to make any conclusions though, it's only some observations because it makes me curious that the value of 3 seems to resurface rather often!&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-7932983370004603077?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/7932983370004603077/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=7932983370004603077' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7932983370004603077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7932983370004603077'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2010/12/some-observations-on-software.html' title='Some Observations on Software Estimation'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-4277714231123482063</id><published>2010-11-23T10:57:00.000-08:00</published><updated>2010-12-09T12:48:54.562-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Qt'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='servlets'/><title type='text'>Yet Another... Web Framework (in C++)</title><content type='html'>&lt;p&gt;What? YAWF - yet another web framework? But this is mine(!) ... and it's very small - a Simple Embeddable C++ Webframework for &lt;a href="http://www.blogger.com/Qt"&gt;Qt&lt;/a&gt;!&lt;/p&gt;&lt;h2&gt;1. The need&lt;/h2&gt;&lt;br /&gt;I have discussed this topic on this blog earlier*, so you shouldn't be surprised to hear about it again: a C++ web framework. You'd think there isn't such thing? Wrong! From my own research and from the comments of friendly internauts I collected a quite a list of possible frameworks:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.total-knowledge.com/progs/cppserv/"&gt;CppServ&lt;/a&gt; &lt;li&gt;&lt;a href="http://trustleap.ch/en_iis.html"&gt;gwan &lt;/a&gt;&lt;li&gt;&lt;a href="http://www.ddj.com/184405023"&gt;Bobcat&lt;/a&gt; (defunct) &lt;li&gt;&lt;a href="http://www.webtoolkit.eu/wt/"&gt;Witty &lt;/a&gt;&lt;li&gt;&lt;a href="http://xaxxon.slackworks.com/ehs/"&gt;EHS&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;And recently I found even another one:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://cppcms.sourceforge.net/wikipp/en/page/main"&gt;CppCMS &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://cppcms.sourceforge.net/banner-small.png"&gt;&lt;img style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 146px; CURSOR: hand; HEIGHT: 161px" alt="" src="http://cppcms.sourceforge.net/banner-small.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Do you see its cool logo? It says that &lt;strong&gt;programming in C++ is a good thing&lt;/strong&gt;, as it isn't hard on the environment, and thus can maybe even stop the global warning ;). I must admit that I never seen C++ from that angle! Interesting point, isn't it? Ok, when you think of all that multicores and figths about cache lines then C++ does quite naturally comes to mind with its very direct memory control, doesn't it? Kind of "lean programming" :).&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;And don't forget the new kid on the block:&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://github.com/cpp-netlib/cpp-netlib"&gt;cpp-netlib &lt;/a&gt;by &lt;a href="http://cplusplus-soup.com/"&gt;Dean Michael Berris &lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It's rather a wide range of possiblities, so you'd think the world doesn't need another framework, and least at all by yours truly. That's what I thought too, untill I stumbled upon a rather simple problem. Currently I develop a Qt application that runs in the background (call it demon, service, headless, etc.) and would like to have an admin interface for it. Of course I could write a standalone GUI client connecting to the application's command socket but that's so nineties! Only a web interface is fashionable these days. Thus I need a small webapp for the admin console.&lt;br /&gt;&lt;br /&gt;So at first then, I thought I'd use some open source code from the above list. But all of them would either not integrate well with Qt events, or require 3rd party includes and dependencies, and &lt;em&gt;gwan&lt;/em&gt; would even have to be started as an external server! Well, I didn't use &lt;em&gt;gwan&lt;/em&gt; before and it does sound like a border case usage for it, just imagine all that debugging of its servlet compiler in run-time...&lt;br /&gt;&lt;br /&gt;Then you may ask: isn't there any HTTP server in the Qt framework? Yes indeed, I found one, but it's an extension of the framework (they call it an option I think...) and it's running as Windows service, not as an additional interface to an existing binary. So we've got the same case as with &lt;em&gt;gwan&lt;/em&gt;. BTW, why hasn't C++ a standard HTTP server class? Go has one, Python has one, Javascript has one, but C++ - nope! Well, that's not completely true, &lt;a href="http://libcinder.org/features/"&gt;CINDER&lt;/a&gt; framework has one, and &lt;a href="http://glynos.github.com/cpp-netlib/http_client.html"&gt;cpp-netlib&lt;/a&gt; got one as well, but I wanted to avoid big includes and dependencies like Boost. &lt;/p&gt;&lt;p&gt;But hey, Qt has a couple of HTTP support classes, so I thought: boy, that cannot be that hard! And I just hacked my own mini HTTP server. &lt;/p&gt;&lt;h2&gt;2. The design&lt;/h2&gt;&lt;p&gt;Of course that gives me an opportunity to design a web framework the way it should be always designed at last :-), because all the others seem to be somehow overcomplex or overcomplicated :-). So let's go down to the brass tacks then!&lt;br /&gt;&lt;br /&gt;First we have to decide on the name - let simply try YAWF(4q), and in best software giant tradition I'll use an internal codename, for example "CutieW".&lt;br /&gt;&lt;br /&gt;The design will be simple, plain and oldskool, as I need something working and that fast. Besides, never underestimate the power of KISS! &lt;/p&gt;&lt;p&gt;The basic ingredients are the Qt classes for TCP socket handling and HTTP request and response parsing. Then we'll have request handler objects with a &lt;em&gt;process()&lt;/em&gt; method. The handler objects (kind of servlets for the Java minded) will have to be derived from a superclass (how uncool, I know) and statically instatiated, so that they can register themself with the server in the startup phase. They register with a name string**, for example &lt;em&gt;"user"&lt;/em&gt; or &lt;em&gt;"page",&lt;/em&gt; so they can be bound to an URI (see below for the example).&lt;br /&gt;&lt;br /&gt;Let's sum it up: there will be a server executable, it will set the URL path configuration in startup phase, each path wil get its own handler. When a request arrives, a fresh instance of the handler will be created, this the handler classes need a &lt;em&gt;clone()&lt;/em&gt; method for this.&lt;br /&gt;&lt;br /&gt;The server will thus find the matching handler prototype for the URI, clone it, and then invoke its &lt;em&gt;process()&lt;/em&gt; method. As you see, there's 1 to 1 relation betweem URI and the handler object in the current implementation, but an extension to "multiple dispatch" isn't difficult, and I'll program it when I have some spare time.&lt;/p&gt;&lt;p&gt;Now to the general usage pattern of YAWF4q. In Clojure you'd write the following: &lt;/p&gt;&lt;pre&gt;  (defn &lt;span style="color:#cc66cc;"&gt;display&lt;/span&gt; []&lt;br /&gt;     (html [&lt;span style="color:#cc66cc;"&gt;:h1&lt;/span&gt; "hello!"]))&lt;br /&gt;&lt;br /&gt;  (defroutes &lt;span style="color:#cc66cc;"&gt;myroutes&lt;/span&gt;&lt;br /&gt;     (GET "/" [] (display)))&lt;br /&gt;&lt;br /&gt;  (defonce &lt;span style="color:#cc66cc;"&gt;server&lt;/span&gt; (run-jetty #'myroutes&lt;br /&gt;       {&lt;span style="color:#cc66cc;"&gt;:join? false&lt;br /&gt;&lt;/span&gt;        &lt;span style="color:#cc66cc;"&gt;:port &lt;/span&gt;8080}))&lt;/pre&gt;In cpp-netlib this:&lt;br /&gt;&lt;pre&gt;  struct hello_world {&lt;br /&gt;    void operator()(server::request const &amp;amp;request,&lt;br /&gt;                    server::response &amp;amp;response) {&lt;br /&gt;                       &lt;span style="color:#009900;"&gt;// your code here ...&lt;br /&gt;&lt;/span&gt;                   }&lt;br /&gt;  } handler;&lt;/pre&gt;&lt;pre&gt;  server server_(argv[1], argv[2], handler);&lt;br /&gt;  server_.run();&lt;/pre&gt;But in yawf4q it's all pretty plain, non-clever, and almost boring: &lt;pre&gt;  #include &lt;span style="color:#cc0000;"&gt;"CuteHttpServer.hpp"&lt;/span&gt; &lt;span style="color:#009900;"&gt;// the cutie&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;  int main(int argc, char* argv[])&lt;br /&gt;  {&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// your application&lt;/span&gt;:&lt;br /&gt;    QApplication* qtAppl = new QApplication(argc, argv);&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// the webserver on port 3100&lt;/span&gt;&lt;br /&gt;    ibkrj::yawf4q::CuteHttpServer testServer(3100);&lt;br /&gt;    string error;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    if(!testServer.start(error))&lt;br /&gt;        return -1;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// run Qt&lt;/span&gt;&lt;br /&gt;    qtAppl-&amp;gt;exec();&lt;br /&gt;  }&lt;/pre&gt;The server just starts, finds the config file (using a default, hardcoded name), sets the routes, and waits for requests. If you don't define any handlers, a simple "I'm alive" response is sent back.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;3. The example&lt;/h2&gt;&lt;br /&gt;How to write your handlers? Look, you have to derive them from the &lt;em&gt;TestHandlerBase&lt;/em&gt; class. First let us implement the handler of the &lt;em&gt;index&lt;/em&gt; page:&lt;pre&gt;  class TestHandlerBase&lt;br /&gt;    : public MiniHttpHandler&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    TestHandlerBase()&lt;br /&gt;        : MiniHttpHandler("TestHandlerBase") {};&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// base overrides&lt;/span&gt;&lt;br /&gt;    virtual MiniHttpHandler* clone() { return new TestHandlerBase; }&lt;br /&gt;    virtual void process(AnalyzerRequest&amp;amp; reqData, std::string&amp;amp; respData);&lt;br /&gt;  } g_handler1;&lt;/pre&gt;OK that's rather much boilerplate, as we need to supply the name string plus the &lt;em&gt;clone()&lt;/em&gt; and &lt;em&gt;process()&lt;/em&gt; methods, so maybe I should provide a macro like this:&lt;br /&gt;&lt;pre&gt;  &lt;span style="color:#009900;"&gt;// --- OR maybe a MACRO?:&lt;/span&gt;&lt;br /&gt;  class TestHandlerBase&lt;br /&gt;    : public MiniHttpHandler&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    BASE_TEST_HANDLER_FUNC(TestHandlerBase)&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    &lt;span style="color:#009900;"&gt;... your functions ...&lt;/span&gt;&lt;br /&gt;  } g_xxx;&lt;/pre&gt;I don't know, as a matter of fact I hate macros in frameworks! But as an alternative maybe it isn't that bad. Another possibility would be using &lt;a href="http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern"&gt;CRTP&lt;/a&gt;, as to automatically add the &lt;em&gt;clone()&lt;/em&gt; method, but wouldn't you say this would be somehow too clever when compared with the rest of the design?&lt;br /&gt;&lt;br /&gt;And here is the processing method:&lt;br /&gt;&lt;pre&gt;  void TestHandlerBase::process(AnalyzerRequest&amp;amp; reqData, std::string&amp;amp; respData)&lt;br /&gt;  {&lt;br /&gt;    respData = &lt;span style="color:#990000;"&gt;" TestHandlerBase alive!!!! "&lt;/span&gt;;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    respData =&lt;br /&gt;        &lt;span style="color:#990000;"&gt;"&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;"&lt;br /&gt;        "&amp;lt;title&amp;gt;TestHandlerBase is alive!&amp;lt;/title&amp;gt;"&lt;br /&gt;        "&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;"&lt;/span&gt;;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    respData.append&lt;span style="color:#990000;"&gt;("&amp;lt;h1&amp;gt; Input your user data: &amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;"&lt;/span&gt;);&lt;br /&gt;    respData.append(testform); &lt;span style="color:#009900;"&gt;// HTTP form for UserName, UserMail and Text, action="person"&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    respData += &lt;span style="color:#990000;"&gt;"&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;"&lt;/span&gt;;&lt;br /&gt;  }&lt;/pre&gt;OK this doesn't look very cool, but the view component isn't yet there, wait a little. What this handler does is to ask for some user data. Now the second handler follows, which will processes the submitted user data:&lt;br /&gt;&lt;pre&gt;  class TestHandlerPerson&lt;br /&gt;    : public MiniHttpHandler&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    BASE_TEST_HANDLER_FUNC(TestHandlerPerson); &lt;span style="color:#009900;"&gt;// here process() is already defined&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;  } g_handler2;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;span style="color:#009900;"&gt;///////////// impl:&lt;/span&gt;&lt;br /&gt;  void TestHandlerPerson::process(AnalyzerRequest&amp;amp; reqData, std::string&amp;amp; respData)&lt;br /&gt;  {&lt;br /&gt;    respData =&lt;br /&gt;        &lt;span style="color:#990000;"&gt;"&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;"&lt;br /&gt;        "&amp;lt;title&amp;gt;TestHandlerBase is alive!&amp;lt;/title&amp;gt;"&lt;br /&gt;        "&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;"&lt;/span&gt;;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    respData.append&lt;span style="color:#990000;"&gt;("&amp;lt;h2&amp;gt; Thank you for your data! &amp;lt;/h2&amp;gt;"&lt;/span&gt;);&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// parse the data for display:&lt;br /&gt;&lt;/span&gt;    map&amp;lt;string,string&amp;gt;&amp;amp; data = reqData.formularData;&lt;br /&gt;    map&amp;lt;string,string&amp;gt;::iterator iter;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    respData.append(&lt;br /&gt;        &lt;span style="color:#990000;"&gt;"&amp;lt;table border=\"1\"  width=\"70%\"&amp;gt;&amp;lt;tr&amp;gt;"&lt;br /&gt;&lt;/span&gt;&lt;pre&gt;&lt;/pre&gt;&lt;span style="color:#990000;"&gt;        "&amp;lt;th&amp;gt;&amp;lt;b&amp;gt;Field&amp;lt;/b&amp;gt;&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;&amp;lt;b&amp;gt;Value&amp;lt;/b&amp;gt;&amp;lt;/th&amp;gt;"&lt;br /&gt;        "&amp;lt;/tr&amp;gt;"&lt;/span&gt;);&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    for(iter = data.begin(); iter != data.end(); iter  )&lt;br /&gt;    {&lt;br /&gt;        respData.append(&lt;span style="color:#990000;"&gt;"&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;"&lt;/span&gt;).append(iter-&amp;gt;first).append&lt;span style="color:#990000;"&gt;("&amp;lt;/td&amp;gt;"&lt;/span&gt;);&lt;br /&gt;        respData.append(&lt;span style="color:#990000;"&gt;"&amp;lt;td&amp;gt;"&lt;/span&gt;).append(iter-&amp;gt;second).append(&lt;span style="color:#990000;"&gt;"&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;"&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    respData.append(&lt;span style="color:#990000;"&gt;"&amp;lt;/table&amp;gt;"&lt;/span&gt;);&lt;br /&gt;    respData.append(&lt;span style="color:#990000;"&gt;"&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;a href=\"/index.html\"&amp;gt;Back&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;"&lt;/span&gt;);&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    respData += &lt;span style="color:#990000;"&gt;"&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;"&lt;/span&gt;;&lt;br /&gt;  }&lt;/pre&gt;&lt;p&gt;Rather grotty servlet or .jsp style here, isn't it? Mixing presentation with code?! &lt;/p&gt;&lt;p&gt;Don't despair, you can use a template. Yes, let's be modern! I chose the &lt;a href="http://mustache.github.com/"&gt;mustache :{{&lt;/a&gt; template syntax. I decided for mustache, well, because it's pretty new, generates much buzz, and isn't looking too bad. For those who don't know mustache, it is a simple HTML templating syntax with values encoded like this: &lt;/p&gt;&lt;pre&gt;  {{value}}&lt;/pre&gt;and sections, which can be rendered multiple times, if they receive a list as input data: &lt;pre&gt;  {{#section_X}}&lt;br /&gt;    {{value1}} =&amp;gt; {{value2}}&lt;br /&gt;  {{/section_X}}&lt;/pre&gt;So there's no need to code anly loops in the template. &lt;strong&gt;YAWF contains an implementation of mustache :{{&lt;/strong&gt;, which seems to render correctly all the examples I found in the online mustache docs. The implementation is based on a simple idea: the template is parsed into a linear sequence of "nodes", and the data items passed to the template take care of rendering and walking the node list. Have a look at the source code*** if you want.&lt;br /&gt;&lt;br /&gt;So our response handler would now look like this:&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;  // using templating:&lt;/span&gt;&lt;br /&gt;  #include "CuteMstchData.hpp"&lt;br /&gt;  void TestHandlerPerson::process(CuteSrvRequest&amp;amp; reqData, std::string&amp;amp; respData)&lt;br /&gt;  {&lt;br /&gt;    string templ =&lt;br /&gt;&lt;span style="color:#990000;"&gt;      "&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;TestHandlerBase is alive!&amp;lt;/title&amp;gt;"&lt;br /&gt;      "&amp;lt;/head&amp;gt; &amp;lt;body&amp;gt; &amp;lt;h2&amp;gt; Thank you for your data! &amp;lt;/h2&amp;gt;"&lt;br /&gt;      "&amp;lt;table border=\"1\"  width=\"70%\"&amp;gt;"&lt;br /&gt;      "&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;&amp;lt;b&amp;gt;Field&amp;lt;/b&amp;gt;&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;&amp;lt;b&amp;gt;Value&amp;lt;/b&amp;gt;&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;"&lt;br /&gt;      "{{#datatable}}"&lt;br /&gt;      "&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt; {{field}} &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; {{value}} &amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;"&lt;br /&gt;      "{{/datatable}}"&lt;br /&gt;      "&amp;lt;/table&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;"&lt;br /&gt;      "&amp;lt;a href=\"/index.html\"&amp;gt;Back&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;"&lt;br /&gt;      "&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;";&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// convert data to JSON represenation:&lt;/span&gt;&lt;br /&gt;    map&amp;lt;string,string&amp;gt;&amp;amp; inpData = reqData.formularData;&lt;br /&gt;    map&amp;lt;string,string&amp;gt;::iterator iter;&lt;br /&gt;    int i;&lt;br /&gt;    ibkrj::yawf4q::CuteMstchValMap templData;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    for(iter = inpData.begin(), i = 0; iter != inpData.end(); iter++, i++)&lt;br /&gt;    {&lt;br /&gt;      templData.addToList("datatable", i, "field", iter-&amp;gt;first);&lt;br /&gt;      templData.addToList("datatable", i, "value", iter-&amp;gt;second);&lt;br /&gt;    }&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;    &lt;span style="color:#009900;"&gt;// display page with data (the View of MVC)&lt;/span&gt;&lt;br /&gt;    respData = CuteHttpHandler::renderThis(templData, templ);&lt;br /&gt;  }&lt;/pre&gt;It maybe doesn't look much better than the plain HTML code, but here we could save the template in file, and read it in at the runtime. And we've got the View part of the MVC pattern. The handler objects stand for &lt;em&gt;"C",&lt;/em&gt; but so far don't have support for &lt;em&gt;"M"&lt;/em&gt; in YAWF4q.&lt;br /&gt;&lt;br /&gt;Now, as last part of the puzzle, we have to configure the server paths, but this is simple: &lt;pre&gt;&lt;span style="color:#990000;"&gt;#&lt;br /&gt;# test configuration&lt;br /&gt;#&lt;/span&gt;&lt;br /&gt;index.html$ :: TestHandlerBase&lt;br /&gt;person/.*$ :: TestHandlerPerson&lt;/pre&gt;&lt;p&gt;You see, regular expressions are supported. Now let it run baby! The first handler gives us: &lt;/p&gt;&lt;p&gt;&lt;a href="http://2.bp.blogspot.com/_79IsVE3vX_Y/TPaNFsLvbmI/AAAAAAAAAGU/qtgXxoekjKA/s1600/yawf-1.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5545775120052612706" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 320px; CURSOR: hand; HEIGHT: 290px" alt="" src="http://2.bp.blogspot.com/_79IsVE3vX_Y/TPaNFsLvbmI/AAAAAAAAAGU/qtgXxoekjKA/s320/yawf-1.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then we willingly give our data:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_79IsVE3vX_Y/TPaNjctL2eI/AAAAAAAAAGc/iQTsmLq4H-0/s1600/yawf-2.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5545775631293995490" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 320px; CURSOR: hand; HEIGHT: 318px" alt="" src="http://1.bp.blogspot.com/_79IsVE3vX_Y/TPaNjctL2eI/AAAAAAAAAGc/iQTsmLq4H-0/s320/yawf-2.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&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;&lt;p&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;And see the results: &lt;/p&gt;&lt;p&gt;&lt;a href="http://3.bp.blogspot.com/_79IsVE3vX_Y/TPaNwqXcd-I/AAAAAAAAAGk/8upklUZlZkQ/s1600/yawf-3.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5545775858299205602" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 320px; CURSOR: hand; HEIGHT: 190px" alt="" src="http://3.bp.blogspot.com/_79IsVE3vX_Y/TPaNwqXcd-I/AAAAAAAAAGk/8upklUZlZkQ/s320/yawf-3.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;4. Summing up&lt;/h2&gt;&lt;p&gt;At the moment the code*** is only very basic, as I haven't got time to work on it a much as I'd like. I wrote it on my private time, as my customer did decide in favor of a general, grand-scheme, system management solution. So as for today, I wrote only a single test, that one which was described above, and tested it with Visual C++ on Windows. YAWF isn't more than a toy just now as many features are simply missing, for example I'd like to have a built in support for configurable error pages to round the things off. And as next thing, I'd like to add the Model component using my CuteWorkers framework (I hope I'll come to write a post about Qt-workers too).&lt;br /&gt;&lt;br /&gt;But there's much more that could done, like:&lt;br /&gt;&lt;br /&gt;- HTTPS support in the sever (that shouldn't be very difficult as Qt offers QSslSocket and other classes)&lt;br /&gt;- cookies and session data handling&lt;br /&gt;- dynamic loading and caching of the templates&lt;br /&gt;- dynamic loading of the servelts vial DLL (kind of what ASP is doing)&lt;br /&gt;- a "Clojure example" like dynamic interface&lt;/p&gt;&lt;p&gt;and so on, and so on. Look at my TODO list in the github repository. Nonetheless it's simple (KISS!), it's pluggable, it doesn't have any dependecies other than Qt. Requirements fullfilled! &lt;/p&gt;&lt;p&gt;--&lt;br /&gt;* check out these previous posts: &lt;a href="http://ib-krajewski.blogspot.com/2007/09/servlets-in-c.html"&gt;servlets-in-c.html&lt;/a&gt;, &lt;a href="http://ib-krajewski.blogspot.com/2008/10/c-servlets-again.html"&gt;c-servlets-again.html&lt;/a&gt;, &lt;a href="http://ib-krajewski.blogspot.com/2009/02/c-server-pages.html"&gt;c-server-pages.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;** we cannot forget that C++ hasn't much to offer in terms of introspection. But we won't give up automatic registration and detection of handler prototypes!&lt;/p&gt;&lt;p&gt;*** You can find the code at Github: &lt;a href="https://github.com/mrkkrj/yawf4q"&gt;https://github.com/mrkkrj/yawf4q&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-4277714231123482063?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/4277714231123482063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=4277714231123482063' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4277714231123482063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4277714231123482063'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2010/11/yet-another-web-framework-in-c.html' title='Yet Another... Web Framework (in C++)'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_79IsVE3vX_Y/TPaNFsLvbmI/AAAAAAAAAGU/qtgXxoekjKA/s72-c/yawf-1.jpg' height='72' width='72'/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-6804157334734692975</id><published>2010-11-13T06:21:00.001-08:00</published><updated>2010-11-23T10:36:03.686-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><title type='text'>Engineering Decency</title><content type='html'>&lt;p&gt;&lt;/p&gt;A couple of days ago I was quite unpleasantly touched by a tweet (a Twitter tweet :-) of a so called &lt;em&gt;"expert"&lt;/em&gt; (you know, the people doing only presentations and learning new languages only to write their next book...) ridiculing a developer about a failed &lt;a href="http://www.carlosble.com/?p=719"&gt;project&lt;/a&gt;. Somehow I didn't like that - come on, the guys just tried to capitalize on a promise Google (yes, that&lt;strong&gt; &lt;/strong&gt;big engineering powerhouse) made! And they were &lt;a href="http://highscalability.com/google-appengine-second-look"&gt;not alone&lt;/a&gt;...&lt;br /&gt;&lt;br /&gt;What is that, that the programmers &lt;strong&gt;find it so hard to show some engineering decency&lt;/strong&gt;? I've seen it again and again. Is it so much fun* to flame someone to feel better? The experts should know best that doing stuff mean means making mistakes. Or maybe have they forgotten how it is to be working with real stuff instead of powerpoint metadata?&lt;br /&gt;&lt;br /&gt;If you are skiing difficult terrain, you know that the question isn't if you will fall, the question is when you will. That's the same in software - you don't want to believe this now (and me neither) but you will make (sometimes stupid) mistakes! So please, show a little decency. The guys you are going to deride probably just tried to create a working system for a given set of requirements which then turned out to be lagerly false and for a specific platform, which then emerged to be broken. We've all been there.&lt;br /&gt;&lt;br /&gt;And because it's difficult and needs to be learnt, I have an example of how to excercize engineering decency (found &lt;a href="http://ct.techrepublic.com.com/clicks?t=611183859-ffbd30de1524954db69bb7c97f85b199-bf&amp;amp;brand=TECHREPUBLIC&amp;amp;s=5"&gt;here&lt;/a&gt;). Instead of the usual:&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;What idiot with even half a handful of moldy cottage cheese for brains would ever create a pile of stinking filth like this and call it an application?! The true feat of engineering here is that this code monster didn’t swallow your whole organization in the black hole of its utter lameness. Where did this person learn programming — NBC?”&lt;/em&gt;&lt;/blockquote&gt;Try saying that:&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;“This will take me longer than we had discussed. In my initial examination of the system, I missed some design decisions in the existing code that conflict directly with what we need to accomplish. I didn’t anticipate the approach adopted by earlier developers, because I would not have designed it that way myself. I’m sure they had their reasons for choosing that direction, but so far those reasons have eluded me.”&lt;/em&gt;&lt;/blockquote&gt;That's decency, that's humility. Maybe there's a reason you just don't see now. But even if that's really a load of crap, frankly, who of us can say he never ever wrote bad code (or a bad powerpoint presenation for that reason)?&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;* well, if we'd like to get freudian, we could say that the unconscoius fear of doing some big, stupid mistake reveals itself by attacking others, and that we can maybe reason from that, that the majority of programmers are not well trained for their job. But that would be only a mere speculation to discuss with friends on a lazy evening...&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-6804157334734692975?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/6804157334734692975/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=6804157334734692975' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6804157334734692975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6804157334734692975'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2010/11/engineering-decency.html' title='Engineering Decency'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-5459000595088131639</id><published>2010-08-16T14:14:00.000-07:00</published><updated>2010-08-16T14:46:01.786-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Named function arguments for C++</title><content type='html'>&lt;p&gt;&lt;/p&gt;For me a high quality code is a readable one. Consider a hypothetical method like this:&lt;br /&gt;&lt;pre&gt;  class XXX:&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    void func(int aaa, string bbb, bool optionX = true);&lt;br /&gt;    ...&lt;br /&gt;  };&lt;/pre&gt;now try to call it:&lt;br /&gt;&lt;pre&gt;  func(1, "test", true);&lt;/pre&gt;What irritates me here is, that &lt;strong&gt;I don't know what exactly does &lt;em&gt;true&lt;/em&gt; mean at the first glance&lt;/strong&gt;! Thus I found myself quite often writting code like this:&lt;br /&gt;&lt;pre&gt;  bool useOptionX = true;&lt;br /&gt;  func(1, "test", useOptionX);&lt;/pre&gt;Well, that's better, but what about this:&lt;br /&gt;&lt;pre&gt;  bool useOptionX = false;&lt;br /&gt;  func(1, "test", useOptionX); &lt;span style="color:#009900;"&gt;// should I use it or not?&lt;/span&gt;&lt;/pre&gt;a little bit misleading, isn't it? Not that this would be a big problem, but it's nevertheless a small hitch obstructing us from reading the code effortlesly. OK, next try:&lt;br /&gt;&lt;pre&gt;  bool dontUseOptionX = false;&lt;br /&gt;  func(1, "test", dontUseOptionX ); &lt;span style="color:#009900;"&gt;&lt;span style="color:#009900;"&gt;// don't use is false, so I should use it?&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;A total mess! And what about constructors?&lt;br /&gt;&lt;pre&gt;  class XXX:&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    XXXX(bool optionY);&lt;br /&gt;  ...&lt;br /&gt;  };&lt;/pre&gt;&lt;pre&gt;  class YYY: public XXX&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    YYY() : XXX(true) {}; &lt;span style="color:#009900;"&gt;// true what???&lt;/span&gt;&lt;br /&gt;  ...&lt;br /&gt;  };&lt;/pre&gt;Call me pedantic, but I don't like that at all! What we really need here are Python's named arguments:&lt;br /&gt;&lt;pre&gt;  sameFuncInPython(aaa=&lt;span style="color:#6600cc;"&gt;1&lt;/span&gt;, bbb=&lt;span style="color:#990000;"&gt;"pythonistas"&lt;/span&gt;, optionX=&lt;span style="color:#6600cc;"&gt;True&lt;/span&gt;)&lt;/pre&gt;Simple, effective, readable! Is there a way to emulate this in C++? Recently, as I was especially annoyed with the constructor example from above, I devised a following solution:&lt;br /&gt;&lt;pre&gt;  class XXX:&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    XXXX(bool optionY);&lt;br /&gt;    ...&lt;br /&gt;    typedef useOptionY bool;&lt;br /&gt;  };&lt;/pre&gt;&lt;pre&gt;  class YYY: public XXX&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    YYY() : XXX(useOptionY(true)) {};&lt;br /&gt;    ...&lt;br /&gt;  };&lt;/pre&gt;and now the other code can be wtritten totally plausibly too:&lt;br /&gt;&lt;pre&gt;  typedef bool useOptionX; &lt;span style="color:#009900;"&gt;// local namespace!&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;  func(1, "test", useOptionX(false));&lt;br /&gt;  func(1, "test", useOptionX(false)); &lt;/pre&gt;and what would you say to the following?&lt;br /&gt;&lt;pre&gt;  waitOnSocket(sec(1), usec(20));&lt;/pre&gt;&lt;p&gt;Small thing, but it improves my source code. I like it!&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;&lt;span style="font-size:130%;"&gt;PS:&lt;/span&gt; After I wrote this, I remembered reading something in this vein about Java. And really, this post &lt;a href="http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/"&gt;http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/&lt;/a&gt; by &lt;em&gt;Codemokeyism&lt;/em&gt; proposes generally the same solution: &lt;/p&gt;&lt;pre&gt;  new Customer(firstName(&lt;span style="color:#990000;"&gt;"Stephan"&lt;/span&gt;), name(&lt;span style="color:#990000;"&gt;"Schmidt"&lt;/span&gt;)); &lt;/pre&gt;Alas, instead of a benign &lt;em&gt;typedef&lt;/em&gt;, you have to write a whole new class named &lt;em&gt;name&lt;/em&gt; and &lt;em&gt;firstName&lt;/em&gt; etc. Without doubt it's and improvement, but the costs and the clutter... But on the other side Java tends to be verbose nonetheless, so maybe it's OK.&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-5459000595088131639?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/5459000595088131639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=5459000595088131639' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/5459000595088131639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/5459000595088131639'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2010/08/named-function-arguments-for-c.html' title='Named function arguments for C++'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-888990991749389843</id><published>2010-06-14T10:07:00.000-07:00</published><updated>2010-08-16T14:39:57.665-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='multithreading'/><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><title type='text'>Javascript on the server?</title><content type='html'>&lt;p&gt;&lt;/p&gt;Recently, I stumbled upon an iteresting presenation about server I/O parallelism and multithreading. Surprisingly it was in a &lt;em&gt;Javascript&lt;/em&gt; conference, as I sometimes have a look at the &lt;em&gt;Javascript&lt;/em&gt; language developments. I'd never expect to find something like that in this contex though.&lt;br /&gt;&lt;br /&gt;The general message of the presentation was that threads suck and asynchronous programing is the king. Come again? I don't quite agree with that (or rather agreed, as you'll see in brief) - wasn't that for the threads to save us from the onerous asynchrounous programming with its context information and callbacks (remember Windows event programming?)! The threads justly delivered a convenient abstraction to group the logically connected data and logic in separate units of execution. &lt;strong&gt;So now we are doing a full circle: from asynchronous to threads to asynchronous?&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;OK, on the surface that may be looking like that, but there's more to that. The problem is that when we apply threads to parallel I/O they are just to slow (you know, context switching, thread stampedes and all that). Thus there's a host of asynchronous I/O methods starting with the venerable &lt;em&gt;select()&lt;/em&gt; UNIX call. Ok, agreed, for that special field the threading model isn't very appealing, but for the general usage I'd just hide this inside of an I/O thread...&lt;br /&gt;&lt;br /&gt;Now there's this pesentation (Ryan Dahl’s &lt;a href="http://jsconf.eu/2009/video_nodejs_by_ryan_dahl.html"&gt;talk&lt;/a&gt; on &lt;em&gt;Node.js&lt;/em&gt;) and what the author says is exactly that: callbacks and asynchronicity are good! How that? We all know it's a pain in practice? His response (an this is the valuable insight got when watching this) is that we just didn't have a good enough programming language to realise that! When you do in in C (as you'd likely to do when programming performant I/O) you are messed up, but if you take &lt;em&gt;Javascript&lt;/em&gt;...&lt;br /&gt;&lt;br /&gt;See, that's the crux here: &lt;em&gt;Javascript&lt;/em&gt; was &lt;strong&gt;designed&lt;/strong&gt; &lt;strong&gt;to work in a callback driven environment&lt;/strong&gt;, so the language has unique mechanisms which no other language can offer. Thus if we take Javascript and do event oriented programming it's a breeze then! The idea is to take the ultra higspeed C library (&lt;em&gt;libev&lt;/em&gt; in that case) and wrap it with event-friendly &lt;em&gt;Javascript&lt;/em&gt; hull. Here's an example code from &lt;a href="http://nodejs.org/"&gt;node.js&lt;/a&gt; site:&lt;pre&gt;  var net = require('net');&lt;br /&gt;  net.createServer(function (socket) {&lt;br /&gt;    socket.setEncoding(&lt;span style="color:#006600;"&gt;"utf8"&lt;/span&gt;);&lt;br /&gt;    socket.addListener(&lt;span style="color:#006600;"&gt;"connect"&lt;/span&gt;, function () {&lt;br /&gt;      socket.write(&lt;span style="color:#006600;"&gt;"Echo server\r\n"&lt;/span&gt;);&lt;br /&gt;    });&lt;br /&gt;    socket.addListener(&lt;span style="color:#006600;"&gt;"data"&lt;/span&gt;, function (data) {&lt;br /&gt;      socket.write(data);&lt;br /&gt;    });&lt;br /&gt;    socket.addListener(&lt;span style="color:#006600;"&gt;"end"&lt;/span&gt;, function () {&lt;br /&gt;      socket.end();&lt;br /&gt;    });&lt;br /&gt;  }).listen(8124, &lt;span style="color:#006600;"&gt;"127.0.0.1"&lt;/span&gt;);&lt;/pre&gt;&lt;p&gt;Well, maybe it isn't a thing of beauty (if you're not into &lt;em&gt;Javascript&lt;/em&gt;) but it's concise, everything is at one place, and you can read it without reading tons of manuals first. So maybe this is the way of doing this? Another thing I liked that &lt;em&gt;node.js&lt;/em&gt; never provides a blocking API - even filesystem calls are asynchronous! That's consequence!&lt;br /&gt;&lt;br /&gt;Sorry for the short post, but it's summer, I want to go out and watch some worldcup!&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;br /&gt;1. the talk to be found here: &lt;a href="http://jsconf.eu/2009/video_nodejs_by_ryan_dahl.html"&gt;http://jsconf.eu/2009/video_nodejs_by_ryan_dahl.html&lt;/a&gt;&lt;br /&gt;2. and here's the code: &lt;a href="https://gist.github.com/a3d0bbbff196af633995"&gt;https://gist.github.com/a3d0bbbff196af633995&lt;/a&gt;&lt;br /&gt;3. if you'd like some more technical details, here's an excellent post by Simon Wilson: &lt;a href="http://simonwillison.net/2009/Nov/23/node/"&gt;http://simonwillison.net/2009/Nov/23/node/&lt;/a&gt;&lt;br /&gt;4. node.js critique (yes, there's such a thing too!): &lt;a href="http://al3x.net/2010/07/27/node.html"&gt;http://al3x.net/2010/07/27/node.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Addendum:&lt;/strong&gt;&lt;br /&gt;- here is a simple blog engine in less than 200 lines of code using &lt;em&gt;node.js &lt;/em&gt;: &lt;a href="http://github.com/zefhemel/persistencejs/blob/master/test/node-blog.js"&gt;http://github.com/zefhemel/persistencejs/blob/master/test/node-blog.js&lt;/a&gt;. Not bad, I'd say.&lt;br /&gt;- &lt;em&gt;Multi-node&lt;/em&gt;: how to implement a &lt;strong&gt;concurrent&lt;/strong&gt; &lt;em&gt;node.js&lt;/em&gt; HTTP server: &lt;a href="http://www.sitepen.com/blog/2010/07/14/multi-node-concurrent-nodejs-http-server/"&gt;http://www.sitepen.com/blog/2010/07/14/multi-node-concurrent-nodejs-http-server/&lt;/a&gt;&lt;br /&gt;- &lt;em&gt;Hummingbird&lt;/em&gt;: an impressive application based on &lt;em&gt;node.js &lt;/em&gt;- &lt;a href="http://mnutt.github.com/hummingbird/"&gt;http://mnutt.github.com/hummingbird/&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-888990991749389843?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/888990991749389843/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=888990991749389843' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/888990991749389843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/888990991749389843'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2010/06/nodejs.html' title='Javascript on the server?'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-357129503399205970</id><published>2010-06-13T09:36:00.000-07:00</published><updated>2010-08-16T14:36:49.857-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><title type='text'>Software estimation and re-reading the classics</title><content type='html'>&lt;p&gt;&lt;/p&gt;Recently I stumbled upon the &lt;em&gt;"Software Top-Ten List"&lt;/em&gt;* again. At first I though, OK, that's old, they did mainframes at that time! But then I read it nonetheless. Maybe because it's so short? It's only 3 pages. Whatever. I read it I was surprised about how refreshing it was. Not mouldy, stale and irrelevent, but interesting and fresh! Surprisingly, because the findings are supposed to be well known.&lt;br /&gt;&lt;br /&gt;One interesting thought came after I read the point 8:&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;Software systems and software products each typically cost 3 times as much per instruction to fully develop as does an individual software program.&lt;/em&gt; &lt;/blockquote&gt;I immediately thought about that old estimation rule: estimate how long it will take to be done, and then multiply it by two. I always though it to be unserious or a manifestation of intellectual laziness. What, you aren't able to say how long this effing program will take to be written? Just sum up the parts (as shown below)!&lt;br /&gt;&lt;br /&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 320px; DISPLAY: block; HEIGHT: 267px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5482668754058180018" border="0" alt="" src="http://4.bp.blogspot.com/_79IsVE3vX_Y/TBZaLvLFdbI/AAAAAAAAAGE/jVz8EyC5-as/s320/estimate.jpg" /&gt; But let's look at the problem from a little more different angle: what if programmers do not take into account the costs of polishing the program, making it user-friendly, plus all the problems and dependencies from other programmers located in other deparments of the company - &lt;em&gt;"L'enfer, c'est les autres"! &lt;/em&gt;Normally you do not take this factors into account when estimating, and you even cannot estimate it properly. We use either a brute-force 20% project buffers or a statistical estimate based on the PERT method, but it somehow doesn't work out that good. &lt;p&gt;So maybe we should take the above citied measurement data, at use it when estimating? Just multiply our technical-only estimate by the "real world" factor? Personally, I still cannot believe that the "real world" factor be so high as 3! Am I too optimistic? But I think that &lt;em&gt;f&lt;span style="font-size:78%;"&gt;rw&lt;/span&gt;&lt;/em&gt;&lt;span style="font-size:100%;"&gt;&lt;em&gt;=2&lt;/em&gt; should be a good choice! &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Although I'm a little afraid here, as I always imprement a given piece of code faster than my own PERT estimate. But recently, when estimating the entire system, I missed the point completely: new requirements, unexpected dependencies on not so great libraries, the internal pressure to please the customer... This all sums up in a greater project! An at that point I should have been to muliply so high as by 4! Welcome in the real world.&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;* Harry W. Boehm, "Industrial Software Metrics: A Top-Ten List", &lt;/span&gt;&lt;a href="http://csse.usc.edu/csse/TECHRPTS/1985/usccse85-499/usccse85-499.pdf"&gt;http://csse.usc.edu/csse/TECHRPTS/1985/usccse85-499/usccse85-499.pdf&lt;/a&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-357129503399205970?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/357129503399205970/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=357129503399205970' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/357129503399205970'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/357129503399205970'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2010/06/software-estimation-and-re-reading.html' title='Software estimation and re-reading the classics'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_79IsVE3vX_Y/TBZaLvLFdbI/AAAAAAAAAGE/jVz8EyC5-as/s72-c/estimate.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-6268764529112607920</id><published>2010-04-29T09:59:00.000-07:00</published><updated>2010-08-16T14:35:54.472-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Bug hunting or how dumb can you get, really?</title><content type='html'>&lt;p&gt;As a programmer you sometimes can't help but feel really stupid! Really stupid-stupid! Look at this code snippet for example of a foolish bug that kept me busy for some time. The story behind this is that I added a feature to the product I'm writing for a customer, and was totally happy with it. There was a real customer benefit and it worked like a charm through my tests. However, when deployed to the internal test system, it crashed unexpectedly now and than. &lt;/p&gt;&lt;p&gt;That was a kind of shock, because the product was running stable for more than a year in this environment, and I was totally unsettled as I didn't want to believe that the new feature could have something to do with it. It was tested rock-solid. There must be a mysterios bug somewhere else in the program. And it hid for one year before it disclosed its identity! Bad! &lt;/p&gt;&lt;p&gt;However, after I ran the collected test data on my development machine, it turned out to be a pretty uncomplicated bug:&lt;/p&gt;&lt;pre&gt;    for(size_t i = 0; i &amp;lt; a_prInput-&gt;frameCount(); i++)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color:#009900;"&gt;// header&lt;/span&gt;&lt;br /&gt;        size_t start = a_prInput-&gt;NettoDataParts[i].uOffset;&lt;br /&gt;        size_t pos = start;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;        DnsHeaderData header = parseHeader(a_prInput, pos);&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;        &lt;span style="color:#009900;"&gt;// interesting data there?&lt;/span&gt;&lt;br /&gt;        if(!header.isResponse)&lt;br /&gt;        {&lt;br /&gt;            TRACE("dns: packet isn't a response, ignoring...");&lt;br /&gt;            continue;&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;        &lt;span style="color:#009900;"&gt;// skip the questions&lt;/span&gt;&lt;br /&gt;        for(int i = 0; i &amp;lt; header.questions; i++)&lt;br /&gt;        {&lt;br /&gt;            if(!parseDnsName(a_prInput, start, pos))&lt;br /&gt;            {&lt;br /&gt;                TRACE_ERR("dns: cannot parse a question record");&lt;br /&gt;                m_uGoodByteCnt = pos - a_prInput-&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;NettoDataParts&lt;/span&gt;&lt;span style="color:#cc0000;"&gt;[i]&lt;/span&gt;&lt;/strong&gt;.uOffset;&lt;br /&gt;&lt;br /&gt;                continue;&lt;br /&gt;            }&lt;/pre&gt;&lt;p&gt;You see? The code was referencing the data form the outer loop with the index of the inner one! And it did it only in error case, and crashed only if it was out of luck. Arrgh... There was no problem with fixing this, but it started me thinking: &lt;strong&gt;I'm programming for some 20 years, I know C++ in and out, why did I make this bug in the first place?&lt;/strong&gt; Did I violate some programming rule or best practice? Is it possible to avoid such bugs by some sound practices? Some answers come to mind: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;There should be a warning from compiler&lt;br /&gt;That would be the ideal solution. But what warning should that be? And what if I really wanted this that way? I'd need to use an ugly &lt;em&gt;#pragma&lt;/em&gt; then? No, better let it be.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;I should have used &lt;em&gt;at()&lt;br /&gt;&lt;/em&gt;What should I say, er, well, &lt;em&gt;at()&lt;/em&gt; is for wimps! And if that wouldn't be the case, we have a choice between at() and the [] operator. So we want to excercise our rights!&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Use telling names&lt;br /&gt;Well, of course, I could name each loop variable accordingly, but come on, can you imagine the hassle? Because if this has to be of any good you have to be consequent. So maybe only do this for nested loops? Maybe, but if I start to do this as to avoid this error, and something else to avoid some other error, you guess it, it becomes a pain! We need something more general,&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Use &lt;em&gt;for_each()&lt;/em&gt;, as we don't do any addressing here&lt;br /&gt;That's more interesting, as logically speaking, the inner loop isn't indexing single elements, but rather wants only to skip over the uninteresting headers. But, on the other side, &lt;em&gt;for_each()&lt;/em&gt; is annoying, as it requires start and end of the sequence, which isn't a problem if I'd use the iterator, but gets pointless if I never want to use the iterator directly! &lt;/li&gt;&lt;br /&gt;&lt;li&gt;use iterators to go high level&lt;br /&gt;Isn't that the same as the above? No, because it's not an application of a specific technique in a specific situation, but rather a conscious decition for rising of the abstraction level. And quite serendipitously we can avoid the above mentioned error! Or are we? What if both outer and inner loop are using the same name for the iterators? Here we are agan back on the square one and have to use &lt;em&gt;for_each()&lt;/em&gt; for the inner loop as to be safe.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Alas, none of them is satisfactory. Well, I know, there's one more solution: &lt;strong&gt;code reviews (or pair programming).&lt;/strong&gt; But first, my customer isn't doing them that often, and second, I doubt this bug would be found in a review/pair. But even assuming it would be found: the price is much to hight! It took me a couple of minutes to fix it, once I had the right data, and my customer expects "results just now".&lt;/p&gt;&lt;p&gt;What is the key point? What does this all mean? Are we doomed? I think that there are two possiblities here: either use iterators or some other high level constructs (which admittedly is somehow of an overkill), or be prepared for occasionally fits of stupidity. In the end we are only humans, and &lt;em&gt;errare humanum est... &lt;/em&gt;And who wants to be safeguarded against everything?&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;&lt;span style="font-size:130%;"&gt;PS:&lt;/span&gt; Sorry, I started this entry long ago, but in the meantime I was so distracted that I couldn't come round to write anything for the blog. Besides, microblogging isn't doing it any easier ;-).&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;PS2:&lt;/span&gt; Other possibility: write shorter functions, use a &lt;em&gt;skipNameRecords() &lt;/em&gt;method and you are saved! But really, that function is under 1 page lenght, How long should functions be? Five lines or so? Or seven as adjust to humain brain's cognitive limitations?&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-6268764529112607920?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/6268764529112607920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=6268764529112607920' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6268764529112607920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6268764529112607920'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2010/04/bug-hunting-or-how-dumb-can-you-get.html' title='Bug hunting or how dumb can you get, really?'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-6201384203462603930</id><published>2010-02-28T11:18:00.001-08:00</published><updated>2010-02-28T11:23:41.219-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Fooling the ODR (and the compiler)</title><content type='html'>&lt;p&gt;&lt;/p&gt;I just discovered a technique that is prety convenient but rather not self-explaining, nonportable (?), and possibly a maintenance nightmare. So you should never use it, should you? Except, as it's sort of cool, if you'd like to go a little on the geeky side...&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;1. The need for speed&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Imagine you are writing some quick classes in the Java style (i.e. no header files), locate them in some C++ source file, and forget about them. Then you discover that you need to refactor your program (in my case it was a custom test framework) and to move some classes out to a separate file (a.k.a. compilation unit). &lt;strong&gt;Now you shun to do the right thing&lt;/strong&gt; (i.e. to refactor) because you'd have to cut up your classes in two: the .h file and the .cc file, &lt;strong&gt;and to duplicate some (non always trivial) amount of code&lt;/strong&gt;. So yo aren't doing that...&lt;br /&gt;&lt;br /&gt;But stop,&lt;strong&gt; following trick did it for me&lt;/strong&gt;: I defined the classes in a separate .h file and kept the .cc file with the extracted classes unchanged. I included the new .h file in the rest of the old .cc file where the classes were removed from. Then I just linked the the whole thing, et voilá, everything worked like a breeze - a refactoring as we like it!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;2. Why does it work?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But wait, we spared some editing work, but didn't we violate the One Definition Rule of C++? I'd say we did. So why didn't the compiler complain? Well, as to answer it, we've got to look at the example a little closer.&lt;br /&gt;&lt;br /&gt;The extracted classes looked like that:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;TestThreads.cpp:&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;&lt;em&gt;&lt;/em&gt;&lt;pre&gt;  #include &lt;span style="color:#cc0000;"&gt;"WorkerThread.hpp"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:#009900;"&gt;// test thread A&lt;br /&gt;&lt;/span&gt;  class ThreadA : public WorkerThread&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    &lt;span style="color:#009900;"&gt;...&lt;/span&gt;&lt;br /&gt;  private:&lt;br /&gt;    &lt;span style="color:#009900;"&gt;...&lt;/span&gt;&lt;br /&gt;  } g_workerA;&lt;/pre&gt;&lt;pre&gt;  &lt;span style="color:#009900;"&gt;// test thread B&lt;br /&gt;&lt;/span&gt;  class ThreadB : public WorkerThread&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    &lt;span style="color:#009900;"&gt;...&lt;/span&gt;&lt;br /&gt;  private:&lt;br /&gt;    &lt;span style="color:#009900;"&gt;...&lt;/span&gt;&lt;br /&gt;  } g_workerB;&lt;/pre&gt;Note that there's no &lt;em&gt;TestThreads.hpp&lt;/em&gt; definition file here, thus we don't have a direct ODR violation for the compiler to complain! The newly created definitions file &lt;em&gt;TestThreads.hpp&lt;/em&gt; looked like this:&lt;pre&gt;  #include &lt;span style="color:#cc0000;"&gt;"WorkerThread.hpp"&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;  class ThreadA : public WorkerThread&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    virtual void addRequest(Request&amp;amp; r);&lt;br /&gt;    &lt;span style="color:#009900;"&gt;...&lt;/span&gt;&lt;br /&gt;  };&lt;/pre&gt;&lt;pre&gt;  class ThreadB : public WorkerThread&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    virtual void addRequest(Request&amp;amp; r);&lt;br /&gt;    &lt;span style="color:#009900;"&gt;...&lt;/span&gt;&lt;br /&gt;  };&lt;/pre&gt;The &lt;em&gt;WorkerThread.hpp&lt;/em&gt; definition file looks like this:&lt;br /&gt;&lt;pre&gt;  class WorkerThread&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    virtual void addRequest(Request&amp;amp; r);&lt;br /&gt;    &lt;span style="color:#009900;"&gt;...&lt;/span&gt;&lt;br /&gt;  };&lt;/pre&gt;And the rest of the&lt;em&gt; TestMain.cpp&lt;/em&gt; file where the TestThread classes were previously placed:&lt;br /&gt;&lt;pre&gt;  #include &lt;span style="color:#cc0000;"&gt;"TestThreads.hpp"&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/span&gt;  extern TestThreadA g_workerA;&lt;br /&gt;&lt;br /&gt;  extern TestThreadB g_workerB;&lt;/pre&gt;&lt;pre&gt;  g_workerA.addRequest(req);&lt;/pre&gt;Can you see why we could fool the ODR? Well, in this special case we didn't used the constructors directly in the &lt;em&gt;TestMain.cpp&lt;/em&gt; file, only the methods of the &lt;em&gt;WorkerThread&lt;/em&gt; superclass which then call the appropriate virtuall methods defined in the &lt;em&gt;ThreadA&lt;/em&gt; class.&lt;br /&gt;The linker then generates a reference to the virtual &lt;em&gt;ThreadA::addRequest()&lt;/em&gt; method. Well, guess what, a method with the very name can be found in &lt;em&gt;TestThreads.cpp&lt;/em&gt;, and the linker can resolve it no probs!&lt;br /&gt;&lt;br /&gt;Although we clearly have two definitions of the &lt;em&gt;ThreadA&lt;/em&gt; class, we get away with it! The ultimate reason for that is that the C++ compiler doesn't have the global knowledge of the whole program - it works only on the compilation unit level, and the relinquishes the responsibility for the complete programm to the linker! I.e. there's no whole programm optimization possible (at least not in the standard model, although Visual C++ compiler can do it).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;3. How to extend the "hidden" classes?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Suppose we'd like to call a new method in the &lt;em&gt;TestThread.cpp&lt;/em&gt; file from the outside. You cannot call this method directly, as we do not include the real definitions of the &lt;em&gt;TestThread&lt;/em&gt; classes, but only the "fake" ones. &lt;strong&gt;Alas, there is a price to pay for fooling the compiler and for beeing lazy!&lt;/strong&gt; The price here is, that we have to modify the base class (&lt;em&gt;TestWorker.hpp&lt;/em&gt;) by adding a new public virtual method, if we need a new &lt;em&gt;TestThreadA&lt;/em&gt; method to be called in the &lt;em&gt;TestMain.cpp&lt;/em&gt; file!&lt;br /&gt;&lt;br /&gt;Not pretty, uh? You know, sometimes you can go away with breaking the rules, but in the end you'll have to face the consequences. In the art of software design, your skills are measured at your ability to estimate for how long you will go away with laziness and tricks, and when you have to resort to the known, sound and boring "best practices".&lt;br /&gt;&lt;br /&gt;But nonetheless, the price I had to pay was OK for the deeper knowledge of the compiler-linker cooperation and the increased knowlede of my own code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-6201384203462603930?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/6201384203462603930/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=6201384203462603930' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6201384203462603930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6201384203462603930'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2010/02/fooling-odr-and-compiler.html' title='Fooling the ODR (and the compiler)'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-7738264472826176216</id><published>2010-02-14T12:11:00.000-08:00</published><updated>2010-07-03T04:47:05.644-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='patterns'/><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><title type='text'>Do you GoF - the belated anniversary and the ladder</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;p&gt;Last year we had the 15th (or so?) anniversary of the seminal &lt;em&gt;"Gang of Four"&lt;/em&gt; book. Is it that old already? So maybe discussing the design patterns is all an old and boring stuff now? Well, shame on me, I wanted to write up my ideas on that matter for such a long time that I run the risk of them beeing irrelevant. But on the other side it's a kind of unfinished business for me, and I have a to kind of close it up.&lt;br /&gt;&lt;br /&gt;Some time ago I &lt;a href="http://ib-krajewski.blogspot.com/2007/09/do-you-gof.html"&gt;wondered&lt;/a&gt; - why didn't I use the design patterns that much in my programming and design work? I came to the conclusion then, that the design patterns are useful as a common vocabulary as to speak about designs, but then some new ideas surfaced in my mind. By the way, why should I use a pattern vocabulary if I don't use any patterns in my designs?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;1. Ideas from chess and math&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_79IsVE3vX_Y/S3hlIwj8O5I/AAAAAAAAAF8/yh33mQkfZuI/s1600-h/chess_mate_rowtrap.gif"&gt;&lt;img style="MARGIN: 0px 10px 10px 0px; WIDTH: 118px; FLOAT: left; HEIGHT: 121px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5438207751198882706" border="0" alt="" src="http://2.bp.blogspot.com/_79IsVE3vX_Y/S3hlIwj8O5I/AAAAAAAAAF8/yh33mQkfZuI/s320/chess_mate_rowtrap.gif" /&gt;&lt;/a&gt;If you're playing chess (need a Wikipedia link here? ;-) you are accustomed to seeing the board in patterns: check-mate patterns it is! You try to imagine what kind of a check-mate setup could be possible in a given situation, and then work towards that by moving your pieces and trying to chase away your opponent's pieces as to complete the pattern you have in your mind. I must admit that I never had this feeling when writing software. Some pattern in my mind which is the solution for some design problem? Nope.&lt;br /&gt;&lt;br /&gt;Read the &lt;em&gt;"Refactoring to Patterns"&lt;/em&gt; book by Joshua Kerievsky? When I first heard of the book &lt;strong&gt;I though he struck the right idea&lt;/strong&gt;: only use patterns to refactor code which is a mess. But then when actually reading the book, it was rather a feeling (in most cases) of doing something wrong to the code, well, like overengineering it! So the book didn't reconcile me with patterns too, as it didn't give me the chess-like feeling of a pattern just matching a given situation.&lt;br /&gt;&lt;br /&gt;The other problem with patterns is their presentation. This overly formal template with "Forces" (why not just problems?), "Intent", "Consequences", etc, etc... This makes me think about &lt;em&gt;"The mathematicians lament"&lt;/em&gt;* - where a matematician reproaches his fellow scientists of over-formalization of mathematics with the effect of its incomprehensibility. What he is saying is basically the following: yes we need the formalism, but only in some very difficult cases where our intuitions don't work. But not in every and one case: &lt;em&gt;"nobody's dying here!"&lt;/em&gt;*, you can relax a bit!&lt;br /&gt;&lt;br /&gt;It's the same with patterns: the stern formality of presentation is both somehow comical and making the contents rather indigestible, and an dry, uninspiring read. I can only say, relax, we are not deliberating about the meaninig of infinity like Cantor did! We are just describing some not so complicated techniques of object composition! Could you stop to be so pompous?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;2. Dreyfus et al.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Do you know the Dreyfus model of knowledge acquisition**? It defines several phases in learning a specific skill: beginner, advanced beginner, competent, proficient and expert. Beginners need rules and recipies, competents can continue learning on their own, proficients and experts see the big picture and fly by the seat of his pants.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://unifyingnotion.files.wordpress.com/2008/04/dreyfus_model.jpg"&gt;&lt;img style="MARGIN: 0px 10px 10px 0px; WIDTH: 530px; HEIGHT: 370px; CURSOR: hand" border="0" alt="" src="http://unifyingnotion.files.wordpress.com/2008/04/dreyfus_model.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Where do the design patterns fit in this scheme?&lt;/strong&gt; Well, at the beginner level they aren't useful, as they are not "step by step" recipies. On the other side, for the proficients and experts, they are some kind of rules, and experts do not like rules and recipies by definition!&lt;br /&gt;&lt;br /&gt;I personally think that patterns appeal rather to the lower ranges of the skill spectrum. Did you see the hopelessly overengineered software full of design patterns written by the beginners? I've seen it only too often!&lt;br /&gt;&lt;br /&gt;So maybe they are for the competent? And the usage by competent and proficient users? Let me tell you a little story here. It's not entirely true that I don't use patterns! Lately, I thought that I could warrant the use of the visitor pattern in my current product, as to extract the reporting aspect out of several content managing classes. Well, it has a kind of worked at first, but now, as this whole aspect has to be redesigned, I noticed that this design is rather unintuitive and I cannot simplify the reporting without dumping visitor first. Ok, experiment failed, but my initial problem was that I didn't really search for a solution of my problem, but rather stopped at the point where I found the (as I thought then) matching design pattern! But I didn't think it trough as thoroughly as I should!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;3. Summing up&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So maybe the thing with patterns is that they are like the "Wittgenstein's Ladder"? You know, what he said in his &lt;em&gt;"Tractatus Logico-Philosophicus"&lt;/em&gt; (I cite from memory): &lt;/p&gt;&lt;blockquote&gt;&lt;em&gt;...this book is like a ladder, use it, but then throw it away.&lt;/em&gt;&lt;/blockquote&gt;Isn't it the same with patterns? &lt;strong&gt;Use them to expand your experience, but don't use them in your software! &lt;/strong&gt;And as to make the discussion complete, let us state a completely different point of view, a Lisper's critique***: &lt;blockquote&gt;&lt;em&gt;When I see patterns in my programs, I consider it a sign of trouble. The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least, that &lt;strong&gt;I'm using abstractions that aren't powerful enough&lt;/strong&gt;-- often that I'm generating by hand the expansions of some macro that I need to write.&lt;/em&gt;&lt;/blockquote&gt;&lt;p&gt;This is the typical smug Lisp programmer assertion, as they mean that all other languages will in limes converge to Lisp, but newly I tend to think along the lines of the Lispers: the design patterns are a fix for lacking feature in language A, which you know from language B. But as we cannot change the language in most cases, and we are doing OO in the mainstream, just mind the ladder parable!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Update (June 2010):&lt;/span&gt; &lt;/strong&gt;There's another explanation which I didn't think of before. I came across that when reading some programming book (which I cannot come up with now, &lt;span style="color:#ff0000;"&gt;sorry&lt;/span&gt; for the author!). Recall the mid 90-ties: it was the time of the "object craze", everybody wanted to be part of OO. But nobody really understood OO, and as the book went &lt;em&gt;"Stroustrup gave us the C++ but he didn't tell us how to use it"&lt;/em&gt;! Her come the patterns, a kind of missing OO manual! This would explain my feelin that half of them was trivial (or not so difficult to figure them up by yourself) and the other half was implemeting language features missing from C++. Very sober diagnose, but at the moment it's my favourite.&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* Paul Lockhart, &lt;em&gt;"A Mathematician’s Lament", &lt;/em&gt;&lt;a href="http://www.maa.org/devlin/LockhartsLament.pdf"&gt;www.maa.org/devlin/LockhartsLament.pdf&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;** I found it in the book of Andy Hunt, &lt;em&gt;"Pragmatic Thinking and Learning"&lt;/em&gt;, Pragmatic Bookshelf, Oct. 2008, but here's a blog post &lt;a href="http://blog.bruceabernethy.com/post/The-Dreyfus-Model-of-Skills-Acquisition.aspx"&gt;link&lt;/a&gt;, and here &lt;a href="http://www.coderfriendly.com/2009/05/22/when-do-we-reach-the-expert-stage/"&gt;another one&lt;/a&gt; &lt;/p&gt;&lt;p&gt;*** Paul Graham, "Revenge of the Nerds", &lt;a href="http://paulgraham.com/icad.html"&gt;http://paulgraham.com/icad.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-7738264472826176216?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/7738264472826176216/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=7738264472826176216' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7738264472826176216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7738264472826176216'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2010/02/do-you-gof-belated-anniversary-and.html' title='Do you GoF - the belated anniversary and the ladder'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_79IsVE3vX_Y/S3hlIwj8O5I/AAAAAAAAAF8/yh33mQkfZuI/s72-c/chess_mate_rowtrap.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-7481825544492963345</id><published>2009-12-21T00:56:00.001-08:00</published><updated>2010-01-05T04:51:23.559-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='misc'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Local language trends 2009</title><content type='html'>&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's have a look at the languages which are most popular in the freelance 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 be 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: 491px; CURSOR: hand; HEIGHT: 308px; 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 with 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 includes 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 unmistakeably the 500 pound gorilla here, but it's 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, and 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 (still 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 (plus "service and support"), however the suply here 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 &lt;em&gt;SAP&lt;/em&gt; programming - in the past the eternal cash cow with 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 of "IT consulting", where I don't have any idea what it is, sorry, no comments there :-/. One interesting field is "Executive consulting" with so much demand and so little supply, maybe everyone is just 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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/7481825544492963345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=7481825544492963345' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7481825544492963345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7481825544492963345'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/12/local-language-trends-2009.html' title='Local language trends 2009'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></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>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-1554477698462078016</id><published>2009-12-16T14:07:00.001-08:00</published><updated>2010-02-16T13:04:04.438-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Even more new C++ features!</title><content type='html'>&lt;p&gt;&lt;/p&gt;Hi everybody! As I had a look on the new C++ proposal the &lt;a href="http://ib-krajewski.blogspot.com/2009/01/ive-read-on-my-local-german-c-forum.html"&gt;last time &lt;/a&gt;, I found many small interesting things apart form the big, important features. But this was only a first look. Recently I had another look there (and at the C++0x FAQ* by Bjarne Stroustrup as well) and discovered even more interesting crittures. So what did I miss?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;&lt;strong&gt;1. &lt;/strong&gt;Some Syntax&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;First of all the &lt;strong&gt;new function definition syntax&lt;/strong&gt;! Now I can write something like*:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  using PF [](double) -&amp;gt; void;&lt;/pre&gt;along the lines of lambda function definition! Well, that's definitely a treat, what a relief from&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  typedef void (*PF) (double);&lt;/pre&gt;&lt;p&gt;To be honest, I don't know if I've got the last one right, I have always to look thes syntax up or copy and paste from my other code! The &lt;em&gt;[]&lt;/em&gt; notation can be generally used to say to the compiler that "the function type will be specified later"! Thusly we can write the following when usign embedded type like &lt;em&gt;List::Link&lt;/em&gt; &lt;/p&gt;&lt;pre&gt;  [] List::erase(Link* l) -&amp;gt; Link* { ... } ;&lt;/pre&gt;We postpone the return type definition utill we have entered the scope of List, and thus no scope specifier is needed!&lt;br /&gt;&lt;br /&gt;I liked this notation (it makes the code look a little Groovy-like), but alas, it seems that not everyone does so, as the related "auto arrow" notation proposal was rejected recently**! What is auto-arrow? Look at that***:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  auto f() -&amp;gt; int;&lt;br /&gt;  typedef auto PF() -&amp;gt; int;&lt;/pre&gt;the first one is a function from void to int, and the second one is a function type definition for the same signature. Looks good enough, but consider this one:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  auto *pf(auto *p() -&amp;gt; int) -&amp;gt; auto *()-&amp;gt;int;&lt;/pre&gt;I don't even want to discuss what it means, if you are curious look it up in ***! So after that proposal was justly rejected, I'm a little afraid of the fate of the&lt;em&gt; []&lt;/em&gt; notation - is it the next one to be scrutinized? I hope not!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;2. Initalization and initializers&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I though I've understood the new initalizer notation, but I was surprized how ubiquitous it became! At first I though it would be only used in assignment like&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  vector&amp;lt;int&amp;gt; xs = {1, 2, 3 };&lt;/pre&gt;Not so, nowadays you can use it (i.e. the new &lt;em&gt;{}&lt;/em&gt; notation) everywhere, even instead of classic parentheses!&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  X x{a};&lt;br /&gt;  f({a}); &lt;span style="color:#009900;"&gt;// initializes a temporary&lt;/span&gt;&lt;br /&gt;  X* p = new X{a};&lt;/pre&gt;This all does look pretty strange to me, and to be honest I don't like it that much, but on the other side you can use it to avoid verbosity with pretty good results:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  map1.insert({a, b}); &lt;span style="color:#009900;"&gt;// sic!&lt;/span&gt;&lt;/pre&gt;The other improvement with initialization is that we can initialize the string and integer class members directly in the definition of the class!&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  class X&lt;br /&gt;  {&lt;br /&gt;    int a = 7;&lt;br /&gt;    string s{"abcd"}; &lt;span style="color:#009900;"&gt;// new syntax!&lt;/span&gt;&lt;br /&gt;  };&lt;/pre&gt;I can only say&lt;strong&gt; AT LAST&lt;/strong&gt; and amen!!!&lt;br /&gt;&lt;br /&gt;Belonging to the "initialization" block of features, we must mention the access to the inherited constructors (in addition to the also new feature of delegating constructors, i.e. constructors which can be invoked of another constructors of the same class):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  class A { public: A(){} };&lt;br /&gt;  class B : public A&lt;br /&gt;  {&lt;br /&gt;    using A::A; &lt;span style="color:#009900;"&gt;// imports all the A's constructors into current scope!&lt;/span&gt;&lt;br /&gt;  };&lt;/pre&gt;&lt;pre&gt;  &lt;span style="color:#009900;"&gt;// now this is possible:&lt;/span&gt;&lt;br /&gt;  B b;&lt;/pre&gt;At this place I'd like to mention another related feature: disallowing copy and assignment operators. You can write for example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  X&amp;amp; operator= (const&amp;amp; X) = delete;&lt;/pre&gt;to disallow it! Well, if I consider that Google even has a macro exaclty for that reason (&lt;em&gt;DISALLOW_COPY_AND_ASSIGN()&lt;/em&gt;, see &lt;a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Copy_Constructors"&gt;here&lt;/a&gt;) and that I used an UML tool to generate the private version of it for my every class I think that the default-generating them was a bad language design idea! If we want a copy semantics we'd better tell the compiler so! Hindsight is 20/20.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;3. Threading etc.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Of course thread, mutex, condition variables and atomics are there as basic support (as expected). On the higher level we have futures and a &lt;em&gt;packaged_task&lt;/em&gt; class, which wraps features for simpler usage. Moreover, Bjarne does promise that an async task launcher (logically named &lt;em&gt;async&lt;/em&gt;) will be included in C++0x as well. Then we could launch tasks simply like that:&lt;br /&gt;&lt;pre&gt;  auto f1{async(funcX(100))};&lt;br /&gt;  auto f2{async(funcX(200))};&lt;/pre&gt;&lt;pre&gt;  return f1.get() + f2.get(); &lt;span style="color:#009900;"&gt;// waits on both futures&lt;/span&gt;&lt;/pre&gt;If he's right it would be very nice!&lt;br /&gt;&lt;br /&gt;As GC is connected to multithreading in an intimate way (at least in my eyes, sholud blog about it some time soon!), I must state here that the &lt;strong&gt;GC is still missing&lt;/strong&gt;!&lt;br /&gt;&lt;br /&gt;But not entirely, we've got some minimal support for third party garbage collectors in there (&lt;em&gt;20.8.13.7 Pointer safety&lt;/em&gt;). It defines what a "safely drived" (i.e reacheable) or an "disgused" pointer is (&lt;em&gt;3.7.4.3 Safely-derived pointers&lt;/em&gt;) and lets the programmer specify where such pointers can/cannot be found with &lt;em&gt;declare_reachable()&lt;/em&gt;/&lt;em&gt;declare_no_pointers()&lt;/em&gt; functions.&lt;br /&gt;&lt;br /&gt;One thing that struck me however in the threading library classes is the &lt;strong&gt;flexibility of interfaces&lt;/strong&gt;. Take the &lt;em&gt;std::thread&lt;/em&gt;'s constructor for example. You can use it like that ****:&lt;br /&gt;&lt;pre&gt;  void hello_func() { &lt;span style="color:#009900;"&gt;...&lt;/span&gt; }&lt;br /&gt;  &lt;span style="color:#009900;"&gt;// say hello&lt;/span&gt;&lt;br /&gt;  std::thread t{hello_func};&lt;/pre&gt;or like that, using a functor: &lt;pre&gt;  class Greeting&lt;br /&gt;  {&lt;br /&gt;  public:&lt;br /&gt;    explicit Greeting(std::string const&amp;amp; message) { &lt;span style="color:#009900;"&gt;...&lt;/span&gt; }&lt;br /&gt;    void operator()() const  { &lt;span style="color:#009900;"&gt;...&lt;/span&gt; }&lt;br /&gt;    void greet(std::string const&amp;amp; message) const  { &lt;span style="color:#009900;"&gt;...&lt;/span&gt; }&lt;br /&gt;  };&lt;br /&gt;  &lt;span style="color:#009900;"&gt;// say goodbye&lt;/span&gt;&lt;br /&gt;  std::thread t(Greeting("goodbye"));&lt;/pre&gt;or currying the thread function with &lt;em&gt;std::bind&lt;/em&gt;:&lt;br /&gt;&lt;pre&gt;  void greeting_func(std::string const&amp;amp; message) { &lt;span style="color:#009900;"&gt;...&lt;/span&gt; }&lt;br /&gt;  std::thread t(std::bind(greeting_func, "hi!"));&lt;/pre&gt;or without &lt;em&gt;std::bind&lt;/em&gt;:&lt;br /&gt;&lt;pre&gt;  std::thread t(greeting_func, "hi!");&lt;/pre&gt;or without &lt;em&gt;std::bind&lt;/em&gt; and with more arguments:&lt;br /&gt;&lt;pre&gt;  void write_sum(int x, int y){&lt;span style="color:#009900;"&gt; ...&lt;/span&gt; }&lt;br /&gt;  std::thread t(write_sum, 123, 456);&lt;/pre&gt;or using the member function pointer&lt;br /&gt;&lt;pre&gt;  Greeting x;&lt;br /&gt;  std::thread t(&amp;amp;Greeting::greet, &amp;amp;x, "greet");&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:#009900;"&gt;// or by a smart pointer&lt;/span&gt;&lt;br /&gt;  std::shared_ptr&amp;lt;Greeting&amp;gt; ptr(new Greeting);&lt;br /&gt;  std::thread t1(&amp;amp;Greeting::greet, ptr, "hello");&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:#009900;"&gt;// or by reference&lt;/span&gt;&lt;br /&gt;  std::thread t2(std::ref(x));&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:#009900;"&gt;// or directly!&lt;br /&gt;&lt;/span&gt;  std::thread t2(x);&lt;/pre&gt;See, you don't need to worry about the initalization, the new constructs will just take anything you throw at it!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;4. Miscellanea&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;First the &lt;strong&gt;variadic templates&lt;/strong&gt;. What a name for templates with viariable number of arguments! I guess it's an interpolation of the "dyadic" concept which just means "of two arguments" :-). But seriously, we can writhe things like&lt;br /&gt;&lt;pre&gt;  template&amp;lt;typename Head, typename... Tail&amp;gt;&lt;/pre&gt;doing recursion and typematching like in Clojure or Haskell ;-) Well a kind of, but it looks like that at least. Look at the n-tuple definition using variadic templates in Bjarne's FAQ*.&lt;br /&gt;&lt;br /&gt;Further, the new and &lt;strong&gt;improved enums&lt;/strong&gt; (which are class based now) can be now &lt;strong&gt;forward defined ! &lt;/strong&gt;But I'm doing this all the time with C++ Visual Studio 2005! Ouch...&lt;br /&gt;&lt;br /&gt;No for the geeky ones: we have &lt;strong&gt;user defined literals&lt;/strong&gt;! You can define new literal types using the following new operator type: &lt;em&gt;operator""() &lt;/em&gt;(plus &lt;em&gt;constexpr&lt;/em&gt;!), for example&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  "abc"s; &lt;span style="color:#009900;"&gt;// s: string literal&lt;/span&gt;&lt;br /&gt;  2i;     &lt;span style="color:#009900;"&gt;// i: imaginary literal&lt;/span&gt;&lt;/pre&gt;For details have a look at Bjarne's FAQ*. NIce feature, but will I use it? It is readable for the maintainer? We'll see.&lt;br /&gt;&lt;br /&gt;The next 2 features look to me as if they came straight from &lt;em&gt;Python&lt;/em&gt;. First the &lt;strong&gt;raw strings&lt;/strong&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  string s = R"[ahjh/?=(%/$§%§%\w\\w///]";&lt;/pre&gt;Why not just&lt;em&gt; R"..."&lt;/em&gt;? Dunno. Next the &lt;strong&gt;foreach&lt;/strong&gt; variant of the old &lt;em&gt;for()&lt;/em&gt; loop.Together with initilizers we can now have some &lt;em&gt;Python&lt;/em&gt; feeling in C++:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  vector&amp;lt;string&amp;gt; xs = {"aba", "bab", "aab" };&lt;br /&gt;  for(auto x:xs) cout &amp;lt;&amp;lt; x; &lt;span style="color:#009900;"&gt;// x:xs looks even a little Haskell-like ;-))&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;So there are many new things, some of them making C++ look like entirely another language. No I wonder - &lt;strong&gt;will the C++ programmers use it&lt;/strong&gt;, or will they stuck to the old, but known evil (like the old function definition syntax)?&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;&lt;br /&gt;*Bjarne's &lt;em&gt;"C++0x - the next ISO C++ standard",&lt;/em&gt; &lt;a href="http://www2.research.att.com/~bs/C++0xFAQ.html"&gt;http://www2.research.att.com/~bs/C++0xFAQ.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;** Danny Kalev: &lt;em&gt;"The Rejection of the Unified Function Syntax Proposal"&lt;/em&gt;, &lt;a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;amp;seqNum=460"&gt;http://www.informit.com/guides/content.aspx?g=cplusplus&amp;amp;seqNum=460&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;*** Daveed Vandevoorde: &lt;em&gt;"The Syntax of auto Declarations",&lt;/em&gt; &lt;a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2007/n2337.pdf"&gt;http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2007/n2337.pdf&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;**** for completness' sake, the examples are partially taken from: &lt;a href="http://www.justsoftwaresolutions.co.uk/threading/multithreading-in-c++0x-part-1-starting-threads.html"&gt;http://www.justsoftwaresolutions.co.uk/threading/multithreading-in-c++0x-part-1-starting-threads.html&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;&lt;/pre&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-1554477698462078016?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/1554477698462078016/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=1554477698462078016' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1554477698462078016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1554477698462078016'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/12/even-more-new-c-features.html' title='Even more new C++ features!'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-735207385071851953</id><published>2009-11-24T08:23:00.001-08:00</published><updated>2009-12-14T00:33:50.381-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>More about Java Closures</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/735207385071851953/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=735207385071851953' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/735207385071851953'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/735207385071851953'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/11/more-about-java-closures.html' title='More about Java Closures'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-2615814880097962593</id><published>2009-11-11T23:36:00.000-08:00</published><updated>2009-11-11T23:57:08.919-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='misc'/><title type='text'>Songs in code</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/2615814880097962593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=2615814880097962593' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/2615814880097962593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/2615814880097962593'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/11/songs-in-code.html' title='Songs in code'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-8850633943384280247</id><published>2009-10-30T09:29:00.001-07:00</published><updated>2009-11-08T11:42:05.142-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Java's Closures Debate for C++ Eyes</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/8850633943384280247/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=8850633943384280247' title='19 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/8850633943384280247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/8850633943384280247'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/10/javas-closures-debate-for-c-eyes.html' title='Java&apos;s Closures Debate for C++ Eyes'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>19</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-1072959027103826050</id><published>2009-08-27T03:52:00.001-07:00</published><updated>2009-10-09T08:17:50.919-07:00</updated><title type='text'>Tony Hoare and the meaning of life (well, almost...)</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/1072959027103826050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=1072959027103826050' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1072959027103826050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1072959027103826050'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/08/tony-hoare-and-meaning-of-life-well.html' title='Tony Hoare and the meaning of life (well, almost...)'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-7774980874085542426</id><published>2009-07-28T07:16:00.001-07:00</published><updated>2009-09-01T02:31:57.783-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Two C++ curiosities with a deeper meaning</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/7774980874085542426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=7774980874085542426' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7774980874085542426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7774980874085542426'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/07/two-c-curiosities-with-deeper-meaning.html' title='Two C++ curiosities with a deeper meaning'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-4619346420649647229</id><published>2009-06-27T06:58:00.000-07:00</published><updated>2009-08-31T03:55:00.045-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='OO'/><title type='text'>For German Speakers only...</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/4619346420649647229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=4619346420649647229' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4619346420649647229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4619346420649647229'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/06/for-german-speakers-only.html' title='For German Speakers only...'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-3258416785269826120</id><published>2009-05-28T05:31:00.000-07:00</published><updated>2009-10-14T01:11:12.349-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>Windows not so bad after all?</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/3258416785269826120/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=3258416785269826120' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/3258416785269826120'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/3258416785269826120'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/05/windows-not-so-bad-after-all.html' title='Windows not so bad after all?'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-8787738731653239243</id><published>2009-05-19T03:02:00.001-07:00</published><updated>2009-05-28T07:05:47.997-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL'/><title type='text'>Two Java Collection Utilities</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/8787738731653239243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=8787738731653239243' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/8787738731653239243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/8787738731653239243'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/05/two-java-collection-utilities.html' title='Two Java Collection Utilities'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-5147223979862345848</id><published>2009-04-29T13:22:00.000-07:00</published><updated>2009-09-01T02:37:36.775-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>From DLL- to XML-hell</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/5147223979862345848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=5147223979862345848' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/5147223979862345848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/5147223979862345848'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/04/from-dll-to-xml-hell.html' title='From DLL- to XML-hell'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-5132085552792956908</id><published>2009-04-04T12:09:00.001-07:00</published><updated>2009-10-05T23:22:34.049-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='distributed computing'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL'/><title type='text'>Some distributed computing news: cuddly elephans, pigs, nymphs and couch computing</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/5132085552792956908/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=5132085552792956908' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/5132085552792956908'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/5132085552792956908'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/04/some-distributed-computing-news-cuddly.html' title='Some distributed computing news: cuddly elephans, pigs, nymphs and couch computing'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-830265476823376730</id><published>2009-03-30T01:06:00.000-07:00</published><updated>2009-03-30T03:35:45.514-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='OO'/><title type='text'>One cute microdesign example and some thoughts on language design.</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/830265476823376730/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=830265476823376730' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/830265476823376730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/830265476823376730'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/03/one-cute-microdesign-example-and-some.html' title='One cute microdesign example and some thoughts on language design.'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-6590446349965494586</id><published>2009-02-21T07:40:00.001-08:00</published><updated>2009-03-11T04:57:28.671-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='multithreading'/><title type='text'>Fibers, at last!</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/6590446349965494586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=6590446349965494586' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6590446349965494586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6590446349965494586'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/02/fibers-at-last.html' title='Fibers, at last!'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></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>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-4457588877567592514</id><published>2009-02-18T04:24:00.000-08:00</published><updated>2009-10-07T06:42:22.323-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='servlets'/><title type='text'>C++ Server Pages</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/4457588877567592514/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=4457588877567592514' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4457588877567592514'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4457588877567592514'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/02/c-server-pages.html' title='C++ Server Pages'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></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>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-2721713454827245943</id><published>2009-01-27T23:32:00.000-08:00</published><updated>2009-03-12T02:00:53.194-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='multithreading'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Reading the new C++ Standard</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/2721713454827245943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=2721713454827245943' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/2721713454827245943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/2721713454827245943'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2009/01/ive-read-on-my-local-german-c-forum.html' title='Reading the new C++ Standard'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-5302008647317752688</id><published>2008-12-11T00:01:00.001-08:00</published><updated>2009-02-21T08:45:47.256-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Groovy'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Do we need destructors?</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/5302008647317752688/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=5302008647317752688' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/5302008647317752688'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/5302008647317752688'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/12/do-we-need-constructors.html' title='Do we need destructors?'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-1298428911258670764</id><published>2008-11-26T23:26:00.000-08:00</published><updated>2009-02-21T08:46:34.832-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SW processes'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='OO'/><title type='text'>C vs C++ and some celebrity gossiping</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/1298428911258670764/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=1298428911258670764' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1298428911258670764'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1298428911258670764'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/11/c-vs-c-and-some-celebrity-gossiping.html' title='C vs C++ and some celebrity gossiping'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-8759849630219260471</id><published>2008-11-19T00:23:00.001-08:00</published><updated>2008-12-15T07:33:38.482-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='windows'/><category scheme='http://www.blogger.com/atom/ns#' term='Qt'/><title type='text'>A letter from DLL hell: msvc60.dll and msvcr80.dll</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/8759849630219260471/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=8759849630219260471' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/8759849630219260471'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/8759849630219260471'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/11/letter-from-dll-hell-msvc60dll-and.html' title='A letter from DLL hell: msvc60.dll and msvcr80.dll'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-4513946346506388855</id><published>2008-10-25T13:54:00.000-07:00</published><updated>2009-02-21T08:46:08.471-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='distributed computing'/><category scheme='http://www.blogger.com/atom/ns#' term='Erlang'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Erlang and Map-Reduce</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/4513946346506388855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=4513946346506388855' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4513946346506388855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4513946346506388855'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/10/erlang-and-map-reduce.html' title='Erlang and Map-Reduce'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-2996392714347967893</id><published>2008-10-07T04:47:00.001-07:00</published><updated>2009-02-21T08:46:57.379-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='servlets'/><title type='text'>C++ servlets - again</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/2996392714347967893/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=2996392714347967893' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/2996392714347967893'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/2996392714347967893'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/10/c-servlets-again.html' title='C++ servlets - again'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-176294107655529443</id><published>2008-09-29T03:03:00.001-07:00</published><updated>2009-02-21T08:47:39.691-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Beautiful code</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/176294107655529443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=176294107655529443' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/176294107655529443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/176294107655529443'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/09/beautiful-code.html' title='Beautiful code'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-4718725880623557102</id><published>2008-09-17T05:00:00.000-07:00</published><updated>2009-02-21T08:48:08.780-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='J2EE'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Google's technology stack</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/4718725880623557102/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=4718725880623557102' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4718725880623557102'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4718725880623557102'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/09/googles-technology-stack.html' title='Google&apos;s technology stack'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-6523889957327908512</id><published>2008-08-27T13:30:00.000-07:00</published><updated>2009-02-21T08:48:40.494-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>The end of dumbing-down of programming?</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/6523889957327908512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=6523889957327908512' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6523889957327908512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6523889957327908512'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/08/end-of-dumbing-down-of-programming.html' title='The end of dumbing-down of programming?'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-6997310083301352782</id><published>2008-07-09T14:16:00.000-07:00</published><updated>2009-02-21T08:54:24.710-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>C++ pocket lambda library, the last</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/6997310083301352782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=6997310083301352782' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6997310083301352782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6997310083301352782'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/07/c-pocket-lambda-library-last.html' title='C++ pocket lambda library, the last'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-4000154837178929040</id><published>2008-06-25T01:35:00.000-07:00</published><updated>2009-02-21T08:49:11.466-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Qt'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='OO'/><title type='text'>The future of C++</title><content type='html'>&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;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/4000154837178929040/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=4000154837178929040' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4000154837178929040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4000154837178929040'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/06/future-of-c.html' title='The future of C++'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-8573674109983032611</id><published>2008-06-08T11:09:00.001-07:00</published><updated>2009-02-21T08:52:00.402-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='Haskell'/><title type='text'>C++ pocket lambda library, part III</title><content type='html'>&lt;p&gt;&lt;/p&gt;As I first wrote my C++ lambda code about a year and a half ago, I didn't know that I'm hitting such a hot topic. I wanted just to reduce the amount of code I had to write, and didn't have any high-church functional programming thingy in mind. But now lamdbads and closures are all the rage: look at all those Groovy articles on&lt;em&gt; developerWorks&lt;/em&gt; for example. Even Java 7 will have closures (or won't it?). Definitely, Ruby has made programming languages an interesting topic again!&lt;br /&gt;&lt;br /&gt;BTW, do you know how currying and lambdas looks like in&lt;span style="color:#009900;"&gt; Haskell&lt;/span&gt;, a popular functional (dynamically and strongly typed) language? If you don't know what it is, we've discussed currying in a previous posting of this mini-series*. In Haskell it is very natural syntactically, you can just write (well, almost, I skipped the &lt;em&gt;T=&amp;gt;T=&amp;gt;T&lt;/em&gt; type definition):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    product = a b = a*b&lt;br /&gt;    double = product 2    &lt;span style="color:#009900;"&gt;&amp;lt;-- curried!&lt;/span&gt;&lt;br /&gt;    double 2&lt;/pre&gt;This is basic, but look at that:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    doubleEach = map (2 *)&lt;/pre&gt;i.e. we define a partially evaluated function (as map needs 2 arguments, a function and a list) waiting for application. It's like you'd be using the &lt;em&gt;bind()&lt;/em&gt; template of our last posting* in C++. And look at the cute lambda function shortcut: &lt;em&gt;(2 *)&lt;/em&gt; is a function (unsurprisingly, as in Haskell everything is a function, contrary to Ruby or Groovy where everything is an object, even the functions ;-)). I like it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. Getting exxpresive&lt;/h2&gt;&lt;br /&gt;Admittedly the code in the 2nd part of this mini series was rather bland*: some hyper technical stuff but not really very entertaining like the 1st part (which was really fun for me to code). I wrote it only for completness' sake, as it is part of my code. I hope this installment will be more fun again.&lt;br /&gt;&lt;br /&gt;So let us tackle the last topic we need to implement as to have an usable lambda mini-library: the expression templates. The what? Wy do we need it exacltly? I'm certainly not going to write code like: &lt;em&gt;__expr template &amp;lt;class Expressible&amp;gt; express_anger(Expressible&amp;amp; e); -&lt;/em&gt; not in my life!!! Ok, ok, let's introduce the concept gently.&lt;br /&gt;&lt;br /&gt;Do you know for example the Boost (e)Xpressive library? It expresses (expressively) regular expressions (Boost Spirit library does in much greater style for grammars) by C++ code constructs. I.e. instead of:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    sregex rex = sregex::compile( "(\\w+) (\\w+)!" );&lt;br /&gt;&lt;/pre&gt;you can write&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    sregex rex = (s1= +_w) &amp;gt;&amp;gt; ' ' &amp;gt;&amp;gt; (s2= +_w) &amp;gt;&amp;gt; '!';&lt;br /&gt;&lt;/pre&gt;using the domain specific language (buzzword alarm!!!) instead. The string: &lt;em&gt;"\\w+"&lt;/em&gt; is replaced by an (Xpressive) expression &lt;em&gt;+_w&lt;/em&gt;. You recognize perhaps the usage of placeholders, like our&lt;em&gt; _$1&lt;/em&gt; or &lt;em&gt;_$2&lt;/em&gt;, operator overloading and assignment of partial matches to external variables (external to the closure, you'd say in Perl or Groovy). But in this case we don't have a single operation which should create a functor, neither a combination of two different operations. &lt;strong&gt;Here we have one operation applied again and again&lt;/strong&gt; (&amp;gt;&amp;gt; concatenator), and we have to encapsulate it &lt;strong&gt;in a single lambda functor&lt;/strong&gt;!&lt;br /&gt;&lt;br /&gt;The same problem emerges in the context of out mini-library.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    for_each(vec.begin(), vec.end(), cout &amp;lt;&amp;lt; "--&amp;gt;" &amp;lt;&amp;lt; _$1 &amp;lt;&amp;lt; "\n");&lt;br /&gt;&lt;/pre&gt;we have to collect all the items which have to be sent to cout, which can be infinite in number!&lt;br /&gt;&lt;br /&gt;Here expression templates come to the rescue. First described by Todd Veldhuizen**, they let us to define recursive templates with operator overloading. And recursion can go infinitely deep down, so we can accomodate our long shift operator sequences with our usual aplomb! What we need is following tree structure:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;                  expr&lt;br /&gt;                    ¦&lt;br /&gt;                   op &amp;gt;&amp;gt;&lt;br /&gt;                 /    \&lt;br /&gt;               op &amp;gt;&amp;gt;   \&lt;br /&gt;             /   \      \&lt;br /&gt;           op &amp;gt;&amp;gt;  \      \&lt;br /&gt;         /        \      \&lt;br /&gt;      s1=+_w  ' ' s2=+w_  '!'&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;True to the "Modern C++ design" book's ubiquitous typelists usage, we can express this runtime structure in compile time with a following monstrous type:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    Op&amp;lt;Op&amp;lt;Op&amp;lt;Char, Expr&amp;gt;, Expr&amp;gt;, Char&amp;gt; rex;&lt;br /&gt;&lt;/pre&gt;Here, all the structural information has been recorded: just read the type from left to right and compare it with the picture of the parse tree. Now we have to supply the arguments to the constructor of an object of this type and then call a method of the rex object. But we don't do it in classical sense, the construction and the type definition will be done recursively while compiler is parsing the expression. Hence the name of the expression templates #B-D.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;2. First real exxpressive code&lt;/h2&gt;&lt;br /&gt;To convince the compiler to to some sensible work for us we first define the following recursive template:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;    // Shift represents a node in the parse tree&lt;br /&gt;    // ---&lt;/span&gt;&lt;br /&gt;    template&amp;lt;typename Left, typename Op, typename Right&amp;gt;&lt;br /&gt;        struct Shift  : public lambda_expr&lt;br /&gt;    {&lt;br /&gt;        Left leftNode;&lt;br /&gt;        Right rightNode;&lt;br /&gt;        std::ostream&amp;amp; out;&lt;br /&gt;&lt;br /&gt;        Shift(Left t1, Right t2, std::ostream&amp;amp; os)&lt;br /&gt;            : leftNode(t1), rightNode(t2), out(os) { }&lt;br /&gt;&lt;br /&gt;        template &amp;lt;class T&amp;gt;&lt;br /&gt;            void operator() (T&amp;amp; t) { Op::print(leftNode, rightNode, t); }&lt;br /&gt;    };&lt;br /&gt;&lt;/pre&gt;You can see, the structure of the tree node is different form the monstrous type given as example above, well, it's even more complicated. Using this approach we would express the above example tree as:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    Node&amp;lt;Node&amp;lt;Node&amp;lt;Char, Op, Expr&amp;gt;, Op, Expr&amp;gt;, Op, Char&amp;gt; rex;&lt;br /&gt;&lt;/pre&gt;Ok, why not. If it's supposed to help, I couldn't care less... ;-)&lt;br /&gt;&lt;br /&gt;But what has this all with our lambda library? The answer is, we can apply the same concept to the problem of priniting data to cout: supposed we have a following lambda function&lt;em&gt;: cout lt;&amp;lt; "element:" &amp;lt;&amp;lt; _$1,&lt;/em&gt; we'll can build a type tree like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;                  expr&lt;br /&gt;                    ¦&lt;br /&gt;                  &amp;lt;&amp;lt; op&lt;br /&gt;                 /    \&lt;br /&gt;             &amp;lt;&amp;lt; op     \&lt;br /&gt;             /   \      \&lt;br /&gt;            /     \      \&lt;br /&gt;         cout "element:" _$1&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;One interesting thing to note is the ()-operator, which prints the actual node of the parse tree using a mysterious &lt;em&gt;T&amp;amp; t&lt;/em&gt; argument: it is the actual parametr of the lambda function, i.e. the uderlying iterator itself!&lt;br /&gt;&lt;br /&gt;So if we have the top level tree node (i.e. the expr in the diagram above), we'll just call its ()-operator an the whole tree is printed out, hopefully! Two problem pose themselves here:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.&lt;/strong&gt; how to descend to the subnodes of the tree while printing, and&lt;br /&gt;&lt;strong&gt;2. &lt;/strong&gt;how do we get the whole tree structure constructed in the first place?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;3. Recursive printing&lt;/h2&gt;&lt;br /&gt;To answer the first question we need the representation of the recursive printing operation in code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    struct shiftOp &lt;span style="color:#009900;"&gt;// Represents &amp;lt;&amp;lt; operation&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        template &amp;lt;class Left, class Right, class T&amp;gt;&lt;br /&gt;            static void print(Left&amp;amp; left, Right&amp;amp; right, T&amp;amp; t)&lt;br /&gt;            {&lt;br /&gt;              print(left.leftNode, left.rightNode, t); &lt;span style="color:#009900;"&gt;// walk down&lt;/span&gt;&lt;br /&gt;              left.out &amp;lt;&amp;lt; right(t);  &lt;span style="color:#009900;"&gt;// if right needs t? : &amp;lt;&amp;lt; _$1*2 ???&lt;/span&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;pre&gt; &lt;/pre&gt;        template &amp;lt;class Right, class T&amp;gt;&lt;br /&gt;            static void print(std::ostream&amp;amp; left, Right&amp;amp; right, T&amp;amp; t)&lt;br /&gt;            {&lt;br /&gt;              left &amp;lt;&amp;lt; right(t);  // at the beginning&lt;br /&gt;            }&lt;pre&gt; &lt;/pre&gt;&lt;br /&gt;        template &amp;lt;class Left, class T&amp;gt;&lt;br /&gt;            static void print(Left&amp;amp; left, placeholder&amp;lt;1&amp;gt;&amp;amp; right, T&amp;amp; t)&lt;br /&gt;            {&lt;br /&gt;                print(left.leftNode, left.rightNode, t);&lt;br /&gt;                left.out &amp;lt;&amp;lt; t; // special case placeholder&lt;br /&gt;            }&lt;br /&gt;    };&lt;br /&gt;&lt;/pre&gt;First we walk down the tree in the depth first, left to right mode (the first &lt;em&gt;print()&lt;/em&gt; function). When we arrive at the lowest left node of the tree we do the first print, then go back and print the corresponding right node. Note that &lt;strong&gt;we don't walk a physical tree here, we walk a type expression &lt;/strong&gt;which is organized like a tree! The &lt;em&gt;print()&lt;/em&gt; functions will "match" a part of the type-tree, print the matched part, and match the subtype in a recursive manner. So we &lt;strong&gt;are treating types in compile time as we'd treat data in the runtime&lt;/strong&gt;! That's why this is called template &lt;strong&gt;META&lt;/strong&gt;-programming.&lt;br /&gt;&lt;br /&gt;Then we need only 2 specialisations: one for the first invocation of the shift operator, where the left operand is the output stream itself, and the second one to deal with our lambda mini-library's placeholder types. The placeholder will be printed directly to the stream. Our tree expression for the simple example above will be then as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    Shift&amp;lt;Shift&amp;lt;cout, shiftOp, "element"-Expr&amp;gt;, shiftOp, _$1&amp;gt; lambda;&lt;br /&gt;&lt;/pre&gt;Now just imagine how the &lt;em&gt;print() &lt;/em&gt;function will work on it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;4. Growing the tree&lt;/h2&gt;&lt;br /&gt;To answer the second question we need 2 simple ;-) operator overloading definitions:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// The overloaded operator which does parsing for expressions of the&lt;br /&gt;    //  form "a&amp;lt;&amp;lt;b&amp;lt;&amp;lt;c&amp;lt;&amp;lt;d" =&amp;gt; Shift&amp;lt;Shift&amp;lt;Shift&amp;lt;A, op, B&amp;gt;, op, C&amp;gt;, op, D&amp;gt;()&lt;br /&gt;&lt;pre&gt; &lt;/pre&gt;    // for ostream: cannot be taken by value!&lt;/span&gt;&lt;br /&gt;    template&amp;lt;class Left, class Right&amp;gt;&lt;br /&gt;        Shift&amp;lt;Left&amp;amp;, shiftOp, Right&amp;gt; operator&amp;lt;&amp;lt; (Left&amp;amp; left, Right right) {&lt;br /&gt;            return Shift&amp;lt;Left&amp;amp;, shiftOp, Right&amp;gt;(left, right, left);&lt;br /&gt;            &lt;span style="color:#009900;"&gt;// left IS an ostream!&lt;/span&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;pre&gt; &lt;/pre&gt;    &lt;span style="color:#009900;"&gt;// for lambda_expr: must be taken by value!&lt;/span&gt;&lt;br /&gt;    template&amp;lt;class Left1, class Left2, class Right&amp;gt;&lt;br /&gt;        Shift&amp;lt;Shift&amp;lt;Left1, shiftOp, Left2&amp;gt;, shiftOp, Right&amp;gt;&lt;br /&gt;            operator&amp;lt;&amp;lt; (Shift&amp;lt;Left1, shiftOp, Left2&amp;gt; left, Right right) {&lt;br /&gt;                return Shift&amp;lt;Shift&amp;lt;Left1, shiftOp, Left2&amp;gt;, shiftOp, Right&amp;gt;(left, right, left.out);&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;The first one starts the recursive template definition at the "&lt;em&gt;cout &amp;lt;&amp;lt;&lt;/em&gt;"-expression, an the second one goes one nesting level deeper and one &amp;lt;&amp;lt;-operator application to the right. It's an elaborate syntax, but conceptually it's not a rocket science! Note how the stream (&lt;em&gt;cout&lt;/em&gt;) parameter is handed down the expression tree.&lt;br /&gt;&lt;br /&gt;Yeeee-ha! We are done now! Let us try it out:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    for_each(vec.begin(), vec.end(), cout &amp;lt;&amp;lt; _$1);  &lt;span style="color:#009900;"&gt;// OK&lt;/span&gt;&lt;br /&gt;    for_each(vec.begin(), vec.end(), cout &amp;lt;&amp;lt; _$1 &amp;lt;&amp;lt; "\n" ); &lt;span style="color:#009900;"&gt;// compile error???&lt;/span&gt;&lt;br /&gt;    for_each(vec.begin(), vec.end(), cout &amp;lt;&amp;lt; i++ &amp;lt;&amp;lt; ":" &amp;lt;&amp;lt; _$1 &amp;lt;&amp;lt; " " ); &lt;span style="color:#009900;"&gt;// again!!!&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Did you see that? We still cannot use our lambda library. What is it this time? Well, we need a last building block, and for discussioon of that we need a separate paragraph.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;5. External data in lambda functions &lt;/h2&gt;&lt;br /&gt;The problem is, that inside of an lambda expression we are working with functors, and not with native C++ data types. This means, we need a function call operator for each element of the lambda expression. What can be easier than that! We can make a trivial functor, which, when evaluated returns our literal value i.e. "\n" or ":"!&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;    // constant_ref&lt;br /&gt;    //  ---&lt;/span&gt;&lt;br /&gt;    template&amp;lt;class T&amp;gt; struct Const : public lambda_expr&lt;br /&gt;    {&lt;br /&gt;        T&amp;amp; val;&lt;br /&gt;        Const(T&amp;amp; t) : val(t) { }&lt;br /&gt;        const T&amp;amp; operator()() const { return val; }&lt;br /&gt;        const T&amp;amp; value() const { return val; }&lt;br /&gt;&lt;br /&gt;        template &amp;lt;class S&amp;gt; &lt;span style="color:#009900;"&gt;// for different context: needed for Shift!!!&lt;/span&gt;&lt;br /&gt;            const T&amp;amp; operator()(S&amp;amp; s) const { return val; } &lt;span style="color:#009900;"&gt;// ignore input&lt;/span&gt;&lt;br /&gt;    };&lt;br /&gt;&lt;pre&gt; &lt;/pre&gt;    template&amp;lt;class T&amp;gt;&lt;br /&gt;        Const&amp;lt;T&amp;gt; delay(T&amp;amp; t) { return Const&amp;lt;T&amp;gt;(t); }&lt;br /&gt;&lt;/pre&gt;This can be described as a delayed evaluation: the compiler first wraps the constant in a functor, and the constant's value is used in runtime instead of compile time. Now a lambda like: &lt;em&gt;auto lambda = (cout &amp;lt;&amp;lt; _$1 &amp;lt;&amp;lt; "\n");&lt;/em&gt; will work. BTW I wonder if that would compile...&lt;br /&gt;&lt;br /&gt;Maybe you don't remebmer, but it the IIa part of this series*** I showed the following code snippet:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// assign to a external counter&lt;/span&gt;&lt;br /&gt;    int aaa;&lt;br /&gt;    for_each(vecx.begin(), vecx.end(), aaa += _$1-&amp;gt;*(&amp;amp;XXX::value));&lt;br /&gt;&lt;/pre&gt;only to say, that it wouldn't work yet. What's the problem? Basically the same one: we are using native C++ type instead of a functor. The solution is of course the delayed evaluation from above, but now must cater for the basic operations:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;    // variable_ref&lt;br /&gt;    //  ---&lt;/span&gt;&lt;br /&gt;    template&amp;lt;class T&amp;gt; struct Var : public lambda_expr&lt;br /&gt;    {&lt;br /&gt;        T&amp;amp; val;&lt;br /&gt;        Var(T&amp;amp; t) : val(t) { }&lt;br /&gt;        T&amp;amp; operator()() const { return val; }&lt;br /&gt;        T&amp;amp; operator()(T&amp;amp; t) const { return val; } &lt;span style="color:#009900;"&gt;// ignore input&lt;/span&gt;&lt;br /&gt;        T&amp;amp; value() const { return val; }&lt;br /&gt;&lt;br /&gt;        AssgnTo&amp;lt;T&amp;gt; operator=(T t) { return AssgnTo&amp;lt;T&amp;gt;(val, t); }&lt;br /&gt;&lt;br /&gt;        template &amp;lt;class S&amp;gt;  // assign from lambda_expr&lt;br /&gt;            AssgnTo&amp;lt;T&amp;gt; operator=(S s) { return AssgnTo&amp;lt;T&amp;gt;(val, s); }&lt;br /&gt;    };&lt;br /&gt;&lt;pre&gt; &lt;/pre&gt;    template&amp;lt;class T&amp;gt; Var&amp;lt;T&amp;gt; globvar(T&amp;amp; t) { return Var&amp;lt;T&amp;gt;(t); }&lt;br /&gt;&lt;/pre&gt;Here we enabled the assignment to the C++ data type. The addional operators could be implemented like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;    // OPEN todo: be more modular!!!&lt;br /&gt;    //  --- return lambda_operation&amp;lt;lambda_exp, oper_type&amp;gt;&lt;/span&gt;&lt;br /&gt;    template&amp;lt;class T&amp;gt;&lt;br /&gt;        AddAssg&amp;lt;T&amp;gt; operator+=(Var&amp;lt;T&amp;gt; v, const T&amp;amp; t) { return AddAssg&amp;lt;T&amp;gt;(v.value(), t); }&lt;br /&gt;    template&amp;lt;class T&amp;gt;&lt;br /&gt;        AddAssg&amp;lt;T&amp;gt; operator+=(Var&amp;lt;T&amp;gt; v, placeholder&amp;lt;1&amp;gt;) { return AddAssg&amp;lt;T&amp;gt;(v.value()); }&lt;br /&gt;&lt;pre&gt; &lt;/pre&gt;    template&amp;lt;class T&amp;gt;&lt;br /&gt;        Incr&amp;lt;T&amp;gt; operator++(Var&amp;lt;T&amp;gt; v, int) { return Incr&amp;lt;T&amp;gt;(v.value()); }&lt;br /&gt;&lt;/pre&gt;Now we can finally write:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    int xxx = 0;&lt;br /&gt;    for_each(vecx.begin(), vecx.end(), globvar(xxx)++);&lt;br /&gt;    for_each(vecx.begin(), vecx.end(), globvar(xxx) += 5);&lt;br /&gt;    for_each(vecx.begin(), vecx.end(), globvar(xxx) += _$1-&amp;gt;*(&amp;amp;XXX::value));&lt;br /&gt;&lt;/pre&gt;and, for example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    for_each(vec.begin(), vec.end(), cout &amp;lt;&amp;lt; _$1 &amp;lt;&amp;lt; delay("\n") );&lt;br /&gt;    for_each(vec.begin(), vec.end(), cout &amp;lt;&amp;lt; globvar(i++) &amp;lt;&amp;lt; delay(":") &amp;lt;&amp;lt; _$1 );&lt;br /&gt;&lt;/pre&gt;But &lt;em&gt;not&lt;/em&gt;, among others: &lt;em&gt;globvar(aaa) = _$1-&amp;gt;*(&amp;amp;XXX::value)&lt;/em&gt;, as it's not a complete, orthogonal, and idustrial strength library. It was only a little pastime of mine...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;6. The End?&lt;/h2&gt;&lt;br /&gt;Ehm, I thought this will be the last part of the description of my simple implementation, but no, I'll need another blog entry as not to bore you to death with this one. Meantime, the &lt;strong&gt;writing of this description has taken&lt;/strong&gt; &lt;strong&gt;more time than the actual implementation itself!!!&lt;/strong&gt; But I have some more points to make, and at the end of a long post, there are rater unlikely to be given much attention. So long then!&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* Part II: &lt;a href="http://ib-krajewski.blogspot.com/2008/01/c-pocket-lambda-library-part-2.html"&gt;http://ib-krajewski.blogspot.com/2008/01/c-pocket-lambda-library-part-2.html&lt;/a&gt;&lt;br /&gt;** Techniques for Scientific C++: &lt;a href="http://ubiety.uwaterloo.ca/~tveldhui/papers/techniques/techniques01.html"&gt;http://ubiety.uwaterloo.ca/~tveldhui/papers/techniques/techniques01.html&lt;/a&gt;&lt;br /&gt;*** Part IIa: &lt;a href="http://ib-krajewski.blogspot.com/2008/04/pocket-c-lambda-library-part-iia.html"&gt;http://ib-krajewski.blogspot.com/2008/04/pocket-c-lambda-library-part-iia.html&lt;/a&gt;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-8573674109983032611?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/8573674109983032611/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=8573674109983032611' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/8573674109983032611'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/8573674109983032611'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/06/c-pocket-lambda-library-part-iii.html' title='C++ pocket lambda library, part III'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-4575520232924482181</id><published>2008-05-30T00:47:00.001-07:00</published><updated>2009-02-21T08:49:44.289-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><category scheme='http://www.blogger.com/atom/ns#' term='OO'/><title type='text'>God wrote in LISP: programming and genesis.</title><content type='html'>&lt;p&gt;&lt;/p&gt;Did you ever ask yourself what programming language God used to implement the Universe? I mean, he had a pretty tight deadline - only 6 days - so he must have been using something rather high level. And a rather complex one to boot. And as a programmer, you don't have any doubts thet God must have been using a programming language for the task: without abstraction the task is just too complex ;-).&lt;br /&gt;&lt;br /&gt;I came across this song while hearing the OOPSLA podcasts and everything became clear: he used LISP! Hear it here: (&lt;a href="http://share.ovi.com/media/marek_krajewski.public/marek_krajewski.10001"&gt; &amp;gt;&amp;gt; &lt;/a&gt;)*. I must say, I really like it a lot. It's wonderful: it's like a hymn on a great, dead language. The lyrics come from &lt;em&gt;Bob Kanefsky&lt;/em&gt;. All I could trace about him is that he wrote some parody songs, but he must be a programmer himself judging from the quality of lyrics.&lt;br /&gt;&lt;br /&gt;And the lyrics are right: Object Oriented languages &lt;strong&gt;describe how we humans are thinking about the world&lt;/strong&gt;, but LISP (or functional languages in general) describe the thoughts of God... so pure... ;-). Let me cite: &lt;em&gt;"Don’t search the disk drive for man.c..."&lt;/em&gt;. It's almost ontology, I like it :-).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;PS:&lt;/strong&gt; As always there is a monority opinion as well, see &lt;a href="http://www.xkcd.com/224"&gt;http://www.xkcd.com/224&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* or here, if embedding works:&lt;br /&gt;&lt;br /&gt;&lt;embed src="http://share.ovi.com/flash/audioplayer.aspx?media=" width="145" height="60" type="application/x-shockwave-flash" channelname="marek_krajewski.public"&gt;&lt;/embed&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-4575520232924482181?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/4575520232924482181/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=4575520232924482181' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4575520232924482181'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/4575520232924482181'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/05/god-wrote-in-lisp-programming-and.html' title='God wrote in LISP: programming and genesis.'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-1608405281042690208</id><published>2008-05-15T02:26:00.001-07:00</published><updated>2009-02-21T08:50:02.663-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MDD'/><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><title type='text'>Why is software engineering not engineering?</title><content type='html'>&lt;p&gt;&lt;/p&gt;As I had a look over Philippe Kruchten's book &lt;em&gt;"The Rational Unified Process. An Introduction"&lt;/em&gt; I noticed the following passage. I mean, the book is rather dry, it just describes some organizational process, but this paragraph was different:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;"Software engineering has not reached the level of other engineering discipline .... because the underlying "theories" are week and poorly understood and the heuristics are crude."&lt;/em&gt; &lt;/blockquote&gt;Well, nothing new here, just like we all know it to be. Then:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;"Software engineering may be misnamed. At various times it more closely resembles a branch of psychology, philosophy or art than engineering. Relatively straightforward laws of physics underlie the design of a bridge, but there's no strict equivalent in software design. Software is "soft" in this respect."&lt;/em&gt;&lt;/blockquote&gt;Indeed! In programming &lt;strong&gt;we are not working with physical materials but with mental objects&lt;/strong&gt; (or should I say artifacts?) denoted by an array of characters on a sheet of paper. Sometimes even with just boxes and lines*. So what we really are doing, when we're trying to set up some laws in software, is looking for the "laws of thought", i.e. we are trying to find a good way to organize our ideas! Ideas which will then become flesh when executed on a complicated machine. As we are working with mental objects to a much greater extend than traditional engineering, the methodology cannot be the same. The world of human thought is not so well explored as the physical world. Or maybe the physical world is just much, much simpler?&lt;br /&gt;&lt;br /&gt;This discussion would lead us too far**, but one thing is sure: on some level of abstraction, we are no more thinking about the underlying machine, a thing which couldn't happen when we were designing a bridge. Because of that I maintain that in programming we are basicaly working with mental and not physical objects, so it cannot be counted as engineering. That might be the case earlier on, as programmers had all the iron on their hands, setting plugs and connecting cables. It had an engineering-like looks. But today? Just look on an corporate IT department - it's all about organisation, processes, abstractions of every level. For me it has more to do with "management science" and even "social science", only on a different scale.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;So it should be best called&lt;/strong&gt; &lt;strong&gt;computer &lt;em&gt;"science"&lt;/em&gt; - not in the "scientific" sense, but rather in the "soft-science" sense?&lt;/strong&gt; This would however mean, that it is somehow an art... Well, it's not what the industry wants to hear! But we don't have to tell them ;-).&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* MDD (or should I call it MDA?) takes it to the extreme: you don't write &lt;strong&gt;ANY code at all&lt;/strong&gt;, instead you are writing the &lt;em&gt;"computation independent model"&lt;/em&gt;, of course in UML, which constitutes a description of the functionality of the system. Then you are transforming this model into another model: &lt;em&gt;"platform independent model"&lt;/em&gt;, which represents the abstract computation model, then you are tranforming this into a &lt;em&gt;"platform specific model"&lt;/em&gt; at last. And all of this is done using tools, profiles, configurations, cartriges. Ideally, you should only model the required functionality, choose the target platform, and start the model transformation chain. Cool! But is it still programming? Theoreticall it is.&lt;br /&gt;&lt;br /&gt;** i.e. into philosophy. Just consider that civil engineers are working with mental models too, and, on the other side, the matematicians are working with "mental objects", which miraculously can describe the physical worlds with a great precision...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-1608405281042690208?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/1608405281042690208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=1608405281042690208' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1608405281042690208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/1608405281042690208'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/05/why-is-software-engineering-not.html' title='Why is software engineering not engineering?'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-6019411597645743145</id><published>2008-04-27T23:00:00.000-07:00</published><updated>2008-05-15T04:45:22.727-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Groovy'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>pocket C++ lambda library, part IIa</title><content type='html'>Are you wondering about the title of this entry? Well, it really should by part of a previous one*, but after looking at it I decided that the previous entry is pretty long already, and I wasn't willing to blow it up even more. And the theme isn't such an interesting one as to deserve a separate part in this mini-series. What is it we are talking about?&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. Access to the members&lt;/h2&gt;&lt;br /&gt;In the past I sometimes really wanted to be able to do the following:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    struct XXX { int value; int getValue() { return value; } };&lt;br /&gt;    vecx&amp;lt;XXX*&amp;gt; vec_x;&lt;/pre&gt;&lt;pre&gt;    find_if(vec_x.begin(), vec_x.end(),  _$1-&amp;gt;value == alive);&lt;/pre&gt;i.e. to access the members of an object out of the lambda function. Of course I'd like a code like &lt;em&gt;_$1.value&lt;/em&gt; the best, but C++ doesn't allow us to overload the dot operator! Why not? This would mean that we could customize the method invocation mechanism itself! As it's the case in Groovy, Perl, Python or even Java**:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;// Groovy:&lt;/span&gt;&lt;br /&gt;Object invokeMethod(String name, Object args)&lt;br /&gt;{&lt;br /&gt;    log("Just calling me: $name");&lt;br /&gt;    def result = metaClass.invokeMethod(this, name, args);&lt;br /&gt;}&lt;/pre&gt;If you have that, &lt;strong&gt;you can do things like Rails in Ruby and builders in Groovy&lt;/strong&gt;. You just intercept calls to the nonexisting methods (i.e. overload the &lt;em&gt;methodMissing()/method_missing()&lt;/em&gt; in Groovy/Ruby or &lt;em&gt;__getattr__()&lt;/em&gt; in Python) and install the "code block" (a closure, as to be exact) passed as one of the parameters in a custom hash map with the name parameter as key... You've got the message.&lt;br /&gt;&lt;br /&gt;This isn't possible in C++, as &lt;strong&gt;it would introduce the metaclass notion into the language&lt;/strong&gt;. At least it would require a common superclass for all C++ objects, and this contradicts the design of C++ classes (AFAIK) as thin wrappers for physical memory segments. On the other side, C++ has a more primitive notion of call intercepting: overloading of the&lt;em&gt; -&amp;gt;&lt;/em&gt; operator! Alas, it only works with pointers, so we cannot provide a general solution for value based containers. An that is a bad thing enough.&lt;br /&gt;&lt;br /&gt;So let's concentrate on the less ambitious goal: &lt;em&gt;_$1-&amp;gt;getValue()&lt;/em&gt;! Unfortunately, even this syntax canot be made work in our context! Why? Because for the C++ compiler the expression &lt;em&gt;getValue()&lt;/em&gt; doesn't make sense! It doesn't refer to a class' method &lt;em&gt;getValue()&lt;/em&gt;, which we could feed to the &lt;em&gt;-&amp;gt;&lt;/em&gt; operator, it's just a string which we'd like to transform somehow in a function reference!&lt;br /&gt;&lt;br /&gt;So what can we do (if anything)?&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;2. The Implementation&lt;/h2&gt;&lt;br /&gt;The best I could produce is the following:&lt;br /&gt;&lt;pre&gt;    iterx = find_if(vecx.begin(), vecx.end(), _$1-&amp;gt;*(&amp;amp;XXX::value) == 2);&lt;br /&gt;    iterx = find_if(vecx.begin(), vecx.end(), _$1-&amp;gt;*(&amp;amp;XXX::getValue) == 1);&lt;/pre&gt;Well, what can I say, it's passable. Now the compiler has a meaningful information in form of a member address, and it's not too ugly. How to implement it? With a standard technique from the first part***:&lt;br /&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// -&amp;gt;*&lt;/span&gt;&lt;br /&gt;    template&amp;lt;class V, class O&amp;gt; struct ArrowStar : public lambda_expr {&lt;br /&gt;        V O::* mptr;&lt;br /&gt;        ArrowStar(V O::*m): mptr(m) { }&lt;br /&gt;        V operator()(O* o) const { return o-&amp;gt;*mptr; }&lt;br /&gt;    };&lt;/pre&gt;we are overloading the member call operator for memebr access. For function member calls we need 2 more overloads. First for calls with 1 argument:&lt;br /&gt;&lt;pre&gt;    template&amp;lt;class R, class O, class A&amp;gt; struct ArrowStarF : public lambda_expr {&lt;br /&gt;        R(O::*fptr)(A);&lt;br /&gt;        ArrowStarF(R(O::*f)(A)): fptr(f) { }&lt;br /&gt;        R operator()(O* o, A a) const { return o-&amp;gt;*fptr(a); }&lt;br /&gt;    };&lt;/pre&gt;and for calls without arguments:&lt;br /&gt;&lt;pre&gt;    template&amp;lt;class R, class O&amp;gt; struct ArrowStarFv : public lambda_expr {&lt;br /&gt;        R(O::*fptr)();&lt;br /&gt;        ArrowStarFv(R(O::*f)()): fptr(f) { }&lt;br /&gt;        R operator()(O* o) const { return (o-&amp;gt;*fptr)(); }&lt;br /&gt;    }&lt;/pre&gt;nothing new here as well, just the standard operator overloading technique. For the == operation to work, I extended the &lt;em&gt;EqTo&lt;/em&gt; operator from the part 1*** to do a little forwarding. I know, I should use the forwarders (like &lt;em&gt;Le2_forw&lt;/em&gt; in part 1), but I was lazy:&lt;br /&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// lambda_expr ==&lt;/span&gt;&lt;br /&gt;    template&amp;lt;class S, class T&amp;gt; struct EqTo : public lambda_expr {&lt;br /&gt;        ...&lt;br /&gt;        EqTo(S s, T t) : lexpr(s), val(t) { }&lt;br /&gt;        template &amp;lt;class R&gt;&lt;br /&gt;            bool operator()(R r) { return lexpr(r) == val; }&lt;br /&gt;    };&lt;/pre&gt;So let's do something useful at last:&lt;br /&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// shouldn't clash with lambda_expr: *_$1 &amp;lt;= *$2 !!!&lt;/span&gt;&lt;br /&gt;    iterx = find_if(vecx.begin(), vecx.end(), _$1-&amp;gt;*(&amp;amp;XXX::getVal) &amp;lt;= 2);&lt;/pre&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;    // read field values from vecx&lt;/span&gt;&lt;br /&gt;    vector&amp;lt;int&amp;gt; v10_1(10);&lt;br /&gt;    transform(vecx.begin(), vecx.end(), v10_1.begin(), _$1-&amp;gt;*(&amp;amp;XXX::getVal));&lt;/pre&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// assign to a external counter&lt;/span&gt;&lt;br /&gt;    int aaa;&lt;br /&gt;    for_each(vecx.begin(), vecx.end(), aaa += _$1-&amp;gt;*(&amp;amp;XXX::value));&lt;/pre&gt;Ok, the last one won't be working just now ;-), you must wait for the part 3 of the series! For the first one to work, we must extend the forwarding class from part 1*** a little for the case where only one side must be forwarded:&lt;br /&gt;&lt;pre&gt;    template &amp;lt;class S, class T&amp;gt; struct Le2_forw : public lambda_expr&lt;br /&gt;    {&lt;br /&gt;        S e1;&lt;br /&gt;        T e2;&lt;br /&gt;        Le2_forw(S s, T t) : e1(s), e2(t) { }&lt;br /&gt;        .....&lt;br /&gt;        template &amp;lt;class U&amp;gt; &lt;span style="color:#009900;"&gt;// one side is bound! OPEN: assume left side!&lt;/span&gt;&lt;br /&gt;            bool operator()(U a) const { return e1(a) &amp;lt;= e2; }&lt;br /&gt;    };&lt;/pre&gt;And now everything is buzzing!&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;3. Discussion&lt;/h2&gt;&lt;br /&gt;If you think the sytax of the meber function call ist just horrible, there is another possibility to use the member functions: bind them! This you have seen (and frowned upon) in part 2*:&lt;pre&gt;    for_each(vecx.begin(), vecx.end(), cout &amp;lt;&amp;lt; bind(&amp;amp;XXX::getVal, _$1));&lt;/pre&gt;it's even less readable, is it? Or maybe not? Look, compared with &lt;em&gt;_$1-&amp;gt;*(&amp;amp;XXX::value)&lt;/em&gt; it's no more SUCH a bad sight! Maybe something like &lt;em&gt;call_func(_$1, &amp;amp;XXX::getVal)&lt;/em&gt; would be more readable here? The advantage of this solution is that we could accept value objects in the container, and take it's address internally. I leave the decision to you, the implementation is more or less trivial.&lt;br /&gt;&lt;br /&gt;Summing up, &lt;strong&gt;I couldn't achieve much progress here&lt;/strong&gt;, because of inherent C++ design features. So maybe a macro solution? Or another level of indirection? What we really needed here is a hook for compiler errors (method not found), where we could install our own code snippet. Wait a minute! Something like compile time asserts? But how can I get around the &lt;em&gt;string =&amp;gt; function&lt;/em&gt; coding problem?&lt;br /&gt;&lt;br /&gt;Something primitive like this would be possible:&lt;br /&gt;&lt;pre&gt;    ...&lt;br /&gt;    ArrowStarStr(string&amp;amp; name): fname(name) { }&lt;br /&gt;    R operator()(O* o) const {&lt;br /&gt;        return (o-&amp;gt;func_hashtable.get(name))(); &lt;span style="color:#009900;"&gt;// and don't crash here!&lt;/span&gt;&lt;br /&gt;    }&lt;/pre&gt;But you cannot use a POCppO anymore, you need some macro gadgetry like in Qt,&lt;br /&gt;for example:&lt;br /&gt;&lt;pre&gt;    struct XXX {&lt;br /&gt;        int value;&lt;br /&gt;        int getValue() { return value; }&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#009900;"&gt;        // now decorate:&lt;/span&gt;&lt;br /&gt;        STORE_LAMDBA_FUNC(getValue);&lt;br /&gt;    };&lt;/pre&gt;&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// or property based:&lt;/span&gt;&lt;br /&gt;    struct XXX {&lt;br /&gt;        DEF_LAMBDA_PROPERTY(value, int);&lt;br /&gt;    };&lt;/pre&gt;Not so pretty, not elegant, much to much effort needed. But it is the solution we have to use following the C++ language design. We just don't have introspection and cannot overload the dot. Sorry. Any ideas?&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;* &lt;a href="http://ib-krajewski.blogspot.com/2008/01/c-pocket-lambda-library-part-2.html"&gt;http://ib-krajewski.blogspot.com/2008/01/c-pocket-lambda-library-part-2.html&lt;/a&gt;&lt;br /&gt;** with dynamic proxies: see &lt;a href="http://gleichmann.wordpress.com/2007/11/22/mimicry-in-action-dynamically-implement-an-interface-using-dynamic-proxy/"&gt;http://gleichmann.wordpress.com/2007/11/22/mimicry-in-action-dynamically-implement-an-interface-using-dynamic-proxy/&lt;/a&gt;&lt;br /&gt;***&lt;a href="http://ib-krajewski.blogspot.com/2007/12/c-pocket-lambda-library.html"&gt;http://ib-krajewski.blogspot.com/2007/12/c-pocket-lambda-library.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-6019411597645743145?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/6019411597645743145/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=6019411597645743145' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6019411597645743145'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/6019411597645743145'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/04/pocket-c-lambda-library-part-iia.html' title='pocket C++ lambda library, part IIa'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-980253859362488011</id><published>2008-04-06T11:55:00.000-07:00</published><updated>2009-02-21T08:50:16.737-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Perl'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Language trends and waiting blues.</title><content type='html'>&lt;p&gt;&lt;/p&gt;Hi everbody! I recently skimmed over an interview* about programming language trends in the DDJ. In general, there was nothing new in there, rather a re-statement of the widely known programming trends. But some phrases caught my eye nonetheless:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;PJ: C and &lt;strong&gt;C++ are definitely losing ground&lt;/strong&gt;. There is a simple explanation for this. Languages without automated garbage collection are getting out of fashion.&lt;br /&gt;....&lt;br /&gt;&lt;strong&gt;Another language that has had its day is Perl.&lt;/strong&gt; It was once the standard language for every system administrator and build manager, but now &lt;strong&gt;everyone has been waiting on a new major release for more than seven years.&lt;/strong&gt; That is considered far too long.&lt;/em&gt;&lt;/blockquote&gt;As I'm mainly a C++ programmer in my bussines life, the news of the proceeding C++'s demise worry me, if only it acknowledges what I see with my own eyes. So this fact alone is not what I want to talk about, but rather about C++ similarity to Perl. Why?&lt;br /&gt;&lt;br /&gt;Look, can't you see a parallel to the Perl's fate here? I cite: &lt;em&gt;"everyone has been waiting on a new major release for more than seven years"&lt;/em&gt;. And there's still no Perl 6! Recall, there were plans for Parrot**, a common VM for Perl and Python (or was it just a joke?). Everyone was excited, but nope, Python won't use Parrot, Parrot is only in its 0.x versions**, so Perl 6 won't come soon, and the situation generally is a mess.&lt;br /&gt;&lt;br /&gt;Isn't that somehow similiar to the situation of C++? The last standard (or rather a correction of it) &lt;strong&gt;dates back to 1998, i.e. 10 years ago! It's even longer than Perl&lt;/strong&gt;. So maybe C++'s retreat is due to lack of new language standard like in Perl's case? When I look at Java, I must admit I envy it. Just recall the evolution: while Java 4 was still rather a primitive language without much interesting features (sorry, perhaps with exception of proxies and introspection), already Java 5 brought foreach, generics, annotations, lock-free synchronisation, lock-free data structures, autoboxing and a new the memory model. Admittedly Java 6 wasn't that iteresting language-wise but Java 7 will get things like closures or fork-join support for easy multicore parallelism***! This gets you a wholly new, interesting language.&lt;br /&gt;&lt;br /&gt;Contrast that with years-long discussion about what is to be included in the C++0x standard. And I still don't know what exactly is to come! Will a new memory model be included? And lambda functions? Garbage collection? Sometimes we all think that the new Standard won't be named C++0x, because years and years of discussion will be still needed!&lt;br /&gt;&lt;br /&gt;So maybe the quote of Bjarne Stroustrup****: &lt;blockquote&gt;&lt;em&gt;"Java shows that a (partial) break from the past—supported by massive corporate backing — can produce something new. C++ shows that a deliberately evolutionary approach can produce something new — even without significant corporate support."&lt;/em&gt; &lt;/blockquote&gt;is false? Mabe only a corporate-backed language has a chance today? Look how quickly Java developed and how the new C++ standard stalls. But maybe it's the "design by committe"-effect on the side of C++? I don't know.&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;* Programming Languages: Everyone Has a Favorite One: &lt;a href="http://www.ddj.com/cpp/207401593"&gt;ttp://www.ddj.com/cpp/207401593&lt;/a&gt;&lt;br /&gt;** Parrot Virtual Machine: &lt;a href="http://www.parrotcode.org/"&gt;http://www.parrotcode.org/&lt;/a&gt;&lt;br /&gt;*** Java theory and practice: Stick a fork in it, Part 1: &lt;a href="http://www.ibm.com/developerworks/java/library/j-jtp11137.html"&gt;ttp://www.ibm.com/developerworks/java/library/j-jtp11137.html&lt;/a&gt;&lt;br /&gt;**** his interview of 2006: &lt;a href="http://technologyreview.com/Infotech/17868/page3/"&gt;http://technologyreview.com/Infotech/17868/page3/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-980253859362488011?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/980253859362488011/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=980253859362488011' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/980253859362488011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/980253859362488011'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/04/language-trends-and-waiting-blues.html' title='Language trends and waiting blues.'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-7321349359302758621</id><published>2008-03-30T11:29:00.001-07:00</published><updated>2008-04-06T12:30:46.032-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='Qt'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>QString conversions, bugs, suprises and design</title><content type='html'>&lt;h2&gt;1. A trivial bug&lt;/h2&gt;&lt;br /&gt;It started with a pretty simple piece of code:&lt;br /&gt;&lt;pre&gt;    &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;QDomElement&lt;/span&gt; e = n.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;toElement&lt;/span&gt;(); &lt;span style="color:#009900;"&gt;// try to convert the node to an element.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    if(!e.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;isNull&lt;/span&gt;())&lt;br /&gt;    {&lt;br /&gt;        TRACE(e.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;tagName&lt;/span&gt;());&lt;br /&gt;        ....&lt;br /&gt;&lt;/pre&gt;where &lt;em&gt;TRACE()&lt;/em&gt; sends an object to &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;cout&lt;/span&gt;&lt;/em&gt;. The simplest of tasks you'd say, but it didn't compile. What? What year is it now? Are we in the early nineties? Doesn't library writers know about the standard library? It turned out, they know, so I used a slightly modified code:&lt;br /&gt;&lt;pre&gt;    TRACE(e.tagName().toStdString());&lt;br /&gt;&lt;/pre&gt;but it always crashed with Qt 4.3, Windows XP and VisualStudio 2005! Why? No time to check. After some reading of Qt docs, I settled with:&lt;br /&gt;&lt;pre&gt;    TRACE(e.tagName().toAscii().data());&lt;br /&gt;&lt;/pre&gt;It worked, but the code looked &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_5"&gt;extremely&lt;/span&gt; ugly! After copy-pasting it for &lt;em&gt;n &lt;/em&gt;times (no, &lt;em&gt;n &lt;/em&gt;wasn't equal to 3, as it should be according to the Agile gospel, sorry!!!) I longed for something more elegant and explicit, something like:&lt;br /&gt;&lt;pre&gt;    TRACE(&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;qstr&lt;/span&gt;_cast&amp;lt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;const&lt;/span&gt; char*&amp;gt;(e.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;tagName&lt;/span&gt;()))&lt;br /&gt;&lt;/pre&gt;The code was quickly written and worked instantly:&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;    // helper for &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;QString&lt;/span&gt; conversions&lt;br /&gt;    //  -- cute and explicit syntax: &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;qstr&lt;/span&gt;_cast&amp;lt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_13"&gt;const&lt;/span&gt; char*&amp;gt;()!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    template &amp;lt;class T&amp;gt;&lt;br /&gt;    &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_15"&gt;inline&lt;/span&gt; T &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_16"&gt;qstr&lt;/span&gt;_cast(&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_17"&gt;const&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_18"&gt;QString&lt;/span&gt;&amp;amp; s)&lt;br /&gt;    {&lt;br /&gt;        return T(s.toAscii().data());&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_19"&gt;inline&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_20"&gt;const&lt;/span&gt; char* &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_21"&gt;qstr&lt;/span&gt;_cast(&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_22"&gt;const&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_23"&gt;QString&lt;/span&gt;&amp;amp; s)&lt;br /&gt;    {&lt;br /&gt;        return s.toAscii().data();&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;Well, it worked on my machine but not in the target environment, and only in one (different) case. Why? Of course I blamed the Qt &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_24"&gt;runtime&lt;/span&gt; support, which already let me down with the &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_25"&gt;toStdString&lt;/span&gt;()&lt;/em&gt; function. Then I saw the same effect in the debugger on my &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_26"&gt;developemnt&lt;/span&gt; machine, and I blamed it on &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_27"&gt;multithreading&lt;/span&gt;: there must be something wrong with locking when accessing this particular &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_28"&gt;QString&lt;/span&gt;&lt;/em&gt; instance. But at last I found time to remove this bug, and looked at the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_29"&gt;sychronisation&lt;/span&gt;, and it was 100% correct. The bug was hidden elsewhere. The new (correct) code is:&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#009900;"&gt;    // helper for &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_30"&gt;QString&lt;/span&gt; conversions&lt;br /&gt;    //  -- cute and explicit syntax: &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_31"&gt;qstr&lt;/span&gt;_cast&amp;lt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_33"&gt;const&lt;/span&gt; char*&amp;gt;()!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    template &amp;lt;class T&amp;gt;&lt;br /&gt;    &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_35"&gt;inline&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_36"&gt;QByteArray&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_37"&gt;qstr&lt;/span&gt;_cast(&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_38"&gt;const&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_39"&gt;QString&lt;/span&gt;&amp;amp; s, T* t = 0)&lt;br /&gt;    {&lt;br /&gt;&lt;span style="color:#009900;"&gt;        // the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_40"&gt;QByteArray's&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_41"&gt;const&lt;/span&gt; char* conversion op. will be applied&lt;br /&gt;        // by the compiler in the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_42"&gt;const&lt;/span&gt; char* context!&lt;/span&gt;&lt;br /&gt;        return s.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_43"&gt;toAscii&lt;/span&gt;();&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;As you can see, the old code returned a pointer to the data of a temporary instance of an &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_44"&gt;QByteArray&lt;/span&gt;&lt;/em&gt; object, and of course it pointed into the void. End of story!&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;2. Discussion of the trivial bug&lt;/h2&gt;&lt;br /&gt;Why am I writing this? Isn't it just a banal and stupid bug? I don't think so. I think there are some points to be made.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The first one&lt;/strong&gt; is that Qt doesn't follow the &lt;em&gt;"Principle of Least Surprise"&lt;/em&gt;*. This code should work out of the box: &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_45"&gt;cout &amp;lt;&amp;lt; qtStringObj;&lt;/em&gt;! Why? Because C++ programmers wrote code like this for centuries! Well, almost. In the "freedom languages" ;-)** you are accustomed to writing just: &lt;em&gt;print &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_49"&gt;someObj&lt;/span&gt;;&lt;/em&gt; and it always works. Mind I didn't use the word "modern languages" but in modern times we expect it just to be working!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The second one&lt;/strong&gt; is that Qt doesn't want me to use the standard library! There is no shift operator for &lt;em&gt;std::&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_50"&gt;ostream&lt;/span&gt;&lt;/em&gt; instead they want me to use their &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_51"&gt;QStream&lt;/span&gt;&lt;/em&gt; class, which I don't know and have no desire to learn. As for &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_52"&gt;QString&lt;/span&gt;&lt;/em&gt; class the Qt partisans maintain that it is vastly superior to the &lt;em&gt;std::string&lt;/em&gt; class, but what about &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_53"&gt;cout&lt;/span&gt;&lt;/em&gt;? It is somehow an C++ keyword by now. And besides, why aren't I allowed to make my own choices, even if I choose to use an inferior alternative? Maybe I don't have to be that fast in my prototype implementation? You somehow feel trapped in the proprietary Qt world, and somehow cast back in time. Is that the backwards &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_54"&gt;compatibility&lt;/span&gt; with the original 80-ties or 90-ties design? It feels somehow frumpy.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The third one&lt;/strong&gt; is that once I decided on the syntactic appearance of the function (i.e. &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_55"&gt;qstr&lt;/span&gt;_cast&amp;lt;&amp;gt;()&lt;/em&gt; and not for example&lt;em&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_57"&gt;cstr&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_58"&gt;ptr&lt;/span&gt;()&lt;/em&gt; or &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_59"&gt;CSTR&lt;/span&gt;()&lt;/em&gt;), I subconsciously settled on a implementation: just get the internal string data and export the pointer to the char buffer. Alas, in case of the &lt;em&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_60"&gt;QString&lt;/span&gt;&lt;/em&gt; this doesn't work that way! Moreover, it's not only the name choice alone, this code would work with all the string classes I knew in my long C++ life. So maybe I chose the name because &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_61"&gt;subconsciously&lt;/span&gt; I already knew how to implement it? We pride &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_62"&gt;ourself&lt;/span&gt; on being rational beings, &lt;strong&gt;but we don't know how much we depend on &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_63"&gt;subconscious&lt;/span&gt; shortcuts&lt;/strong&gt;, which will normally work in a familiar territory, but fail when trying something new. Just like me, as I'm relatively new to Qt.&lt;br /&gt;&lt;br /&gt;And what's &lt;strong&gt;the moral&lt;/strong&gt;? It's elementary dear Watson: RTFM first! Or perhaps: don't mix Qt and &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_64"&gt;STL&lt;/span&gt;???&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* for example &lt;em&gt;"Applying the Rule of Least Surprise"&lt;/em&gt; from &lt;em&gt;"The Art of Unix Programming"&lt;/em&gt; by E.S. Raymond: &lt;a href="http://www.faqs.org/docs/artu/ch11s01.html"&gt;http://www.faqs.org/docs/artu/ch11s01.html&lt;/a&gt; or &lt;em&gt;"Principle of Least Astonishment"&lt;/em&gt; at Portland Pattern Repository: &lt;a href="http://c2.com/cgi/wiki?PrincipleOfLeastAstonishment"&gt;http://c2.com/cgi/wiki?PrincipleOfLeastAstonishment&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;** I thought it was a joke, but not, it's an essay by Kevin Barnes: &lt;a href="http://codecraft.info/index.php/archives/20/"&gt;http://codecraft.info/index.php/archives/20/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-7321349359302758621?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/7321349359302758621/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=7321349359302758621' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7321349359302758621'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/7321349359302758621'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/03/qstring-conversions-bugs-suprises-and.html' title='QString conversions, bugs, suprises and design'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-8080620801422537065</id><published>2008-02-26T23:09:00.001-08:00</published><updated>2008-02-26T23:47:54.465-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='servlets'/><category scheme='http://www.blogger.com/atom/ns#' term='private'/><title type='text'>Rentree plus Some Comments on Google-Solvers &amp; Co</title><content type='html'>Hi everybody! I'm back from my travels and can write some more blog-gobbledegook again (which I'll gladly do). I was away for some serious off-piste skiing in St.Anton, descending some pretty steep, big faces, and taking my first pinwheel tumble on a 40 degrees, Alaska-like, highly exposed, rock-fringed slope. Whow! And then I was back in town, and procuring my next project in just 2 days, taking a head-first plunge here as well ;-).&lt;br /&gt;&lt;br /&gt;So let me start my rentree into the blogosphere with something less exciting, i.e. some comments on my previous posts. In fact, I wanted to comment on the Google-Solvers post for quite a long time, so it suits me fine.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Commenting on Java vs. C++&lt;/h2&gt;&lt;br /&gt;As some of you maybe remember, in a previous post* I compared the perfomance of Python, Perl, Java and C++ (admittedly in a rather ad-hoc manner), and made at first the error of not using the optimization switch of my C++ compiler. Me, a die-hard C++ hacker!!! This resulted in Java and C++ being on par performance-wise. So you can imagine my amazement some time ago when I saw in Uncle Bob's blog these statements**:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;You can blame this &lt;b&gt;on the non-optimized gcc compiler I was using (cygwin) &lt;/b&gt;but again: Oh boo hoo!. If there are any C++ programmers out there who smirk at the supposed slowness of Java, I think you'd better reconsider.&lt;br /&gt;...&lt;br /&gt;I'll grant you that the JVM can be large. However, if you assume it's already there, then the size of the bytecodes for the application itself need not be very large at all. And the heap can be constrained to a relatively small size to prevent virtual memory thrashing. So, if _engineered_ a java app &lt;strong&gt;should give a C++ app a run for it's money in most cases&lt;/strong&gt;. -UB&lt;br /&gt;&lt;/em&gt;&lt;/blockquote&gt;&lt;br /&gt;Well, this started me thinkig. When you are looking for information concerning Java performance, you can see some typical quotes like this on the web ***:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;John Davies: It is just the main reason why there are &lt;b&gt;still diehards that stick with C/C++ &lt;/b&gt;because you can guarantee performance, not necessarily faster, but it just guarantees the performance and we will run something in Java, it will run quite frequently faster on C [he means JVM] than it would have done in C/C++, but every now and then it will just pause and that pause can be extremely expensive.&lt;/em&gt;&lt;/blockquote&gt;If you'll allow a small comment (hypothesis?, heresy?) from yours truly: &lt;b&gt;what if all those measurements are done without the -O2 switch? &lt;/b&gt;It's an all to easy trap to fall into (see my own sufferings*) and an excellent opportunity for the marketing people to use some techniques from the seminal book &lt;em&gt;"How to Lie with Statistics"&lt;/em&gt; ;-). Becuse you really can't explain to me that a language which is: 1. interpreted, 2. relies heavily on dynamic memory allocation, and 3. supports garbage collection, can be faster than one which doesn't do it, no matter how much optimization you throw at it! Or can you? If you've read the &lt;em&gt;"Discipline of Programming"&lt;/em&gt; book of E. Dijkstra, you know that the first law he establishes there is the "there-are-no-miracles law" :-). So you may guess my position on this.&lt;br /&gt;&lt;br /&gt;BTW, maybe I (or someone else) should email Mr. Stroustrup on this one, and see what he's got to say. It would be interesting, I guess, so maybe I'll do it anyway.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;And now more comments&lt;/h2&gt;&lt;br /&gt;Let's continue in the commenting vein: sometime ago I was looking for web-frameworks in C++, and wanted even reimplement Java's Servlet classes in C++ (well, I didn't...). But in the last DDJ I saw an article**** about a C++ web-framework at last! Fortunately, I didn't implement the C++ servlet classes, because it was a really stupid idea! The Wt-framework ("witty" - &lt;a href="http://www.webtoolkit.eu/wt/"&gt;http://www.webtoolkit.eu/wt/&lt;/a&gt;) seems to be rather like modern Java frameworks - GWT, ThinWire or Wicket - you define your application classes in C++, and the HTML rendering comes from the framework! In contrast to the Servlet specification, which is very low level and which nobody uses directly now! Thank God I was lazy! I'll have to try Wt out, perhaps there is an C++ alternative for web-programming anyway.&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* &lt;a href="http://ib-krajewski.blogspot.com/2007/07/google-solvers.html"&gt;http://ib-krajewski.blogspot.com/2007/07/google-solvers.html&lt;/a&gt;&lt;br /&gt;** here he did basically the same but with Ruby in place of Python: &lt;a href="http://butunclebob.com/ArticleS.UncleBob.SpeedOfJavaCppRuby"&gt;http://butunclebob.com/ArticleS.UncleBob.SpeedOfJavaCppRuby&lt;/a&gt;&lt;br /&gt;*** "Improving JVM scalability and performance": &lt;a href="http://blog.chinaunix.net/u1/45382/showart_356477.html"&gt;http://blog.chinaunix.net/u1/45382/showart_356477.html&lt;/a&gt; or &lt;a href="http://go.techtarget.com/r/1950475/6108168"&gt;http://go.techtarget.com/r/1950475/6108168&lt;/a&gt;&lt;br /&gt;**** "Wt: A Web Toolkit": &lt;a href="http://www.ddj.com/cpp/206401952"&gt;http://www.ddj.com/cpp/206401952&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-8080620801422537065?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/8080620801422537065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=8080620801422537065' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/8080620801422537065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/8080620801422537065'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/02/rentree-plus-some-comments-on-google.html' title='Rentree plus Some Comments on Google-Solvers &amp; Co'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-3835119328357633623</id><published>2008-01-31T02:40:00.000-08:00</published><updated>2008-01-31T03:53:37.265-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>C++ pocket lambda library, part 2</title><content type='html'>In the previous post in this series* I promised to tackle some more advanced topics from my pocket lambda library. To start with something, let us gratuitously choose &lt;em&gt;"currying"&lt;/em&gt; first. Do you know what currying is? No, it has nothing to do with food, but rather with an american mathematician named, ehm..., Haskell B. Curry. In his formalization of the notion of a computable function (λ-calculus) he used (for simplicity's sake) only functions with one parameter. Come again? What about all the other functions? For this he used a trick: he defined a function which returns a new function where the first argument is fixed, and the second one remains unbound. When used recursively, we can reduce any function of n-arguments to n functions of 1 argument! &lt;strong&gt;Mathematics can be as cool as programming sometimes!&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I bet you've seen (and used) it before! Yes, STL provides &lt;em&gt;bind1st&lt;/em&gt; and &lt;em&gt;bind2nd&lt;/em&gt; functions, which are doing exaclty that: currying! In other languages like Python, Perl, Ruby, Haskell, etc, it's possible too, though sometimes through a library extension. Groovy supports IMHO the most explicite (and cool) form:&lt;pre&gt;    def triple_it = {x,y -&gt; x*y }.curry(3);&lt;/pre&gt;&lt;h2&gt;1. Our task&lt;/h2&gt;&lt;br /&gt;What we want to do is to extend the STL binder such that they would work the &lt;em&gt;_$1&lt;/em&gt; placeholders. I think of something like the following:&lt;pre&gt;    for_each(vec.begin(), vec.end(), bind(countVector, 'X', 1.222, _$1));&lt;br /&gt;    for_each(vec.begin(), vec.end(), bind(countVector1, _$1, 1.222, 'Y'));&lt;br /&gt;    for_each(vec.begin(), vec.end(), bind(countVector2, _$1));&lt;br /&gt;&lt;br /&gt;    for_each(vec.begin(), vec.end(), bind(pr_sinus, _$1*2));&lt;br /&gt;    const float pi = 3.14; &lt;span style="color:#009900;"&gt;// well, not exactly ;-)&lt;/span&gt;&lt;br /&gt;    for_each(vec.begin(), vec.end(), -bind(sinus, _$1*(pi/180.0)) ); &lt;/pre&gt;We assume here that the bind function is pulled in by the appropriate namespace definition, as I want avoid to have to write it like &lt;em&gt;kmx::lambda::bind(sinus, kmx::lambda::_$1).&lt;/em&gt; In fact, I never tried out the fully qualified form, shame on me :-(((.&lt;br /&gt;&lt;br /&gt;How can we do that? Well there's no need to reinvent the wheel - Boost library already has it, and it's even a part of the C++0x TR.1 standard library extension (&lt;em&gt;tr1::bind&lt;/em&gt;). So we can look at the code, or even read about the techniques needed in the implementation**. So if you want, you can spare yourself this post and read ** instead!&lt;br /&gt;&lt;h2&gt;&lt;br /&gt;2. Basic mechanisms&lt;/h2&gt;&lt;br /&gt;Well, here is the bind function for the 2 arguments case:&lt;pre&gt;    &lt;span style="color:#009900;"&gt;// 2 args&lt;/span&gt;&lt;br /&gt;    template &amp;lt;class F, class A1, class A2&amp;gt;&lt;br /&gt;        binder&amp;lt;F, list2&amp;lt;A1, A2&amp;gt; &amp;gt; bind(F f, A1 a1, A2 a2)&lt;br /&gt;    {&lt;br /&gt;        typedef list2&amp;lt;A1, A2&amp;gt; list2_type;&lt;br /&gt;        list2_type list(a1, a2);&lt;br /&gt;        return binder&amp;lt;F, list2_type&amp;gt;(f, list);&lt;br /&gt;    } &lt;/pre&gt;What is it doing? Basically it stores the arguments to be bound in a custom argument list (&lt;em&gt;class list2&amp;lt;&amp;gt;&lt;/em&gt;). Then the function and its arguments are used to create the instance of the actual binder class:&lt;pre&gt;    template &amp;lt;class F, class List&amp;gt; class binder : public lambda_expr&lt;br /&gt;    {&lt;br /&gt;        F m_f;&lt;br /&gt;        List m_list;&lt;br /&gt;&lt;br /&gt;     public:&lt;br /&gt;        binder(F f, List list): m_f(f), m_list(list) {}&lt;br /&gt;&lt;br /&gt;        &lt;span style="color:#009900;"&gt;// OPEN TODO --&amp;gt; only working for void funct!!!&lt;/span&gt;&lt;br /&gt;        template &amp;lt;class A1&amp;gt; void operator() (A1 a1)&lt;br /&gt;        {&lt;br /&gt;            list1&amp;lt;A1&amp;gt; list(a1); // store the actual arg&lt;br /&gt;            m_list(m_f, list); // forward to curried funct: m_f+m_list&lt;br /&gt;        }&lt;br /&gt;    }; &lt;/pre&gt;What is it doing now? It's a functor accepting (in the H.B.Curry's true manner) only one argument. Which one? In the context of an STL algorithm it will be the current value of the iterator. So our task is to sort out to which of the arguments of a function this iterator is bound. Take our previous example: &lt;em&gt;for_each(vec.begin(), vec.end(), bind(countVector1, _$1, 1.222, 'Y')).&lt;/em&gt; Here the iterator has to be bound to the first argument of the function - 1.222, and &lt;em&gt;'Y'&lt;/em&gt; to the second and third ones. The binder object stores the actual argument in the custom argument list (&lt;em&gt;class list1&amp;lt;&amp;gt;&lt;/em&gt;) and invokes the function &lt;em&gt;m_f&lt;/em&gt; in the context of the bound arguments &lt;em&gt;m_list,&lt;/em&gt; remembering the current argument in the custom argument list &lt;em&gt;class list1&amp;lt;&amp;gt;&lt;/em&gt;. All this is accomplished by heavy use of the &lt;em&gt;listN&amp;lt;&amp;gt;&lt;/em&gt; classes, to which we turn our attention now:&lt;pre&gt;    template &amp;lt;class A1, class A2&amp;gt; class list2&lt;br /&gt;    {&lt;br /&gt;&lt;span style="color:#009900;"&gt;        // args: one of them is a placeholder!&lt;br /&gt;        //  -- list1 will detect it!&lt;/span&gt;&lt;br /&gt;        A1 m_a1;&lt;br /&gt;        A2 m_a2;&lt;br /&gt;     public:&lt;br /&gt;&lt;br /&gt;       list2(A1 a1, A2 a2): m_a1(a1), m_a2(a2) {};&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#009900;"&gt;       // apply to arguments and placeholders!&lt;/span&gt;&lt;br /&gt;       template &amp;lt;class F, class List1&amp;gt;&lt;br /&gt;           void operator() (F f, List1 list1)&lt;br /&gt;           {&lt;br /&gt;               f(list1[m_a1], list1[m_a2]);&lt;br /&gt;           }&lt;br /&gt;    }; &lt;/pre&gt;Well, &lt;em&gt;list2&amp;lt;&amp;gt;&lt;/em&gt; doesn't do that much, it invokes the curried function, but the detection of bound arguments is redirected to the most important class here: &lt;em&gt;list1&amp;lt;&amp;gt;&lt;/em&gt;! Let us have a look at it:&lt;pre&gt;    template &amp;lt;class A1&amp;gt; class list1&lt;br /&gt;    {&lt;br /&gt;        A1 m_a1;&lt;br /&gt;&lt;br /&gt;     public:&lt;br /&gt;        explicit list1(A1 a1): m_a1(a1) {}&lt;br /&gt;&lt;br /&gt;        &lt;span style="color:#009900;"&gt;// if placeholder:&lt;/span&gt;&lt;br /&gt;        A1 operator[] (placeholder&amp;lt;1&amp;gt;) const { return m_a1; }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color:#009900;"&gt;// not placeholders: return the ball&lt;/span&gt;&lt;br /&gt;        template &amp;lt;class T&amp;gt;&lt;br /&gt;            T operator[] (T val) const { return val; }&lt;br /&gt;    }; &lt;/pre&gt;Well, this isn't very complicated: complier will detect when a placeholder was placed and use then the current argument (i.e. the iterator). In other cases, the stored argument value will be used, i.e. the value used to curry the function &lt;em&gt;f&lt;/em&gt;. As the value is stored in the &lt;em&gt;listN&amp;lt;&amp;gt;&lt;/em&gt; class, it is done via a trick: the&lt;em&gt; listN&amp;lt;&amp;gt;&lt;/em&gt; class tries to access the placeholder's &lt;em&gt;_$1&lt;/em&gt; value by using the index operator of the &lt;em&gt;list1&amp;lt;&amp;gt;&lt;/em&gt; class, but in non-placeholder cases the index value is simply returned to &lt;em&gt;listN&amp;lt;&amp;gt; &lt;/em&gt;to be used as n-th argument (a kind of rebound!).&lt;br /&gt;&lt;br /&gt;For the sake of completeness, i.e. in case of &lt;em&gt;bind(sinus, _$1)&lt;/em&gt; (who'd need something like that?), we need the function call operator in the &lt;em&gt;list1&amp;lt;&amp;gt;&lt;/em&gt; class:&lt;pre&gt;    template &amp;lt;class A1&amp;gt; class list1&lt;br /&gt;    {&lt;br /&gt;       ...&lt;br /&gt;       &lt;span style="color:#009900;"&gt;// apply to arguments and placeholders!&lt;/span&gt;&lt;br /&gt;       template &amp;lt;class F, class List1&amp;gt;&lt;br /&gt;           void operator() (F f, List1 list1)&lt;br /&gt;           {&lt;br /&gt;               f(list1[m_a1]);&lt;br /&gt;           }&lt;br /&gt;    };&lt;/pre&gt;To bind 3-argument functions we need two more templates to be added: the &lt;em&gt;list3&amp;lt;&amp;gt;&lt;/em&gt; class and the &lt;em&gt;bind(F f, A1 a1, A2 a2, A3 a3)&lt;/em&gt; function, for 4 arguments another two, and so on, and on... But I don't think anyone should need more than 5 arguments in their functions, do you?&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;3. Extensions&lt;/h2&gt;&lt;br /&gt;With the above techniques we can write &lt;em&gt;bind(countVector1, _$1, 1.222, 'Y')&lt;/em&gt; but not &lt;em&gt;bind(countVector, _$1*2)&lt;/em&gt; or &lt;em&gt;bind(sinus, _$1*(pi/180.0)).&lt;/em&gt; What can we do about this? Above we wondered about the &lt;em&gt;bind(sinus, _$1) &lt;/em&gt;case, but here we can use it to our advantage. We extend the &lt;em&gt;list1&amp;lt;&amp;gt; &lt;/em&gt;class like that:&lt;pre&gt;    template &amp;lt;class A1&amp;gt; class list1&lt;br /&gt;    {&lt;br /&gt;       ...&lt;br /&gt;        template &amp;lt;class T&amp;gt;&lt;br /&gt;            T operator[] (Mul&amp;lt;T&amp;gt;&amp;amp; e) const { return e(m_a1); }&lt;br /&gt;   };&lt;/pre&gt;So we can see that the &lt;em&gt;list1&amp;lt;&amp;gt;&lt;/em&gt; class is indeed a central one! We extended its rebound mechanism to support the multiplication. Oh, uhm, that wasn't pretty! Why couldn't we simply use a general forwading here? The reason is, I left is as a TODO in code (shame on me :-((() but never came around to implement this. I tried the following:&lt;pre&gt;    A1 operator[] (lambda_expr&amp;amp; e) const { return e(); }&lt;/pre&gt;but I didn't finish it, and I don't remember if it worked and if it didn't, why. It was almost one year ago and I don't remember all the details, sorry. OK, that could be done better, but (as I said in my previous post*) "it's a simple library". If you need another operation to be supported in the &lt;em&gt;bind&lt;/em&gt; context, simply add it to the &lt;em&gt;list1&amp;lt;&amp;gt;.&lt;/em&gt; It remains to be clarified if the simplicity of this library is an advantage, but some measurements were reported, which say that the many layers in a fully grown-up lambda library (like Boost) have a detrimental effect on the performance, because the code gets so complex that the optimizers cannot cope with it!*** And the compilation gets longer too. &lt;strong&gt;So maybe such a primitive implementation isn't totally in the wrong?&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;There is another extension I tried. Again we have to extend the central &lt;em&gt;list1&amp;lt;&amp;gt;&lt;/em&gt; class:&lt;pre&gt;    template &amp;lt;class A1&amp;gt; class list1&lt;br /&gt;    {&lt;br /&gt;       ...&lt;br /&gt;       &lt;span style="color:#009900;"&gt;// bind a void member function e.g.: int (T::*)(void *)&lt;/span&gt;&lt;br /&gt;       template &amp;lt;class T, typename Ret, class List1&amp;gt;&lt;br /&gt;           Ret operator() (Ret(T::*f)(void), List1 list1)&lt;br /&gt;           {&lt;br /&gt;               return ((list1[m_a1])-&amp;gt;*f)();&lt;br /&gt;           }&lt;br /&gt;    };&lt;/pre&gt;What does it do? It is supposed to be used like that:&lt;pre&gt;    vector&amp;lt;SomeClass&amp;gt; vec(10);&lt;br /&gt;    for_each(vec.begin(), vec.end(), bind(&amp;amp;SomeClass::compute(), _$1);  &lt;/pre&gt;So for each object in a collection its (void) member function will be called. But again, I don't know if it actually worked, as there is no testcase for that in my code (but I think it should). And not everything that's possible makes sense anyway: here the code is misleading, we'd rather like to express this with &lt;em&gt;_$1-&amp;gt;compute()&lt;/em&gt;!&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;4. Last words&lt;/h2&gt;&lt;br /&gt;Well, that's everything I can say about currying support in my library. In the next post(s) I'll show you how to support lambda expressions like: &lt;em&gt;cout &amp;lt;&amp;lt; "---" &amp;lt;&amp;lt; _$1 &amp;lt;&amp;lt; "\n",&lt;/em&gt; and how to access a member or a member function of an object from a collection. What else? Maybe some conditional lambda expressions and some general discussion? Look out.&lt;br /&gt;&lt;br /&gt;A general question can be answered here: what about the code of my library? Will it be publicly available? And what about the TODOS? And the missing orthogonality? The anwer is, I don't want to (and haven't got time, for that matter) polish the rough edges and add some more orthogonality. It was a fun writing the library, it took me only a couple of days (about 4, I think) , it is simple, &lt;strong&gt;and it has shown me that you don't have to be scared of the template metaprogramming&lt;/strong&gt;. Of course, I wasn't a novice with templates, but I expected more resistance from C++. Maybe it's because of the library's simplicity?&lt;br /&gt;&lt;br /&gt;Whatever. This library is not ready, is not complete, and I leave it as it is now.&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* &lt;a href="http://ib-krajewski.blogspot.com/2007/12/c-pocket-lambda-library.html"&gt;http://ib-krajewski.blogspot.com/2007/12/c-pocket-lambda-library.html&lt;/a&gt;&lt;br /&gt;** Chris Gibson, "How Do Those Funky Placeholders Work?", Overload 73: &lt;a href="http://www.accu.org/index.php/journals/1397"&gt;http://www.accu.org/index.php/journals/1397&lt;/a&gt;&lt;br /&gt;*** C++0x proposal: "Lambda expressions and closures for C++" : &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-3835119328357633623?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/3835119328357633623/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=3835119328357633623' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/3835119328357633623'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/3835119328357633623'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/01/c-pocket-lambda-library-part-2.html' title='C++ pocket lambda library, part 2'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-5545422710873904135</id><published>2008-01-25T14:30:00.001-08:00</published><updated>2008-01-29T01:26:40.475-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='web sevices'/><category scheme='http://www.blogger.com/atom/ns#' term='SOA'/><title type='text'>SOA in practice: a YAMS?</title><content type='html'>In a recent installmet of this blog I already wrote about SOA a little*, but I said that I'm going to read a book of a highly valued author to answer a couple of questions which seemed to stem from my lack of understanding of the subject. Basically my gut feeling was, that SOA (and SOAP) is just a new hype, selling old concepts in new disguise and under new acronyms. Or, in other words: &lt;strong&gt;why do we need yet another middleware standard &lt;/strong&gt;(YAMS)? On the other hand I wondered: if so many highly intelligent people are buying this (i.e. the YAMS), there must be some value in it!&lt;br /&gt;&lt;br /&gt;As not to leave my judgements to the mercy of my gut feelings I decided to read some no-nonsense SOA book. This would be close to impossible until recently, as most SOA books were full of marketing drivel and pseudo-scientific, wishy-washy definitions. But recenly a more practical SOA book was published:&lt;em&gt; "SOA in Practice"&lt;/em&gt; by N. Josuttis**. As for now, I've read somehow 1/3 of it, which enables me to present some thoughts based based on more solid fundaments.&lt;br /&gt;&lt;br /&gt;OK, so was my gut feeling right? Well, both yes and no! SOA is about defining basic services (which can be compared to defining the remote procedures of old), then to combine those simple services (or RPC calls) into more complete, well... services, and then building a business process flow out of those building blocks. And this using SOAP protocol and Web-Services technology. Let me say it: there's nothing new here - &lt;strong&gt;nihil novi sub sole!&lt;/strong&gt; The issues coming up when designing a SOA architecture (i.e. a service-oriented one) are all familiar to me from distributed system design, and the author himself admits it readily. So I was right in my previous post? Technically, yes, with perhaps an exception of BPEL. But???&lt;br /&gt;&lt;br /&gt;...but I must admit that SOA indeed has brought in something new, althought in a rather unexpected way! At at the first sight, SOAis only an application of sound distributed system design in corporate settings. And here it is: in corporate settings! As it seems, that wasn't so common before, the organisational and departamental issues were most important then, and now system design issues are on par with them! And that's a huge step forward. Apparently, &lt;strong&gt;you need a massive hype vawe to convince corporate people to use some common&lt;/strong&gt; &lt;strong&gt;sense when designing systems&lt;/strong&gt;!*** And as a Garnter analyst coined the SOA term**** and other Gartner analysts hyped it, the busines people started to hear. And this, and not the usage of SOAP protocol or Web-Services is the real breaktrough of SOA.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;PS:&lt;/strong&gt; And, of course, SOA &lt;strong&gt;is&lt;/strong&gt; SOAP and WS-* in practice, just as I conjectured*, contrary to what you'd read in some high-brow SOA books.&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* here I tried to answer the question why SOAP and Web-Services aren't simple (which is the first letter of the SOAP acronym!): &lt;a href="http://ib-krajewski.blogspot.com/2007/11/web-services-soa-and-rrest.html"&gt;http://ib-krajewski.blogspot.com/2007/11/web-services-soa-and-rrest.html&lt;/a&gt;&lt;br /&gt;** book's homepage: &lt;a href="http://www.soa-in-practice.com/"&gt;http://www.soa-in-practice.com/&lt;/a&gt;&lt;br /&gt;*** or putting it more friendly: there's a huge chasm between business and technical people!&lt;br /&gt;**** SOA-definition by Gartner: &lt;a href="http://www.gartner.com/DisplayDocument?ref=g_search&amp;amp;id=302868&amp;amp;subref=browse"&gt;http://www.gartner.com/DisplayDocument?ref=g_search&amp;amp;id=302868&amp;amp;subref=browse&lt;/a&gt; and &lt;a href="http://www.gartner.com/DisplayDocument?ref=g_search&amp;amp;id=302869&amp;amp;subref=browse"&gt;http://www.gartner.com/DisplayDocument?ref=g_search&amp;amp;id=302869&amp;amp;subref=browse&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-5545422710873904135?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/5545422710873904135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=5545422710873904135' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/5545422710873904135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/5545422710873904135'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2008/01/soa-in-practice-yams.html' title='SOA in practice: a YAMS?'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-835490308044251717</id><published>2007-12-31T10:31:00.001-08:00</published><updated>2008-01-25T14:24:48.074-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='private'/><title type='text'>Some jokes for the new year</title><content type='html'>Happy new year everybody!&lt;br /&gt;&lt;br /&gt;What about some (programming) jokes for a smooth beginning of a new year? Let's start with an old one:&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;em&gt;How many software developers does it take to change a lightbulb? 10 to discuss the requirements, 10 more to do the analysis, 10 more to do the design, &lt;strong&gt;and one to write the code&lt;/strong&gt;, 12 years later.&lt;/em&gt;&lt;/blockquote&gt;&lt;div&gt;Well, that's definitely a &lt;em&gt;"waterfall-model"&lt;/em&gt; one! Do you know some XP-jokes? I don't think there are any, as Agility (with the capital A!) is much to cool nowadays to be joked about ;-)! So, as not to let you think I'm a hopeless oldtimer, here is some more modern one, actually a cartoon* : &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img id="BLOGGER_PHOTO_ID_5153061479568296066" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 449px; CURSOR: hand; HEIGHT: 258px; TEXT-ALIGN: center" height="179" alt="" src="http://bp0.blogger.com/_79IsVE3vX_Y/R4NaHRNqyII/AAAAAAAAABU/OubIc7x1aes/s320/JSF_cartoon.jpg" width="357" border="0" /&gt;Well, a discussion could begin about Java, its low-level interfaces, its megatons of frameworks, etc... but not this time.&lt;br /&gt;&lt;br /&gt;And here's another one, this time more higher-order and functional (Haskell, if I'm right)**:&lt;br /&gt;&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5153061870410320018" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_79IsVE3vX_Y/R4NaeBNqyJI/AAAAAAAAABc/MM4OvhJ3zJ4/s320/haskell-io-monad.jpg" border="0" /&gt;Isn't it cute?&lt;br /&gt;&lt;br /&gt;And, at last, hava a look at a day in programmers life: &lt;a href="http://www.muza.pl/7001.html?cc=0.6113369317218645&amp;amp;mode=image&amp;amp;img=0#gallery"&gt;http://www.muza.pl/7001.html?cc=0.6113369317218645&amp;amp;mode=image&amp;amp;img=0#gallery&lt;/a&gt;. It's really hard sometimes!!!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;PS:&lt;/strong&gt; If you know some XP or Agile jokes, please let me know!&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;* sorry, don't remember the source :-((&lt;br /&gt;** source: &lt;a href="http://arcanux.org/lambdacats.html"&gt;http://arcanux.org/lambdacats.html&lt;/a&gt;, thanks to Philip Wadler ;-) &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3870801931584460413-835490308044251717?l=ib-krajewski.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ib-krajewski.blogspot.com/feeds/835490308044251717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3870801931584460413&amp;postID=835490308044251717' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/835490308044251717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3870801931584460413/posts/default/835490308044251717'/><link rel='alternate' type='text/html' href='http://ib-krajewski.blogspot.com/2007/12/some-jokes-for-new-year.html' title='Some jokes for the new year'/><author><name>Marek Krj</name><uri>http://www.blogger.com/profile/16877868679118775297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_79IsVE3vX_Y/R4NaHRNqyII/AAAAAAAAABU/OubIc7x1aes/s72-c/JSF_cartoon.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3870801931584460413.post-3720685909889039744</id><published>2007-12-15T06:23:00.000-08:00</published><updated>2007-12-24T05:43:11.960-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Boost'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>C++ pocket lambda library</title><content type='html'>What I wanted to do first was to write an article for my old homepage and describe my private C++ lambda library implementation, as I wantded to jazz up my web-site, and to brag a little too... And only because I couldn't write this article this very blog was born. So at last I'm going to do what I should have done long ago, despite of the pre-christmas madness, and the fact that I've got to find a new project middle in the holiday season!&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;1. The Problem &lt;/h2&gt;&lt;br /&gt;I like STL. But one thing always drives me crazy! In C++ you cannot write this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  for_each(v.begin(), v.end(),&lt;br /&gt;           new class&amp;lt;T&amp;gt; Homomorphoize { void operator()(T* t){do_it(t);}( ));&lt;/pre&gt;nor even that:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  class&amp;lt;T&amp;gt; Homomorphoize { void operator()(T* t){do_it(t); };&lt;br /&gt;  for_each(v.begin(), v.end(), Homomorphoize() );&lt;/pre&gt;You must declare the doer &lt;em&gt;Homomorphoize&lt;/em&gt; functor in the global scope, as to be able to use it in the &lt;em&gt;for_each&lt;/em&gt; template instantiation. Yada, yada, yada? Let's see what it means in practice. One of my C++ files looked roughly like that:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  &lt;span style="color:#009900;"&gt;//--- helper classes: no inner classes in C++ :-((&lt;/span&gt;&lt;br /&gt;  ...&lt;br /&gt;  class Finalizer&lt;br /&gt;  {&lt;br /&gt;    public: void operator()(Worker* w) { ...&lt;br /&gt;    ...&lt;br /&gt;  };&lt;br /&gt;  class Starter&lt;br /&gt;  {&lt;br /&gt;    void operator()(Worker* w) { ....&lt;br /&gt;    ...&lt;br /&gt;  };&lt;br /&gt;  class NotifSrcFilter : public Worker::TestEventObj&lt;br /&gt;  {&lt;br /&gt;    virtual bool test(D_ev* ev) const { ....&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:#009900;"&gt;&lt;br /&gt;  // --- main&lt;/span&gt;&lt;br /&gt;  main() {&lt;br /&gt;    ...&lt;br /&gt;    // and start&lt;br /&gt;    for_each(m_workers.begin(), m_workers.end(), Starter());&lt;br /&gt;    ...&lt;/pre&gt;And as I like STL rather much, thers will be always a couple of such classes starting each of my C++ files. So what is so wrong with it? Certailnly you could live with this, couldn't you? Well, I don't like the separation of code parts pertaining to a single task. Typically the functors so defined are rather short and will be used in a one single place! So IMHO it's a waste of time looking up the functor definition from the place where it is used in some STL algorithm. And it always annoys me when I'm reading the code: the long prelude which &lt;strong&gt;must be skipped to arrive at the real code!&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;2. The solution&lt;/h2&gt;&lt;br /&gt;So what could be done? There are several alternatives.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Write the code in Perl, Pyton, Groovy, etc: these languages have some support for lambda expressions, and many of us would readily jump to the occasion, however in commercial environment it is not always an option. And beside this, not everything would be possible in Python, for example, as it doesn't support full-blown lambda functions, only lambda expressions! In Java there are anonymous classes and they can be used to do exacltly that, but they aren't fully functional closures too*.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Write an general fuctor which can be parametrized before it's used in an STL algorithm: I think I've seen such an implementation in the "Imperfect C++" book, but I was not really convinced. For brevity's sake I won't discuss this technique here.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Use the Boost lambda library: it's exactly what we need here! However... it's not a part of the standard C++ library, and so it's sometimes not an option in commencial environment! &lt;strong&gt;And it's big:&lt;/strong&gt; did you look into the code? In includes other parts of Boost and is not very comprehensible (I didn't understand much)! We'll see later that this is unevitable as the complexity of the library increases, but I don't want to do everything what goes! There is only some subset of the general lambda functionality which I'd use in many programs. &lt;/li&gt;&lt;/ol&gt;So the result of this investigation was a decision to write small, lightweight and comprehensive lambda library for my own usage. I simpl
