Saturday, December 31, 2005

Happy New Year!!!

December 31th...

Time passes by and we don't even realize...

This year wasn't nice to me... My wife had a miscarriage in August... I got downsized a few weeks later...

But on the Eve of a New Year... Hope is always high...

Hope for a better tomorrow... for a better future...

New Year, New Life...

Most people have "New Year's Resolutions", I'm no different.

Here are mine, in order of priority:
  1. Get a new job!
  2. Keep this site alive.
  3. Make peace with the scale.
Nope, I don't have a huge list. I learned somewhere down the road that we need to keep our priorities short, this way they are easier to achieve.

Well, that's it for now...

I hope you all have a wonderful celebration... and a great 2006!!!

Happy New Year!!!

Tuesday, December 27, 2005

It's funny how people think...

I am a subscriber of many newsletters... (sometimes I think it's too much for my own sake)

Today I was reading THIS post and it prompted me to write a somewhat lengthy reply.

I'm not sure if I got the right tone... But I'm posting the reply here just in case.

Hi...

Like most developers of my generation I had my first contact with computers with BASIC... Some 20 years ago.

When I started coding in BASIC the most powerful systems were developed using COBOL, Fortran, Algol, etc...

Anyway... Back then all you had to do to program in BASIC was pull up a chair, sit on your computer and (usually) start typing something like...

2 CLS
10 PRINT "Hello World!"
20 GOTO 10
Hehe... It was easy... :-P

As I grew older BASIC grew up with me... It overcame many obstacles in its way. It left the ugly spaghetti programming, to become a procedural language... when you need to type something like:
Sub Main()
While (True)
Print "Hello World!"
Wend
End Sub
Then BASIC became an event-oriented programming (as of Visual Basic 1.0 for DOS -- I still have the Install :-) Where you'd need to type something like
Sub Button_Click()
MsgBox "Hello World!"
End Sub
And for quite some time it was an event-oriented language. Regarded as a second level language for many C programmers that liked their curly brackets and their ugly syntax.

The difficulty to develop software was ever increasing as the time went by. Computers got twice as much power every six months. Moore's Law was obeyed more than Gravity's Law.

BASIC wasn't keeping up with the demands of this new era. Many saw the end of BASIC as certain as death and taxes...

But then in 2001 Microsoft presented us with VB.NET.

It was not the BASIC everyone knew... Yet, it was a familiar ground...
Something that we understood... We knew we could Master it.

The learning curve was not that steep -- but there was a learning curve. It took time. We had to learn how to do simple things once more... But it was good... It was fun...

And that's what everything is about... FUN!

Sure thing... A lot of us code for money... But there's a great deal of people who code because it's FUN! (and if we are paid for doing this, it is even better :-)

If you code for some time you know what I am talking about...

With VB.NET we had to learn about Classes, Interfaces, Polymorphism, Overloads, Shadows, Inheritance, etc, etc, etc...

So many new things were thrown so hard at us that many of us had a very hard time adjusting themselves. But we managed to learn everything we needed to know.

So... If you want to write that "Hello World" program now with VB.NET 2005, all you have to do is:
Module HelloWorld
Sub Main()
Do While (True)
System.Console.WriteLine("Hello World!")
Loop
End Sub
End Module
Oh yeah! I forgot to mention... Now we can build console application again... :-)

Friday, December 23, 2005

Strange Bug in VB 2005 - Follow-up

OK. After some time figuring out what caused the bug, I finally discovered how to reproduce it EXACTLY.

I was reading a stream of bytes, but I was a little bit reckless -- because it was only a test not a production project -- and my reading code was something like this:
Imports System.Text

Dim aBytes() as Byte = {}

Do
Try
Redim Preserve aBytes(aBytes.Length)
aBytes(aBytes.Length - 1) = TheStream.ReadByte()
Catch ex as Exception
Exit Do
End Try
Loop

Dim strList as String = _
Encoding.UTF8.GetString(aBytes).Replace(vbLf, "").Split(vbCr)
Apparently it is in THIS case that the non-String bug occurs.

When I fix my sloppy code to something more suitable the bug didn't occur anymore. Like this:
Dim aBuffer(1024) as Byte
Dim mStream as New System.IO.MemoryStream
Dim bytesRead as Integer

