Web Snob

You are a Web Snob if:

  • you say "URI" rather than "URL"
  • You say "ECMA script" rather than "Javascript"
  • you pronounce "Bayesian" correctly
  • You apply a title attribute to all your anchor tags
  • You say "anchor tags" rather than "links"
  • When assessing a potential employer the first thing you do is look at their website
  • When looking at a website the first thing you do is "view source"
  • From a distance of thirty metres you can tell if a fragment of XML is well formed
  • Your spelling is poor yet you type "<br />" rather than "<br>"
  • You know (without thinking) what '&#252;' means
  • You don't say & you **say** &amp;
  • You have your own Wiki, Weblog, web-forum and Webserver; yet you have nothing to say

 

An Open Letter to Technical Authors

This is addressed to you, you übergeeks who spew out endless books intended to help us learn the wiles of .Net, the secrets of COM+ and so on.

I have two gripes with you lot, so listen up.

Problem 1: Boring Business Examples

Why are your business examples so boring? Why are they so devoid of creativity?

Here are some rules and I want you to follow them:

  • Don't use examples from the publishing world.
  • Don't use HR departments as examples. They have been used one million times too many.
  • Don't use "northwind".
  • Never ever under any circumstances use the word widget.

The next time I see Widget used in print, the author and publisher will both be named and shamed.

When explaining polymorphism:

  • don't use examples from the animal kingdom.

Why not try inventing new metaphors? Why not dip into the right side of your brain and see if somewhere in there you have a smidgen of creativity?

Perhaps the new examples might be more illuminative than these sad cliches. Perhaps they could help broaden our thinking - make us understand the concepts in a less cliched way. And hopefully the examples you create can be vivid enough to stop us from falling asleep in our cubicles.

Problem 2: Poorly Formatted Code Examples

Check that the example code actually compiles. Is that really so hard? If you change something - no matter how small - then recheck the code using a compiler (at the very least).

If you are rewriting C# into VB.net, please take care! Check that the resultant code will compile. Check that it is a **good** example of VB.net.

But there is a worse crime of which you are all so very very guilty.

Is it 1968? Tell me? Is it 1968?? It's not 1968! Code editors use colour to highlight syntax. So why don't your code examples?

