Chest Reconstructuion – Nuss Procedure
This is a completely off topic post about my personal life.
I’m now back at home after one week at hospital due to chest reconstruction.
Since my teens I’ve got Pectus Excavatum, a chest deformity where the chest bone is deformed and gives the chest a concave appearance.
Pectus affects about 1 out of 1000 people.
In my case, the PE was not only cosmetic, it also gave me chest pains when deep breathing and also putting pressure on my heart.
When I was a teen, the only way to fix the problem was to cut the ribcage open and cut everything off and then rebuild a new chest.
That alternative wasn’t very appealing to me so I did not do anything about it at that point.
However, now some 20ish years later, I found out about the Nuss procedure, a procedure where you implant a steel bar into the chest, putting preassure on the chest bone and ribcage from the inside and thus forcing a correct shape.
The Nuss procedure have apparently been around for some 10 years, but I guess there are no newsletters for that kind of information ;-)
The reason why I write this post is because I found it very hard to find information regarding Nuss for adults, e.g. information about how long I should expect to be off from work, and what results to expect from the procedure.
So here are some facts.
Age: 34
Pectus: Mild/Medium
Procedure duration: 1.5 H
Time in hospital: 6 days
Pain after procedure: Way less than expected, was up and walking the day after.
Current status: 9 days since procedure and I feel quite OK with some occasional pain spikes.
Putting on socks or getting in and out of the car is extremely painful.
And don’t even think about sneezing ;-)
Before images:
As can be seen on the “before images”, my chest bone was sunken into my chest by some 2-3cm.
After images:
These images are taken 9 days after the procedure.
The steel bar was inserted just below my man-boobs (where the tape is).
I will now have the bar for about 3 years before it is removed and hopefully the bones have been re-shaped by that time.
X-Ray:
I guess I can’t get through airport security checks anymore…
Genetic Programming: Code smarter than you!
Here in sweden there are currently circulating some email with a challange about solving a math puzzle.
It’s nothing special really but the mail goes something like this (translated):
(Don’t blame me for the claims in the quote, it’s not my words)
It’s said that only people with an IQ over 120 can solve the following problem:
If we assume that:
2 + 3 = 10
7 + 2 = 63
6 + 5 = 66
8 + 4 = 96How much is?
9 + 7 = ????
The mail contains an excel file with a password and can only be opened if you know the answer to the above.
Just for the hell of it I entered the problem into my old genetic expression evolver:
http://rogeralsing.com/2008/02/07/genetic-programming-math/
The application is based on genetic programming and does use genetic crossover and a real population (unlike my EvoLisa sample).
The problem was described like this:
problem.Cases.Add(new Case(2, 3, 10));
problem.Cases.Add(new Case(7, 2, 63));
problem.Cases.Add(new Case(6, 5, 66));
problem.Cases.Add(new Case(8, 4, 96));
The first and second arguments are variable values and the last argument is the expected output.
And here is the output of the application:

