What was I up to? – 2 Months of no blogging?

20. October 2009

Long time no see… Things have been hectic in last 2 months. While I had a pretty good plan for the August and October, an unexpected internship opportunity in the US showed up. Thins like Visa interview and accommodation was almost a blocker, but I was able to dealt with them. I was lucky that I was qualified for an “Urgency Visa”.

Anyway, in the month of September, I was an intern in a university, and worked on several scientific projects. The lab that I worked at was mainly working on autonomous systems, and path planning algorithms. There I had studied those algorithms a bit and also involved in software design for several projects.

As soon as I went there, I found myself in an atmosphere of competition. The competition was about designing an algorithm so that the drone we own can go from one point to another without crashing any other drones or obstacles in the stage. The behavior of those drones was semi-stochastic and depending on that preknowledge given to us, we are asked to implement this algorithm. Even though we couldn’t make into competition, I can say that I learnt a lot.

My first task was to implement this semi-stochastic behaviors of enemy drones. It was pretty fun, and it taught me how seemingly easy thing can contain a lot of challenges. While dealing with this stuff, i learnt some other stuff regarding to games, which i hope to blog about.

Here is the work that I had after a short while

image

 

My other task was to implement a 2D visualizer for the drones. The data was coming from a system know as Vicon which is used to track objects. It could give the orientation data with up to 1 cm precision, which was pretty cool. This task took only a few days and it was easy.

In the last few weeks, while dealing with other minor tasks, like programming the rover, or fixing bugs in our competition code, I started designing a 3D visualizer using XNA for the lab as a hobby project.  Below is a view from one of the cameras. There are several other cameras and also a dirty console implementation.

image

The future of this project is more likely to be a simulator, with a physics engine.

Nowadays, I am really busy with doing homeworks and getting ready for graduate school applications. They take a lot of time and a lot of money (standardized tests like TOEFL, GRE). I hope to blog about those too.

I hope this feature will be my boost post, and i hope to continue blogging regularly.

My Thoughts on ORM comparisons

22. August 2009

I am a bit late to the party but there we go.

Last several days, there have been a hot debate on the performance and capability of NH vs some other commercial/noncommercial ORMs. This issue has been discussed both in NHibernate Developer List and in Ayende’s blog. I have recently noticed another benchmark between NH and EF, which I hope to address, too.

Fallacies of benchmark

What I have seen in those benchmarks is the wrong use of ORMs. This statement has two aspects: Wrong use of ORM and wrong use of NH itself.

In ORM, you don’t use it to do bulk operations. And 0.001 second difference will not differ anything in your application. If it does, you don’t also use RDBMS, you use something else.

There is no point on making a loop of thousands of iterations which saves an entity. Davy has well pointed out that this has a lot of implications in NHibernate, unlike some other ORMs. First of all, NHibernate first-level cache will be in action and it will fill the cache with each item saved. Secondly, as NH makes use of POCO it has no mechanism of things like INotifyPropertyChanged, it has to compare the old to the new value. As you may guess, the more entity you have, the longer it will take. No exception. If you want to leave first-level cache out of the game, you use StatelessSession feature of NHibernate, no exception. Actually when you check Fabio Maulo’s post you’ll see it can even become faster without Stateless Session.

Another point I have noticed in both benchmarks is that they are/were not fair. If I compare it to EF, lets say, ctx.SaveChanges() will batch the chages and send the query to the database in one go. NH has this feature, as Ayende already pointed out, since 2006. However, NH by default doesn’t make use of it, and this is not a bug, it is a feature. You have to use setting to enable it.

Benchmark the community, too

NHibernate has a big community, and great minds as committers. It really does matter. Let me give you some statistics about NHibernate development and its community

Here is the commit statistics.

image 

It is one of the most active projects in .net environment. The image above doesn’t include the contrib projects. A great kiss goes  to Fabio Maulo for his massive efforts.

Let’s look at discussion group, shall we?

image

Do you know any other group with that activity? I don’t know.

 

In addition, NHibernate gives you more than _ANY_ ORM can give. It gives you a lot of extensibility points which can be used in a lot of scenario. Validator, Search, Spatial, Shards to name a few.