Do
bytesRead = TheStream.Read(aBuffer, 0, 1024)
mStream.Write(aBuffer, 0, bytesRead)
Loop While (bytesRead <> 0)

Dim strList as String = _
Encoding.UTF8.GetString( _
mStream.ToArray()).Replace(vbLf, "").Split(vbCr)

Strange Bug in VB 2005

That's THE strangest bug I ever encountered while working with Visual Basic. Ever!

I was parsing a list of strings that was separated by a CR/LF pair. Something like this:
The quick brown fox jumped over the lazy dog.[CR][LF]
Miss Piggy sent Kermit an email.[CR][LF]
Lois was cheating on Clark[CR][LF]
So, I used the following command to get an array of strings:
Dim aStrList as String() = _
strFullList.Replace(vbLf, "").Split(vbCr)
Simple, right?

And then I went to my loop:
For Each strItem As String In aStrList
If (strItem = "") Then
Exit For
End If

'... do whatever...
Next
The first time I ran it it crashed my code. I took me some time to discover why.

Apparently the last item of the array, instead of being and empty string, is a String which contains a single "character" Nothing.

The ONLY way I could find to workaround this stuff was changing my test line to look like this:
If (strItem.Chars(0) = Nothing) Then
For the sake of completion, this strange string has the following properties:

TestResult
strItem = ""False
strItem = NothingFalse
strItem.Length = 0False
strItem.Length = 1True

However when examined in the "Quick Watch" window it does show strItem as an empty string.

Tuesday, December 20, 2005

Firefox's strange behavior

Firefox's strange bahavior
Same browser, different rendering.

Above: the page on a reader screen
Below: the same page on my test computer

Let me get this straight first: I have nothing against Firefox.

But sometimes I wonder why people praise this browser so much. The first time I used it to test my site it broke my design. After days of hard work trying to fix the design to work on both browsers, I finnaly got it done.

Or so I thought.

Just yesterday a reader sent me a screen capture of what he sees when he's reading this site. I was stunned. Firefox again broke the design.

Take a look at the image at the right, on the top it's the screen of my fellow reader, at the bottom the one on my computer. Looks like two different pages, but they are the same markup, the same code, the same everything.

I'm going to try to workaround once again the Firefox behavior.

So... back to the drawing board.

Monday, December 19, 2005

Internet Explorer 2 X 1 Firefox (and the game is still on)

Looks like a series, huh? Well it was not my intention, but here it is.

A few days ago I complained about the fact that I needed to write twice as much code in Firefox than I needed in IE.

Today I discovered something else. Subtle, but it can be extremely annoying.

Do you see the List of Articles I wrote on the left side of the page? It's updated automatically from an XML file that holds the article titles and a small description of each article. Just reload this page and you'll see the "Reading..." message while the list is updated.

So, that's the problem. Due to a small misconfiguration on 50webs.com servers the XSL file that contains the transformation rules from XML to HTML is sent from their servers with a mime-type of "text/plain" instead of the correct "text/xml".

IE reads both just fine. However, Firefox doesn't.

On my server, the configuration was done automatically and I didn't need to worry about it. I just came across this odd behavior of Firefox because the code that worked when I was looking at the page hosted on my test server was not behaving as expected when the page was rendered from the server.

At first I thought it could be some problem regarding safety issues, once my test server is "localhost". I knew that Firefox was loading the right file, but maybe it was some distortion when the file was downloaded from 50webs server.

So I opened the XSL file on Firefox... and discovered the error.

The solution, or should I say workaround, was simply rename the file to have an XML extension instead of the proper XSL.

I've sent a note to the guys at 50webs and hopefully they will adjust their server configuration.

It's easier than requesting the Mozilla to fix their code.

Saturday, December 17, 2005

Internet Explorer 1 X 1 Firefox

OK... I know I've talked about it just on my previous post, but something happened.

I'm in the process of creating my home page, and thus making several experiments with design and configurations and because of this I never came across with this un-feature of IE: the lack of support to PNG transparent files.

I'm a web developer, not a web designer. So, I never quite came across it.

There are several workarounds on the net and I implemented one, which I found in the WebFX site, of them using IE CSS behaviors.

Friday, December 16, 2005

Internet Explorer X Firefox (a rant)

I have a list of articles that I published on the site, pretty much like the list of recent posts of this blog, and I used an XML file to store the links and descriptions of each article, like an RSS.