As you can see on the screenshot, the application have solved the equation in 250 generations (a few milliseconds).
That’s probably faster than you solved it ;-)
PS.
If it makes you feel better, I didn’t solve it at all, I go into fetus position on the floor when I see math problems ;-)
//Roger
RX Framework – Building a message bus
I’ve been toying around with the Reactive Extensions (RX) Framework for .NET 4 the last few days and I think I’ve found a quite nice usecase for it;
Since RX is all about sequences of events/messages, it does fit very well together with any sort of message bus or event broker.
Just check this out:
Our in proc message bus:
public class MiniVan
{
private Subject<object> messageSubject = new Subject<object>();
public void Send<T>(T message)
{
messageSubject.OnNext(message);
}
public IObservable<T> AsObservable<T>()
{
return this
.messageSubject
.Where(m => m is T)
.Select(m => (T)m);
}
}
Subscribing to messages:
bus.AsObservable<MyMessage>()
.Do(m => Console.WriteLine(m))
.Subscribe();
The nice thing about this is that you get automatic Linq support since it is built into RX.
So you can add message handlers that filters or transform messages.
Pretty slick isnt it?
I’m currenty writing an example IRC chat client based on this idea which I will publish in a week or two.
//Roger
Massive parallelism – F# in the cloud?
I’m still trying to learn a bit of F# and I thought of a quite nice experiment.
Since F# supports quotations (for you C# devs, think Linq Expressions on roids) wouldn’t it be possible to serialize such quotation and pass it to a webservice and execute that code there?
Imagine the following code for a fractal calculation:
for y = 0 to 100000 do
CloudExec(
<@
let Fractal xx yy =
.....fractal calculation....
for x = 0 to 100000 do
Fractal x y
@>)
If “CloudExec” passes the code quote for individual scanlines of the fractal to the cloud, we could get some massive parallelism.
It would be just like PLinq but instead of executing a delegate in multiple threads, we would execute blocks of code on multiple threads on multiple machines (please ignore how naïve the code sample above is).
The biggest problem as far as I can tell would be to pass a result set back to the client in some way (that is missing in the sample code).
Input data doesn’t seem to be a problem since values defined outside the quotes are represented as constants in the quote.
It would ofcourse madness to expose such services to the public since you could pass in any code you want, but maybe it would work in an isolated environment.
Have anyone done such thing already?
//Roger
F# Pipelining in C#
Here is one such example where F# developers try to make it look like F# can do things that C# can not.
http://lorgonblog.spaces.live.com/blog/cns!701679AD17B6D310!165.entry
F# code
F# code that apparently is much easier to read than C# code:
HttpGet "http://www-static.cc.gatech.edu/classes/cs2360_98_summer/hw1" |> fun s -> Regex.Replace(s, "[^A-Za-z']", " ") |> fun s -> Regex.Split(s, " +") |> Set.of_array |> Set.filter (fun word -> not (Spellcheck word)) |> Set.iter (fun word -> printfn " %s" word)
C# code
My attempt to accomplish the same in C#.
HttpGet("http://www-static.cc.gatech.edu/classes/cs2360_98_summer/hw1")
.Transform(s => Regex.Replace(s, "[^A-Za-z']", " "))
.Transform(s => Regex.Split(s, " +"))
//.AsParallel() // [EDIT] now with parallelism support
.Distinct()
.Where(word => !Spellcheck(word))
.Process(word => Console.WriteLine(" {0}", word))
.Execute();
I think that’s fairly similar?
OK, I cheated, “Transform”,”Process” and “Execute” does not exist out of the box in C#.
You would have to write those extension methods yourself.
However, they are reusable and fits nicely into a util lib.
public static class Extensions
{
public static TOut Transform<TIn, TOut>(this TIn self, Func<TIn, TOut> selector)
{
return selector(self);
}
public static IEnumerable<T> Process<T>(this IEnumerable<T> self, Action<T> action)
{
return self.Select(item =>
{
action(item);
return item;
});
}
public static ParallelQuery<T> Process<T>(this ParallelQuery<T> self, Action<T> action)
{
return self.Select(item =>
{
action(item);
return item;
});
}
public static void Execute<T>(this IEnumerable<T> self)
{
self.ToList();
}
public static void Execute<T>(this ParallelQuery<T> self)
{
self.ToList();
}
}
Either way, I hope this shows that you can accomplish the same thing using good old C# instead of F#.
I still don’t get F#
I think that Microsoft are trying to sell F# to us as something new and awesome, but I’m having serious problems seeing the benefits over C#.
But F# can do function currying!
Well, so can C#.
string Foo(int a,bool b)
{
//do stuff
}
void UseCurry()
{
Func<int,string> curriedFooWithTrue = a => Foo(a,true);
//invoke curried function.
var res = curriedFooWithTrue(123);
}
F# can do pipelining!
Well, so can C#
var listOfInts = new List<int> {1,2,3,4,5,6};
Func<int,int> squared = x => x*x;
var squaredListOfInts = listOfInts.Select(x => squared).ToList();
F# can use tuples!
Well, they are built into .NET 4 as a generic type so they are available for all .NET languages with generics support.
F# can do tail recursion.
OK, you got me, it can.
Now let me know the last time you really needed that?
All tail recursive algorithms can be implemented as iterative.
But sure, syntactic sugar is nice to have.
F# makes it easier to write async code.
This was one of the arguments at a demo of F# at PDC 2008.
They showed how it was made possible by using PLinq wrapped up in a C# assembly.
Maybe I’ve misunderstood every example I’ve seen, but most of them can be done in C# with pretty much the same amount of code.
What I would like to see is a really good F# example that would be very hard or impossible to accomplish with C#.
If F# is just slightly better than C# on some tasks, then the cost of bringing F# competence into a project will always outweight the slight benefits it brings.
Another argument is that it targets a completely different problem area.
OK, show us where F# shines without lying about what C# can and can not do.
Anyone got such example?
My predictions for 2010
I predict that the C# 4 “dynamic” keyword will be the most abused feature.
It will be used for everything from ducktyped dependency injection, dynamic dictionaries and about a million Rails like frameworks.
All in a very non refactor friendly way.
…It will rarely be used to interop with dynamic .NET languages.
The least used will be the co/contra variance feature.
In 2011 not even the C# team will remember it exists.
The most frustrating feature will be code contracts.
Developers will cry out in pain when they realize that it might not be so easy as they expected it to be.
I’m just guessing :-)
Alsing christmas dance
Merry christmas to all of you!
Linq To Sql: POCO and Value Objects
Fetching POCO Entities and Value Objects using Linq To SQL
Linq To Sql support neither POCO Entities nor Value Objects when using it as an O/R Mapper.
What we can do is to treat it as a simple auto generated Data Access Layer instead.
By treating it as a DAL we can manually handle the data to object transformations in a type safe manner.
If we for example want to fetch a list of POCO Customers that also have an immutable Address value object associated to them,
we could use the following code to accomplish this:
//Poco prefix only used to distinguish between l2s and poco entities here
IList<Customer> FindCustomers(string name)
{
var query = from customer in context.Customers
where customer.Name == name
select new PocoCustomer
{
Id = customer.Id,
Name = customer.Name,
Address = new PocoAddres
(customer.AddressStreet,
customer.AddressZipCode,
customer.AddressCity)
};
return query.ToList();
}
This approach is quite handy if you work with multiple data source and don’t want to mix and match entities with different design in the same domain.
I’m sure many will find this approach quite dirty, but I find it quite pragmatic;
You can be up and running with a clean domain model in just a few minutes and simply hide the Linq To Sql stuff behind your DAL classes.
This works extremely well if you are into the “new” Command Query Separation style of DDD.
You can use Linq To Sql to create typed transformations from your Query layer and expose those as services.
Personally I’ve grown a bit tired of standard O/R mapping frameworks, simply because they try to do too much.
There is a lot of magic going on, it’s hard to keep track on what gets loaded into memory and when they will hit the database.
If I’m required to use both a memory profiler and a O/R mapper profiler in order to use the framework successfully, then something is very wrong with the whole concept.
This dumbed down DAL approach to Linq To Sql however makes the code quite explicit, you know when you hit the DB and what you get from it.
Sure you lose features like dirty tracking that mappers generally give you, but this can be accomplished by applying a Domain Model Management framework on top of your POCO model.
Or maybe you just want to expose your objects as services and don’t care about those features.
[Edit]
In reply to Patriks comment:
If you go for Command Query Separation, you would only query the query layer, so you wouldn’t need to handle updates there.
And when it comes to writing data, you do that in the command layer , the commands carries the changes made from the GUI and thus you wouldn’t need to “figure out” what has changed.
The commands will carry that information for you.
Tracking changes in the GUI could simply be done by storing snapshots of the view specific data when you send a query.
Then pass a user modified projection together with the original snapshot to a command builder.
You could then submit the commands for processing.
[/Edit]
( hmmm, I somehow managed to turn a post about Linq To Sql into a rant about other O/R mappers, I usually do it the other way around :-) )
Linq To Sql: Dynamic Where Clause
Dynamic where clause using Linq To SQL:
Let’s say we need to implement a search method with the following signature:
IEnumerable FindCustomers(string name,string contactName,string city)
If the requirement is that you should be able to pass zero to three arguments to this method and only apply a “where” criteria for the arguments that are not null.
Then we can use the following code to make it work:
IList<Customer> FindCustomers(string name,string contactName,string city)
{
var query = context.Cutomers;
if (name != null)
query = query.Where ( customer => customer.Name == name );
if (contactName != null)
query = query.Where ( customer => customer.ContactName == contactName );
if (city!= null)
query = query.Where ( customer => customer.City == city );
return query.ToList();
}
This way we can pass different combinations of arguments to the method and it will still build the correct where clause that executes at database level.
Do note that this only works when the different criteria should be “AND”‘ed together, but it’s still pretty useful for use cases like the one above.





Design by