Ah the world we think we live in…

Posted by Terrance A. Snyder on July 31st, 2008

You ever sit down, think about existence,  and just be baffled? Given our impending doom from the Large Hadron Reactor, I set myself to sitting down and getting a bit “punch drunk” from the insanity of our existence. And here is what I found.

A.) The act of observing (measuring) our world, creates things. (Measurement problem)

B.) The act of supposition creates outcomes, real or fantasy they all become the same.

There are actually scientific experiments to identify these quandaries. For example the first point, by mere observation we effect the outcome. A classic example is Schrodingers cat.

http://en.wikipedia.org/wiki/Schr%C3%B6dinger%27s_cat

http://en.wikipedia.org/wiki/Double-slit_experiment

Best Artical

http://en.wikipedia.org/wiki/Delayed_choice_quantum_eraser

In short, through the double split test we observe a violation in causality. Such that, in quantum entanglement, information from one source is transmitted faster than the speed of light to it’s partner sourc.

In the process what they have learned is that by constraining the path taken by one of a pair of entangled photons they inevitably control the path taken by the partner photon, and that by permitting the partner photon the opportunity to take two paths so constructed that they will permit that photon to interfere with itself they then find the first photon will behave in a way consistent with its having interfered with itself —- even though there is no double-slit device in its way.

More friendly test of causality violations

http://www.physorg.com/news132830327.html

More advanced reading:

http://en.wikipedia.org/wiki/Quantum_entanglement

http://en.wikipedia.org/wiki/Bell_test_experiments

http://en.wikipedia.org/wiki/Mary%27s_room

Project Mis-Management and How It Works

Posted by Terrance A. Snyder on July 15th, 2008

Imagine your on a project, this project’s deadline is your health. You get a fever, the project gets a fever, you get sick the project gets sick, you get the general idea. You are now disusing the status of meeting your objectives and deadlines with your manager(s). Things are not looking too good, and your in pretty bad shape.

Right about now you are sitting there with one of your arms cut off (bureaucracy), an eye on the verge of retinal detachment (lack of strategic vision/requirements), and a slight headache (you drank last night). Your manager is your triage nurse, making sure you come out of this alive and well. Because alive and well looks better on paper than horribly dead.

So your nurse looks up, and says, “Okay first thing is first, lets get that fever taken care of, we wouldn’t want you to get sick. ”

You ask, “Why my fever first!? My freak n’ arm is cut off I can’t do as much work to meet the deadlines, I only have one arm?!”

Triage Nurse - “We can mitigate that.”

You - “But it’s my bloody arm?!”

Nurse - “Listen…. All we need to do is go out and get another person to help you. We can just add another person and they will do what your left arm did. In-fact, by my calculations, you’ll actually have 1 extra arm. Given that you will have an extra arm, you should actually be done with your stuff in 1/2 the time.”

You - “But what about my eye?!”

Nurse - “Again, since we are adding this extra body, you’ll now have 2 eyes, plus a spare.”

You - “Wow, adding bodies can fix a lot of problems”

Nurse - “Yes. Now, onto that headache of yours.”

.NET Performance Tip #1

Posted by Terrance A. Snyder on July 12th, 2008

I’ve seen some dramatic failures because people have waited till the end. Only until after they were ‘done coding’ did they get the shock that it takes 30 seconds for their application to return “Hello World” and that Hello World call took 99% of cpu utilization and 600MB of ram.

If there was any tip/trick to writing high performance applications it would be that performance goals should constantly be mentioned, examined, and logged from day one. I don’t know how many times I have seen teams crumble as deadlines approached to see their applications fail any reasonable performance metric.

The problem for them? THEY NEVER MEASURED IT IN THE FIRST PLACE.

If you reach the end, and you find yourself in this situation. Just stop what you are doing and examine your choices:

A.) Start throwing spaghetti at a wall and see what sticks. Hope above all else you’ll find some glaringly obvious design flaw that caused your performance problems, because there isn’t a chance in hell you’re going to be able to correct a performance problem because of architecture or worse, small little choices sprinkled in a huge code-base which may or may not have inverse relationships to each other.

