<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<?xml-stylesheet type="text/css" href="http://blog.copton.net/styles/feed.css"?>
<title type="html">copton.net</title>
<link rel="alternate" type="text/html" href="http://blog.copton.net" />
<link rel="self" type="application/atom+xml" href="http://blog.copton.net/atom.xml" />
<updated>2008-11-19T21:26:30+01:00</updated>
<author>
<name>Alexander Bernauer</name>
<uri>http://blog.copton.net</uri>
</author>
<id>http://blog.copton.net/</id>
<generator uri="http://nanoblogger.sourceforge.net" version="3.3">NanoBlogger</generator>
<entry>
<title type="html">ZML</title>
<author>
<name>Alexander Bernauer</name>
</author>
<link rel="alternate" type="text/html" href="http://blog.copton.net/archives/2008/11/19/zml/index.html" />
<id>http://blog.copton.net/archives/2008/11/19/zml/index.html</id>
<published>2008-11-19T21:23:09+01:00</published>
<updated>2008-11-19T21:23:09+01:00</updated>
<category term="Publikationen" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[
<p>
<a href="http://downgra.de">Fire</a> and I are proud to introduce <a href="//projects.spamt.net/zml">ZML</a>.
</p>

<p>
Basically, ZML is a markup language with a C-style syntax and lots of syntactic suggar. Furthermore the ZML toolchain provides a ZML to XML compiler, which means that ZML is a convinient way of writing XML. So you could regard it as an alternativ to a feature rich XML editor.
</p>

<p>
But ZML is more. It is also a technique of code generation, thus an alternativ to Model Driven Architecture. These two aspects fit together when you know that ZML code generation is done with XSLT. Using the ZML syntax instead of the XML syntax for XSLT stylesheets makes it very easy to write a code generation tool whenever approriate. No BNF, flex and bison, no theoretical knowledge about gramar and parser classes. Just some XML, XSLT and XPATH, denoted in a convinent way. 
</p>]]>
</div>
</content>
</entry>
<entry>
<title type="html">Mailfilter</title>
<author>
<name>Alexander Bernauer</name>
</author>
<link rel="alternate" type="text/html" href="http://blog.copton.net/archives/2008/10/30/mailfilter/index.html" />
<id>http://blog.copton.net/archives/2008/10/30/mailfilter/index.html</id>
<published>2008-10-30T00:30:36+01:00</published>
<updated>2008-10-30T00:30:36+01:00</updated>
<category term="Publikationen" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[<p>
Ever tried to do something advanced with <a
href="http://www.procmail.org/">procmail</a>? I did. Enough pain to sit 
down and find something better.
</p>
<p>
So <a href="http://downgra.de">fire</a>, who is a friend of mine, and I came together one afternoon to write <a href="http://projects.spamt.net/mailfilter">Mailfilter</a>. This enables you to do your mail filtering with <a href="http://www.python.org">Python</a>.
</p>
<p>
I really like the result. Check out this few lines which automatically result in one folder for each mailinglist I am subscribed at.
<pre>
@filter("List-Id", "(.*)$")
@filter("List-Post", "&lt;mailto:(.+)&gt;")
@filter("List-Id", "[^&lt;]*&lt;([^&gt;]+)&gt;")
def mailinglists(mo):
    return "ml." + esc(mo.group(1))

@filter("Mailing-List", "contact (.*)-help@(.*); run by ezmlm")
def ezmlm(mo):
    return "ml.%s-%s" %(esc(mo.group(1)), esc(mo.group(2)))
</pre>
</p>]]>
</div>
</content>
</entry>
<entry>
<title type="html">secrets</title>
<author>
<name>Alexander Bernauer</name>
</author>
<link rel="alternate" type="text/html" href="http://blog.copton.net/archives/2008/10/25/secrets/index.html" />
<id>http://blog.copton.net/archives/2008/10/25/secrets/index.html</id>
<published>2008-10-25T19:12:12+01:00</published>
<updated>2008-10-25T19:12:12+01:00</updated>
<category term="Zitate" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[<blockquote>
Only the small secrets need to be protected. The big ones are kept secret by public incredulty.
</blockquote>
<a href="http://en.wikipedia.org/wiki/Marshall_McLuhan">Marshall McLuhan</a>]]>
</div>
</content>
</entry>
<entry>
<title type="html">economy</title>
<author>
<name>Alexander Bernauer</name>
</author>
<link rel="alternate" type="text/html" href="http://blog.copton.net/archives/2008/10/25/economy/index.html" />
<id>http://blog.copton.net/archives/2008/10/25/economy/index.html</id>
<published>2008-10-25T18:50:01+01:00</published>
<updated>2008-10-25T18:50:01+01:00</updated>
<category term="Zitate" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[<blockquote>
Anyone who believes exponential growth can go on forever in a finite world is either a madman or an economist.
</blockquote>
<a href="http://en.wikipedia.org/wiki/Kenneth_E._Boulding">Kenneth E. Boulding</a>]]>
</div>
</content>
</entry>
<entry>
<title type="html">const or not const</title>
<author>
<name>Alexander Bernauer</name>
</author>
<link rel="alternate" type="text/html" href="http://blog.copton.net/archives/2008/10/25/const_or_not_const/index.html" />
<id>http://blog.copton.net/archives/2008/10/25/const_or_not_const/index.html</id>
<published>2008-10-25T14:37:49+01:00</published>
<updated>2008-10-25T14:37:49+01:00</updated>
<category term="C++" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[<p>
From the <a href="http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.7">C++ FAQ</a>:
<blockquote>
const identifiers are often better than #define because:
<ul>
<li>they obey the language's scoping rules</li>
<li>you can see them in the debugger</li>
<li>you can take their address if you need to</li>
<li>you can pass them by const-reference if you need to</li>
<li>they don't create new "keywords" in your program.</li>
</ul>
[...]
There are cases where #define is needed, but you should generally avoid it when you have the choice.
</blockquote>
</p>

<p>
Nice said, and everybody believes it. Util you realize that these "const identifiers" in real are "const variables" which is an oxymoron. Already the fact that const variables have an address shows that they are no identifiers.</p>

<p>
"Distinction without difference.", you think? Well, then look at this example:
<pre><code>
const double FACTOR = 0.75;
const unsigned HEIGHT = unsigned(FACTOR * 5);
unsigned char a[HEIGHT];
</code></pre>
which let's the compiler dump the following error
<pre>
error: array bound is not an integer constant
</pre>
Ah, yes, an unsigned const variable is no integer constant, right.... wtf?
</p>

<p>
As far as I understood the standard the compiler does not have to calculate the value of <code>HEIGHT</code> at compiletime. This is allowed because <code>const identifiers</code> are nothing but read only variables. So this simple example already is a case where you have no other choice but use the good old C style:
<pre><code>
#define FACTOR 0.75
#define HEIGHT unsigned(FACTOR * 5)
unsigned a[HEIGHT]; // unsigned a[unsigned(FACTOR * 5)]
</code></pre>
This example compiles. The C++ compiler is now forced to do the calculation at compile time.
</p>]]>
</div>
</content>
</entry>
<entry>
<title type="html">Who said C++ was unintuitive!?</title>
<author>
<name>Alexander Bernauer</name>
</author>
<link rel="alternate" type="text/html" href="http://blog.copton.net/archives/2008/10/05/who_said_c_was_unintuitive/index.html" />
<id>http://blog.copton.net/archives/2008/10/05/who_said_c_was_unintuitive/index.html</id>
<published>2008-10-05T15:55:32+01:00</published>
<updated>2008-10-05T15:55:32+01:00</updated>
<category term="C++" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[
<a href="http://www.xs4all.nl/~weegen/eelis/analogliterals.xhtml">Multi-Dimensional Analog Literals</a>]]>
</div>
</content>
</entry>
<entry>
<title type="html">default arguments and name lookup</title>
<author>
<name>Alexander Bernauer</name>
</author>
<link rel="alternate" type="text/html" href="http://blog.copton.net/archives/2008/06/11/default_arguments_and_name_lookup/index.html" />
<id>http://blog.copton.net/archives/2008/06/11/default_arguments_and_name_lookup/index.html</id>
<published>2008-06-11T12:57:41+01:00</published>
<updated>2008-06-11T12:57:41+01:00</updated>
<category term="C++" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[<p>
from <a href="http://blog.fefe.de">fefe's blog</a> two
<a href="http://blogs.msdn.com/vcblog/archive/2008/06/05/some-c-gotchas.aspx">C++ gotchas</a> about default arguments and name lookup rules.
</p>]]>
</div>
</content>
</entry>
<entry>
<title type="html">template type arguments</title>
<author>
<name>Alexander Bernauer</name>
</author>
<link rel="alternate" type="text/html" href="http://blog.copton.net/archives/2008/05/26/template_type_arguments/index.html" />
<id>http://blog.copton.net/archives/2008/05/26/template_type_arguments/index.html</id>
<published>2008-05-26T22:30:57+01:00</published>
<updated>2008-05-26T22:30:57+01:00</updated>
<category term="C++" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[<p>
To gain code locality I often use local types. I really like this feature as
it allows me to define a type a the location where it is needed.
</p>

<p>
A frequent use for this would be compare or ordering functors for standard
algorithms like <code>sort</code> or standard containers like
<code>hash_map</code>s. This look's like this: 
<blockquote><code><pre>
void foo(const std::vector&lt;Bar&gt; bars)
{
    struct Sort {
        bool operator()(const Bar& lhs, const Bar& rhs) const 
        { /* ... */ }
    };
    std::sort(bars.begin(), bars.end(), Sort());
}
</pre></code></blockquote>
Other languages have code blocks or other features which allow you to write the
sort criteria straight away. Local types are an tolerable alternative to this in my
eyes.  
</p>

<p>
Ähm, I mean, they could have been. But the standard prevents this. Section 14.3.1.2 says:
<blockquote>
A local type, a type with no linkage, an unnamed type or a type compounded from
any of these types shall not be used as a template-argument for a template
type-parameter.
</blockquote>
</p>

<p>
Oh my <a href="http://en.wikipedia.org/wiki/Pastafarian">nudels</a>. Why?  Does
anybody know a good reason for this? I can't imagine any. Furthermore I wonder
how the syntax would look like when using an unamed type as a template
parameter. 
</p>

<p>
To make the confusion complete the GNU C++ compiler (version 4.2.3) dumps the
following error when compiling the above example.
<blockquote>
error: no matching function for call to
'sort(__gnu_cxx::__normal_iterator&lt;Bar*, std::vector&lt;Bar, std::allocator&lt;Bar&gt; &gt;
&gt;, __gnu_cxx::__normal_iterator&lt;Bar*, std::vector&lt;Bar, std::allocator&lt;Bar&gt; &gt; &gt;,
foo(std::vector&lt;Bar, std::allocator&lt;Bar&gt; &gt;&)::Sort&)' 
</blockquote>
Yeah, right.
</p>]]>
</div>
</content>
</entry>
<entry>
<title type="html">anonymous classes</title>
<author>
<name>Alexander Bernauer</name>
</author>
<link rel="alternate" type="text/html" href="http://blog.copton.net/archives/2008/05/26/anonymous_classes/index.html" />
<id>http://blog.copton.net/archives/2008/05/26/anonymous_classes/index.html</id>
<published>2008-05-26T19:46:49+01:00</published>
<updated>2008-05-26T19:46:49+01:00</updated>
<category term="C++" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[<p>Recently I tend to group semantically related members into nested classes or
structs. For instance imagine a class with concurrent access:
<blockquote><code><pre>
class Foo {
public:
    int getSomething() {
        Lock l(purpose.mutex);
        return purpose.something;
    }
private:
    struct {
        Mutex mutex;
        int something;
    } purpose;
    
};
</pre></code></blockquote>
</p>

<p>
To avoid redundancy I don't name such nested structs. Why should I? C++
provides the feature of anonymous classes and structs and this technique is a
good example why one would like to have it.
</p>

<p>
But as often with C++ this language feature collides with others and makes it
less usable. In this case you are getting problems when the grouped members
need to be initialized. As a constructor must have the name of the class
anonymous classes can not have constructors.
</p>

<p> 
Orthogonality must definitly be a design goal for usable general purpose
languages. And this property is greatly missing in C++ which is the matter for
my blog entries.
</p>]]>
</div>
</content>
</entry>
<entry>
<title type="html">signed or unsigned</title>
<author>
<name>Alexander Bernauer</name>
</author>
<link rel="alternate" type="text/html" href="http://blog.copton.net/archives/2008/05/26/signed_or_unsigned/index.html" />
<id>http://blog.copton.net/archives/2008/05/26/signed_or_unsigned/index.html</id>
<published>2008-05-26T18:32:04+01:00</published>
<updated>2008-05-26T18:32:04+01:00</updated>
<category term="C++" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[<p>
I'm programing in C++ for years now and I still experience frequent surprises.
Even on topics where I was dead sure.
</p>

<p>
Is an <code>int</code> signed or unsigned? The standard clearly says (section 3.9.1.2)
<blockquote>
There are four signed integer types: "signed char", "short int", "int", and "long int." 
</blockquote>
So writing just <i>int</i> means the same as <i>signed int</i> which is as expected.
</p>

<p>
And here is the surprise: this is not always true. Section 9.6.3 says:
<blockquote>
It is implementation-defined whether a plain (neither explicitly signed nor
unsigned) char, short, int or long bit-field is signed or unsigned. 
</blockquote>
</p>

<p>
Unbelievable... It would have been too easy otherwise, I guess...
</p>

<p>
Thanks, Roker
</p>]]>
</div>
</content>
</entry>
</feed>
