July 15, 2010 LvivNetUserGroup, NHibernate, Presentation No comments
July 15, 2010 LvivNetUserGroup, NHibernate, Presentation No comments
Hello, as many of you know yesterday I spoke to NHibernate at local .NET User Group.
I won 20 beers, because we’ve got > 30 attendees
It was group’s 4-th meeting and it went extremely well. Above 40 people participated and for me it was biggest audience I ever had to talk to during one hour or so. For another speaker – Derik Whittaker – I’m sure that this is not biggest audience he had, but maybe the biggest foreign language speaking audience. If I’m wrong please correct me.
Audience asked questions
People were asking me lot of questions and I tried to answer quickly and easily, but keeping in mind that I should continue and be in time, since it is bad practice to overtime speech.
I asked questions
To my own surprise flow of delivering this presentation was so smooth and harmonic with audience. Asking people simple questions, making them shaking their hands and keeping attention, because maybe another time I’ll ask exactly someone from them.
I’m proud for my presentation skills
From day to day I become better in my ability to talk easily to technical audience. This time I’ve got the most sophisticated audience I ever had. They all had good experience working on different projects. So it was not like talking to university guys, who are very “green” in their understanding of technology and how things should look like.
Presentation itself
You could take a look at my presentation below.
Not enough time to finish my second demo
For my second demo I allocated about 20 minutes, but it turned out, that I got about 10 and also talking to it and coding takes longer than sitting with my own keyboard and typing it at light speed. So sorry guys for not showing what I planned there.
What was planned and I did not show is: demoing lazy loading, chasing, complex Criteria API, and maybe the interesting – implementing own UnitOfWork and NHibernate repositories, approaches to build domain model with NHibernate.
BTW: I’m also going to have another blog post on NHibernate itself.
Really looking forward to get your feedback! Please leave your comments!
July 7, 2010 DevMeeting, Resharper 4 comments
Resharper
Resharper is code refactoring and productivity extension to Visual Studio. While you are typing it analyzes code and highlights errors, suggests quick-solutions and hints on code completion. It allows you generate lot of code, perform code clean-up and do different refactorings. Resharper saves your time.
My reasons why to use Resharper
Why not to use Resharper (*)
Developer’s meeting
Finally I’ve decided to provide developer’s meeting on Resharper. Long time ago (1.5 years) we had developers meeting provided for our team (about 50 people) on regular bases. We’ve lost that process because guy providing those has moved to Austria. Now we have those meetings quite rarely, mainly me trying to provide a lot of them. Help me, post some feedback here.
What you may need to be prepared for such kind of meeting?
It is obvious that we could not have PowerPoint pretension for this topic, so you will need write code illustrating Resharper. Second thing is that you should have some scenario to proceed with. You cannot simply go and create code on the flow, because it may happen that you will fall in wrong corner. So this post represents short plan for meeting and kick-off tutorial for my co-workers if they will like my talk.
Plan Of Attack
Introduction
I would need give some general definition to what Resharper is and show where from we can download it.
As it is recommended good approach is to know your auditory. Few questions? Ask who knows some hotkey, say Ctrl+Alt+G. This is very common hotkey, but not as much as Alt+Enter and answer for this question should allow you see how deeply they know Resharper and how quick you should be with core functionality in Resharper.
SetUp Resharper
Once you have installed Resharper, you may go and change keyboard layout under Resharper->Options->Visual Studio Integration
As I figured out almost each active user of Resharper uses IntelliJ IDEA keyboard layout and I would recommend it for you.
Besides, you may leave some of the VS native shortcuts – first time you are going to use F12 for example it will re-ask you if you want use Resharpers (navigate to error) or VS (go to definition) one. This way you may save most commonly used keys from VS. You can download keymap pdf file from here.
Also it is possible to save all of your configuration in xml file and share with others.
Damn It! Let’s write some code.
KeyboardJedi
For the meeting you will need demonstrate hot-keys you are pressing. For this I’m using KeyboardJedi by Roy Osherove.
On following screenshot we can see that I’ve pressed Shift+F6 and got renaming dialog box. Please note KeyboardJedi at the left.
I renamed file to be Calculator.
Introducing Alt+Enter
This hotkey is the most commonly used. It shows available quick-fixes and context actions. Showing how we can change visibility of class with this. So guys start with learning this hotkey!
Templates usages
Pushing Members Up and Down
We even could mark something as abstract when pushing down.
So this gives us change in 3 different files simultaneously.
public abstract class OperationBase : IOperation
public class OneOperandOperation : OperationBase
Learning Generating Code (Alt+Ins)
Generating constructor, properties, auto-properties, surrounding with some template (Ctrl+Alt+Ins)
Scenario: method needs to be thread-safe, so we surround it with locking (Ctrl+Alt+Ins), and we are refactoring with introducing object lock, then we refactor with introducing field (Ctrl+Shift+R).
Scenario: method has lot of code so we use extract method refactoring (Ctrl+Alt+M).
Navigation (Ctrl+Alt+G)
Navigation is one of the features of resharper that is very important in huge complex solutions. And that is one of my favorite ones. JetBrains did a lot of improvements in navigating through solution.
From any part of code you could easily navigate to whatever you want by pressing: Ctrl+Alt+G.
Navigate to type (Ctrl+N)
When showing this also good to illustrate on big solution, also mentioning about camel cases. So in picture below, you could see that I just typed “CDS” and I’m able to see few different classes that match what I need.
Scenario: Navigation to declaration, implementation and so on.
Navigation to class members (Ctrl+F12).
Unit Testing
Resharper supports unit testing frameworks, so it could easily work with NUnit as well as MSTests in one solution.
Scenario: Writing UT using live template for test method, debugging UT imitating TDD, creating shortcut for UT run.
Live template
When showing unit testing capabilities we may show how to create template for unit test, or some special kind of UT.
Few other scenarios
Links
Everything needed could be found from this page: http://www.jetbrains.com/resharper/
P.S. Items marked with (*) were added after I had posted this article.
July 5, 2010 NHibernate, QuickTip, UnitTesting No comments
Today, I’ve been writing few methods for my DAL classes, of course, I decided to have one or few integration unit tests that hits database and see actual SQLs with NHibernate Profiler.
So in couple of minetes I’ve got unit tests that had following line in the beggining of each:
HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
if you don’t know, this line attaches your execution code with NHibernate Profiler, so I’m able to see SQLs NHibernate generates.
When I run bunch of unit tests in my testing file, I’ve got strange picture with duplicating of queries for each test with arithmetic progression. And N+1 problem, but hold on, I’m sure that I did everything through joins.
Reason is that profiler appends to my code on each new test run and that is why it start thinking that I have multiple selects to get list of something.
Solution, which I would recommend as pattern for writing Unit Tests with NHibernate Profiler is following:
July 3, 2010 Success No comments
But why do I need blog?
[2013-11-21 EDIT: some language corrections]
July 3, 2010 Prototyping, Tools, UI No comments
I was thinking about what to post and I’ve got nice twits like this one:
So why not to try that thing. So I installed Pencil add-on.
Here is screenshot of my try:
Toolbar on the left is rich of different shape collections. Sadly I did not find one for UML diagrams, but they could be easily added and that is great.
So this is the simplest way to have light prototyping machine just in your browser.
July 3, 2010 RhinoMocks, TDD, UnitTesting No comments
Are you married? Yeah, quite not usual question for blog post about mocking, but if you are married you probably asked your girl to become your wife.
So you are playing role of PotentialHasband:
and she is PotentialWife, taking your ask into consideration and answering you true or false.
If she is Linda, you would need to have “I love you” in your speech to get her agreement:
What we are going to test is to see that after you asked, she will definitely give you at least some answer and not ignore you. Also if her answer is “YES” we would like to see MarriageService called Marry method.
Class which we are going to test is named LearningMocking and has constructor that accepts potential husband/wife and marriageService. Whole story takes place in RestaurantDinner method.
First let’s test that after you asked she gives at least some answer. Since we are not interested in concrete instances we just generate mocks for our interfaces, and passing null instead of marriage service. I’m using RhinoMocks in this example.
This ensured that at least she will give you some answer. In next test we will have some mix and will use concrete class Linda. We have generated Stub for return value of your speech, so instead of
writing concrete class for husband we’ve used stub. This test shows that
she will not marry you:
Let’s use another strategy to ask Linda:
Except of verifying that Marry method was called we also verify that it was called with instance of linda and none else with line Arg<IPotentialWife>.Is.Equal(linda). As well you could setup constructor arguments for MarriageService, since it is not an interface. Also with Rhino.Mocks you will need to have method Marry to be virtual. If it is not virtual and you don’t have interface for it you may need to extend that class with your own.
In the end we’ve got this method:
Nice picture:
Please write down if you would like to see more complex mocking examples.
July 2, 2010 Book Reviews, Success No comments
Last weekend I had a chance to read very interesting book, kind of business novel. I was given this book by my managers after we finished with my performance appraisal. Which (btw) went very well.
Book talks about guy, who manages plant where he encounter problem of going behind the schedule and his bosses wanted to close out his plant. But he with colleges, using Theory of Constraints and sophisticated thinking, was able to get plant to the new level.
From first pages I was not sure if book is kind of my thing, since I usually don’t read novels, but it turns out that book is only a bit hard going at the beginning. From page to page it was more gripping to read and in the end it just became a real page-turner.
Book forces us to think that everything is possible, you just need to take a look for wider solutions without using any of your stereotypes. Book never gives you ready answers, so it is thought-provoking one. First it states the problem, describing it in details, after that main hero is bombarded with different questions by friends, which provoke us think in pair with him.
Reading book was really-really enjoyable and I would highly recommend it for your reading. Book indeed is exciting for those who are interested in career development and in manager’s positions.
P.S. I’ve changed this post a bit to use more specific words like: interesting, exciting, thought-provoking, a real page-turner, gripping, kind of my thing, hard going at the beginning, gripping. That was English course activity to have review on some book. I’m lazy to write new one.
July 2, 2010 Design Patterns 2 comments
If you ever played any shooter game, you probably know what do hot-keys F5 & F9 mean. If you did not play those anyway you should be aware of usefulness of quick-save/quick-load functionality. By pressing F5 you save your current location your health/armor levels and maybe some other information, like how many monsters did you kill already. This defines your state which is going to be saved. On pressing F9 you return to your previous saved state (kind of undo operation).
When you are saving your state you don’t wanna it to be accessible by other classes (encapsulation of state), so you will be sure that none will decrease you health level. Also you wanna keep track of savings and maybe you are going to add functionality that will get back through two-three saves by pressing Shift+F9 (+F9).
How can you accomplish this?
Memento pattern is used when you want do undo operations without exposing internal state of the Originator (Game). Coordination of operations is done by Caretaker, or something that simply lists mementos and therefore remembers states without knowing what are they.
Let’s take a look at implementation:
Originator (Game)
public
GameMemento gameSave(){
return
new
GameMemento(_state);
}
public void loadGame(GameMemento memento){
_state = memento.getState();
}
public class
GameMemento {
private
final
GameState _state;
private GameMemento(GameState state) {
_state = state;
}
private GameState getState(){
return
_state;
}
}
}
So it is able to generate memento instance with current game state, as well it is able to get state from existing memento, BUT none else could get that state, since GameMemento is inner class of Game and methods are private.
Caretaker
Or the guy, who keeps track of your F5/F9th. Currently it is able to load the latest one quick save, but it could be easily enhanced.
public
Caretaker() {
_game = new
GameOriginator();
}
public void
shootThatDumbAss(){
_game.Play();
}
public void F5(){
_quickSaves.push(_game.gameSave());
}
public void F9(){
_game.loadGame(_quickSaves.peek());
}
}
Output
With following usage code:
our application generates:
Health: 100
Killed Monsters: 0
Health: 90
Killed Monsters: 2
Health: 81
Killed Monsters: 4
Health: 72
Killed Monsters: 6
Health: 64
Killed Monsters: 8
Health: 90
Killed Monsters: 2
Here is quick UML, that I drew for my example:
June 27, 2010 InfluenceOnPeople, Personal No comments
Yesterday I’ve been in parents home and I had conversation with my youngest sister. I have two of them. She was complaining about her MP3 player, she said that I have much better one and her is completely out of battery and she could not listen to music even longer than hour. Also she continued saying that it was cheap player and that is the reason why it is useless.
She always gets some money from me. I do not say that give her much money. Sometimes 20, sometimes 50, rarely 100 (those are Ukrainian hryvnias). And I do not like how she spends it, so I’ve decided to have a test with her. I asked her following: “How much money do you have now?” “60 hryvnia” – she said. Then I asked how she wants to spend them. She said that she wants roller-skates. Ok, then I followed with questions that brought to her mind and if she will not spend money this month she will get 120 next month or much more. Finally we went to the 1400 next year, but ONLY if she will not spend them on different useless things and if she will not buy rollers. She admitted that if she will stop spending money on crap she will get “rich” in her understanding .
After that I asked question: “Decide now, you either give me your 60 hryvnias and my MP3 is yours, or either you keep them for future!” She tried to avoid direct answer, but I gave her firm offer. Finally she came to me and said, that she will keep money. I praised her and with words “Keep in mind that sometimes right decisions bring your much more than you expect” I gifted her with MP3.
She was so surprised and with shining face ran to my parents saying that she gained MP3 and that is because she is smart girl. I’m sure that if we had no have that conversation before she most likely chose MP3 instead of keeping money.
I think this is simple example how you could show others that some things are good. So you basically change her mind, then you examine her and if she admits your ideas praise her (This will happen most likely, because now she thinks that this is part of her thoughts). In this way you will keep lesson in her mind for some evident time.
P/S Why have I posted this? With my future career growth I will have to be good on managing people. That is why time-to-time you will see such blog posts. But be calm, my blog is still tech blog unless I’m manager.
June 25, 2010 Resharper No comments
Sometimes when you have few huge solutions opened performance of your PC is very critical and having Resharper over that is notable.
For our good luck with new versions of Resharper you could suspend it easily:
But going into menu is boring thing, so I think you would prefer to setup few hotkeys for that.
Basicly you will need to map Resharper_Suspend and/or Resharper_Resume. I bound those to “Ctrl+R, Ctrl+S” for Suspend and “Ctrl+R, Ctrl+R” for Resume.
Also, as I found over internet, JetBrains promise to have 5.1 being faster and without performance issues, but did not found any official words about this, just twits.
Personally I use Resharper Nightly Builds and enjoy them very much.
Hope this helps.