Oct
30.
2005

Just watched Herb Sutter's PDC05 presentation about future concurrency techniques. The talk is very good and is definitely worth a look, it's called C++: Future Directions in Language Innovation (note that the site works in Internet Explorer only). The main theme is how to deal with the increasing need for better concurrency of present and especially future apps due to the processing speeds staying more or less constant while number of cores (and hardware threads) increases.

I'd like to draw your attention to one particular thing present in the talk yet not directly related to it - possible inclusion of concepts for the C++ templates. What are concepts? In a nutshell, they are a way to constrain the template parameters. Reasons for this are illustrated with the classic example - beginners always ask why is it that C++ Standard Library does not contain algorithms that accept not only iterators but containers as well? Well, the following two declarations show why:

template<class T>
void sort(RandomAccessIterator<T> first, RandomAccessIterator<T> last);
template<class T> // without concepts, this one conflicts with the first
void sort(Container<T> &c, BinaryPredicate<T,T> pred);

(examples taken directly from Herb's slides). One of the solutions to this problem is to say more precisely what a RandomAccessIterator is by something like this:

template concept RandomAccessIterator {
// definition of what a RandomAccessIterator should be able
// to do, such as increment, dereference, etc.
};

Note the keyword concept that effectively restricts all the operation possible for RandomAccessIterator.

I don't know about you, but restricting a type to a known set of operations to me looks just like the definition of an interface. Hm, I have seen this before - this is exactly what generics support, no? With generics, you could say:

class Iterator<T> where T : ISomething

and then the allowed operations on T are constrained by ISomething. This is still not the same though - the goal with the former (C++)  is to reduce the complexity of error messages when you mistype something else instead of an iterator. Now the compiler knows there is a deeper difference between RandomAccessIterator and all other classes with one template argument and can even save time by not instantiating the complete template - it can terminate with a meaningful error message immediately. Generic type restrictions in C# are introduced for different reasons yet the motivation (hopefully) was the same - to reduce complexity (number of possible instantiations the compiler has to struggle with).

Luckily, on the .NET 2.0 platform you don't have to choose between generics and templates - you can have both.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Oct
26.
2005

It's a shame - REXML does have a nice interface and it's pure Ruby so it should run anywhere. I just run into a problem where a XPath expression would always be evaluated so that the namespace of the previous sibling node would be considered the namespace of the following node?!?

Here's the thing - I wrote a simple “parser” for RSS 2.0 and was not able to get a pubDate element:

# assume rss is a XML file I got somehow
document = REXML::Document.new(rss.body)
document.each_element('//item') do |item|
  date = nil
  #item.each_element('pubDate') { |l| date = DateTime.parse(l.text.to_s); } # REXML bug
  item.elements.each do |l| 
date = DateTime.parse(l.text.to_s) if l.name == 'pubDate' # slow, works
end

end

Turned out that while iterating over child nodes of the item, REXML would pick up the namespace of the body element (which is XHTML namespace) and use that with the pubDate?!? WTF?

In any case, the fix is brute force iteration over all child nodes of item and manual element name comparison. I should also note that I tried this with 1.8.2 and recently issued 1.8.3 version.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Oct
25.
2005

Turn Eclipse into Visual Studio

Posted by: Drazen Dotlic in Categories: rant.
Tags:

...on the outside, that is ;) I find the default look of Eclipse a bit too busy for my taste. Maybe busy is not a good word - too serif, rounded, colorful? You can probably guess that I am one of those that likes clean skins or no skins for all of my apps (yes, that includes Winamp too).

If you want you can make Eclipse look very much like Visual Studio 2003. Unsurprisingly, Eclipse supports presentation plug-ins but they seem to be rather undocumented which explains why there aren't many of them.

It's probably just a habit thing but I find Eclipse a lot easier on the eyes now.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Oct
24.
2005

You need not be a great mathematician (heck, I graduated (BSc) mathematics with computer science and most of the math stuff is now gone due to no use in everyday life and work) just to think like one to appreciate Haskell.

Haskell is probably the purest of the functional languages out there, but also shares some traits with ML, Scheme and OCaml. Some mathematical concepts are extremely easy to express in Haskell, but that comes at a cost - if you are “just” a C++/Java programmer it will take (quite) some time getting used to the language.

I am learning Haskell from The Haskell School of Expression which is really great. The author is one of the most recognized names in the Haskell community. He is also an university professor and it shows - the way that the language is presented to you is highly pedagogical, very slowly increasing complexity chapter by chapter.

If you like(d) math and programming pick the book up and start learning. Even though Haskell is mainly used in academic circles, lately there have been some surprising real-life projects using it - take a look at Pugs, Perl 6 interpreter written in Haskell that got some great press recently.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Oct
24.
2005

After finishing the game I can safely proclaim the Oddworld Stranger 's Wrath as the best looking game on XBox ever, period. These guys have some serious artistic talent. On top of great graphics the game manages to completely hide the loading from you - enormous levels are loaded all at once (at least that's how it feels) while level of detail stays consistently high and “pop-in” of details like grass and leaves on the trees is very minimal.

