January 2, 2010 Book Reviews No comments
January 2, 2010 Book Reviews No comments
January 1, 2010 Success, YearPlanReport 3 comments
Right now is the first time in this year when I opened google reader and found one interesting post Where Do You Want to Be In a Year? by Tim Barcz. When I read it I realized that I had read book The 7 Habits of Highly Effective People also.
In general all books on Success says that you need to “Begin with the end in mind“, this means that you must have your plan.
At first you need to find out you goal for whole life. That is your target and main thing you need to get. Then you need to do breakdown of tasks you need to accomplish in your life, having them in few levels of term scope like 10 years term, 5 years term and 1 year term… and so on. So question:
My answer:
By the end of 2010 I want:
1. Get Microsoft Certification:
* MCTS (Exams: 70-536 and 70-505)
* MCPD 70-563 and 70-565 (this one is big fish, but I need such!)
2. Read at least 24 books.
3. Become known employee in my company, sharing knowledge and doing presentations, so will have much more authority among co-workers.
4. Familiarize with Java and contribute research and development work to Kohonen Maps world.
5. to be Senior Developer and continue growing…
6. Improve my English skills to have at least upper-intermediate strong level (according to my company graduating)
7. Gather good capital and looking for investments of money.
Write down your answer in comments or give me link to your blog!
December 29, 2009 UnitTesting No comments
Few days ago I did refactoring and as I’m quite sure that we have good coverage I checked-in my code after all tests passed.
But today QA from my team stated that he/she cannot save new Customer. I dived into log files and found that exception occured on SaveCustomer method.
Ok, I moved to the appropriate UT. (Note: it passes ok.) Which looked like:
//now we fetch customer from database requesting with the ID of just saved customer
fetchedCustomer = CustomerRepository.FetchCustomer(savedCustomer.ID);
//if fetched customer is not null we are ok!
Assert.That( fetchedCustomer, Is.Not.Null );
}
catch
{
//do nothing here….
}
finally
{
if ( fetchedCustomer != null )
{
//we want to leave our database clear after test run
CustomerRepository.Delete( fetchedCustomer );
}
}
}
This Unit Test will be succeded anyway, because
Assert.That(fetchedCustomer, Is.Not.Null) and similar asserts generates AssertionException.
Honestly I’m not aware why there was that catch{} piece, but anyway you could put there two catch blocks if it is really needed – one specific for the AssertionException and another for all cases of our life.
When you write your Unit Test you need to see it in both states – first
in failure and then in success. After that you can allow yourself
commit that code.
Main idea is:
December 27, 2009 SVN No comments
December 23, 2009 NHibernate No comments
Next SQL, which verifies if customer row exists in database:
Will be generated with next NHibernate Query:
return result.HasValue;
}
Please note, that you could use not only primary key, but any other property in your where condition.
December 22, 2009 .NET, Regex No comments
This is just another quick example of Regex pattern.
Next pattern matches “at least one symbol which is letter or digit at the begging and then exactly one delimiter ‘|’ and then at least one symbol which is letter or digit in the end“:
Valid is:
Not valid are:
and so on…
Links I’ve used:
Verify your Regex:
http://www.pagecolumn.com/tool/regtest.htm
Cheat Sheet:
http://www.addedbytes.com/download/regular-expressions-cheat-sheet-v2/pdf/
December 22, 2009 CodeReview 2 comments
Sometimes it is hard to convince that catch(…) is not so good!
Today I provided code review to one of my colleague and he was totally sure the he need try{/*code*/}catch(){} in few places.
First looked like:
I rewrote code to:
Then I spent few minutes to convince him that this code is ok and that this is not good to have catch for everything.
Another code looked like:
Now I tried to explain that FirstOrDefault() returns us either first element of collection OR null, so if we got null we just need to do some another stuff,
but if some exception will occur we should allow it fly out OR write some specific catch for exceptions that could be thrown. Code which I propose looks like:
After conversation we decided that try(/*code*/)catch() is not so good.
December 21, 2009 UnitTesting No comments
Have you ever faced with UT that failed once and then you always see it succeeded?
One of such tests could be test where you verify that date properties of some newly created entity are equal if they take DateTime.Now for that.
Today Hudson showed me that some test failed in project I worked near half a year ago, so test looked like:
Test failed because time difference between dates was greater than few milliseconds. This could occur when processor is too occupied.
So I changed assert call to more realistic:
December 9, 2009 NHibernate 4 comments
Sometime ago I faced with NHibernate issue and spent much time on figuring out how to resolve it. Issue was with saving complicated entity.
Error:
With NHibernate Profiler I found that this fails on the next SQL:
With better look you will see that there two times RESOURCE_ID mentioned so this looks like wrong mapping. But I was sure that everything is ok there.
This two References are wrong.
At first glance do you see why? At that moment I was not able also.
References(x => x.ResourceRole)
.Access.AsCamelCaseField(Prefix.Underscore)
.WithColumns(“RESOURCE_ROLE_ID”, “RESOURCE_ID”)
.FetchType.Join();
Here Resource has key (RESOURCE_ID).
ResourceRole has composite key (ROLE_ID and RESOURCE_ID).
After long searching and many tries I found why mapping is not correct. Even have my explanation for it.
When we reference ResourceRole we already use RESOURCE_ID field, so when we setup Resource and say “Hey, there is one more RESOURCE_ID“, then NHibernate cannot find out how to update all this correctly.
Solution:
insert=”false” update=”false” attributes for one of references solves the issue.
In Fluent NHibernate it looks like:
December 7, 2009 NHibernate 2 comments
Image that you want to fetch friends from database by the First Name, Last Name and Age, which are properties of your class Friend. With NHibernate you could write query which will look like:
return friends;
}
But it is wrong. Since Age is the Nullable type (int?), your call GetFriends(“Andriy”,”Buday”,null) will not get my record even if there is such in database and the column AGE is NULL there. So to request you need this: ageExpression = Expression.IsNull(“Age”); but it will not work for not null age.
For our luck there is AbstractCriterion so we can generalize our Expressions like here:
IList<Friend> friends = Session.CreateCriteria(typeof(Friend))
.Add(Expression.Eq(“FirstName”, firstName))
.Add(Expression.Eq(“LastName”, lastName))
.Add(ageExpression)
.List<Friend>();
return friends;
}