B.) Re-write your application. Start with the smallest unit of code and start porting over the “bad” code as you go along. Continuously Integrating and evaluating your performance along the way keep a watchful eye on that performance #.

It’s sad really…. No I really mean it… It’s very sad…..

I’ve seen so many projects also go with choice A. Thinking (read: more like hoping) that somehow, someway, you could make a code base which was never monitored for performance, a codebase of say 30,000+ lines of code, meet performance expectations.

Out of those projects I’ve seen go with choice A, I’ve never seen one come up with a good solution. I’ve seen workarounds (see IT dictionary), and I’ve seen things crash and burn, but I’ve never seen a project that went with choice A succeed. It just will never happen… there is just too many variables unaccounted for.

So if your on a team with a poorly performing application scheduled to go into production….

Realize you have already missed the boat, accept it, and move on. Just don’t make your customers pay the price.

IT Dictionary

Posted by Terrance A. Snyder on July 10th, 2008

Well, here we go. A bunch of people i know came up with a brilliant idea about stuff us IT-folks say, and what we really mean when we say it. Anybody that has any additions just add a comment.

Temporary Solution

This is going to totally suck wind, or worse. We realize it, and accept that we will be lowering the quality of the product. We are not smart enough to really fix the problem, but we can get away with it.

Any statement that has the word “Kinda” or “Sorta” in it

I really don’t want to tell you whats going on because…

  • You won’t like it.
  • You won’t understand it
  • I don’t even understand it.

Any statement that has the word “Technically” in it

I really…

  • Feel you are wrong.
  • Feel I need to talk.
  • Don’t understand what you said, so I’m going to feign that I do and expand on your original statement.

“let me look into that”

I have no idea what is going on, but I don’t want you to know that.

“I’ll have to do some research”

  • I really, really have no idea what is going on. Furthermore, it’s likely that I just told you we can’t do something, and I’m trying to explain why we can’t do what I just told you you can’t do and you just blew a hole in my argument why we can’t do it.
  • I don’t have google next to me, so I can’t answer this question, can I borrow you’re computer?

Any sentence which contains “general requirements”

Person Making Statement is in the following character:

  • We tried our best to come up with something that looks like or smells like requirements, but we failed, horribly.
  • The existing system is so un-clear that I don’t actually know what it does.

Person receiving statement should:

  • Realize the above and re-evaluate their mental condition, ensuring that they you will not driven over the edge for lack of mental state
  • Buy copiousness amounts of whatever relieves your stress, illegal or otherwise.

Anyone with a notepad (the paper kind) in meeting room

I really felt like contributing so I brought some paper, just in case anyone needs it. In the mean time I’m going to doodle.

Anyone saying “Loosely Coupled”, “White Box”, “Black Box”, “Service Oriented”, “… Architecture …”, “… Framework …” more than once in a week.

“I provide no value and am dead weight.”

Could you update the “XYZ Spreadsheet”

“I don’t talk to you frequently and/or I don’t trust you. So, please update this spreadsheet so I know you did at least one thing this week.”

I am (insert any number between 90-99.9%) done. OR
I just need to do this one thing.

I will never be done, if you are asking me my status, I am already late. So i’m just gonna throw some number out there.

You see Trace(), Alert(), Debug()

This code smells bad, the person that wrote it has no idea what is going on.

Seamless

Whatever are the worst things that could happen, they will happen, over and over again.

WCF Multiple Binding / Multiple Hosts

Posted by Terrance A. Snyder on July 4th, 2008

Consider this, you are a hosting company hosting many different customer websites. Your customers pay anywhere between $50.00 to $100.00 a month to have a shared server host there asp.net applications. You business model depends on easily providing the exact same level of support and features to your clients that they could otherwise get if they did it themselves, you can do so at a reduced rate because you cookie-cut their commonly requested features. The key is that you provide “the exact same” level of support and features.

