I recently co-authored an arti­cle with Gael Frai­teur (cre­ator of Post­Sharp) on how AOP frame­works such as Post­Sharp can be used to auto­mate the imple­men­ta­tion of com­mon design pat­terns in .Net.

The arti­cle is now avail­able to view on the InfoQ web­site here. A more offline friendly PDF ver­sion is also avail­able here and from Post­Sharp’s brand new site.

 

Hope you enjoy what we have to say on the topic, and please don’t hes­i­tate to give us your feedbacks!

Share

It’s been 2 weeks since we released any new con­tent into the world of Here Be Mon­sters and for our trap­pers that no doubt feels like an eter­nity! So with great pride, I’d like to tell you that the wait is over and that you have plenty to look for­ward to!!

image

It’s the end of Europe as we know it…

A series of new quests are now avail­able, come speak to mys­tics Jes­sica and Miranda at the Stone­henge to kick off a chain of quests which leads to your encounter of a fear­some and pow­er­ful ruby dragon by the name of Spyrion who reveals to you the where­abouts of the miss­ing trap­per cap­tain Bashak and that she is in urgent need for assis­tance from you!

Nor­ris, the gnome who helped you out at the start of your jour­ney, also needs some help to fend off Spyrion’s army of Gob­lins who are caus­ing havoc in the gnomish home­land. And sur­prise sur­prise, the Pix­ies are up to no good again, seri­ously, those guys…

Along the line you will also receive two pow­er­ful new traps – the Ring of Runes and the Thun­der­dome which you need to reassem­ble in order to cap­ture the great Chimera.

image image

imageimage

image image

Change Folk Appearance

By pop­u­lar demand from our play­ers, you can now change the appear­ance of your ‘folk’ (your avatar in the game) at a small price by bring­ing up the change pro­file dia­logue and choos­ing ‘the ‘Change Appear­ance’ option:

image image

New Chat UI

We have a new chat sys­tem which allows for eas­ier Spot and Buddy chat, and a global chat fea­ture is also in the pipeline for the near future!

image

Craft­ing UI Revamp

We have also revamped the craft­ing UI which now has a uni­fied inter­face for work­ing with any build­ing that can be used for craft­ing — work­shops, lab­o­ra­to­ries, wind­mills, etc.

Also, when you click the ‘Add Suc­cess Potions’ but­ton you no longer have to add suc­cess potions man­u­ally, instead we’ll intel­li­gently apply as many suc­cess rate potions as nec­es­sary from (both your back­pack and barns) to raise the suc­cess rate of your craft­ing task to 100%:

image

Map Improve­ment

You and your bud­dies’ actual homes are now shown on the map, so if you have a nice and big man­sion in your home­stead it’ll be imme­di­ately vis­i­ble and on the map, not a bad way to show off the prowess of your home­stead to your friends!

image image

New Achieve­ments

Sev­eral new achieve­ments that are tied to the new quests have also been added, such as the Guardian of Stone­henge achieve­ment below,

image

 

Wow, that’s it! Quite a big change this week, and we have even more excit­ing improve­ments lined up for you for the next week or so too, keep your eyes peeled and watch this space!!

Share

I talked about the XML and JSON seri­al­iza­tion of F# types in a pre­vi­ous post, and since then F# 3.0 has been released and a new [CLIMutable] was qui­etly added amidst the hype sur­round­ing the awe­some type providers!

 

CLIMutable Attribute

When applied to a F# record type, the CLIMutable attribute tells the F# com­piler to gen­er­ate a default para­me­ter­less con­struc­tor as well as prop­erty get­ters and set­ters so that when work­ing with the record type from other .Net lan­guages it’ll appear as a pretty stan­dard, muta­ble CLI type that you’d expect.

How­ever, when work­ing in F#, the nor­mal rules as far as record types are con­cerned still apply – immutabil­ity by default, pat­tern match­ing, cloning using the with key­word, etc.

For a sim­ple record type Per­son, let’s have a look at the com­pile code with and with­out the CLIMutable attribute:

image image

With­out the CLIMutable attribute, this is how the record type is nor­mally compiled:

image

With the CLIMutable attribute applied, things look a lot different:

image

That’s all well and good, but why is this use­ful you might ask?

Because many seri­al­iz­ers, such as the BCL’s XmlSe­ri­al­izer (as well as other seri­al­iz­ers avail­able in the open source space) only work with types that has a default con­struc­tor and con­tains prop­erty setters.

 

XmlSe­ri­al­izer and Record types

Unlike the Dat­a­Con­tract­Se­ri­al­izer which only requires a type to be dec­o­rated with a Seri­al­iz­able or Dat­a­Con­tract attribute, the XmlSe­ri­al­izer on the other hand, also requires the type to define a para­me­ter­less constructor.

Whilst both seri­al­iz­ers gen­er­ate XML out­puts, Dat­a­Con­tract­Se­ri­al­izer is intended for mar­shalling data (that con­forms to a ‘con­tract’) for trans­porta­tion over the wire and there­fore less con­cerned with read­abil­ity of its out­put and offers lit­tle option for you to cus­tomize the gen­er­ated XML. It’s there­fore quite happy to spit out rather unread­able XML for our Per­son record type above:

 

<FSI_0004.Person xmlns=“http://schemas.datacontract.org/2004/07/”  xmlns:i=“http://www.w3.org/2001/XMLSchema-instance”><Age_x0040_>30</Age_x0040_><Name_x0040_>Yan Cui</Name_x0040_></FSI_0004.Person>

 

