Removing BOM(Byte order marker) characters from your Aspx Pages

The Problem

I recently had a painful problem. I had written a python script to parse aspx files and add a user control, replace some controls with other ones and do a huge batch operation. Everything worked ok, until I started seeing a funny sequence of characters in my pages when I was debugging: 

After googling those exact character I discovered that this is a BOM character. A Byte Order Marker character is used in Unicode files to denote the byte order. As in: is it little Indian… err endian or big endian. Python obviously did this when editing the files. The really neat thing is that Visual Studio did not display these characters. Instead if I could find the invisible character and delete it, Visual Studio would stall for a few seconds and when I save the file it would bitch about the encoding changing and source control. But this was in the lucky cases. In most cases tracking down the visible character was difficult, and Visual Studio didn’t want to delete it. I left gaps of no characters between tags, and that’s where it was. Yes visual studio is an idiot I guess.

The Solution

Notepad2. A freeware editor that has no R&D department behind it, no intellisense, and no really fancy features. Today it was better than visual studio. Opening the offending file in Notepad2 I could already see the character encoding in the status bar. UTF-8. Choose File->Encoding->ANSI and then File->Save and the BOM suddenly shows up, but as a question mark(?). Delete the character and voila!

If you want to get notepad2 you can grab it at : .

The Windows Music Player Battle

Since there is growing competition with music players on Windows lately, I decided to shop around and try them out. Can they replace Winamp? How does foobar2000, iTunes and Songbird measure up to the great Winamp?

I am an avid music listener with a large collection of music. To manage that I need a good media player. Before I start I'd like to say who is the current champion and long time player on my desktop. Winamp. There is a reason I don't want to use Winamp anymore. Winamp seperates playlist from media library and makes the media library a sort of addon. New players have a singular interface where all your controls and media is. The multi window thing just doesnt do it for me anymore. So I decided on this round of installing Windows XP for the millionth time, that I would shop around. The first contender:


First impressions

Songbird looks promising and there has been a lot of hype about it online. There seems to be quite a community around it and there are plugins and skins to choose from. Everything from the website to the installation looks sharp and well done with pretty artwork.


The interface is nothing amazing, but then I wanted a tool, not a piece of art. I did however curiously download 2 themes that looked good on the plug in site, but looked pretty bland when I applied them. Also like Firefox(which is also XUL driven) the application needs to restart to load themes and plugins. This is a bit of a pain.


This was the deal breaker for me. I added some files to my library which worked quite nicely, and set folder monitoring to on. In Winamp this passively load new music into your library. In Songbird this eats up the entire UI and makes the program unresponsive with a modal "Adding files to library..." dialog in the middle of the screen. So you cant do anything when your loading music into the library. Right clicking and getting album art is a gamble. It may show a dialog or it might just do nothing with no indication of failure(that I could see). I could live with most of these things. What I couldn't live with was the fact that scrolling through my list of music was sluggish. And so I uninstalled Songbird.


I don't want to knock Songbird down. After all it is a relatively young player. It has a lot of promise. May I will try 1.x when the performance issues have been sorted out.


First impressions

Foobar is a very small minimal player. It's pretty fast and snappy and has all the necessary elements for a good music player. It's not as impressive as the others, but it gets the job done.


Foobar has the bare basics in user interface elements with no flashy anything. It does however not look bad either. Theres not much to say but it works great.


The user interface for Foobar is complex. There are settings that I don't care about in the preferences and things I will never set. I guess this is nice for someone who needs these features but I don't. I liked the flexible UI but couldn't really find my media library, even though I added folders to it. Usability is not so much an issue in Foobar as it does what it needs to simply.


My problem with Foobar was that it didn't support Last FM, and it didn't have a nice media library. It looks like it's more geared toward old style "add files to playlist" usage. It is however a great player and I feel like I don't want to uninstall it.


First Impressions

Apple always has quite a bit of polish on their products. And this makes all their stuff well... pretty impressive. My first fear of iTunes was that it would be too apple-y. The download was rather large, 69 megs(coincidence?).


