Port/Adapter/Simulator and UI

I’ve been working on a little utility project, and I’ve been using port/adapter/simulator on both the server-side parts and on the UI parts. It has been working nicely, though it took me a while to get there. Initially, I started with a single UI class. After a bit of extension, it looked a bit ugly,…

0

Unit test success using Ports, Adapters, & Simulators–kata walkthrough

You will probably want to read my conceptual post on this topic before this one. The kata that I’m using can be found at github here. My walkthrough is in the EricGuSolution branch, and I checked in whenever I hit a good stopping point. When you see something like: Commit: Added RecipeManager class you can…

0

Unit Test Success using Ports, Adapters, and Simulators

There is a very cool pattern called Port/Adapter/Simulator that has changed my perspective about unit testing classes with external dependencies significantly and improved the code that I’ve written quite a bit. I’ve talked obliquely about it and even wrote a kata about it, but I’ve never sat down and written something that better defines the…

2

Tricks you can play on yourself #789–Linq

I was profile some code this morning, and came across some interesting behavior. Basically, we had some low level code that looked something like this: IEnumerable<Guid> GetSpecialQuestionIds() {     return       GetAllSpecialItems()         .Select(specialItemXml => specialItemXml .CreateFromXml(questionXml))         .SelectMany(specialItem => specialItem.Questions.Select(question => question.UniqueIdentifier)).Distinct();         .Distinct(); } So, it’s taking special item xml, deserializing each special…

2

Simulators or not?

I’ve been spending some time playing with Cockburn’s hexagonal architecture  (aka “ports and adapters”), and the extension I learned from Arlo, simulators. I’ve found it to be quite useful. I was writing some code, and I ended up at a place I didn’t expect. Here’s the situation. I have the following external class (ie “port”)….

0

A Programmer’s Guide to C# 5.0

My author’s copies of the Fourth Edition of my book showed up today: It is significantly updated from the previous version. I especially enjoyed writing the sections on Linq and asynchronous features.      

3

Default parameters in C#

From an internal discussion we’re having on the advisability of using default parameters in C#: Currently, the pain and limitation of doing overloads forces you to rethink how a method should work. Consider the following:  Process(int a); Process(int a, float b); Process(int a, float b, string c);   If I now need to change how…

4

Benchmarking, C++, and C# Micro-optimizations

Two posts (1 2) on C# loop optimization got me thinking recently. Thinking about what I did when I first joined Microsoft. Way back in the spring of 1995 or so (yes, we did have computers back then, but the Internet of the time really *was* just a series of tubes), I was on the…

6

Why does C# always use callvirt? – followup

I was responding in comments, but it doesn’t allow me to use links, so here’s the long version:  Judah, Yes, marking everything as virtual would have little performance impact. It would, however, be a Bad Thing. It’s #3 on my list of deadly sins…  ShayEr, cmp [exc], exc is the solution to the problem. It’s there because…

3

Why does C# always use callvirt?

This question came up on an internal C# alias, and I thought the answer would be of general interest. That’s assuming that the answer is correct – it’s been quite a while. The .NET IL language provides both a call and callvirt instruction, with the callvirt being used to call virtual functions. But if you…

15