Mean­while, in the land of the XmlSe­ri­al­izer, its sole pur­pose of exis­tence is to gen­er­ate XML and offers a pla­toon of options to help ensure its out­put meets your func­tional and aes­thetic needs. By default it’ll gen­er­ate nice, indented out­put for our CLIMutable ver­sion of Per­son record type:

 

<?xml version=“1.0″?>

<Per­son xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”>

  <Name>Yan Cui</Name>

  <Age>30</Age>

</Person>

 

In addi­tion, you can cus­tomize the XML out­put using the nor­mal XML-related attributes:

image

<?xml version=“1.0″?>

<Per­son xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” PersonName=“Yan Cui”>

  <PersonAge>30</PersonAge>

</Person>

 

OSS Seri­al­iz­ers

Of the OSS JSON seri­al­iz­ers I bench­mark reg­u­larly, JSON.Net (v4.5.11 tested) works with both nor­mal and CLIMutable record types from F#. ServiceStack.Text (v3.9.37 tested) doesn’t work with ‘vanilla’ record types on dese­ri­al­iza­tion (fields are left with default val­ues), but you can workaround by mak­ing the fields muta­ble or add the CLIMutable attribute to the type.

 

I hope this proves to be use­ful to you, and if like us you have a lot of C# code hang­ing around just to get pretty XML out of your F# record types, dare I say it’s about to throw away those C# code! Winking smile

Share

Just a quick note to say that another minor update to DynamoDB.SQL has been release, you can view the release notes here.

 

The lat­est update adds sup­port for a TSQL style WITH key­word for spec­i­fy­ing optional para­me­ters for tweak­ing the query/scan oper­a­tion. For queries, you can spec­ify the NoCon­sis­ten­tRead and Page­Size options to use even­tu­ally con­sis­tent read and throt­tle the num­ber of items returned per request respec­tively. Sim­i­larly for scans, you can use the Page­Size option for throt­tling your scan requests too, but the DynamoDB scans does not sup­port strong con­sis­tency.

 

Accord­ing to DynamoDB best prac­tices, you should avoid sud­den bursts of read activ­ity, using the new Page­Size option you can make sure that your query/scan does not con­sume too many read capac­ity unit in a short burst and end up caus­ing more crit­i­cal reads to be throttled.

 

For exam­ple, a query which returns 10 items per request using even­tu­ally con­sis­tent read will look some­thing like this:

image

whereas a scan will look like:

image

For more details about the full syn­tax, please refer to the Get­ting Started doc­u­ment, which has been updated to include the new WITH key­word.

 

Enjoy!

Share

Whilst search­ing for an ele­gant solu­tion to apply string intern­ing across a large num­ber of classes (we’re talk­ing about hun­dreds of classes here..) it dawned on me that I can achieve this with ease using PostSharp’s Loca­tion­In­ter­cep­tionAspect. All I needed was some­thing along the lines of:

You can apply this attribute to a class or even a whole assem­bly and it’ll ensure every piece of string con­structed is interned, includ­ing string prop­er­ties and fields defined by its sub­class, which is exactly what I was after.

For exam­ple, take this triv­ial piece of code:

image

If you inspect the com­piled code for the Base class in ILSpy you will see some­thing along the lines of:

image

notice how the set­ter for BaseS­tring­Prop­erty has been mod­i­fied to invoke the OnSet­Value method defined in our aspect above as opposed to the set­ter method. In this case, it’ll call the String.Intern method to retrieve a ref­er­ence to an interned instance of the string and set the prop­erty to that reference.

For more details on PostSharp’s inter­cep­tion aspects, I rec­om­mend read­ing Dustin Davis’s excel­lent posts on the topic:

Post­Sharp Prin­ci­ples: Day 7 Inter­cep­tion Aspects – Part 1

Post­Sharp Prin­ci­ples: Day 8 Inter­cep­tion Aspects – Part 2

 

As we’ve spec­i­fied the mul­ti­cast inher­i­tance behav­iour to mul­ti­cast the attribute to mem­bers of the chil­dren of the orig­i­nal ele­ment, the string prop­er­ties defined in both A and B classes are also sub­ject to the same string intern­ing treat­ment with­out us hav­ing to explic­itly apply the Inter­nAt­tribute on them:

image

 

F# Com­pat­i­ble

What’s more, this attribute also works with F# types too, includ­ing record and dis­crim­i­nated unions types. Take for instance:

image

If you look at the gen­er­ated C# code for the dis­crim­i­nated union type, the inter­nal MyDuType.CaseB type would look some­thing like the following:

image

notice how the two inter­nal item1 and item2 properties’s set­ter meth­ods have been mod­i­fied in much the same way as the C# exam­ples above? The pub­lic Item1 and Item2 prop­er­ties are read-only and get their val­ues from the inter­nal prop­er­ties instead.

Indeed, when a new instance of the CaseB type is con­structed, it is the inter­nal prop­er­ties whose val­ues are initialized:

image

 

Finally, let’s look at the record type, which inter­est­ingly also defines a non-string field:

image

because we have spec­i­fied that the Inter­nAt­tribute should only be applied to prop­er­ties or fields of type string (via the Com­pile­TimeVal­i­date method which is exe­cuted as part of the post-compilation weav­ing process as opposed to run­time), so the inter­nal rep­re­sen­ta­tion of the Age field is left unaltered.

The Name field, how­ever, being of string type, was sub­ject to the same trans­for­ma­tion as all our other examples.

 

I hope this lit­tle attribute can prove to be use­ful to you too, it has cer­tainly saved me from an unbear­able amount of grunt work!

Share