Software and Board Games

Making My Learning Backlog Public

Over the past few weeks I have been reworking my website, in the aim of actually getting back to posting. And part of this includes making personal backlog available publiclly online. I haven’t (yet) added a link to it from the nav bar or similar, but you can find it here. And its split based off the fairly simple split of todo, doing done where I can move items as I look at them and can update to add more information.

Why?

I have been using a trello board in the past to help track things I wanted to learn, but generally found that it was best to clear it out so I didn’t have anything I could go back and review, so I decided to put it on my website for several reasons:

Defining an learning backlog item

First I assume I’ve got the current model wrong, but its in git, I can try to fix it and revert if necessary. But I’ve started with a few simple elements:

Lifecycle of a learning backlog item

If I hear a cool idea, or somehow else get an idea of something to look at it will go as a very brief item into the uncategorised section of interested. Periodically I will review the uncategorised items and either delete it or move into into upcomining. At this point I will also add any first thoughts on particulars I want to look at. When I run out of next items I will review the upcoming and choose the next few to be promoted to next items. This is the last point I will delete an item.

And when I want something to learn I will pick the next item, move into doing. This will be kept up to date with my ongoing thoughts and resources I am using. When I am happy with my current knowledge level on the subject it will move into done, with a refined version of my opinions and resources.

Repeat

What next

Specflow Is A Good Explanation Tool

Recently I’ve been exploring SpecFlow as an alternative to standard NUnit for testing my code, and I have to say I enjoyed working with it. It was easy to set up and write my first test, but it wasn’t until I started using it for test cases that it shone.

What is SpecFlow?

SpecFlow is a tool which allows you to write English-like sentences that can be translated into a standard test. For example the normal test:

1
2
3
4
5
6
calculator.Press("1");
calculator.Press("+");
calculator.Press("2");
calculator.Press("=");
var result = calculator.Result;
Assert.That(result, Is.EqualTo(3));

is equivalent to the SpecFlow test:

1
2
3
4
5
When I Press 1
And I Press +
And I Press 2
And I Press =
Then the result is 3

with the code behind:

1
2
3
4
5
6
7
8
9
10
11
12
[When("I Press (.*)")]
public void PressKey(string key)
{
    calculator.Press(key);
}

[Then("the result is (.*)")]
public void PressKey(decimal result)
{
    var result = calculator.Result;
    Assert.That(result, Is.EqualTo(3));
}

Whilst the amount of code is fairly similar the SpecFlow test itself is really easy to show to non technical people. It can be matched against the spec and really comes into its own when documenting edge cases. I found this when I was attempting to document some legacy code for a code kata. We managed to write a whole suite of tests using just a few methods that could easily be checked against our original spec, and the people we showed it to easily understood what we were trying to test.

Surely there are some issues?

You’d be right, the main one for me is you get runtime errors if you haven’t set up the definitions rather than nice compile time errors. This is more annoying than anything else. Also I find it easier to work entirely in C# as I can understand those tests and I don’t have to jump between the test and its definition. This is the thing that makes me not want to use this for personal projects in the future, but for if there are non technical stakeholders who are interested then SpecFlow is a massive boon.

Exploration Of Micro Services

Once again I am making changes to my EV Tracker project. This time I am looking at splitting up all the logic and storage so I can look after each part separately. To do this I decided to create some Web REST APIs using ASP Net Core and create a simple web page as my GUI. This webpage was using electron to host it, but there was no reason for this other than to try and keep it as a Desktop app.

Before I go much further, a quick disclaimer. This transformation was not complete, just done to a point where I could see how everything would be implemented and could add new features with ease. Also I did nothing about port detection, relying solely on hard coded web calls. But that is something I may tackle in future.

Choices of Services

My choice of services was done by, “Oh, I need to get this set information to display. Guess I’ll create a service to be able to ask that question”. This ended up roughly being one service per model. This may be overkill in certain situations, it would be best to have one service for each model the UI needs to ask about, and one for each model that multiple services need to store/get info about.

What ended up in the UI

In the end my UI was really dumb, I used knockout.js to handle drawing the UI based on my current state. Clicking any button in the UI would send a request to the main Pokémon service and would receive back a new json model of the tracked Pokémon. This would then just overwrite the current data and knockout would redraw everything as necessary. If you want to review the UI code you can look here.