Voice acting is pure genius, gameplay mechanics almost flawless (camera could use just a bit more work) - overall this game has the highest production value I have ever seen (closely followed by Halo 2).

Highly recommended - if you haven't already, run to the store and buy a copy; you won't regret it.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Oct
20.
2005

If you use a mainstream language like Java, C++, C# or VB/VB.NET there are probably several choices for the IDE. But if you'd like to try Ruby or Haskell the choice is not so good.

Ruby is gaining momentum mainly thanks to the Ruby on Rails project but it still is a niche language with rudimentary support for debugging. Haskell is even less popular (for mainstream development, I am not counting academic circles) and has a similar problem - debuggers are not nice to use.

Trying to find a decent IDE in both cases results in frustration as you will most likely run into an awkward editors with a UI and command scheme that only its author could love.

Luckily there is a single IDE that can be used for both of the above languages and sane one at that. Eclipse, well known in the Java world, supports extensions that provide quite good support. If you don't mind a memory hog that Eclipse is (on the other hand which feature rich IDE today isn't a memory hog) try it out. You might be pleasantly surprised.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
1 Comments
Oct
20.
2005
Assume that you are getting the language/region identifier from an external source. What you want is to format numbers, dates and other locale sensitive information. The most natural way to do so is to
// assume lang_id is a std::string
std::ostream out;
out.imbue(std::locale(lang_id.c_str()));
out << data << std::ends;
// etc

This code also assumes that the string lang is in the form specified by RFC1766, so the United States English would be en_US.

If you try to use this with Visual Studio 2003 C++ compiler (and it's standard library) you will get an exception stating that the language was not recognized. If you debug the code, you will see that locale implementation essentially calls C library setlocale and that the parsing code for the language/region is extremely convoluted and does a lot of guesswork. What it doesn't do though is accept proper identifiers. Sigh.

Unsurprisingly this non-conformance is rectified in the .NET Framework library. The identifiers there are of the form en-US (interestingly the name used is now culture and not locale any more) but that conforms to the newer RFC3282 anyway.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Oct
18.
2005

We are living in the times of low quality - the price seems to be the main driver for most of the consumers. Good movies don't sell, same goes to music and games, while trash sells like crazy.

Just few days ago I started playing Oddworld Stranger's Wrath, an excellent game from Oddworld Inhabitants (that's the name of the company, honest, I couldn't be making this up ;-)). Not only is the game fun and original in many aspects, but it has very high production quality. For example, load times are minimal and save is instantaneous - you press save and you're back in the game while a short “Saving” message floats on the right upper corner for a second or two. The game simply flows and there are no interruptions at all to distract you. Great voice acting and really funny lines keep the game fresh throughout the campaign. Really, really good game that probably sold many copies, right?

Wrong. It sold all right but the creators have since moved on to form new company and transfer the Oddworld franchise to TV. They openly complain about the cost of new games going really high and how the industry as a whole has moved on to publishing mainly sequels (going for the easy money).

I've noticed the same trend with movies too. How many original movies have you seen lately? Few, if any - it is much less risky to shoot yet another sequel to the popular franchise. Heck, we now even have sequels to the prequels that have already been made (Batman). Madness.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Oct
18.
2005
XSLT is a funny language. It is XML, yet it is interpreted and partially compiled so that it can be executed and then it transforms one XML document into another (or into any text as a matter of fact). It pretty much looks like a deceptively simple functional language. All this hasn't translated into huge popularity as expected due to not many people being familiar with non-mainstream languages like C++, C# or Java. But it is very useful for the scenarios where you need to seriously operate on the XML structure (and not at all useful for simple iterative changes on the nodes in the XML with very simple structure). Executing XSLT is hard because there are very few debuggers out there and they cost serious money. Well, at least up to now - Visual Studio 2005 brings XSLT debugging to the "masses". It is based on the revolutionaty concept where XSLT is compiled (not partially!) into IL and then executed. The experience is comparable to "normal" debugging session of C# or VB.NET code - you can set breakpoints, examine values of variables and parameters... I made a really stupid typo the other day and for the life of me couldn't find the problem just by looking at the code. Few minutes in the debugger and the mistake was obvious. Hopefully this feature will help many novice XSLT programmers out there and encourage them to use it more. Personally this is the most impressive feature of VS2005 that I have seen up to now.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Oct
7.
2005

I am slowly entering my hate phase with C++ lately (usually to be followed by a love phase, then again back to hate). I have noticed that I spend as much as 20% of my time struggling with pure compilation issues. Some are result of an include file I forgot, some are not exported symbol or missing a typedef and some are just plain old compiler problems (it won't compile something that is obviously correct).

This kind of bickering totally breaks the flow and my mind tends to wonder off until I completely leave the zone. Compare that to C# if you will and you'll notice one thing: it is complex just enough to be bearable; due to do superior packaging model (all modules carry metadata, no need to #include anything) and a compiler that never gets confused with legal C# code, you get additional productivity gain - computer never slows you down for petty reasons.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
2 Comments