In conclusion

NHibernate is the obvious winner.

Even Developers Make Art

12. August 2009

poster1ciktigh6

Found this today last month. If you click on the picture, you’ll see that there are parts that are composed of other images.

I prepared a folder with full of small pictures, and a preprocessor scanned all files in that folder, took their R G and B averages and saved it to a database.

I then divided the big picture into small chunks (the small, the better, but also requires more photos in order not to have repetitions). I took R G B averages of each part and computed the distance from each of the items stored in DB(for efficient access, they are fetched to memory). The distance formula is simply the Pythagoras theorem.

clip_image002[6]

The closer it is, the better it fits to the place. However, there is one problem. Neighbor parts tend to have a correlation (they share similar colors), and if we use the same picture for neighboring cells, it doesn’t look good(above probably left from an early version). What I did was to take closest 10 and select randomly.

The rest is a bit of Image processing(not processing but replacing, lets say)

I had fun doing it :) Art is everywhere even if I don’t think I like it :)

YAGNI in Real Life

7. August 2009

One of my friends wanted to have a cheap SVN hosting (actually wanted to install svn to his hosting, but this part is irrelevant to what I am going to say). I offered him some alternatives including Assembla.

Then the topic came to OpenSource SVN hosting, and he believed SourceForge is superior to Google Code. While I can understand his claims, I have objections to it. As I am contributing to various opensource projects, and being an active user of opensource, I have a bunch of projects in my “OpenSourceProjects” folder. Most of them use SVN, rarely CVS. Most SVN projects was hosted under either Google Code or Sourceforge, some Codeplex.

To begin with, having used’em all, I have pretty much experience with both, at least as a user.

One argument that my friend used that SF has many features. Looking at google code interface, I have to admit that this is true. However, those blown features are not at my center of interest. When I develop the project, I want speed. SF doesn’t give me that much smooth experience, I remember having to update a project 5+ times just to download, and less frequently trying to commit 2+ times. Google, on the other hand, didn’t cause any problem regarding to its SVN usage.

Another problem that we faced recently is that the download counts of NHibernate.Linq project was shown as 0 a week after we released it. I am pretty sure (:) ) that it had thousands of downloads since then, but it is not seen on SF.

To sum up what I have said, I prefer quality of service over the features provided most of the time. Having features that I perhaps will never ever use is “relevant” to this story, it is YAGNI.

DELL increases the Fan speed to hide problems - Yet Another Dell Fail?!

7. August 2009

I got my laptop repaired, thankfully, with the help of the Customer Care (Thank you Mustafa!)

It seems like my laptop suffered from the same problem many others faced. I had my warranty information disappearing from time to time. Because of this reason, I had chance (?) to make phone calls to the USA DELL, and learnt at that time that the issue occurred due to non-updated BIOS. I thought it was something different but now I see that that new BIOS version just increases the fan speed in order to postpone the problem, perhaps till the warranty expires. I am not an expert on Ethics but I believe that this issue is non ethical as they try to hide the real problem instead of fixing it. Another drawback of increased fan is the increased power consumption and therefore less battery life.

As a result of many many complaints, DELL decides to add 1 year extension to limited warranty. Mine still shows 2010 but I hope i’ll figure it out.

Dell lost my respect, even if this is NVIDIA’s fault, Dell’s attitude toward customers is not acceptable.

I hope that I won’t have to buy DELL in some near future.

, ,

Making Transient as Default Lifestyle in Castle Windsor

6. August 2009

This is actually an answer to fellow blogger Jak Charlton, but I see a benefit in sharing it.

Casey pointed out that the default lifestyle should be transient. Even though I understand his reasonings, I am used to this way.

There is a solution for those who wants Transient as the default.

You know what? Yes, the events ! Here is how.

container.Kernel.ComponentModelCreated += new ComponentModelDelegate(Kernel_ComponentModelCreated);


void Kernel_ComponentModelCreated(Castle.Core.ComponentModel model)
{
	if (model.LifestyleType == LifestyleType.Undefined)
		model.LifestyleType = LifestyleType.Transient;
}