What about the services?

Most of the services were dumb and just stored a json file describing their particular models and served that when asked. The only one of note was the Pokémon service as it required talking to multiple services and manipulating the stored data. Fortunately for me ASP Net Core makes it really easy to send and receive C# objects via REST Apis, particularly with the HttpContent Extension ReadAsAsync<T>() method. To get the actual species data for one of my Pokémon in an easy manner, all I had to do is a simple call and read.

1
2
3
4
5
using (var httpClient = new HttpClient())
{
    var speciesResponse = await httpClient.GetAsync($"http://localhost:20640/api/v0/species/{_trackedPokemon.DexNumber}");
    return await speciesResponse.Content.ReadAsAsync<PokemonType>();
}

This is the closest to complex code that I had to add due to splitting stuff out.

Final Thoughts

In a word boilerplate, perhaps this is because this is still a toy example. But the amount of boiler plate code I had easily dwarfs the code that actually does stuff.

As this was a simple app all running on the same machine the response from the ajax calls were quick as was the redraw, in fact it was almost indistinguishable from it just doing normal thinking. But I do believe that if there was lag to the web calls and redraw was slow (perhaps a complex UI) then the extra delay would be noticeable, if it was solely a web app, perhaps this may be fine but as a desktop it isn’t.

I did enjoy being able to separate my UI from anything that resembles work, this being the services and the templating that knockout gave me, but I am unsure if this bonus is worth all the extra hassle of having to talk to multiple services, handling http requests. It probably depends on the app you are building.

The source code can be found on the HttpServices branch of the GitHub repo. But to reiterate this is not complete and needs more work to bring it to feature parity with the WPF app.

Winforms To Wpf Part 5

This will be the last post about moving to WPF, whilst the app is far from complete, the major parts have been moved over, a few auxiliary functions are missing (e.g Save and Load), along with a very poor visual look to the app. These problems are straight forward and not worth talking about, though if you want to hear more, let me know and I may change my mind.

As for today’s work I need to add the last large section from the original Page class, and that is being able to select the game, route and then clicking on a Pokémon to defeat it and gain the relevant effort values.

Surprisingly simple to set up

With all the previous changes I had made and the infrastructure already set up this was remarkably easy to get done. I needed a new command to defeat a pokémon, and be able to display all the pokémon for the selected route. Defeating a pokémon is easy, I just need to know its number, get the associated species and call Defeat using it. So long as the CommandParameter was the dex number of the defeated pokémon then I could call:

1
2
3
var speciesNumber = o as int?;
if (!speciesNumber.HasValue) return;
CurrentPokemon.Defeat(_species[speciesNumber.Value]);

Displaying all the correct pokémon was not hard either, I had already had practice with templates. I could reuse the image display I had used in Part 3. The only difficult part was finding the correct control to use to display a series of buttons, it turns out an ItemsControl/WrapPanel was a perfect combination. Aside from adding a few extra properties to my Context there was very little to do and my new control looked like:</p>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<ItemsControl ItemsSource="{Binding Path=CurrentRoute.Pokemon}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Horizontal" ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button Command="{Binding Path=DataContext.DefeatPokemon, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MainWindow}}}" CommandParameter="{Binding}">
                 <Image Source="{Binding Converter={StaticResource DexNumberToSource}}" Height="64" Width="64"></Image>
            </Button>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

Conclusions

Aside from the last few minor features I now have a working wpf app, there was some head scratching and frustration and times but I’m relatively happy with the outcome and I’m more confident if I ever have to work on a wpf app again. In the future I’m not sure if I’d choose to use wpf out of the gate but I would always prefer it over WinForms. You can find the final code at GitHub.

What did I like?

First and foremost not having to deal directly with updating the screen and just letting the framework handle it. At times the auto layout works nicely but for this app it needs to be booted into shape so whilst I like it in general, this app is not a good fit Unless I rework the design.

What annoyed me?

I’ll start with a minor annoyance, no Numeric Up Downs in standard controls library. Really? Some of the bigger issues is the amount of cruft around what I am trying to show, it is not easy to just look at the xaml and say what it should look like. I also found Context scopes to be quite fiddly at times, in particular if scoped to an individual item and I wanted to talk to the main context I either had to duplicate the definitions, or look for the MainWindow item (I couldn’t even look for the Context of the right type). And finally I don’t like having all the knowledge about INotifyPropertyChanged living in my backend, it requires a bunch of boiler plate code and is indicative of the type of frontend in use, I’d rather my backend cared not a jot about the frontend.