When the page loads, it reads the XML file and updates the list of articles automatically. This way I don't have to worry about updating every single html page.

Side note: The 50webs.com is a very good web hosting service, but so far it only hosts static pages, so I needed this workaround.

Anyway... Because I use the Visual Studio to create my pages and stuff it was pretty straightforward to build the script that loads the XML and produces the list of articles.

It took me only 7 lines of code. Yes, that's right. Only SEVEN lines of code. I tested it on IE and it worked just nice and easy.

Just in case you don't believe me, this is the code to update the list of articles on IE:
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlXsl = new ActiveXObject('Microsoft.XMLDOM');

xmlDoc.async = false;
xmlDoc.load(atom_Articles);

xmlXsl.async = false;
xmlXsl.load(xslFile);

oAL.innerHTML = (xmlDoc.transformNode(xmlXsl));
As you can see they are REALLY seven lines of code.

And then I opened the page on Firefox... BANG!

Nothing. Nada. Niente. Zip.

Just the "Reading..." message I had put to show while the items are being updated.

So once more I went back to the drawing board.

After searching the Firefox documentation, and working for three straight hours on it, I managed to make the same thing on Firefox.

Here is the code:
function ffXslLoaded(e)
{
var htmlDoc =
document.implementation.createDocument("", "", null);

var processor = new XSLTProcessor();
processor.importStylesheet(e.currentTarget);
e.currentTarget.DOC.AL.innerHTML = '';
e.currentTarget.DOC.AL.appendChild(
processor.transformToFragment(
e.currentTarget.DOC, document));
}

function ffDocLoaded(e)
{
var xmlXsl =
document.implementation.createDocument("", "", null);

xmlXsl.DOC = e.currentTarget;
xmlXsl.addEventListener("load", ffXslLoaded, false);

xmlXsl.load(e.currentTarget.XSL);
}

xmlDoc = document.implementation.createDocument("", "", null);

xmlDoc.AL = oAL;
xmlDoc.XSL = xslFile;
xmlDoc.addEventListener("load", ffDocLoaded, false);

xmlDoc.load(atom_Articles);
SIXTEEN lines of code. More than twice the amount of code needed on IE.

OK... I know... It IS a rant... But heck I'm quite frustrated for writing twice as many lines of code to do EXACTLY the same thing that was accomplished with a far less and easily understandable one.

I will not even try to explain WTF is going on with the Firefox code... If you want a detailed explanation leave a comment and I'll do my best to reply.

Thursday, December 15, 2005

Internet Explorer, Firefox, Opera...

Why are there so many browsers out there?

I could understand if there were a few of them for different platforms, like Windows, Mac, Linux, and so forth. But different browsers for the same platform just drives me nuts.

After creating this blog I decided to go crazy and create a whole Internet presence, with home page and all.

So, because I want to be as nice as possible to my readers I'm willing to try to different browsers.

I downloaded Firefox and Opera to work side-by-side with IE.

I'm creating my site at home, with the look and feel matching the blog -- which reminds me to say "thank you very much" to Todd Dominey for the creation of this beautiful design and allowing anyone to use it for free. :-)

I started with Firefox, which a few say that is better than IE, and opened my proto-site. First impression of it: ARRGH!!!

Because it would have to hold more than only my blog postings I had made a few internal changes on the design, which rendered perfectly on IE, and were completely missed by Firefox.

It took me a long time to adjust everything to render perfectly on both browsers.

I've read a lot of things on website design while I was trying to figure out WTF was going on with my design. Many of the designers usually blame IE for not being able to render their beautiful designs, however I had the opposite feeling. IE rendered perfectly while Firefox was breaking the design.

I don't know. Maybe it's because a great number of the designers use Mac, or are in someway anti-Microsoft.

And that reminds me once more of Joel, he says, and I agree, that if you can control your surroundings (even if just a bit) you tend to be a happier person.

Which brings me to another point. I've read and heard people praising the wonders of Firefox, but the first time I tried to use it to see a simple design it let me down. So, I'm not happy with it.

I have read the developers page for Firefox, I admit the proposal is good, but why they need to do things so different from IE? The Firefox Development Team says that they are trying to be as standard compliant as they can, but compliant to what standards?

The W3C standards are fine, but I think that with 95% of market-share IE is a de facto standard so, if you're developing a web browser I think you need to be as close to IE as possible, maybe even mimicking its rendering flaws (OK... not that much :-).

