Friends and namespaces

There are C++ behaviors that may leave you a bit astonished, staring at the lines on the monitor and wondering why the code isn’t compiling, or doesn’t work as expected. Just stumbled in one of these cases.
I usually follow these steps to recover from the puzzled face. First I write a minimal example that reproduces the behavior. It should be a bunch of lines in a single file. Sometimes this could be a daunting task, but I have that it is always worth to grasp the problem.
In fact, once you have the minimal code, you can easily experiment, changing and twiddling bits to see how the behavior changes.
Then you have two options – you can ask your local C++ guru about the problem (if you have one), or you can google the Internet for a clever selection of keywords that describes your problem.
So what happened today?
I decide to move some code I developed into a namespace-constrained library. Everything compiled happily outside the namespace, but failed to do so in the namespace. After some headscraping, I started cutting and shaping a minimum file with the same odd behavior. Here you are:

Now, if you compile it defining the symbol USE_NAMESPACE (e.g. via g++ -Wall -DUSE_NAMESPACE -c, then you get the odd looking error:

While if you compile without the namespace everything works as expected. Since the error was quite meaningless to me, I started investigating on friend and namespace. After some mailing list browsing, I figure it out. And it was simpler than what appeared – just a case for a misleading error.
In fact the friend statement declares a function fn somewhere in the NS namespace, while actually fn is defined in the global namespace. In fact there is just a using statement. To fix the problem, just move the fn function into the NS namespace.
Well and I have figure it out alone, without the need of calling my uber-C++-guru friend Alberto.
On a completely unrelated topic, today is the 25th anniversary of the marvelous ZX Spectrum. Happy Birthday Dear Speccy.

Don’t try this

Ok, I warned you. If you try it out chances are high that your productivity could seize up. On the other hand, with a sensible usage, you’ll waste less time while gaining in knowledge (and since knowledge is power, all sort of savings are within reach). Reader is the name, Google Reader. It is a news feed reader that access Atom feeds and present them in a gmail like fashion on your favorite browser.
You can even mark interesting news for sharing and have them published in your website within an applet:

or you can look them up on a web page, or they can be fed as an RSS feed, or you can mail them via gmail. Pretty impressive!

This or That?

Now in one of my last rants I talked about how difficult is to chose a camcorders nowadays. Now I would talk a bit more specifically of the camcorder models that made it into the finals. Let’s start from the Canon HV20. This camcorder is really new, it is just coming through the usual distribution channels so chances are high that you can order it via Internet but it is still not available at your local dealer. The camera is high definition with miniDV storage and color viewfinder. Canon brochure is lengthy and equally parted between video and still shot functions. Depicting it as a very hybrid device.
Reviews are very good, but I am not enough geeky to jump on the HD train. First I have not the right TV set, nor has any of my friends or relatives, then the computational cost of HD rendering far exceeds the computational resource of Pagani’s Manor, finally I have not the proper storage media for playing it back… worse it is still undecided which the storage media for high definition will be. Blue Ray? HD-DVD? I think that some 10 years are still needed for the wide spread of these technologies and it makes no sense for me to pay money for something that I could use at the end of the camcorder life cycle.
Also, if talking about quality, I have some doubts that a consumer device, even if at the top of its range, could match the quality of a professional device of the previous generation. I mean that the Canon XM2 probably will outperform the HV20 in terms of quality even if it cannot achieve the same pixel resolution.
So, since I have introduced it, let’s talk about the Canon XM2. This is a professional entry level costing around twice the other models I considered. I found a good deal on used device, provided with 1-year shop warranty, in the right price range.
The XM2 is miniDV based and has a standard definition broadcast quality whatever this means. It has plenty of features and although you can use it in fully automatic mode you can set individually shot parameters. Reading the specifications I found lot of stuff that I don’t exactly know what is, but, I suppose, is there to improve the quality in difficult situations.
I think that the most appealing feature is the optics, large fluorite lenses that promise to deal greatly with even the darkest scenes, zooms and wide-angle far superior than the consumer models and a sun shield.
Against this camera count the size (it is 30 cm long) and the look which is very professional and that could attract too much unwanted (and possibly evil-intentioned) attentions. Given the dimension I reckon it is quite uncomfortable to carry during trekking and walks.
Last I got a suggestion about the Panasonic NV-GS500. This is a standard definition, miniDV based, and consumer top-range camera. It has large lenses, 3CCDs of more 1M pixels each, that’s near the double of other standard resolution devices. Weights about half a kilo. It is for sure easier to handle than the Canon XM2 and much less expensive-looking.
I read a couple of reviews (1 and 2) of the NV-GS500. It is praised for its video and audio quality, while its weakness are: the lack of a headphone jack, and that some commands are not directly accessible via buttons, but you have to navigate the camera menu to operate them.
Since I have never used the headphone jack with my current camera in the past 8 years, I don’t think I’ll miss it too much. As for the other problem, I guess it is more a shortcoming for those used to professional or semi-professional cameras. For example I even don’t know that something called zebra-pattern was a camcorder command. (No, I don’t think it is for filming pedestrian crossings).
Well, all that said, yesterday my wife and I went to the shop where the XM2 was on sale. We wanted to have another look at the camera and more specifically to transportability. Once in the shop I asked the clerk: “we’re here to have another look at the Canon XM2”, the clerk answered: “It’s been sold”, me: “… , … ? … ! … “, he: “yes, sold”.
And that was the end of the decision process, yesterday evening I ordered the NV-GS500.

Ten minutes of your time

(English below) Strano scrivere qui in italiano, ma visto che devo segnalare un’iniziativa in questa lingua mi sembra la maniera più semplice.
Fino al 19 Aprile c’è un questionario in linea sulle donazioni. Ci vogliono circa 10 minuti per compilarlo e alla fine è possibile scegliere la destinazione di un euro (donato da SWG, la società che esegue il sondaggio) ad una ONLUS a scelta da un elenco. La segnalazione mi giunge da un’associazione che ha la mia piena fiducia.

Odd writing here in Italian, but this seems to me the simplest way to let you know about an initiative in this language.
Until April, 19th there is an on-line poll about donations. It takes about 10 minutes to fill in and at the end you can choose the destination of one euro (offered by SWG, the company that set up the poll) to one non-profit company from a proposed list. I learned about this from a trusted association.

The Celestines Company

This is another Italian book without an English translation, at least not one you can buy on Amazon.The story is about a group of orphans that escapes from the orphanage to participate in the secret world championship of StreetBall. StreetBall is a specific variation of the football played along the streets of nearly everywhere with much passion and fantasy. The Great Bastard himself, the God of all the orphans, has dictated the rules for Street Ball.
The story takes place in the rich and corrupted country of Gladonia. The orphans are chase both by the (equally rich and corrupted) church in the person of Don Biffero and Don Bracco and the media personified by the journalist Fimicoli. And behind those pawns the egoarch Mussolardi supreme ruler and mostly owner of Gladonia.
As I have already expressed before in other posts, Benni is one of my favorite writers. In this case he manages to achieve a good tale telling, while keeping a meta register. Situations and characters usually live at different levels. The story level is nice, but the plot twists are a bit forced, situations are mostly resolved via Deus Ex Machina. The next level is satirical, Benni portrays the changing Italy, a beautiful country losing its genuine and true origins to progress, corruption, hypocrisy and indifference. What was clean and nice now is polluted, what once was quiet and calm now is crowded and noisy, what once was honest and private, now is criminal and reality show.
Characters are caricatures of real people, the county politician, the clergymen, the orphans, the media, the TV channel owner, and the army.
At a deeper level we find messages. Messages about what is going wrong and what would doom us. The strong message is about the importance of unadulterated youth. Children deserve to grow in a free and genuine environment. Benni strongly criticizes everything menacing this.
I have to admit that I lost most of these deeper levels at my first reading. But the book is so intriguing that the second read was swift.

Which one?

Not a life treatening problem by large, nonetheless something eating up brain cycles. Our camcorder is about to retire after some 7 years of honored service. It is a Sony analog device from (then) budget range. It served quite well to the purpouse, until it gave rather bad results in our [/images/photoalbum/Norvegia/200508/index.html|travel to Norway]. Colors were dull and shots seemed nearly black and white. Maybe that Norway summer wasn’t bright enough for the camera, but we had basically no problem with cameras. Next year we [/images/photoalbum/Greece/200608/index.html|traveled to Greece] and again we weren’t quite satisfied with the shots. This summer we’re going to west USA and we don’t want to risk poor shots, so we’re looking for a new camcorder.
From my understanding this is a sort of critical time in several camcorder technologies – media, definition and sensor.
Most of the camcorders uses tape as storage, either in the DV or miniDV formats. Sony, Panasonic and JVC have started selling Hard Disks based cameras. The hard disk mechanic is simpler than tape (have a look inside a video tape slot if you don’t believe it) and more protected. A MEMS accelerometer senses if the camera is falling and parks the Hard Disk heads in order to avoid major damages. Most of camcorder producers have optical mini-disc (DVD/DVC) cameras in their listings. Although the mechanic is simpler than tape, it has to be much more precise and has lenses to be kept clean (and scratch free).
The real winner in the storage area is, at least based on my thoughts, is the digital flash memory, like SD/HC. This technology is quite mature, but capacity is still limited (4G bytes) for video application. Currently only Panasonic has a top range camcorder with SD/HC but it is missing the viewfinder.
Talking about viewfinders, I find a great shortcoming the lack of this interface in a camcorder. From my experience it is impossible to have a decent view of what you are shooting at under the direct sunlight with the camera monitor. Aside of that all the professional camcorders do have comfortable viewfinders. So I find it nonsensical for producer to remove the viewfinders from top range models. Despite of this Sony, JVC and Panasonic do have such items.
New top range consumer models are now high definition (1080p). From one side this is not so clear to me where the “high” comes from since the number of pixels in the sensor are about the same number of the “low definition” cameras. On the other hand my TV belongs to an era when “High Definition” was something related to analog devices only. My TV is still no flat-screen! So high definition is not a plus to me, but it is just a sign of changing times.
Next, sensors. Traditionally CCD sensors were associated with high performances and better quality. From my understanding CCD are not able to scale up to high definition and thus are being replaced by CMOS, traditionally associated with low quality and every sort of trouble. When I asked to a shop clerk about CCD vs CMOS, he answered that as of today’s technology there is no real difference. It maybe, but professional camcorders are all CCD based.
At this point in time it is quite risky to buy a camcorder. You can get too much on the bleeding edge and got burned (e.g. by choosing a new technology that will have no commercial success and will be shortly dismissed), or being too conservative and buy something that isn’t worth the price. But we have to renew the family camcorder department, so I have to take a decision.
Given that viewfinder is a must and the budget is not unlimited, the choice is quite restricted, Sony is too expensive, JVC has no viewfinders. Panasonic has an interesting previous-generation model the NV-GS500 and Canon has the new generation HV-20. Moreover I found an used semi-pro camcorder in excellent state and at a good price, the Canon XM2.
But this is meat for another post…

Inquiry on Jesus

(This book is Italian only) If you, like me, grew up in a traditional Catholic environment, as it could be anywhere in Italy, or, to a lesser extent in France or Spain, then chances are high that most of what you know on Jesus is wrong.
This book attempts to shred some light on the historical man that so greatly influenced (and still influences) our world. In fact our knowledge about Jesus, his times and his land has considerably improved in the last 30 years. Better analysis techniques and the recent discovery of old writings from the earlier community greatly helped in defining a larger and more consistent picture.
The book takes the form of a loose interview where the writer introduces the argument of the chapter and the starts with questions and answer sessions with the expert.
“Inquiry on Jesus” begins as a sort of myth dispeller: Jesus was a strictly observant Jew; he had a number of brothers and sisters; he was married as his disciples were. He was a Pharisee, he didn’t intend to start a new religion; he had a political message; Gospels weren’t written by the same disciples that lived with him and so on.
The matter is interesting and it is dealt with a tactful approach. Of course the intended audience is everyone that wants to dig deeper in this part of human history with an open mind. Avoid it if you are a believer and don’t feel comfortable in reviewing part of your faith beliefs. I guess that a strong faith couldn’t be shaken by this book content, and that the book could satisfy an interest in the man Jesus.
One of the most striking revelations to me is that Jesus was deeply Jew; he observed every precept of the religion. Moreover he never intended starting a new religion or cult, neither converting anyone. He strongly believed that the Kingdom of God was near to come and that a real conversion and renewal was needed.
Another interesting point is about his sentence. For centuries the Catholic Church based a number of arguments against the Jewish on their guiltiness for sentencing Jesus to dead, basically perpetrating a deicide. These parts of Gospels have indeed been written to ease the position of the new Christian religion towards the Roman Empire. In the desire of appealing to the Romans, earlier Christians, turned the guilt away from Pontius Pilate (the likely real culprit) to the Jewish. What is astonishing is that by reading carefully the Gospels you can find yourself that not everyone in the high council, the Sanhedrin, was enemy to Jesus, in fact some of the people in the council were actually his friends.
Most of Jesus’ teaching, as reported by the Gospels, is easily traced in the religious currents popular at those times. Even the resurrection was a common theme far from being something unheard of. Rather, the specific attention and care to the latest and to poorest in the society is the original part of his message, the real revolutionary part.
The book takes a low profile on miracles, stating that most of the healings and exorcisms can be explained in term of psychic or mental effects. On the other hand, considering the historical character, the book supports the thesis that it is likely that Jesus thought a lot on the matter, considering it as a special gift from God and that by this gift God was calling him to some mission.
Considering that the central core of the Christian message is the resurrection for saving everyone, the book skims over too quickly over the fact that in the first edition of Gospel there was no mention about resurrection. It came as an afterthought during later revisions. Moreover, despite of the claims of Gospels, there are no reports about those exceptional facts (consider a dead man appearing to several hundreds people!) beside of the Gospels themselves.
I think that this is where the narrative scheme of the book falls short. I.e. the interview model allows too easy escape ways on topics that would have a much deeper analysis in a classical popularization book.
Apart from this the book is an interesting and easy read for those with an open mind regardless of the faction.

Easter Aftermath

Happy Easter… usually it starts with something like this, then you find 4 days later at the workplace wondering exactly what happened… Well it happened that supermarket shopping on Friday evening is always nefarious. Everyone, his friends and his brothers are there to shop for the weekend. People with no other goal than staring absent mindedly to shelves while keeping their cart across the corridors. Crowds of long unseen old friends clustering together (and usually complaining about people stopping in the market or about new generations without good manners). This time it had been a bit worse, because someone took our cart at about one third of the process and we had to restart from the beginning.
Then on Saturday it was the Shoes-Day, I spent the whole day with my wife in and out from shoe-shops and outlets in Parabiago. We also succeed in smashing another car door, fortunately no injuries for anyone and not much damage for our car (anyway our insurance fee will raise). We started about at 9:00 and we got back home after 20:00.
On Easter and Monday we paid the belonging to our families.
During this holidays evenings we tried to figure out the best accommodation in Las Vegas for this Summer U.S. travel. When traveling to Norway, two years ago, we found very helpful the website to make hotel reservations in Germany. Unfortunately there isn’t anything so complete for U.S. and we are browsing through endless lists of hotels, motels logdes, bed and breakfasts, inns and so on. At last (after three evenings of hard search and comparison) we found a Travelodge on the strip, close to Bellaggio, at a convenient price.