Uncategorized

Craps Simulation

I’ve been working on a craps simulator in c# lately, to figure out how to maximize my chance of leaving the casino with more money than I came in with. At this point it seems that you have the best chance if you bet about 10% of your total bankroll Read more…

By kryptx, ago
OOP

Interfaces vs. Abstract classes

Another question I was asked yesterday and had difficulty answering is: when would you use an abstract class, and when would you use an interface? The obvious answer is, you use an abstract class when you need to provide some implementation details. Right. But, exactly when is that? Essentially I Read more…

By kryptx, ago
OOP

Composition vs. inheritance

Today in an interview I was asked, when would you use composition and when would you use inheritance? I struggled with this question, not because I have never considered it, but because the interviewer was asking me to translate abstract concepts about which I have strong intuitions but no formal Read more…

By kryptx, ago
.NET

Store-Generated values with Entity Framework

If you are using Entity Framework and you want your data store to generate some values automatically (e.g., to automatically fill a CreateDate with the date and time that the object was created), you should configure the field as Store-Generated. It’s a property on the field in the EDM designer. Read more…

By kryptx, ago
.NET

Guaranteed Deadlock

There was a thread on StackOverflow recently about an interview question where the candidate was asked to write a program that will always deadlock. Eric Lippert’s example is shorter than mine, but I think my answer (which I’m posting here because the question is labeled as a Java question) is Read more…

By kryptx, ago
.NET

Connected Layer, a little deeper

If you're working frequently with the connected layer, the previous post would be sufficient for most purposes (given adequate knowledge of SQL), if perhaps a little awkward. The following information might make your life a little bit easier. (more…)

By kryptx, ago
.NET

ADO.NET – Connected layer basics

In order to send queries to the database, you need an instance of a DbCommand-derived type. This instance is obtained from invoking the CreateCommand method on an instance of DbProviderFactory for the database provider in question, e.g.: 1 2 3 DbProviderFactory df = DbProviderFactories.GetFactory("System.Data.SqlClient"); DbCommand cmd = df.CreateCommand();DbProviderFactory df = Read more…

By kryptx, ago
Uncategorized

Extension methods

Extension methods are methods that are added to existing compiled types. These are useful for adding new members to classes in the BCL or in assemblies for which source code is not available. However, extension methods can also be useful because they can be called on null references. For instance, an immutable Stack(of T) implementation might contain a head of type T and a tail of type Stack(of T). How do you create an empty stack if T is allowed to be a non-nullable value type? (more…)

By kryptx, ago
.NET

Comparing reference types

When comparing two instances of a reference type for equality (in value, not checking to see if they are the same instance), rather than using .Equals it’s best to use an IComparer. In a generic type, if nothing is known about the parameterized types, EqualityComparer<T>.Generic is a good choice.

By kryptx, ago