Enough of Firefox. Let's talk a little about Opera.

I've just installed the little browser (3.66 MB opposed to 4.98MB of Firefox) and opened my proto-site. The design was rendered as beautiful as it should, as I was pleased to see.

But I need to use XML for some of the features and Opera's script capabilities didn't allow me to do so. I'm a little stubborn, so I looked up its documentation and I found nothing useful.

Monday, December 12, 2005

Fonts and Process (or how to make things more complicated)

Last weekend I formatted my computer.

After a few days installing everything back, I found an old CD of mine with thousands of fonts. With nothing better to do, I copied everything to my computer and started examining the fonts.

Have you noticed that, with rare exceptions, the name of the file doesn't match the name of the font?

When we were using Win3.1 that had the file name limitation, it was OK. But today?

Why people still do this kind of thing?

Anyway, searching here and there, I found a nice program from Styopkin Software that does what I was going to do manually: make the file match the font name.

But...

Besides a few duplicated fonts among all those files, the program named a few fonts with wrong names.

And that made my coding fingers itch like hell.

Being a nice developer I wrote a small specification of what the little guy should do, and because I just got my copy of the Visual Studio 2005, I decided that I would build my very own Font Renamer, as a debut project.

Here is what my Font Renamer will do:
  1. Open the font file and examine the name of the font it contains
  2. Close the file and rename it with the name.
Pretty simple, huh? And it is, but I needed to make it complex (oh boy!).

I don't know why I do this kind of stuff... Well... I know. I am a nerd. I admit.

No, not the program. The program it is still simple. The process. The process I made complex.