The inability for you to provide something to them means you lose a piece of your market share and credibility. With hosting companies on razor thin profit margins, you rely on lots of low to mid-range consumers, and I mean lots of them. You’re effectively a wal-mart relying on the poor masses to accumulate large revenue through low over-head.

Now throw in a rather large WCF limitation…..


This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item

Exception Details:

System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item]
System.ServiceModel.UriSchemeKeyedCollection.InsertItem(Int32 index, Uri item) +4564833
System.Collections.Generic.SynchronizedCollection`1.Add(T item) +56
System.ServiceModel.UriSchemeKeyedCollection..ctor(Uri[] addresses) +120
System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +145
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +28
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +323
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +516
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +31
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +498

Hosting multiple sites in Windows 2000-2008 Server typically means that your using IIS to host multiple sites on the same IP Address using host header filters or at worst port level filters.Now enter the above WCF “feature” (aka bug). The simple ability for you to host multiple WCF services for different hosted addresses in IIS is defunct. What does this mean to you? Well if your on a hosted environment (either internal cooperate network, or a classic joe’s hosting company) and you use IIS you are going to have to follow Rob Zelt instructions and it requires a code change!

Workaround #1: Customize your .svc file and use a custom WCF factory.


< %@ServiceHost language=c# Debug="true" Service="Microsoft.ServiceModel.Samples.CalculatorService"
Factory="Microsoft.ServiceModel.Samples.CustomHostFactory" %>

class CustomHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
CustomHost customServiceHost =
new CustomHost(serviceType, baseAddresses[1]);
return customServiceHost;
}
}

class CustomHost : ServiceHost
{
public CustomHost(Type serviceType, params Uri[] baseAddresses)
: base(serviceType, baseAddresses)
{ }
protected override void ApplyConfiguration()
{
base.ApplyConfiguration();
}
}

The reason for this mess is that ServiceHost uses the protocol (string value “http”, “https”) as the key for the BaseAddresses collection. This likely looks something like this inside the core .NET library.


IDictionary<string , string[]> _protocols = new Dictionary</string><string , string[]>();

private void RegisterProtocol(string protocol, string[] addresses) {

// whoops, we forgot to check if _protocols already had the key "protocol".... shucks...

_protocols.Add(protocol, addresses);
}

Somebody had reported that this has been fixed in what was “Orcas” but last I checked it hasn’t.

There is one other workaround (care-of: Jon Flander’s Blog) which involves changing the way you actually host your sites. Albeir this is not something feasible for a hosting provider.

Workaround #2: A way to solve this problem is to setup multiple web sites in IIS (rather than having one site that has multiple Host entries) - and point all the websites to the same directory.

This is, all in all, a great annoyance which will hopefully be fixed in later releases of .NET.

“When People Have A Vendetta”

Posted by Terrance A. Snyder on July 2nd, 2008

Vendetta - an often prolonged series of retaliatory, vengeful, or hostile acts or exchange of such acts. Example: “waged a personal vendetta against those who opposed his nomination”

I know who you are, and I am asking you nicely to get beyond it.

SQL 2005, XML, XPATH, and CUD, Re-Evaluating the ‘Status Quo’

Posted by Terrance A. Snyder on June 5th, 2008

I really hate it. No, you have no idea. I really despise it….

It’s that crusty, old, smelly, and repugnant idea that everything… and I mean everything…. must be in a database. It’s a profuse nauseating waste of effort and time that just wont die. Don’t get me wrong, databases were great, they had a purpose, filling a gap between COBOL programs (that makes schema changes as easy as mixing oil and water) and well… anything else at the time.

I know, I know, all the other alternatives to-date are either not ‘enterprisey’ enough, or have as much performance association that electric hybrids have to every self-indulgent quadruple billionaire 42 year old looking for their next ultra-performance car. It just doesn’t register, no matter how much faster the electric is compared to a Lamborghini Guirado. It’s that perception that bothers me the most; and it is that perception that causes you to receive a slightly grotesque distortion of your co-workers face when you mention not using SQL and a database to store your data.

All that being said, databases are in your server room. They sit there, stunted, childish, semi-retarded things. But hey, lets admit it, we’re all probably working on a project right now using SQL Server 2005. And given that we were are forced to play with a semi-retarded child that eats sand, maybe we can put a bag over his/her head so we don’t have to pay attention to it.

Microsoft makes a-lot of money selling SQL Server, and they realize we (coders) don’t like it. They have at least made the effort in 2005 to add a new data-type with native XPATH, and with this little bit we can at least tolerate it, or at least not look at it so often. How might you ask?

Well consider you are creating a simple authentication process with your website. You want users to have multi-factored authentication. You know, where you get an ugly, plain, and generic picture that you are supposed to memorize to magically prevent you from being the victim of phishing schemes as well as some random security questions.

If your me, you start with your domain objects (contracts). And you come up with some .NET classes that serialize to some xml.
So now, you’ve got some options:

  1. Store your data in an in memory object and be done with it.
  2. Spend the next 2 weeks arguing with a pretentious DBA about a database schema that doesn’t comply with 5th normal form.

So given you are likely here because you can’t choose #1, how do we minimize the impedance-mismatch between our code and the relational database? Answer? Serialize to XML and ‘talk’ to the database using XML.

Going with our XML example (remember generated from XML Serialized C# class). We can use the serialized class and create a stored proc that takes in the serialized XML and maps it to the corresponding relational database. Forget updates, just go with full delete / then update. Example SQL 2005 parsing is shown below.


declare @xml as xml
set @xml = '... string contents of xml file ...'

-- user information
select
doc.value('@Attribute', 'varchar(max)') 'attribute'
, doc.query('Element').value('.', 'varchar(32)') 'Element'
, doc.query('Element/Nested').value('.', 'varchar(32)') 'ElementNested'
, doc.query('data(Element/@Id)').value('.', 'varchar(64)') 'NestedAttributeValue'
from
@xml.nodes('//Root/Items') tbl (doc)

What we are effectively doing is limiting the touch-points between the code and the database. Seperations-of-Concerns says that my objects shouldn’t care about their storage, and that my storage shouldn’t care about my objects. With the above example we would basically have two methods for our data access. Create, and Delete, with Read (Query) being the second part of this exploration and update being a full delete, with a full create.

Next time we can explore a database design, that is both normalized and allows for quick and efficient lookups of information while still allowing for a rich object model that can use the criteria (specification) pattern to deliver rich searching to your application without spreading database concerns throughout your application.

.NET FxColor

Posted by Terrance A. Snyder on June 4th, 2008

Just a quick little post today regarding how you can do some fairly simple color transformations to produce some visual ‘charting’ of data using html. This example stems from an experiment to simulate the StatsPress module that can be included in WordPress. The outcome of this is a color transformation class that can be used to perform some nice color ranges in both HEX (HTML) and System.Drawing.Color. Below is a screenshot of a produced graph. Attached is FxColor Source Code and below is the core class for your review.

FxColor Snippet


using System;
using System.Drawing;
using System.Collections.Generic;

/// <summary>
/// Provides a means to create a color mixer that shifts colors
/// from one color matrix to another.
/// </summary>
public class FxColorMixer
{
int red, green, blue;
int delta;
int iterations;

/// <summary>
/// Initializes a new instance of the <see cref="FxColorMixer"/> class.
/// </summary>
/// <param name="red">The starting red color.</param>
/// <param name="green">The starting green.</param>
/// <param name="blue">The starting blue.</param>
/// <param name="iterations">The number of iterations to produce.</param>
public FxColorMixer(int red, int green, int blue, int iterations)
{
if (iterations < = 0) throw new ArgumentOutOfRangeException("iterations must be greater than 0");

this.red = red;
this.green = green;
this.blue = blue;
this.delta = (int)Math.Round((double)250 / (double)iterations, 0);
this.iterations = iterations;
}

/// <summary>
/// Gets the color at the specified index from the number of iterations specified.
///
/// <param name="index">The index.</param>
/// <param name="sRed">The s red.</param>
/// <param name="sGreen">The s green.</param>
/// <param name="sBlue">The s blue.</param>
/// <returns></returns>
public FxColor GetColor(int index, double sRed, double sGreen, double sBlue)
{
if (index > iterations) throw new ArgumentOutOfRangeException("index is past number of iterations expected.");

double vBlue = (delta * index) * sBlue;
double cBlue = blue + vBlue;

double vGreen = (delta * index) * sGreen;
double cGreen = green + vGreen;

double vRed = (delta * index) * sRed;
double cRed = red + vRed;

cRed = Math.Max(0, Math.Min(255, cRed));
cGreen = Math.Max(0, Math.Min(255, cGreen));
cBlue = Math.Max(0, Math.Min(255, cBlue));

return new FxColor(Color.FromArgb((int)cRed, (int)cGreen, (int)cBlue));
}
}

/// <summary>
/// Represents a adapter over the <see cref="Color"/> class.
/// </summary>
public class FxColor
{
Color c;

/// <summary>
/// Initializes a new instance of the <see cref="FxColor"/> class.
/// </summary>
/// <param name="c">The c.</param>
internal FxColor(Color c)
{
this.c = c;
}

/// <summary>
/// Offsets the current color by the vectors specified.
/// </summary>
/// <param name="vRed">The displacement of red.</param>
/// <param name="vGreen">The displacement of green.</param>
/// <param name="vBlue">The displacement of blue.</param>
/// <returns>Returns a new color from the displacement.</returns>
public FxColor Offset(int vRed, int vGreen, int vBlue)
{
int r = Math.Max(0, Math.Min(255, c.R + vRed));
int g = Math.Max(0, Math.Min(255, c.G + vGreen));
int b = Math.Max(0, Math.Min(255, c.B + vBlue));
return new FxColor(Color.FromArgb(r, g, b));
}

/// <summary>
/// Gets the value.
/// </summary>
/// <value>The value.</value>
public Color Value
{
get
{
return c;
}
}

/// <summary>
/// Gets the HEX value of this color.
/// </summary>
/// <value>The HEX.</value>
public string HEX
{
get
{
return ColorTranslator.ToHtml(c);
}
}
}

Explorations In Code Series: Part 1

Posted by Terrance A. Snyder on May 31st, 2008

You’ve been there, working on a large or small project. Discovering things, learning new things, applying your new knowledge to get further and surpass your previous achievements. And it’s that brilliant, thunderous, and blinding bolt of inspiration that gives way to that beautiful and elegant piece of knowledge, simplistic yet profound, that keeps you moving.

How does this tie into working on a large ‘SOA’ based project at a major financial institution using .NET technologies like WCF (Microsoft Windows Communication Foundation) and ASP.NET? Most of these services just provide lookup information based on a set of criteria supplied to them, so they don’t contain anything more than simplified domain objects, no frills, no rules, no update functionality. Hardly anything interesting…

But yet these services being created are responsible for wading through distributed systems from Unix, to dozens of Windows SQL Server Databases, to CGI calls to mainframe pathways. Their goal, at the end of the day, is to provide an ‘enterprise’ domain model of the organization’s business, and also provide a new web application to be created to provide clients some information about their accounts. (Think Bank Of America, Charles Swabb).

On the surface hardly anything of the above seems interesting, or fun to code, but then, diving deeper we find the patterns, the ability to expand our technical skill set while improving the quality of our delivered code.

With that, this post starts long running series on ‘Explorations in Code’, and ‘Explorations in the Software Business’. Two parallel long running commentaries about my work and the insights I get through the project.

To wet the appetite the following posts will be made in due time:

  • Parallel and Distributed Processing using commodity PC’s in .NET (MapReduce and F(x) algorithms)
  • WCF Tips and Tricks
  • .NET Reflection, Deep Dive
  • Add-In / Plug-In Framework
  • AVP Design Pattern (Assembled-View-Pattern) - Eat your heart out MVP
  • JavaScript, How I Heart Thee
  • Practical REST
  • CSS, XHTML, JavaScript, and the new web.

Copyright © 2007 shutupandcode.net. All rights reserved.