Friday, April 13, 2007

D language (D programming language)

Well, it's a bit older news, but since I did post about D earlier, let me inform that
Digital Mars D Programming Language hit 1.0
(It's at 1.012 right now.)

Well, still waiting for a good debugger, and also a nice IDE.

D Blog - The One With D is still a good blog for news about D.

"aspnet_merge.exe" exited with code 1

"aspnet_merge.exe" exited with code 1 is a nasty build error.

You can see an example and a tip on it at
http://geekswithblogs.net/michelotti/archive/2006/07/31/86754.aspx.

But in my case verbosity is not helping.
The trick was that two aspx files existed with the exact same name (it's not a simple project/solution, we have a framework with files aspx and ascx in it and a custom project with files in it, and the build process builds them together).

Monday, March 19, 2007

SQL 2005 connect ... connect ... connect


Do you bore this image as much as I?
When I drag and drop some files from a folder into Microsoft SQL 2005 Management studio, it will ask for Connection for every file.
Is there a solution for this?

Wednesday, July 26, 2006

Why Can't Database Tables Index Themselves?

from Coding Horror.
A nice post, which problem I also thought about.
But regarding of relational DB indexes, you can do it read optimized or update optimized, and can't have both.
Also, if we make a step back to look more from above the whole DB functionality, why cannot our business object save itself into a normalized form (No, not a wordy serialization, or stream, but real relational form)?

In the comments I've found an interesting link to the blog Tips, Tricks, and Advice from the SQL Server Query Optimization Team, which I didn't know about before.

Saturday, May 27, 2006

Introducing D

I'd like to put up some tutorial material, written in the D programming language.

But first then I'd introduce this D thing...

D programming language is like C++, only "better". It would be hard to define "better", so let me say it has almost everything C++ has to offer, but it is much clearer, and, almost a lot of things have better compile times.
It's a bit like C# or Java, but without a VM, but still multiplatform.
The compiler backend is closed, but D in altogether is free.

The official site of D:
http://www.digitalmars.com/d/
then the Wiki4d site,
and there is also a short introduction on Wikipedia,
and finally a blog with news about D.

And the drawbacks? Well, its still in beta, with no fixed feature sets and roadmap, and some of the major elements have issues, like the garbage collector, template handling, libraries are also still in the making, no ide, no professional debugger. Things can always change and go either for better or worst; lets hope it will be - even - better.

Coloring problems

So, last time I started on a little javascript, which would colorize automatically the sample codes I embed here. Well, I’ve regretted it when I had to fight with RegExp and IE and FF differences (IE - Internet Explorer, FF - Mozilla Firefox).

The first major annoyance (I consider something major annoyance, when you can’t find a solution in Google in less than two minutes, or when there is no general solution, which is the case now, because IE and FF not willing to do things the same) is when I can access html blocks marked with <div id=”code”> in IE as an array (if there is more repeated blocks) with
document.all(“code”)
, but I cannot wit FF. So I can use the standard getElementById, but then it will give back only the first block.
To make a not so long, but mind-bogging story short, finally I came up with what you see in the code in the previous post, using getElementsByName, and marking the div part with both id and name.

And while veteran coders all praise RegExp, and I cannot say different, than to learn it and use it, it has its own ways… and it’s really hard to test the RegExp machine inside javascript, considering it may have differences in IE and FF.

The extra parsing that this blogger site puts into the blog posts doesn’t help also. I had to put and upload my code changes into the template of this site, and check the blog post containing sample code in IE and in FF.
After a lot of trial and error, I begun to think that the replacing approach maybe not the best one, because I still have problems with string literals inside comments, comment characters inside string literals, and keywords in comments and string literals. But to parse the code as a real parser would do just to colorize it, and do it in javascript… well, that’s a task I’m not willing to take.

And I still cannot escape some manual replacement and formatting when posting code, I have to break the long lines, and have to replace lesser than and greater than signs, and this saddens me, because this way I’d even replace all that is needed in one pass, offline, before posting…
But typing in really simple code right into the blogger web ui is much simpler.

If you have ideas to improve the colorizer, or have a completely different solution, let me know.

Thursday, May 18, 2006

Colored code samples - now with sample code!

Not only I 'believe' in the power of modern so-called RAD IDEs, especially in intellisense, support of commenting and use of those comments as internal help in the place of code editing (and more intellisense ;)), code navigation through definitions, but I also believe that colored code is easier to read, and easier to understand it faster.

So when I've started this programming blog, I've liked to give code samples not only formatted right, but colored. But I think it would have been a bit lame to parse from clear code text, because that's how code usually is, and write out html (even with fancy spans and divs and css) (and ruling out the method when I type all the color codes also), I don't want to do this process with every update involving code. And since I have no control how these hosted pages are parsed out, I couldn't automatize such a process.

So I've decided to write a little javascript hack, which will colorize parts on a web page marked as code area.
The javascript colorization itself won't be perfect, because for now I've made the colorizer code to work with C (and D, more on later), and maybe C# keywords...

The entry point is placed onto the page onload event:
<body onload="format()">
The format function, which will just read up all sections from the page marked with div and id="code" (and, also with name="code"... more about that later).
function format()
{
var c = document.getElementsByName('code');
if(c != undefined)
{
if (c.length == undefined)
{
formatcode(c);
}
else
{
for(i=0; i<c.length; i++)
{
formatcode(c[i]);
}
}
}
}
I mark the 'color codes' with font settings in variables. Instead of 'font' html tag, I guess some more css-able thing would be better, and also, instead of variable declaration maybe there is some more elegant solution. However, this isn't the point, and this time a working solution is before an elegant one.
// keyword
kwS = "<font color='#3333FF'>";
kwE = "</font>";
// comment block
commS = "<font color='#339900'>";
commE = "</font>";
// string literal
strS = "<font color='#FF0000'>";
strE = "</font>";
And now onto the relevant part. It will take the argument as text, and doing replaces, and since javascript .replace method is capable of handling regexps, we will use it. I had to include some tricks to counter this blogger site's weird features.

function formatcode(c)
{
ct = c.innerHTML;
//we're just doing a mass search and replace

// replacing blogger included br-s
ct = ct.replace(/<br>/g, "\n");
ct = ct.replace(/<BR>/g, "\n");

// keywords
ct = ct.replace(/((\s|\()(break|case|char|class|
default|else|for|foreach|if|int|import|
public|private|return|struct|switch|typeof|
void(\s|;|:|\[|\())/g, kwS + '$1' + kwE );
ct = ct.replace(/(>)(break|case|char|class|
default|else|for|foreach|if|int|import|
public|private|return|struct|switch|typeof|
void)(\s|;|:|\[|\(<)/g, '$1' + kwS + '$2$3'
+ kwE );
// string literals " "
ct = ct.replace(/(\"[^\"$]*\")/g, strS +
'$1' + strE );

// /* */ block comment
ct = ct.replace(/\/\* /g, commS + "/* ");
ct = ct.replace(/ \*\//g, " */" + commE);
ct = ct.replace(/\n\*\//g, "\n*/" + commE);
// // style comment
ct = ct.replace(/\/\/ /g, commS + "// ");
ct = ct.replace(/(\/\/ .*)($)/gm, '$1' + commE);

c.innerHTML = ct;
}
What do we get now? At first, I had nice colors in IE and something else in FF, then I tweaked and tweaked. Also, as you can see, the "block comment" section in the above code is colored wrong, block comment inside a string literal messes up the replacement. In my next post, I will write about why IE and FF differences bugging me, and well, bugging also this colorizer, and what problems arose with colorizing with regexp replace.

Tuesday, May 16, 2006

The first step - colored code samples

Not only formatted (whew, with the genuine "pre" html tool), but colored.

Let's try it.
int main()
{
printf("hello world\n");
return 0;
}
All right, this is nice, at least for me now.
It has some drawbacks, along with how this blogger works (inserting 'br's instead of leave 'pre's untouched, and inserting some more linebreaks after my 'pre' and 'div' tags).
But all I typed copied is clean text included in html 'pre' tags (preformatted):
int main()
{
printf("hello world\n");
return 0;
}
I've just wrote some javascript to format code blocks, after the page is loaded, on the client. In my next post I will show how I did it, altough you can just simply see it in the page code.

It's a quick and dirty hack, but will do it for now.

Monday, May 15, 2006

Welcome - and what will follow

All right, this is the programming blog of mine.

The bigger part of the community around me, you know, family, friends, and business partners, is really not into information technology. So, although it's impossible to get around the topic, I try not to write about these in my "normal" = not IT blog.

Now I start this one, because this time I really have something to say, beside and a bit aside from those programming thingies I myself do bore, the everyday of my so called professional life, the bugs, the builds, the grind, the sweat...
(I can tell about this part that it is not that rare that I come across a topic I wonder about to blog, but it never worth the effort to me...)

So get ready, more to come.