Winforms To Wpf Part 4

Now that we have stat display, we should allow the user to use certain stat altering items at the press of a button. Pressing this button should update the correct effort value and the appropriate calculated stat.

So let’s add a button

First things first, we need to know which is the currently selected Pokémon, so we can change the correct Pokémon’s stats. This is fairly simple, just add a property to my main Context and bind it to the current tab’s Pokémon:

1
<TabControl Name="PokemonHolder" ItemsSource="{Binding Path=PokemonList}" SelectedItem="{Binding Path=CurrentPokemon}" DockPanel.Dock="Left">;

Now we need to have a command that a button can call to do a particular item’s effect. This command is fairly straightforward, it is a member of the Context so can just call CurrentPokemon.ApplyStatBerry(Stat.SpecialAttack), and wiring the command to a button is almost simplicity itself.

It can’t be that easy, right?

Of course it wasn’t, it would update all the values correctly, but refused to change the value of the effort value shown on screen. It took many attempts and several “walking away from the computer” moments, but I couldn’t get the value in the observable dictionary to be updated on the screen. What would work was to remove the dictionaries and use six properties for each one as well. This was a mechanical change, but forced me to something I had hoped not to do writing the wpf app itself, and that was to change the original WinForms app (thankfully due to the changes I did in prepping for the new UI, I only had to change the Page class). I still left in some functions to allow me to do lookups based of the Stat enum, but when referenced from the xaml I had to reference the new properties rather than a value in a dictionary.

Perhaps there was some way of properly binding to a dictionary value, but I was so frustrated I just moved on. But with this new change everything updated correctly, all I had to do was add new Commands and Buttons for each item and then move them into their own Control. This was done and the app was starting to take shape, the last major problem was to allow the user to click on a Pokémon to defeat it and automatically add the correct effort values. You can see the current state in the GitHub repo

Winforms To Wpf Part 3

And now for the fun of implementing a new UI. Surely this will be easy, oh how I was mistaken. First thing I decided to do was to create a Control that displays a single pokémon, this was originally part of Page but splitting it out would be easiest. It would show the current pokémon details and allow you to manually update level, effort values and individual values.

Final Prep work

Having some small experience with WPF prior to this conversion I knew that INotifyPropertyChanged is instrumental when binding to a wpf control. So I went and made Pokémon implement the interface. I use ReSharper and it gave me a handy shortcut to make all my properties call PropertyChanged. Something I forgot at this point but soon found out was I needed to observe the values in the dictionaries and not just the dictionaries so I went and found a nice NuGet package that did this (MVVMHelpers).

To check that I hadn’t messed this up, I got my Page class to use the PropertyChanged event on Pokémon to UpdateTheForm rather than manually updating every single time I made a change to Pokémon.

Creating my first Wpf Control

For simplicity I created this as part of the Main Window, and once it was working moved it to a Control, so there were less possible causes for any issues.

The first thing was to show the Pokémon header with none of the complexities of showing the stats, the things I aimed to show were:

Loading the values for the drop downs was not satisfying as I had the code:

1
2
var species = new SpeciesLoader().Load();
SpeciesComboBox.ItemsSource = species;

I would prefer to have this automatically loaded for me, and bound from the xaml rather than the code behind. Spoiler Alert: I work out how to do this later, but have yet to fix this part in particular. Each worked, after I overrode the equality checks in PokemonType and Nature. The only difficult thing was binding the image. Rather than putting the image inside the species object I decided to create a converter that would take a dex number and give the path to the image. I chose not to put it in the class because I didn’t want UI only issues to creep into the backend class design. Detailing the path was very simple as I had already the images with the names being equal to the dex number, I just needed to add padding.

1
2
3
4
5
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    var v = value.ToString();
    return $"Resources/{v.PadLeft(3, '0')}.png";
}

And then displaying the image was as simple as binding to the Source property and using the new converter.

1
<Image Source="{Binding Path=Species.DexNumber, Converter={StaticResource DexNumberToSource}}" DockPanel.Dock="Right"></Image>

Now to show some useful information<