On web pages, colour is *always* available. Yet you fools (and I'm looking at you MSDN) insist on serving up code in one colour only. You hurt my sensibilities.

I understand that colour is expensive to provide in print. But it's free on the web. And in books you can use bold to highlight keywords you ninnies. And don't tell me you can't afford the ink!

Use a non-proportional font. (Break this rule and I'll send my boys around to break your legs)

Embed the code in a light-grey box so that it is separate from the supporting text.

Do everything you can to make your code examples easy on the eye.


Follow those rules and nobody gets hurt. Capisco?

 

Ch-ch-ch-changes

i guess i've changed a little over the last few years. Here's a recent depiction and one from six years ago.

(thanks to Chris Doyle's Reasonably Clever for the enabling technology)

This morning on the bus I noted that the woman beside me was reading the instruction booklet for her new coffee machine. A real page turner I bet.

Last night I discovered that I am no longer the world's fittest man. I went to a cardiovascular circuit training class and after half an hour I almost collapsed from lactic acidosis. I had to lie down for the rest of the class and my muscles still feel all shaky. The extreme heat and humidity are no tremendous help. Maybe I'll stick to exercising the grey matter from now on.

Also, last night there was a 10 minute blackout after which it took two hours to reset all the blinking digital clocks. Feature creep is clearly rampant in the appliances world, where every single electronic device *must* contain time-keeping circuitry. I am happy to note that my toaster does not yet have a digital clock. I give it two years.

 

Constraint Files Explained

I've received a number of queries regarding the structure of the constraint files used by my thesis, lecture timetabling using genetic algorithms, so i've decided to post up a page describing the format of these files.

Description of Constraint File

A constraint file is a simple text file, whose name has the extension ".ctr" It stores the specification of a university - its classes, its lecturers and its classrooms.

These files can be written in any text editor.

Each piece of data within the file is stored on a new line. I expect that new lines were marked with a Carriage Return and a Line Feed (character 13 and character 10 respectively, \r\n) though from inspecting the code it seems you only need a line feed character (Character 10, referred to as "\n" or "new line" in the C Language).

Structure of Constraint File

Now I will go through line by line, explaining what the constraint file contains

line 1 and 2: are for comments and are thus ignored (for example line 1 may contain the name of the test and line 2, the name of the university)

line 3: contains the number of classes

line 4: contains the number of class associations. (for example: the number of courses, departments or faculties) (two classes are "associated" if they can't be held at the same time, because for example, they share a lot of students.)

For the remainder of the file, I cannot give specific line numbers (as I did above). So I instead I will just say 'Next line'.

The following section is repeated for each class (e.g., if there are three classes, this section will repeat three times)

Next line: Name of class

Next line: Reference Num of lecturer

Next line: Size of class

Next line:X location of class' administrative office

Next line:Y location of class' administrative office

Next line: class association code (example, course/year code)

(If two classes can be held at the same time, then they would have the same value in their 'class association code')

Next line: the number of lecturers

The following section is repeated for each lecturer:

(e.g., if there are six lecturers, this section will repeat six times)

   Next line: Name of lecturer
   Next line: X location of lecturers office
   Next line: Y location of lecturers office
   For each day of the week:
     for each hour of the day:
        A character that represents the availability of the lecturer
     next hour
    Move to next line   
   next day

Next line: the number of rooms

The following section is repeated for each room:

(ie, if there are eight rooms, this section will repeat eight times)

For each room:
   Next line: the name of the room
   Next line: the capacity of the room
   Next line: the X location of the room
   Next line: the Y location of the room
   for each day of the week:
     for each hour of the day:
        A character that represents the availability of the room 
     next hour
    Move to next line   
   next day

SO... to try and demonstrate this, i've written an example constraint file (I can't test it unfortunately...) for a university called 'The Tiny University'

This university holds two classes, Biology101 and Biology102. They cannot be held at the same time as each other, so I've given them the same "Class Assocation Code" (i gave them both a Class Assocation Code of "1").

Biology101 has fifty students and is taught by lecturer number 1 (whose name turns out to be Prof Freddy101)

Biology102 has seventy students and is taught by lecturer number 2 (whose name turns out to be Dr Jenny102)

The home office for Biology101 is located at co-ordinates 10,10.

While the home office for Biology102 is located at co-ordinates 20,20.

There is only 1 room in this rather tiny university, and that room is called "The Green Room."

the Green room holds up to 75 students and is located at co-ordinates 10,10.

Okay that explains most of the file - but now to explain what is initially the most daunting section: the "Availability Matrix".

That is the section that look like this:

1O1OO1O1O1
1111OOOO11
11OO11O1O1
11O1O1O1OO
O111O111O1

And you will find one "Availability Matrix" for each resource, be it a lecturer or a classroom.

There are three resources in the tiny university (two lecturers plus one classroom) hence you will see three availability matrices.

Each matrix is five line long, representing the five days of the week, monday to friday.

Each line is ten characters long, representing ten working hours of the day.

Each character is either a one or a zero, represting "available" and "not available" respectively.

So if for example you look at the availability matrix under Doctor Jenny102, you will see that in the third line of the matrix (representing wednesday -- the third day of the working week), there is a line that looks like this: 1100110000, representing Jenny's availability on a wednesday. What this means is that she is available for the first two hours of the day, unavailable for the next two hour, available for the two hours after that and then unavailable for the final four hours of the working day.

Availability here relates to prior commitments, and so forth. For example if a lecture hall was booked out to an external party every monday morning, then you would expect to see a few zeros on the first line of the availability matrix for that resource.

OKAY - here's the example constraint file (copy it into a file and rename it Constr3.ctr) (starting with the line 'Test: x16...")


 

Who Plays Golf?

Although this is off topic, I just had a great idea for a New television show: 'Who plays golf?'

The format is as follows:

Contestants are shown two people, one of whom is a golf player and one who has never played golf in their life. The contestant is asked to guess which one plays golf.

(Wait for it, I'm going somewhere with this...)

Home viewers can SMS their guess in, or vote over the internet, or by calling in (costs more from a payphone).

Later in the show, the contestant gets to ask a question to each person - but the questions can only be drawn from questions that have been sent in by home viewers. And no, the question cannot be 'do you play golf?'

At the end of the show, the true golf player reveals himself and if the contestant has guessed correctly, they get a gun with three bullets in it - and three chances to kill the golf player.

If they succeed in killing the golf player, then they get the prize, which is the joy of living in a world that has one less smug golf-playing bastard. If they fail, then the golf player's hands are broken and tongue is cut out, but apart from that he's free to go.

I know I'd be watching!


(if you like critical and sarcastic commentary, you might also like: 'Twitching on Fraser Island')

 

Between Christmas and New Year

Back from holidays on Queensland's sunshine coast. Tanned, fat, happy, all the rest. Made big improvements to '.Net Remoting: the Quick and Dirty Guide' so if you read it previously but left feeling cheated and confused - click again, kiddo.

You may notice the nice code colouring (or 'coloring' as our American cousins say) in that article - thanks to a .Net Code Colouriser (or 'Colorizer' as our American cousins say) I'm working on.

CodeStyler is only at version 0.0 currently, but more details will follow in the new year.

By the way, if you're a geek who's never read Rory Blythe's blog before, let me recommend it now.

Gotta go.

 

.Net Remoting: the Quick and Dirty Guide

Are you studying for Exam 70-310 for MCSD or MCAD? Or has .Net Remoting given you The Fear?

The topic is much much easier than you think, so after studying the .Net Remoting section of Mike Gunderloy's excellent book (MCAD/MCSD Training Guide [70-310]) I've written a Quick and Dirty guide on the topic.

.Net remoting is a way of allowing two chunks of code talk to each other: across the room or across the world.

The first misconception to overcome is, as my boss put it 'But isn't that just Web Services?'

In short, while Web Services are Interoperable with many software vendors, languages and platforms, .Net remoting is Microsoft-Specific, and pretty much .Net specific as well.

And While Web Services must use Http, .Net remoting can use Http or Tcp, and it can be formatted as Binary or Soap. As such they can get a large performance boost over Web Services. Though I'd say they are trickier to write.

Why use .net remoting?

The reasons for .Net remoting are many, but they boil down to:

  1. You want to take a processing/memory load off the client's machines.
  2. There's hardware specific stuff that the clients can't do (e.g. you might have a Megatron Particle Accelerator and you want clients to be able to operate it. .Net remoting is your man!)
  3. You want to share data amongst a large number of clients. (e.g. you want clients to be able to look up data on your EmployeeGenePool database, without them having to individually host that database)
  4. You want your clients to be able to call some of your secret proprietary functionality but you don't want to give them the modules that perform this functionality. (And other control related reasons)
  5. You want to avoid redeploying your objects each time their functionality changes.
  6. Other. There's always an other.

So how do you go about it?

There's just a few important considerations really and after that it's just plug and play.

  1. Choose a Channel protocol. eg Tcp, Http.
  2. Choose a Formatter. eg, Soap, binary.
  3. Choose an Activation technique (ie choose an 'Architecture')
    1. Server activated (singlecall or singleton) (this is referred to as a WellKnown service/client type)
    2. Client activated (this is referred to as an Activated service/client type)

Implement .net Remoting in five minutes!

  1. On the Server:
    1. Create a Remotable Class
    2. Register a New Channel
    3. Register the Remotable Class
  2. On the Client
    1. Register a New Channel
    2. Register the Remotable Class
    3. Instantiate (and use) the Remote Class!

Alrighty. I'll go through each of those steps one at a time, and show you how it's done for each type of channel and activation.

Namespace warning: The following code assumes you've imported these namespaces (as required):

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http and/or:
Imports System.Runtime.Remoting.Channels.Tcp 

On the server: Create a Remotable Class

First, create a Remotable Class. This is the class that your clients are going to be using.

A remotable class looks like any other class except it Inherits MarshalByRefObject. Also, the only constructor it has is the default constructor ("Public Sub New()"), unless it is Client-Activated, in which case it can have overloaded constructors

Class Person
Inherits MarshalByRefObject

'Example property
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property

'The default constructor
Public Sub New()
End Sub

'** Can only use this Overloaded Constructor if
' the class is going to be client activated!
Public Sub New(ByVal pName As String)
_Name = pName
End Sub
End Class

On the Server: Register a New Channel

We're going to write some Channel Registration code.

The following code can sit in the same project as your Remotable Class. That's the easiest way to do it - but not a good method if you're looking at remoting a lot of classes.

So preferably your Channel Registration code will sit in a separate project that acts as a "Remoting Server." The Remoting Server project will need to have a reference to the project that contains the Remotable Class.

(In practice your remoting server wouldn't have a reference to the remotable class, but rather a reference to an interface implemented by the remotable class. See the Extra Credit topic below for more on this practice.)

Where was I? Registering a new channel on the server. Here goes. For TCP do this:

'Register a New TCP Channel on port 1976
Dim channel As TcpServerChannel = New TcpServerChannel(1976)
ChannelServices.RegisterChannel(channel)

For HTTP do this:


'Register a new HTTP server channel on port 1976
Dim channel As HttpServerChannel = New HttpServerChannel(1976)
ChannelServices.RegisterChannel(channel)

On the server: Register the remotable class

For server activated (i.e. WellKnown) do this:

'**For SingleCall:
RemotingConfiguration.RegisterWellKnownServiceType(GetType(Person), _
"Person", WellKnownObjectMode.SingleCall)

'**For Singleton:
RemotingConfiguration.RegisterWellKnownServiceType(GetType(Person), _
"Person", WellKnownObjectMode.Singleton)

For client activated (ie, 'Activated') do this:

'Register the client activated object
RemotingConfiguration.RegisterActivatedServiceType(GetType(Person))

On the client: Register a New Channel

Note that the client code is similar to the host code, but you don't have to specify the port number (the host looks after this!)

For TCP channels...

'Register a new TCP client channel
Dim channel As TcpClientChannel = New TcpClientChannel()
ChannelServices.RegisterChannel(channel)

For HTTP channels...

'Register a new HTTP client channel
Dim channel As HttpClientChannel = New HttpClientChannel()
ChannelServices.RegisterChannel(channel)

On the client: Register the Remotable Class

Warning! This requires that the client project has a reference to the project containing the Remotable Class. Usually this is not only a security risk, but completely impractical. Instead the client project could reference an Interface implemented by the Remotable Class. See the Extra Credit section for further details.

Assuming we've established a reference to the remotable class (or an interface it implements), we are ready to Register the client's with the remoting server.

If it's a ServerActivated (i.e. 'WellKnown') type:

RemotingConfiguration.RegisterWellKnownClientType( GetType(Person), _
"tcp://localhost:1976/Person")

If it's a Client Activated (i.e. 'Activated') type:

RemotingConfiguration.RegisterActivatedClientType( GetType(Person), _
"tcp://localhost:1976")

On the client: Instantiate (and use) the remote class!

Now we can finally access the remotable class from the client. Before we proceed, let's take a moment to appreciate the technical marvel that is .Net remoting.

Somewhere out there, on the other side of the world perhaps, a class sits on a server. The class inherits MarshalByRefObject and it has been registered with a remoting server. Out here, on the client machine, we've fired off a message to tell that remoting server we wish to use the remotable class. Now, the way is cleared and we are able to use that class here on the client as if the code were held locally. Time and space are no match for .Net.

So let's invoke the server-hosted remotable class from the client.

The following works for all types of remote objects:

Dim lPerson as new Person()

'Now do something with the object...
lPerson.Name = "Fred"
Messagebox.Show("Hello " & lPerson.Name)

In the case of Client Activated objects, you also get the ability to call Non-default constructors, for example:

Dim lPerson as new Person("Fred")
Messagebox.Show("Hello " & lPerson.Name)

Extra Credit: Create an Interface for your class

In the infamous 'Real World' you can't allow the client to reference your server-side remotable class.

(Two sufficient reasons for this: If your class implements Secret Business Formulae then you don't want your client to decompile them, and secondly for versioning reasons you don't want to be blatting your remotable classes out to clients every time you make a change.)

Instead you create an interface, bundle that into an assembly and let the clients reference the interface assembly. Try decompiling *that* suckers. You won't find out a thing about our Secret Business Formulae! Your Remotable Class sits safely tucked away on the server, happily implementing the published interface.

Here's our example. First an interface, that will be made available to any clients:

Public Interface IPerson
Property Name()
End Interface

Now we change our remotable class so that it implements the IPerson interface:

Class Person
Inherits MarshalByRefObject
Implements IPerson
Private _Name As String
Public Property Name() As String Implements IPerson.Name
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
Public Sub New()
End Sub

'** This Overloaded Constructor
' cannot be called from an interface!
' (nor from a server activated instance)
Public Sub New(ByVal pName As String)
_Name = pName
End Sub
End Class

On the client side replace all instances of 'Person' with 'IPerson' and you are then able to create the object without having a direct reference to it (only a reference to the interface it implements)

But this creates a new limitation for Client-Activated objects. The interface can't include constructors. So we can no longer call our non-default constructor. This is a real annoyance if you are into Non-Default Constructors. And you should be. In order to get around this limitation, Mike Gunderloy suggests we use a special pattern: The Class Factory.

Create an Interface to a Class Factory

A "Class Factory" is just a term used to describe a Class that creates and returns other classes.

Create a ClassFactory with one method for each of the constructors you want to call in your remotable class. In the example above we'd have an interface called IPersonFactory, which implements two methods: one for the default constructor and one for our overloaded constructor.

Public Interface IPersonFactory
Function CreatePerson()As IPerson
Function CreatePerson(ByVal pName As String)As IPerson
End Interface

Now create a remotable implementation of the IPersonFactory interface

Public Class PersonFactory
Inherits MarshalByRefObject
Implements IPersonFactory

Public Overloads Function CreatePerson() As IPerson Implements IPersonFactory.CreatePerson
Return New Person
End Function

Public Overloads Function CreatePerson(ByVal pName As String) As IPerson Implements IPersonFactory.CreatePerson
Return New Person(pName)
End Function
End Class

The Person Factory will act as a Server-Activated (i.e. WellKnown) singleton - because a single long-lived instance of it can be used to return as many Person objects as the clients desire.

On the client you create an IPersonFactory and use it to return the IPerson object you're after.

Conclusion

If you kept up with all that then bully for you. Mike's book gives a much better coverage, but takes seventy or so pages to cover what we've just covered. In the same chapter he also touches on using 'SoapSuds' to generate proxy classes, using IIS as the activation agent (rather than writing your own remoting server as we did), Leasing, Marshal by Value (explicit Serialization) and much more. I guess it's time to move on, I'd better get out the book and keep studying...

 

Following links can be dangerous...

blog,

Justin King's blog sent me to a link, and this is the response I got from the network's censorship software...

blocked by webmarshal! TextCensor Script Pornography triggered with total weighting of 10

A weighting of 10! I don't think you can get much higher...

Now i'm definitely going to have to read Zgeek!

Isn't it a touch ironic that in order to protect you from certain words, they get all those words, bunch em together and show them to you all at once?

Surely if you are offended by these particular arrangements of letters, then you'll be even more offended by a webpage like that shown in the graphic above, that seeks out offensive words and throws them all at you in one big sick blast??

If you visit a real porn site, do they scoop together all the dirty pictures and present them as thumbnails, with a message saying something like "Blocked: because of these sick images of grannies in latex: [photo] [picture] and this poor photo of an abused shetland pony [another picture...]" and so on?


In other scary news, here's the two strangest search requests that have sent people to my site recently:

  • nudist+beach+review
  • slang+what+does+hung+like+a+horse+mean

Must inform the wife that I am now a known authority on what it means to be hung like a horse....

 

Don't you 'Dare' insult Microsoft

Three strange and interesting reports about Dare Obasanjo have just come light.

(Note: Dare is the main programmer behind RssBandit - an excellent application for keeping up to date with syndicated websites. Dare works for Microsoft)

  1. He just moved the source code for RssBandit from gotdotnet (owned by Microsoft) to sourceforge
  2. he criticised scoble yesterday
  3. his site (25hoursaday) is not working right now!

Has Dare been taken out? Did Scoble put a hit on Dare? Did scoble call up some buddies with big guns and ask them to 'scobleize' Dare??

Something freaky is going on man!

Are the black helicopters circling???

Maybe Torsten has the answers...I'll leave him a few comments see if he knows anything...