Programming
Building a Reputation System
by Joseph on Sep.03, 2009, under Church, Consulting, Programming, Technology
I’m working on a reputation system for a site I’ve been recently working on (http://www.serveandtrade.com). I’m going through some ideas so I thought I’d post them on here and see what people think.
Let’s start buy throwing up what we currently have so we can see where we’re trying to go. Here’s a mockup of what a user will see when they search for trades right now.
I have a couple problems with how it works right now.
- I don’t like that it’s in a grid/table format. I have to fix that first. I’m moving more towards something like a list layout.
- There are some things missing that I would like to be able to do. For instance, if I just searched for “can of soup”, and I see that Michelle has the one I want, I would like to have a button/link/something to click on that says “I want that!” Right now the only thing you can do is go look at the trade, or ask a question.
- Clicking on the owner’s link takes you to their profile, but it doesn’t show you what other trades they have, or trades they are looking for. That information could really be useful.
I’m sure there are other things I could think of, but for now I’m going to start focusing on these three and build some mockups to illustrate these workflows.
First, getting rid of the grid.
This search list looks a lot better I think. There are some more features on here then the other one, but we’ll go over those in subsequent posts.
So at this point I’m looking for any feedback. ANY feedback, good or bad… I’ll take it all. I really haven’t made up my mind at this point yet, but I think I’m heading in the right direction.
Next post will be about the “I want it!” feature. Stay tuned!
C++ had it right, Multiple Inheritance Rocks, Single Inheritance… not so much.
by Joseph on Jun.03, 2009, under Programming, Technology
I’ve been having a lot of problems with my coding lately. I primarily program in C#, but I originally came from a C++ world. When I first learned Java, and was introduced to the idea of Single Inheritance, the sales pitch made a lot of sense to me. How can any class really derive from multiple classes? I drank the kool-aid, and I’ve been living in a Single Inheritance world ever since.
Now, the caveat to all of this was that you had this thing called an interface that actually allowed you to define declarations of behavior that could later be implemented. This could be done any number of times. This also made a lot of sense, and they would do some simplistic model that illustrates the concept. I imagine for purposes of this article we should probably illustrate something as well just to drive home the point. Let’s say you have a Coin. A Coin is a kind of Currency. So the simple inheritance chain would dictate that Coin inherits from Currency, and everything is fine. Of course, in order for this to matter at all, there needs to be some benefit to having Coin inherit from Currency. So let’s say that Currency has some behavior called CalculateBuyingPower that actually figures out what kind of buying power that particular Currency has. Ok, so now we have an inheritance chain, and we have a direct benefit, figuring out the buying power of the Coin.
If that’s as far as you take it, then everything’s all fine and dandy, and Single Inheritance is great. The problem is, that in the Real World, what we call Objects can legitimately “be” multiple things. This is equally true in the Software World. So, going back to the Coin, not only is the Coin a Currency, but the Coin is also a MetalConstruct. A MetalConstruct is just my way of saying something that is made of metal. Why do I care? Simple. At some point during the life of a Coin, it is entirely possible that the buying power of the Coin will reach a point that it would actually be better to melt down the Coin because the value of the Metal in the coin is much higher (look at what a penny is made of nowadays and you’ll see what I mean). Now, a lot of you are going to say, “That’s fine, just define a MetalConstruct interface and you should be good to go.” In a lot of cases that might be true, but in this example we fine a very big problem. The point of the MetalConstruct is to normalize the behavior of melting down the Coin. No matter what kind of MetalConstruct you have, the melting process for it is always going to be the same. Sure there are variations in melting temperature and what not, but the overall process is the same. The point being, that an interface can only declare that behavior MeltDown should exist, but not define the implementation of it. This is the problem with Single Inheritance. I now need a way for the Coin to be both a Currency and MetalConstruct, which provides the Coin with behaviors CalculateBuyingPower and MeltDown. Coin shouldn’t have to define how to do either of those behaviors, because that’s not it’s responsibility.
During software development, when you’re working on defining your domain, this can come up quite often, actually. With the advent of extension methods in .NET, you’re able to ease the pain a bit in C#, but the fundamental problem is really still there. What I would like to see would be one of two things. It would be nice if you could inherit from multiple abstract classes, which would allow you to define Contracts at the abstract class level. Another idea would be to bring forward the construct of a contract as a first-class citizen, it would be similar to an abstract class and an interface in the sense that you could not create one directly, but would allow for definition of behavior while still being able to have a class implement numerous contracts. It would be a totally new way of defining an object, apart from class, struct, or interface entirely perhaps.
So now I’m looking back at C++ and I’m thinking it would be really nice if I had Multiple Inheritance so I can just get past this ridiculous wall I’m having to climb. Possibly with .NET 4.0, Microsoft is bringing forth the idea of Code Contracts , which might help when you’re trying to get around Single Inheritance issues when dealing with Design by Contract, but for real domain model issues, I think the problem still remains.
Food for thought.
The SRP Swiss Army Knife
by Joseph on Mar.07, 2009, under Programming
I read this blog a few weeks back, and while the principles that the author was trying to convey I don’t disagree with, I did have a hard time stomaching the idea that Swiss army knives made for bad OOP design. Why? Because I really like Swiss army knives! I mean come on, what other device lets you have 100+ different kinds of knives, a compass, a light, a magnifying glass, and a USB drive all in one “disappears in your pocket” size container???
Ok so I know what most of you are thinking… I’m just PROVING that they violate SRP right? Not actually. In case you’re not familiar with the principle of SRP, check out this wiki. The reason why I believe the Swiss army knife does NOT violate SRP is because my general rule of them is, if I can state the responsibility of the object in question in one single statement, then I have identified it’s SINGLE responsibility. So I have to ask myself, what is the SINGLE thing that a Swiss army knife does?
Responsibility statement: A Swiss army knife is responsible for allowing it’s user to be able to use any tool that has been installed into it.
Short, simple, and to the point. Now, that sounds all fine and dandy, but if I don’t implement the code the way I’ve dictated in my statement, then I will violate SRP, so how is it that I build a Swiss army knife while preserving my responsibility statement? Enter code.
1: public interface SwissArmyKnife
2: {
3: ITool PullOutTool(ITool tool);
4: void PutAwayTool(ITool tool);
5:
6: IList Tools { get; }
7:
8: ITool ToolBeingUsed { get; set; }
9: }
My interface defines any type of Swiss army knife I ever wish to make. It’s only responsibility is to be able to use a tool that it has. So then how do you use the Tool? Well here’s how an ITool might look like:
1: public interface ITool
2: {
3: void Use();
4: }
Now you can get any tool from the Swiss army knife and then use it. Notice that it’s NOT the responsibility of the Swiss army knife to know HOW to USE the tool, only to get it out or put it away.
So what would violate SRP then? Why did the author choose this particular product to harp on? I think it was a matter of perspective really. The article I read had numerous pictures of knives all decked out such as this one. Here is where I believe the real trickery is. The author shows the pictures of all the swiss army knives with all the tools exposed. If you really tried to use the knife like this, you would probably really screw up your hand! That’s my point. The knife is not of any use to anyone unless you’re using ONE tool at a time. This is why SRP is not being violated.
You might take this a step further and say that you have a Swiss army Factory that would actually build the Swiss army knives, but that would be a discussion for another day.
Anyway, I hope everyone has found this interesting, till next time!
Light up the world in Silverlight!
by Joseph on Mar.07, 2009, under Programming
I just finished watching a variety of videos from Mike Taulty about learning Silverlight. These are exceptionally good videos and I would suggest anyone that is trying to learn Silverlight OR Windows Presentation Foundation (WPF) to take a look at them.
Here are links to all the videos.
- Silverlight – Hello World
- Silverlight – Anatomy of an Application
- Silverlight – The VS Environment
- Silverlight – Content Controls
- Silverlight – Built-In Controls
- Silverlight – Width, Height, Margins, Padding, Alignment
- Silverlight – Using a GridSplitter
- Silverlight – Grid Layout
- Silverlight – StackPanel Layout
- Silverlight – Canvas Layout
- Silverlight – Databinding UI to .NET Classes
- Silverlight – Simple Styles
- Silverlight – Custom Types in XAML
- Silverlight – Binding with Conversion
- Silverlight – List Based Data Binding
- Silverlight – Simple User Control
- Silverlight – Templating a Button
- Silverlight – Resources from XAP/DLL/Site Of Origin
- Silverlight – Animations & Storyboards
- Silverlight – Uploads with WebClient
- Silverlight – Downloads with WebClient
- Silverlight – Calling HTTPS Web Services
- Silverlight – Calling Web Services
- Silverlight – Making Cross Domain Requests
- Silverlight – Using HttpWebRequest
- Silverlight – File Dialogs and User Files
- Silverlight – Using Sockets
- Silverlight – Using Isolated Storage
- Silverlight – .NET Code Modifying HTML
- Silverlight – Using Isolated Storage Quotas
- Silverlight – Calling JavaScript from .NET
- Silverlight – Evaluating JavaScript from .NET Code
- Silverlight – Handling HTML Events in .NET Code
- Silverlight – Handling .NET Events in JavaScript
- Silverlight – Calling .NET from JavaScript
- Silverlight – Displaying a Custom Splash Screen
- Silverlight – Passing Parameters from your Web Page
- Silverlight – Loading Media at Runtime
- Silverlight – Dynamically Loading Assemblies/Code
- Silverlight – Reading/Writing XML
- Silverlight – Multiple Threads with BackgroundWorker
- Silverlight – Insert/Update/Delete with the DataGrid
- Silverlight – Getting Started with the DataGrid
- Silverlight – Embedding Custom Fonts