Well, if I am going to read the font file, I need to know what I need to look, I need to know how the font file is structured, and everything else. So, I searched a little bit more and found all I needed to know (and a little more that I didn't need too) at Microsoft Typography.

After reading all the documentation about the font files, I was starting to think that it was not that good idea to write my own Font Renamer... But since I'm too much of a stubborn for my own good, I decided to keep going.

And then, looking through the .NET documentation, I found the PrivateFontCollection, which methods allowed dig into the font file and allow not only to retrieve information from the file, but also even to draw text with non-installed fonts.

So, with a few lines of code I built my Font Renamer.

Friday, December 09, 2005

Thoughts, development and who I am.

After reading Joel for some time, I decided that I could throw my two bits worth of thought into the wild world out there.

Sure thing I didn't give much of a thought about what to write here, so it will be just a series of mumbling ideas and (maybe) tips on software development.

I won't pretend that I'm as good as Joel, it would be too much even for me -- people say that I have an ego the size of Montana... and I tend to agree with them. Anyway, I think I need to exercise humbleness and today is a good day to start.

Well, first a little bit about me.

I have been a software developer for the last two thirds of my life. I started coding my first lines when I was 9, only five years after I've learned how to read. As happened to many people from my generation my first contact with development was with BASIC, following a great deal of COBOL.

Before I started coding, my parents had me go through a computer class on a school near home and there was a young teacher there (whose name, for my deepest sorrow and shame, I completely forgot), who taught me the greatest law of software development, something that would guide my whole professional life: "There is no programming language. There is programming LOGIC."

And that lesson was the only thing I've ever learned about software development. If you can code in BASIC, you can do the same in C, COBOL, Pascal, Delphi, Lisp, Logo, LUA, you name it. All you need is the language documentation and enough time.
Click for better quality.
Coco: my first computer

After my parents talked to my computer teacher, they gave me my first computer: a Coco. I'm not sure if it was only this one or if it was common, but my Coco came with a two inches thick manual that I read from cover to cover almost 10 times, I did every sample program on the book and then started doing my own... and I didn't stop anymore.

For the kids that were born with floppy disks, CDs and all this modern stuff, back on those days we didn't have diskettes to store our programs, we had to store them on tapes. To save them we used a (now ancient) tape recorder -- and it baffles me why they still sell micro-systems with tapes included.

I was confident enough with my coding skills, but my parents weren't, so they sent me to another computer school. This new school had the most advanced computer available those days: an Apple ][. They had floppy disks and all the stuff, but the school was so clueless that most of the time the teacher would come to me when he had doubts about a specific command. After that fiasco, I quit the computer school.
Click for better quality.
MSX: a nice computer

A few years later I bought my second computer an MSX. With a disk drive! Boy, I was happy. No more waiting, no more tape problems. And the MSX had a high screen resolution of 256x192 pixels with 16 different colors! I was in heaven.

The language was still BASIC, just a little bit different from that of the Coco, but nothing that would cause big problems and so it was fine. I could build my programs and save them on floppy disks with the enormous capacity of 360 kilobytes.

Since I first laid my eyes on a computer I knew that my future was somehow connected with computers. When I coded my first program, I was hooked. I would be a software developer.

And then I was in high school. The PCs were getting strong on the market, and if I ever wanted a job I would need to know all about PCs. So I enrolled myself in a computer school near home.
Click for better quality.
MS-DOS Logo

What a laugh! The school focus wasn't on development but on applications, and so they had classes on DOS, Wordstar, and dBase. Although I couldn't learn anything useful (at least that's what I thought) I learned everything I could to master the applications the school had.

Ok, let's be fair. Knowing Wordstar back then was great. It was the first, and for every practical purpose the only, text editor available. And dBase taught me everything I needed to know about databases -- I still need to see a database that can do more than SELECT, INSERT, UPDATE, and DELETE.

Not being able to learn what I wanted in a school I decided to be a self-learner. But first I needed to know what the market wanted me to learn, it would be cool to learn Fortran, for instance, but if no one else was using it I wouldn't have job.

So, I grabbed the Sunday newspaper, opened on the "Help Wanted" pages and started looking for what kind of people the companies were hiring. And they were hiring Clipper developers.

Obviously, I gathered everything I could to learn Clipper and learn it fast.

I was a freshman at college when I took my first job as a computer programmer. It was a small branch of a company that sells supplies to telephone companies across the country.

They used an off-the-shelf program to control their sales and finances, but the program (as it's common with this kind of software) didn't provide the management with enough information for them to make educated decisions about the company, or even strategic ones.

What was my job then? Provide the management with such information.

I had no clue on how that system worked at first, but I dove inside it, reverse-engineered the database (they used Clipper) and was able to deliver all the information they needed.

I was pleased with myself. I took a software that I knew nothing about and was able to deliver everything they needed, as fast as they needed. Not bad for a 16-year-old boy.

During my freshman year at college I was able to get in touch with a lot of things that I had no idea they existed. Mostly because I was a nerdy kind of guy who use to hang out near the computer lab when I was not working or in class.

Many times I saw senior years struggling with their final projects, developing software using Pascal or C, and noticing the despair on their looks I usually offered help. They tended to laugh at first, but when I solved many of their problems they started to look at me with awe and admiration.

As the time went by I gathered a lot of experience on software development, and using Clipper as my language of choice then I gathered a huge code library. I had about 1.2 Megabytes worth of code.

I had code for most of the common tasks I faced while developing software. Menus, checkboxes, listboxes, help files, etc. We needed to code everything back then, and my library saved me a lot of time.
Click for better quality.
Windows splash screen

Then came Windows. I remember the first time I saw a computer running Windows. It was at the Comdex. It was Windows 3.1. There was that huge line of people wanting to play with it. Yes, play. There was a game on that computer: "Solitaire."

And the world was never the same.

Different from the DOS boxes, Windows was naturally colorful. And people like colors.

If people like colors, the management will like colors too. And then they will demand colors from their systems. So, I needed to learn how to create software for Windows.

As I did with Clipper, I gathered everything I could for that task.

I won't fool you, it was a nightmare. Every book I found on the subject was saying that it was terrible to develop for Windows because you no longer had control of your own program. And furthermore, the only way to code for Windows was writing code in C or C++.

But I was adamant. I knew that the future was in developing software for Windows, so I needed to know how. Despite all the books I read were telling me to back off, I went on.

I started to oil back my knowledge in C, and started to create a "Hello World" program.

What a mess! Everything I managed to do was to freeze my computer. I was frustrated. No, I was devastated. Developing for Windows was really as hard as the books were saying.

Then someone on Redmond had the brilliant idea of porting to Windows a very marginal software, that I happened to use at home to create small personal programs.
Click for better quality.
VB 1.0 Splash Screen

The software? Visual Basic.

And life was easy again.

Yes, even though I was a Clipper developer back then, I had never quit programming with BASIC. And the same old BASIC I used to use on my first Coco was the way of the future.

The rest, as they say, is history.