Posted by Samnang Chhun on Tuesday, February 03, 2009
I have been using Visual Studio for a couple of years, but I only work with default environment. Last night, I decided to switch to use new theme to get different taste with black screen editor. I felt so strange at first, but after I worked with it one hour. Then I realized I really love it. It’s like to make my brain refresh and learn something new. Scott Hanselman posted a gallery of ready to use themes to any taste, you can try to get your best environment.
My New Visual Studio Theme
If you want it, you can download it here. Give an alternate theme a try and let me know what you think.
Posted by Samnang Chhun on Tuesday, January 20, 2009
Last weekend, I gave Ruby a try. Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. I'm a .NET coder, everyday I use C# for developing projects in my company. There are few reasons that bring me to try Ruby because I see a lot programmers mention Ruby is a very powerful and flexible programming language, is it true? And the main reason, I would like to try something new because almost my programming skills are just in static typed language and a bit dynamic typed language with Javascript.
After I played with Ruby about a few hours, I started loving it. Ruby is a fun toy. Like the differences between spoken languages, Ruby differs from most other programming languages not only by syntax, but by culture, grammar, and customs. And some programmers consider Ruby is English for computers. Ruby brings a new way of thinking about programming and software development. I would like to show you very basic examples, let’s go to see snippet code comparing between C# and Ruby.
Code comparisons above are not to show which language is bad and another is good, but I just want to show how I feel about new language. Ruby code is short and readable like in English. There are lots of more powerful features in Ruby that I haven’t mentioned here.
If you haven’t touched something new recently, why don’t you give Ruby a try?
Posted by Samnang Chhun on Tuesday, December 30, 2008
No blog posts for a whole month is unprecedented. We are busy in completing projects & touch some new technologies. We will do our best to grow all together in our new year.
Some plans that I will focus on new year:
- Touch in new features of C# 4.0
- Get deeper in ASP.NET MVC and MonoRail
- All codes should be done by test codes first
- Get more understanding on ORM, especially NHibernate
- RESTful in .NET
- Switch to use MVP for developing presentation layer of Windows App.
- Looking for a good CMS framework in .NET for building websites
- Keep growing IT communities
New year is coming, I wish all of you will bring good stuff in new year and leave bad stuff in the old year.
Posted by Samnang Chhun on Saturday, November 15, 2008
This is a presentation of NHibernate that I have presented to my colleagues as like in my Techtalk few months ago after I have spent some times for taking look at NHibernate. It focuses on a brief overview of the power of NHibernate. I decide to publish and hope that it will be useful for someone who is new and wants to get started on NHibernate.
For the moment you can download the slide or view it on slideshare.
Posted by Vorleak Chy on Friday, November 14, 2008
If you have the algorithms with conditional statements in the client code it will be messy. The Strategy pattern moves an algorithm from the client code to a separate class. A program that requires a particular service or function and that has several ways of carrying out that function is a candidate for the Strategy pattern. Programs choose between these algorithms based on computational efficiency or user choice. There can be any number of strategies, more can be added, and any of them can be changed at any time. One of the dominant strategies of object-oriented design is the "open-closed principle".
There are a number of cases in programs where we would like to do the same thing in several different ways. Here is a list that can be strategy:
- Compress files using different algorithms
- Save files in different formats
- Use different link-breaking strategies to display text data
- Capture video data using different compression schemes
- Plot the same data in different formats: line, graph, bar chart, or pie chart
Let's consider a simplified sorting an array using quick sort or bubble sort which a client will choose as an algorithm to sort elements in array. Here is an example below I have to do now in both C# and JavaScript:
Code in C#
There are QucikSort and BubbleSort as concrete classes will implement an interface because they have the same method, the only different is an algorithm.
using System;
namespace Patterns.Strategy
{
public interface ISortStrategy
{
void Sort(string[] arr);
}
public class QuickSort : ISortStrategy
{
public void Sort(string[] arr)
{
Console.Write(string.Format("QuickSort array contains {0} elements", arr.Length));
}
}
public class BubleSort : ISortStrategy
{
public void Sort(string[] arr)
{
Console.Write(string.Format("BubleSort array contains {0} elements", arr.Length));
}
}
public class SortableArray
{
private readonly ISortStrategy sortStrategy;
public SortableArray(ISortStrategy sortStrategy)
{
this.sortStrategy = sortStrategy;
}
public void SortArray(string[] arr)
{
sortStrategy.Sort(arr);
}
}
}
Here is a client code will choose which algorithm is needed to sort an array.
using System;
namespace Patterns.Strategy
{
internal class Program
{
private static void Main(string[] args)
{
var array = new[] {"a", "b", "c", "d", "e"};
var sortableArray = new SortableArray(new QuickSort());
sortableArray.SortArray(array);
Console.Read();
}
}
}
Code in JavaScript
var Patterns = {};
Patterns.Strategy = {};
Patterns.Strategy.SortableArray = function(sortStrategy) {
this.sort = function(arr) {
sortStrategy(arr);
};
};
Patterns.Strategy.SortStrategy = {
quickSort : function(arr){
console.log('QuickSort array contains ' + arr.length + ' elements');
},
bubbleSort : function(arr){
console.log('BubbleSort array contains ' + arr.length + ' elements');
}
};
var array = ["a", "b", "c", "d", "e"];
var sortableArray = new Patterns.Strategy.SortableArray(Patterns.Strategy.SortStrategy.quickSort);
sortableArray.sort(array);
If you meet this problem and need to solve it please go to your application and do the code refactorings which is now the ReSharper tool add-in to Visual Studio is very powerful to do this and much more. Doesn't it?