The next part of the screen I aimed to display was the Pokémon’s stat grid, that is the base value, individual value, effort value and current value for each of the six stats. This grid, it turns out, was very easy to set up, with the changes I had made to Pokémon updating any of the values, would update the associated calculated values.

All I had to do now was to stick this (still rather ugly) control into its own file, and then add it to a tab control on the Main Window to give it a similar look and feel to the winforms control. My MainView Now looked like:

1
2
3
4
5
6
7
<TabControl Name="PokemonHolder" ItemsSource="{Binding Path=PokemonList}">
    <TabControl.ContentTemplate>
        <DataTemplate>
            <wpf:PokemonControl></wpf:PokemonControl>
        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>

It didn’t auto select the first page just, but for now I was happy enough to move on. My next aim was to allow users to apply stat items to the current pokemon, but this was a bit of a minefield which I’ll explore next time. You can see the current state in the GitHub repo

Winforms To Wpf Part 2

So we had a slightly better code base to move to WPF, but still not great. In particular I was not confident in just swapping out the UI as there were no tests and the UI was tightly coupled to the business logic. So in this session I decided to focus on a particular part of the UI to decouple from the logic, today I tackled the Pokémon tab control. Last time around I had pulled out the tab page structure into its own file, but it still had the logic to handle the updating the model, and some of that logic was still in the form class. My objectives for the session were for each button press/value change to be simplified to a two liner.

1
2
Pokemon.DoUpdate(UpdateDetails);
RedrawTabPage();

If I could do this then the move to WPF for this control should be fairly relaxed.

Simple things first

The first problem I saw was the special code I had for loading a Pokémon. This forced me to always create a page with the Null Pokémon (which is the ever faithful MissingNo), and then load the Pokémon. The main issue for me was the Page class needing special control for the idea of the Null Pokémon and having to have two seperate methods for updating the static parts of the tab page with the dynamic parts. To fix this I took the code from Load and put it into UpdateForm. But know how do you initially set the Pokémom, the constructor seems sensible so we can make a simple change to the creation of the Pokémon field and set it to a new parameter.

Alongside this simple change I noticed just how bad my updating of the model and view was. In essence it was:

  1. Update appropriate user controls
  2. Set the models properties to match the UI
  3. Update all the user controls with computed values

This is cumbersome and really I’d much prefer:

  1. Update appropriate model properties
  2. Update all the user controls with model values

This was fairly straightforward, I already had methods that matched steps 2 and 3, What I wanted was to expand step 3 to all value (Not too difficult), get rid of step 2 and only ever assign to UI controls in the UpdateForm method. Again while not simple to do this was straightforward, but did make changes that started at step 2 more complicated as they now need to update the model, then call UpdateForm().

Having logic in Page is illogical

So we have several methods that manipulate the Pokémon state that live in the Page class, specifically the places where an Item is involved (Apply Item and the item buttons come to mind). But with the most recent change, all these methods do is call Pokemon.Property = function();UpdateForm(). So we can simply move them into the Pokémon class and just call them. Now the Page class is pretty much all:

1
2
Pokemon.DoUpdate(UpdateDetails);
RedrawTabPage();

Hang on, you said some logic was in Form?

Correct, and it still is and has similar problems to those I just mentioned. Previously clicking the button ran the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Form1 : Form
{
    void b_Click(object sender, EventArgs e)
    {
        var i = (int)((Button)sender).Tag;
        var dict = _pokemonTypes[i].GivenEffortValues;
 
        if (dict.ContainsKey(Stat.HP)) _current.UpdateStat(Stat.HP, dict[Stat.HP]);
        if (dict.ContainsKey(Stat.Attack)) _current.UpdateStat(Stat.Attack, dict[Stat.Attack]);
        if (dict.ContainsKey(Stat.Defence)) _current.UpdateStat(Stat.Defence, dict[Stat.Defence]);
        if (dict.ContainsKey(Stat.SpecialAttack)) _current.UpdateStat(Stat.SpecialAttack, dict[Stat.SpecialAttack]);
        if (dict.ContainsKey(Stat.SpecialDefence)) _current.UpdateStat(Stat.SpecialDefence, dict[Stat.SpecialDefence]);
        if (dict.ContainsKey(Stat.Speed)) _current.UpdateStat(Stat.Speed, dict[Stat.Speed]);

        _current.ApplyItem(((Items) _current.HeldItem.SelectedItem));
    }
}