The first thing I did was try to see if I could change the default skin. It's not that I don't like Apple's brushed metal fetish, it's just that I like things to be a bit more consistent with my desktop. I couldn't find any such option. I also had this big fat message saying Genius sidebar is not available in my country. No problem. I probably won't miss it(since I don't know what it is.) Coverflow view is really impressive. I am really liking this interface


iTunes decided it would be a good idea to convert all my WMA files. I agreed since I hate WMA. Trying to download album art required me to sign up for an iTunes store account. When I was doing this I was slapped a EULA that if printed could wipe out at least one hectare of trees. And now it's time to uninstall. If I want to use get cover art I need a credit card to get an account. Screw it, I'm not getting a credit card just for that.


This really sucks. It seems like a very nice player. Being impressed with cover flow I would have really liked to use it with album covers, but Apple seems to want a credit card for that. This player is made for Apple, and not for the user... sadly. They want me to buy songs from them, so never mind that then.

And the winner is...

Winamp by a landslide. Winamp still reigns supreme on Windows. Songbird has a chance of competing, but will probably have more market penetration on Linux. I wanted to list Amarok 2 here, but having tested it on Windows I wasn't convinced. The user interface in 2.0 took a strange turn and I can't live with that yet. KDE applications are still too unstable on Windows anyways.

It sucks that I set out to replace Winamp and ended up using it. I guess it really does kick the Lama's ass, and all the other Windows music players' asses too.

Why dislike VB (.Net)?

When I first started programming with VB. Net I hated it. Then after university I started to understand it, and now I am fully aware of many of it's features. Hating a .Net language is like hating car because of it's colour, because after its been CLR'd, the language effectively loses it's identity. This is because all languages in .Net use .Net libraries and functions, and have to adapt to the .Net way of doing things. But syntactically some arguments remain... so why do developers hate VB so much?

The Default Argument In Favour Of VB
Vb .net has one feature C# lacks. Vb .Net has default arguments. The C# team(or whatever) decided that default arguments where not a good idea...

Why? Well they have their reasons:

But if you read the comments in that post you can clearly see that this was a mistake.
One that VB does not make.

And a brief rebuttal from someone at D:

VB .Net 9+ has all the features of C# and in some cases it's a bit easier to use... but one of the main problems with VB is it's legacy.

mid, trim, right, left and even rem are still valid in VB .Net 9. VB 6 Programmers come to .Net and write shitty second rate half aborted VB6 mixed with some object orientation abuse. That is those who are not interested in learning the .Net framework or proper OOP.

The Skill Pool
The skills legacy does make VB attractive, because they can draw from a larger skills pool. VB's got a lot more old hands. C# kiddies(like myself) are still relatively inexperienced, and those who are are rare.

VB <> Standard
Another VB problem is standards. VB is a rebel by design. It's a very stupid language for that reason. After th 400th time End If becomes kind of redundant, but Microsoft has the solution to this problem. Automate text entry! So before you know it your sitting with huge chunks of meaningless keywords. Other language's syntax are much more aligned with C, the base of modern programming.

The <> character is also not a popular choice for not, and writing out the keywords may not be either.

One Liners
The thing that pisses me off the most is that the language parser is very unforgiving. Everything has to happen on one line or else... you have to put a _ at the end of the line. This has been fixed to some extent in VB 10, because it's a stupid limitation with no value whatsoever, but my fear is that remnants might remain. This causes lazy developers to shove everything into one line, and makes long concatenated strings especially tedious.

The conclusion of using VB for almost 2 years on the job is that I don't recommend anyone to it as a learning language. It seems to attract the wrong kind of programmer in many cases. A little bit of syntax can go a long way, and a language like VB is not syntactically sound or pleasing. The final nail in the coffin is that when you learn C# you will have the advantage of being able to adapt easier to Java, C and C++, with VB, your left with pretty much nothing.

The sad part here is that default arguments is the only defense I could think of for VB. VB is my bread and butter, and so I guess I owe it at least a bit of thanks.

Regular expression find and replace with Visual Studio

Recently I had an interesting problem. I had functions in the form of:

func(param, param2)

I had to replace func with func2 which didnt take param 2, but only func 2 where param 2 was equal to a certain value, say ... x. Param was completely unpredictable , except that it was a string.

Regular expressions saved the day:

regex: {func1\("}{.+}{", x\)}

replacement string: newFunc("\1")

func1("aaasdds", x)
func1("Goodbye cruel world!!!! :(", x)


newFunc("Goodbye cruel world!!!! :(")

By creating groups with the curly brackets {} you can replace only certain parts of a string, and match things around it.

The nice thing I've noticed about the . character is that it matches until your next match string. Meaning you can put just about anything in a string and still pull it out of a function call. Even the string below is matched:

func1("Goodbye cruel ""world!!!! :(""", x)

In python you can use re.sub. There is a slight difference here though. The groups must be contained in round brackets().

IF you are a developer and are ever confronted with a batch of string replacements, and you do not use regex... you sir, are an idiot and your the torture of the mundane work is your fault only....