, ,

NHibernate Linq Released

27. July 2009

Just as a reminder, even though you might have seen it before on twitter or nhforge or Ayende’s blog

As of today, we released the first version of NHibernate.Linq. It is currently based on criteria api, and can handle many situations that Criteria API can handle.

Oh one more thing, NHibernate.Linq was the first project that I contribute as a committer (it was in Rhino Tools), it is a strange feeling to see its release.

I would like to thank Oren Eini(Ayende), Chad Lee and Will Shaver for making this project come true.

You can read the official announcement here on NHForge

Implementing EnrichWith(of StructureMap) with Castle

15. July 2009

UPDATE: This facility made its way into Castle Microkernel, with name OnCreateFacility. I also made it possible to specify more than one actions.

In one of Joshua Flanagan's recent post he mentioned about how they handle application configuration and I have to say that I liked their way. I also liked how SM can post-modify an object created, and looked for a way to do it in Castle. As many other stuff, I was able to achieve the same effect with a custom Facility.

If I go further in the details, I had to catch ComponentCreated event of Kernel.

public class EnrichWithFacility:AbstractFacility
{
	public const string ExtendWithPropertyKey = "extendwith";
	protected override void Init()
	{
		Kernel.ComponentCreated += Kernel_ComponentCreated;
	}
	void Kernel_ComponentCreated(ComponentModel model, object instance)
	{
		if(model.ExtendedProperties.Contains(ExtendWithPropertyKey))
		{
			var action = model.ExtendedProperties[ExtendWithPropertyKey] as ExtendComponentDelegate;
			action(this.Kernel, instance);
		}
	}
}

Whenever a component is created, I will catch it and ask if there is any EnrichWith registered for the ComponentModel, and if there is any, invoke the action.

I also added a fluent registration extensions (Castle style!) in order to make it easy to register enrichments.

container.Register(Component.For<IService>().ImplementedBy<MyService>()
			 .EnrichWith((kernel, instance) => ((IService) instance).I++));

 

The code for the facility, fluent registration interface,and the tests can be found on our never-ending blog engine, BlogSharp codebase.

, ,

Long Live, Nikola Tesla!

10. July 2009

This is the 153th birthday of The Man Who Invented 20th Century (and also 21st century). There are a lot to say on his works and life, and how Edison prevented his work, etc, but i am not going to go over and detail them.

Tesla was a great man, and a researcher mostly known for his interest in Magnetism and Electricity. He is also the real inventor of Radio. He’s the inventor of Alternative Current, which we use today. He designed the future in his mind. Rumor is that he worked on transferring energy in the air and actually designed them. Research is still going on this topic, roughly 100 years after his works.

I found a great video on his life and works, recommend you to watch.

 

Tesla doesn’t have the fame he deserve today, but for me, he is the hero of today’s technology, not Edison!

Querying on Child Count With NHibernate

10. July 2009

This is a recent question raised in NHibernate Users Group. The user wanted to realize the following query with Criteria api.

var result = db.Person.Where(x => x.Pets.Count > 0 && x.Alive)
.OrderBy(x => x.Name);

This is not a simple query, but it has a solution

DetachedCriteria crit = DetachedCriteria.For(typeof (Person), "p2")
    .CreateCriteria("p2.Pets","Pets")
    .Add(Restrictions.EqProperty("p.Id", "p2.Id"))
    .SetProjection(Projections.Count("Pets.Id"));

ICriteria c = s.CreateCriteria(typeof (Person), "p")
    .Add(Restrictions.Gt(Projections.SubQuery(crit), 0))
    .Add(Restrictions.Eq("p.Alive",true))
    .AddOrder(Order.Asc("p.Name"));

What we had to do is to create a DetachedCriteria and on that execute CreateCriteria so that we can do querying on our collection.

The other way is simpler, but requires you to use HQL (below query is provided by Fabio Maulo)

session.CreateQuery("from Person p where  size(p.Pets) > 0 and p.Visible = true order by p.Name")

or

session.CreateQuery("from Person p where  p.Pets.size > 0 and p.Visible = true order by p.Name")

 

I hope this helps.