class Page
{
    public void UpdateStat(Stat stat, int statIncrease)
    {
        Pokemon.UpdateStat(stat, statIncrease);
        UpdateForm();
    }

    public void ApplyItem(Items item)
    {
        Pokemon.ApplyItem(item);
        UpdateForm();
    }
}

And lets be honest the form should not know about stats. What clicking the button means is defeat the Pokémon associated with the button. So lets just move the code into a method inside Page, and then into Pokémon. Whilst doing this I also made sure that we only passed the associated Pokémon in and never interrogated it.

Final clean up

I was fairly happy with the Page class but I could see one final small change to do, and that was to simplify using it. Lets not make it have a TabPage, but instead just make it a TabPage and easily pass it around in the form. This would reduce my need for abusing the Tag system in WinForms (also a tabpage contained the associated Page, which points back at the TabPage. So lets just add the : TabPage and remove the TabPage field from Page. All the changes simply fell out in Page, and mostly in Form as well. The final thing was I really didn’t need to store the current Page object showing if its always tabSelector.Current, so just use that.

Next time, I’m actually going to attempt to start moving to WPF. You can see the current state in the GitHub repo

Winforms To Wpf Part 1

So, I’m a bit of a Pokémon fan and a few years ago I decided to have a crack creating a stat tracker for the Pokémon Black and White. It worked and all that but I created it 3 years ago and my skills have improved since then.

Recently I wanted to have a go at creating a WPF app so I thought I’d crack this old code out and have a go at updating it. I’m going to blog about the update as I go. So first the code as it was when I picked it up (see the Github repo) was a bit of a mess and required some fixes before I started working. So I added the .gitignore file and updated to Visual Studio 2015 so I could use shiny new features.

Now I had a code base I could work on it was time to get cracking. But I immediately hit several problems: I had no tests, had static managers, the form was also a bit unwieldy as it contains all the logic for updating the views. So I decided to start with the low hanging fruit.

Fixing some low hanging fruit

My first pick of the fruit was to have a pass at all my ReSharper squiggles. This was mostly moving files and removing unused code. But it helped to remind me what the classes were and roughly what they were for. I then noticed I was not using the using pattern when serializing stuff to files, so I quickly did that.

About now I start cursing my younger self for not having any tests. So, I decided to look at adding tests, but I found this very hard with my current set up so I went back to safe changes with the mindset of making it testable, or at least making it so the UI was really dumb.

Interspersed with ReSharper fixes I also made the manager non static, then got rid of it entirely. Instead just passing in the objects that it would have supplied.

This is when I spotted a nasty piece of UI code I decided I could safely change with just quick manual tests.

Creating tab pages

Part of the UI has tab pages that relate to a single tracked pokemon, and you can have many of these tabs. And the code for producing these pages was, of course, entirely in the Form class. So out it came into its own class, it still had a bunch of problems but it was starting to look like a combined WPF control and model. This was mostly pain free, and actually reduced the number of lookups needed as each tab page could look after itself rather than the form needing to work out the correct stuff knowing what the current page is.

Previously had something akin to:

1
2
3
4
5
6
7
8
9
int i = (int)((Button)sender).Tag;
IDictionary&lt;Stat, int&gt; dict = _pokemonTypes[i].GivenEffortValues;
foreach (Stat s in dict.Keys)
    switch (s)
    {
        case Stat.HP: _current.EVHP.Value = Math.Min(dict[s] * (_current.HeldItem.SelectedItem.ToString() == GetEnumDescription(Items.MachoBrace) ? 2 : 1) * (_current.Pokerus.Checked ? 2 : 1) + _current.EVHP.Value, 255);
						break;
        // Cases omitted for brevity
}

Which now looks something like

1
2
if (dict.ContainsKey(Stat.HP)) _current.UpdateStat(Stat.HP, dict[Stat.HP]);
// Other cases omitted for brevity

with the code calling

1
2
3
4
5
6
7
8
UpdateStat(statIncrease, _statNumericUpDowns[stat]);

// Which is this method
private void UpdateStat(int statIncrease, NumericUpDown numericUpDown)
{
    var items = HeldItem.SelectedItem as Items?;
    numericUpDown.Value = Math.Min(statIncrease * (items.HasValue && items.Value == Items.MachoBrace ? 2 : 1) * (Pokerus.Checked ? 2 : 1) + numericUpDown.Value, 255);
}

Summary

Well, this is going to take longer than I thought but at least its fodder for blogging about. You can see the code as it stood after my first session on GitHub, the code is in a slightly better state, but for the User the only change is there is no longer an installer. Next up, the form should not be dealing with loading of a file, so lets stop that.

Formula D

Formula D, it might surprise you to learn, is a racing car themed board game designed by Laurent Lavaur and Eric Randall. This is another game I first saw on Tabletop, where I thought it looked light with a sprinkling of strategy. Having now played it myself it feels the strategy is massively out gunned by your die rolling skills.

Overview

The aim of Formula D is exactly what you would expect from from a racing game. Cross the finish line in first or, if you have my luck when I played it, try not to crash. Each player starts with their car on the starting grid, and some hit points for different parts of their car (e.g. Engine and suspension). Each turn you can change gear and move according to a dice roll, making sure you go slow enough through corners.

If you do something daft, like speed through a corner or get too close to another car, then parts of your car will lose health. If any car part loses all its health then the car stops working and you are out of the game.

What i enjoyed

The theme was spot on, it felt like you were in a high speed race. You had to take care of your car and you could feel the danger in approaching a corner too quickly. The ability to push your luck at the expense of health gave me satisfaction, particularly on the last corner where I could either go slow and take 4th or chance a crash to make an overtake. Of course I took the dangerous option, with one of my few good die rolls that night I took 3rd and celebrated more than the person in first.

What wasn’t so good

There were two main problems:

I mainly want to labour the second point as the first stands for itself. I find that the longer a game goes on the more agency I want on its outcome. Take zombie dice, or love letter. They are both heavily reliant on luck but are still fun to play. But if they took half an hour or more then they would be a slog. On the other hand Betrayal at the House on the Hill, which requires frequent die rolls and draws from shuffled decks, takes about an hour but the player choices generally outweigh the luck. This game gets the worst of both worlds - a long play time and high luck factor.

Would I recommend it?

Don’t get me wrong I thoroughly enjoyed playing it, I think you should definitely play it, though probably someone else’s copy.

Exploring Sql Server Collations

This is now instalment 3 in the Exploring SQL Server series, and I’m going to step back and talk a bit about a simpler topic - Collations. These are simply how to compare two pieces of text. Do I care about case, or accents? In what character set should I use?

So what values does it compare?

It compares all of your text columns - the non-unicode char, varchar, and text, along with the unicode types ncharnvarchar, and ntext.

And how does it affect comparisons?

When sorting it defines the order of the sort. For example if you use traditional Spainish, then ‘ch’ will come at the end of the ‘c’ section rather than the middle.

As well as sorting it also affects how to tell if two strings are equivalent. Some of the more obvious things it will check for are case and accents: For example If you use a case and accent insensitive collation then ‘Pokemon’ and ‘pokémon’ will be considered as equal.

Another thing it can be sensitive to is Japanese kana mora characters. Should it treat symbols from different kana as the same if they mean the same mora. e.g. [あ]]https://en.wikipedia.org/wiki/%E3%81%82)‚ and  both stand for the mora ‘a’.

Does it do anything else?

When using non unicode types the collation determines the character set to use. E.g. a latin collation will support standard latin characters like the ones I am using now. These are actually in most code pages as part of ASCII, this is just the first part of the page. If you look at the later part in the latin collation it is full of accented charters used in western European languages. But if I use a Japanese collation it will have Kanji, a Russian collation would have Cyrillic characters and so on.

So, if if used a standard latin collation, I could not store the value Д, which is from the Cyrillic alphabet.

So how do I use it?

Quick answer, if you have a database already then you already are. When you install SQL Server it will set the default collation to match the machine it is installed on.

How do I change it then?

Well, as is the case in a lot of SQL Server, it is fairly straightforward, and can be done on a variety of levels. You can set it at the server/database/column/query level.

For example I want to create a Chinese column for my table, I can add the COLLATE Chinese_PRC_CS_AS to my column definition. Or if I wanted to do it a SELECT statement I can do the same.

Hope this helps clear up what a collation is and why you might want to change the default. Though if you just wish to use Unicode then it is mostly just sorting and whether two characters should be considered equal.