e8johan is currently certified at Journeyer level.

Name: Johan Thelin
Member since: 2004-05-06 12:14:55
Last Login: 2007-07-11 12:38:34

FOAF RDF Share This

Homepage: http://www.digitalfanatics.org/e8johan

Notes: Has a formal education in electronics and computer sience and several years of experience from both open source development and software consulting.

This person is:

Projects

Recent blog entries by e8johan

Syndication: RSS 2.0

6 Jul 2008 »

STL, redux

Funny to see that claiming that the following code is readable stirred up quite a few comments.
std::transform( list.begin(), list.end(), std::back_inserter( res ), std::bind2nd( std::plus<int>(), 42 ) );

Now, there are basically three points that you guys like to point out:

Try another language - the short answer, no. The longer answer, I like C/C++, much because I've grown to know them, but also because I can see the actual machine code that the code I write will produce. This, to me as an electronics guy, is really neat. It gives me a sense of control.

Also, I've tried Haskell and Lisp (and Excel, if you want another functional language), and I like the concept, but creating something large and actually useful using these tools... I don't know. I'm sure that you can point out a million examples, but... nah. Not for me. At least not for proper work.

C++0x can do this better - but why change a winning concept. Lambda expressions does not belong in C++. The C-family of languages contains imperative languages, not functional ones. Call me old, call me granddad, but I like it the way it is. If I could go back in time, I'd rather spend my time pushing MS to improve their implementation than changing the specs.

You call that readability? - yes I do, and seeing examples from other languages, I do so even more. The trick is to read code from the right direction. For example, compare reading an ordinary mathematical expression to reading it in RPN. Neither is fun, but as soon as you know how to approach it, both are simple.

I try to read C/C++ from the inside out. Take, the troublesome expression that started this. I would start with the arguments. The first two are simple - just limiting the input data. The third is a bit more tricky: std::back_inserter( res ). Try starting from the inside, what is res? A list of integers. What could a back_inserter do to a list? Perhaps insert stuff at the back of it.

Continuing with the operation: std::bind2nd( std::plus<int>(), 42 ). Again, starting from the inside, plus probably adds two arguments together, integers judging from the template specialization. So, bind2nd? Coming from an engineering background (and having done this a couple of times) I thing that it is quite clear that it binds (locks) the second argument to a value, in this case 42. I can admit that this is not 100% clear if you're not familiar with the topic.

So, taking one last step out I find myself looking at the word transform. So, a list of items is transformed into another list. Again, not too hard to grasp, but you might want to look up the details in an STL reference. Speaking of such, SGI hosts are really good STL reference. So, for the curios readers, given these links I think that you also can call the transform expression readable:

Syndicated 2008-07-06 08:31:00 from Life of a Developer

5 Jul 2008 »

STL rocks

I've just been writing a small article on the "gems of STL" and found that I really like what I'm seeing. A personal favorite is the transform operation (found in the functional header file). For example, lets do some adding.
#include <functional>
#include <list>

...

{
std::list<int> list;
list.push_back( ... ); // Populate

std::transform( list.begin(), list.end(), list.begin(), std::bind2nd( std::plus<int>(), 42 ) );
}
So, the transform method takes three iterators and an functor. The operators are, from the left, the starting point of the input, the end point of the input and the starting point of the output. The function simply specifies what to do with each list entry to create the output. In this case, std::plus takes two arguments, but we bind the second argument to 2. What this does is that it adds 42 to every item in the list (between begin and end), and replaces the original items (the results are placed from begin and onwards).

If you want the results to end up in another list, just use the back_inserter magical interator and point it to your results list.
{
std::list<int> list, res;
list.push_back( ... ); // Populate

std::transform( list.begin(), list.end(), std::back_inserter( res ), std::bind2nd( std::plus<int>(), 42 ) );
}

Quite readable and really cool code if you ask me.

Syndicated 2008-07-05 11:47:00 from Life of a Developer

1 Jul 2008 »

QCodeEdit

A spin-off from the Edyuk project has finally been released with a website of its own. The QCodeEdit project looks really promissing. What you get is a code editor with syntax highlighting for a range of languages (yes, you can add support for more languages) developed using Qt - i.e. 100% cross platform - and good looking as well.

Syndicated 2008-07-01 10:06:00 from Life of a Developer

19 Jun 2008 »

Storebror - Big Brother

As the Swedish parliament passed the "FRA law", a.k.a. the big brother law, it is time to change broad band provide. The ISP Bahnhof will not follow the new law and promises to reroute its traffic to avoid it if needed.

They offer ADSL at reasonable prices (24 Mbit/s @ 239 SEK/month) - place your orders.

Syndicated 2008-06-19 12:01:00 from Life of a Developer

8 Jun 2008 »

What a drive!

Congratulations to the entire BMW Sauber F1 team and all the supporters!

Syndicated 2008-06-08 20:14:00 from Life of a Developer

302 older entries...

 

e8johan certified others as follows:

  • e8johan certified uwog as Journeyer
  • e8johan certified Anthony as Journeyer
  • e8johan certified jpablo as Journeyer
  • e8johan certified santana as Journeyer
  • e8johan certified davidz as Journeyer
  • e8johan certified Uraeus as Master
  • e8johan certified brouhaha as Journeyer
  • e8johan certified deekayen as Journeyer
  • e8johan certified berend as Journeyer
  • e8johan certified robocoder as Journeyer
  • e8johan certified alejandro as Journeyer
  • e8johan certified salmoni as Journeyer
  • e8johan certified mjw as Journeyer
  • e8johan certified nymia as Journeyer
  • e8johan certified pjf as Journeyer
  • e8johan certified Mmarquee as Journeyer
  • e8johan certified mbrubeck as Journeyer
  • e8johan certified menthos as Master
  • e8johan certified whir as Journeyer
  • e8johan certified nutella as Apprentice
  • e8johan certified markandre as Journeyer
  • e8johan certified gary as Journeyer
  • e8johan certified jamesh as Master
  • e8johan certified rmathew as Journeyer
  • e8johan certified rbultje as Master
  • e8johan certified johnnyb as Journeyer
  • e8johan certified skx as Journeyer
  • e8johan certified ncm as Master
  • e8johan certified walken as Master
  • e8johan certified bolsh as Master
  • e8johan certified mirwin as Apprentice
  • e8johan certified pcolijn as Journeyer
  • e8johan certified mathieu as Journeyer
  • e8johan certified lkcl as Master
  • e8johan certified gnumuthu as Journeyer

Others have certified e8johan as follows:

  • metaur certified e8johan as Apprentice
  • lerdsuwa certified e8johan as Apprentice
  • brouhaha certified e8johan as Journeyer
  • Lobster certified e8johan as Journeyer
  • Highlander certified e8johan as Journeyer
  • kilmo certified e8johan as Journeyer
  • mirwin certified e8johan as Journeyer
  • daverd certified e8johan as Journeyer
  • pipeman certified e8johan as Journeyer
  • mazurek certified e8johan as Journeyer

[ Certification disabled because you're not logged in. ]

New Advogato Features

FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!

X
Share this page