The Book “Introduction to Programming with Java” - Ready for Publishing!

сряда, 31 декември 2008 г.

The book
I am very happy that my last post for this year is this one. I want to share with you the news that the book “Introduction to Programming with Java”, in which I have taken part as an author, is about to be published.

As you probably remember from my previous post, it covers a lot of different topics on the fundamentals of computer programming. The book does not focus on the Java language – it just uses the Java language as a tool for writing the samples. That’s why we believe it will become one of the prime sources of knowledge for beginners in computer science short after it is on the market. There I have written a chapter about one of the most widely used advanced data structures – trees and graphs.
Hopefully one will be able to buy a paper copy of the book in the first months of the New Year. Probably I haven't mentioned, but the book is free - you just buy the paper. It is 920-930 pages! For more information, you can look here. You can download a free copy of the book from here.

Instead of conclusion
This year was very interesting and dynamic. A lot of things were changed. I hope the next year will be very productive and good for all of us!

I wish you all the best, dear readers! I wish you having your dreams came true, but.. not all of them. Lets have some for the years coming, too!

Best regards,
Vesko Kolev

Vesko Kolev - what happened with this guy?

събота, 22 ноември 2008 г.

Hello, folks!
I haven’t blogged for a long time. Do you remember me? Just to be sure that you haven't forgot my face - on the right side is a picture of me ;-). A lot of things happened, a lot of future topics came in my mind trough this period. For sure you will see soon what I am talking about.

I have postponed this post for some time but think that the point at which to write it came.

What happened with me?
Firstly, I have left my previous company. I have been there for more than 2 years. I have worked on and led as a team leader a lot of different .NET projects and had the chance to work with a lot of great professionals from all over the world. My team and I have produced a lot of great functionality to our clients which was our first goal. However my decision to leave was based on some differences in thinking between me and my bosses – there were things, which I just cannot accept. The people, who know me well, will confirm that I am a very principled man. The good news is that this is an old story and is behind in the past. Now only the good memories will persist and of course the great amount of experience piled there.

Meanwhile…
Apart from that – I have joined a team, led by Svetlin Nakov, which started (and soon will finish) writing a book on a software development topic called “Introduction to Programming with Java”. It covers a lot of different topics on the fundamentals of computer programming. The book does not focus on the Java language – it just uses the Java language as a tool for writing the samples. That’s why we believe it will become one of the prime sources of knowledge for beginners in computer science short after it is on the market. There I have written a chapter about one of the most widely used advanced data structures – trees and graphs. You can find more information about the book here.

In the same period I have started to work as a part time .NET trainer at National Academy for Software Development. There have led different courses in some of the cutting edge Microsoft technologies. In my previous company training the new members of the development teams was one of my responsibilities and I liked doing it.

Where am I today?
Later I joined NASD .NET team as a full time employee. My responsibilities there include leading a team of very skilled .NET developers working on variety of different .NET projects using the latest technologies and best practices. Another major part of my job is to train people in advanced concepts of .NET programming. But still - why choosing NASD? I have refused some great offers of other good companies and chose this one, because there one can find one of the best and most popular software engineers in Bulgaria. It is a pleasure for me to work with such guys. Of course meeting new people almost every day at our courses is something which I also highly appreciate.

What you can expect?
You know me… Three months is a lot of time and in this period I have worked on and solved a lot of different problems. I will try to write more frequently sharing with you my everyday experience with the software engineering as a whole. I will be happy to hear from you from time to time about your experience with the same or similar problems which you have.

See you soon!

Algorithms: A real world example

вторник, 12 август 2008 г.

Introduction
Hi guys!
Today we are going to dive into a real world example of using algorithms + data structures. The task is not very hard, but I think it is very useful example how important is one to have an in-depth knowledge of algorithms and data structures.

What is the problem?
These days a friend of mine asked me the following question: “How can we retrieve the different files (in the terms of different names) from given two directories, including the subdirectory files?” In other words the question is how we can get the files from one directory(or in some of its subdirectories) which doesn't exist in the other and the opposite - the files which are in the second directory(or in some of its subdirectories) and does not exist in the first one.
Yes… I know that you can solve this. You can do it even in 5 minutes using whatever data structure you want which has a contains method (or equivalent). But do you think that this approach is going to be the fastest one? Or a more scientific question – is your algorithmic complexity good enough for the needs of your enterprise application?
In general there is uncountable number of algorithmic tasks out there and most of them have more than one good algorithmic solution. I am going to show you a problem with a possible solution.

The algorithm
The approach is based on one classical algorithm. This algorithm merges two given sorted sequences in a new sorted sequence, which contains the elements from both sequences in linear time. On the following picture, you will see two sorted input sequences. The algorithm to get the result sequence is the following:


1)While both sequences are not empty - get the minimum of the two top elements and put it at the end of the result sequence. Remove the element from the input.
2)Now if there are any elements left in the input, they should be in only one of the input arrays. If there are some element left – add them at the end of the new sequence and remove them from the input.

In our case we first have 0 and 1. 0 < 1 therefore we put 0 in the new sequence. The first input sequence will be 3, 3, 15, 19, 76, 89, 99. We are doing this till the moment when the second sequence (which is shorter than the first one) is over. Than we just add the element 76, 89 and 99 to the end of the result sequence.

What is the modification?
You just need to get your both sequence of files in an ascending sorting manner. If the files on the top of the two sequences are equal, then just remove them. If the files are different, then take the one which is name is “less” in the terms of lexicographical order and put it at the end of the result sequence (Note: Here you should check whether the result sequence doesn’t already ends in this filename. Think of a situation in which this is required.). If one of the sequences is not empty, we get its entire elements and put them at the end of the result sequence again taking in mind the above note.

Which are the data structures?
As we saw, we access only the top elements in the input sequences. This is the major feature of the Stack data structure. The result sequence – we add elements at its end and need to peek the last added element. So we can use for example Queue or Linked List depending on the implementation which we are using.

Conclusion
In this post I have tried to show you one problem which can be solved optimally with an elegant algorithm. I have tried not to be bounded to any programming language and not to be clear enough, because want you guys to think of the rest! This is the way in which I believe one should learn to program – with logical thinking and researching.

Hope you learned something new!

Tricks: How to get N random rows from a table in T-SQL

петък, 18 юли 2008 г.

Hi readers!

What is this blog post for?

Today I am going to present you the first post of my second series - Tricks. As I said before I will show "Technology Specific Tricks - short posts about something, which I have researched and which I want to preserve and share with you all."
The first one is about T-SQL


The problem - How to get N random rows from a table?



A little explanation - actually ORDER BY NEWID() sorts the rows in a random way. In our case we just take as much of the first as we need.


Conclusion

You just saw what you can expect from this type of posts.
Hope this helps!

Basics: Why to use accessors and mutators?

сряда, 16 юли 2008 г.

What is this blog post for?

This is the first post from my new series – Basics. In this series I will add things which are (in my opinion) really important and should be perfectly known by every Developer/Senior. I will add topics which I have been asked for or things which I have expected to be known by the mass, but it wasn’t that case. I will try to be as much platform independent as possible. Of course I will add some general knowledge about new things in C# 3.0. I will try to be as much detailed as possible but will appriciate any help/comments on making things broader. No matter – lets go back to basics!
This post is for the so called accessors and mutators / getters and setters / get and set methods / properties in C# / etc. and why we need them at all?


The explanation

public class Person
{
public int age;
}


public class Person
{
private int age;
public int getAge()
{
return age;
}

public int setAge(int value)
{
age = value;
}
}

Firstly, accessors and mutators are used mainly for encapsulating fields of a class (an example for different usage can be given for storing information in the Session or ViewState). It’s not good practice to expose public fields (or why it is better to use getters and setters), because:

- If you use get and set method, you are able to control the access of the property. For example you can give public get and protected/private/etc. set.

- You can put any kind of validation in the set method. If there is a need you can throw an exception.

- The situation may need to set other dependant properties, too, when accessing/setting the current one.

- When you access the get/set method you can rise an event (for example OnValueChanged)

- You can convert the value which you return from the getter to more informationless data (for example you can have a value for a price and you want to return it with 2 digits after the decimal point, but in your calculations it should be as much digits as possible for more correct calculations).

- It is easier to bind against proeprties.

- If you expose public fields, later you cannot change them into properties without recompiling.


Still why?

And yet again – why to use getters and setters when we have just a simple integer field which we do not think will need any special work now? Why should I “loose” my time writing additional code? Because in our everyday life almost every time the specification is changed and almost every time there is a situation which we didn’t take in mind at the time of writing the code. In general in my opinion a good developer is the one that can write as much extensible code as possible, as much reusable as possible and as easier to change as possible nomatter which platform is used. The practice of using getters and setters gives you the flexibility to be the winner in the battle between you and the changing specification. It gives you a very simple rule of a thumb which makes your code keeping tight encapsulation.


Something in addition for C# 3.0

Yes – one of the greatest things in C# (compared to Java for example) is its properties. In Java you do not have such structure (as I have heard this is going to be changed in some of the future releases of Java. I will just ask - where are my get* and set* methods!?!?!). Most of the code one will see in an average Java program is a bunch of getters and setters (hopefully generated).
In C# we have the chance to work with this more clear structure called property. However in C# 1.1 there was a little problem – there was no way in which you can say “I want to have a public getter and a private setter”. The only ability was to say whether you want to have get and/or set with an one and the same access modificator.
In C# 2.0 we were given the access modification functionality for each of the two property parts. This was great. But there was still something which missed me all the time – I wanted to have a way to enforce everybody to use the property and not the field (in general this has sense if you think about the access of the field in the class in which it is defined). Here the C# 3.0 come one day and say “I can fix this!” The magic is called Automatic properties. See the following example which shows an automatic property:
int Age
{
get;
set;
}

As you can see we do not need to explicitly define field for this property. What actually happens is that when the C# 3.0 compiler see an empty get/set property it will automatically generate a private field for you. This means – less code to write and more to generate. Another effect is the fact that you cannot directly access the fields which solves the problem mentioned above.


Conclusion:

Just think of all the mentioned things in the above post. You as developer can only benefit from this. If you didn’t find any sense of using getters/setters, to be honest with you - just find a better field for you.

P.S. If you want to get more information on automatic properties and what happens under the covers you can go to Bart De Smet Blog.

Future plans

Hi guys!

I haven't blog for a while, but I can assure you that a lot things for blogging come to my mind for this period. I just haven't enough time last days as I had a lot of work for the university and for my new company.

As you can see I am starting with a change - my new blog design (here I should add one big thanks to Peter Velichkov for his help tuning the theme :-)).

What you can expect recently? I can divide the posts from the near future in the following directions:
- Advanced Basics - the things which every senior should know.
- .NET 3.0/3.5 Technologies - I will try to provide some posts about the new things in 3.5 as well as some of the W* technologies from 3.0.
- Mobile Software/Hardware - here I will try to share some of my personal experience with the Apple's iPhone , Asus EEEPC and some thoughts about Symbian.
- Technology Specific Tricks - short posts about something, which I have researched and which I want to preserve and share with you all.

Hope you like my new blog theme and my future topics. I will try to be regular in blogging because it really is very important for me as a person and for the community as whole.

Expect my next post in a short time!

Bulgarian is supported by Google Translate!

понеделник, 19 май 2008 г.

Yeeeeah... it's true! Goolge have recently added translation capabilities for 10 new languages! The new languages include Bulgarian, Croatian, Czech, Danish, Finnish, Hindi, Norwegian, Polish, Romanian and Swedish.

Finally Bulgarian is supported! What does this means to you guys? At least you can read my blog in Bulgarian (using the translator on the right side of my blog).

P.S. Martin - at last there is Bulgarian! :-)
P.P.S. You can find the full blogpost here.

How to create branch under SourceSafe in 5 steps?

сряда, 26 март 2008 г.

Hi guys!

A lot of people (including me of courseJ) had a lot of troubles when they had to create their first branch under SourceSafe. Why? In my opinion this program (talking about version 8.* of SourceSafe) has a lot of problems connected with the friendliness of the UI. Actually I think that it isn't user friendly at all. So here are my bits about solving one of the problems – branching. In the following lines I will provide an algorithm in 5 steps about how to do this activity. I do not know whether there is shorter way to do this but for me this is short enough and the most important thing – it works.

The algorithm is the following. I assume that you are in the database, where is the project you want to branch. Note, that the backward blue diagonals on white background cover some data, which is important only for me.

Step 1: Select the root of your DB, right click on it and select Create Project.




Step 2: Give your new project a name – this will be the name of your new branch. Click OK.




Step 3: Go to the folder you just created – right click on it. Select Share to $/ Your_Branch.




Step 4: Select the project which you want to branch. Check Branch after share (in the bottom) and click Share.




Step 5: You can select new name of the project, which will be branched in your new folder (the one which you created on Step 1). Check Recursive. You can add your Comment in the provided box and then click OK.




After these 5 steps you are ready to wait for your new branch. The speed of actual creating the branch depends on your project size, database, etc.

Hope this helps!

How to get the free available memory with C#? The first sample of using a performance counter.

петък, 21 март 2008 г.

There are a lot of cases in which we as developers want to know how much free memory is there (or the state of some of the other system resources). This can be used for deciding whether we can handle another request, or is there enough memory (and CPU of course) to start some background work meanwhile. A lot of examples can be given about such situations.

Ok, but how we can answer this question in C#?
The approach which I will show is a very good start for diving in the topic of monitoring. What is the way to monitor the system resources in Windows? The answer is: Performance Counters. There are a lot of counters out there which can give a lot of data. Yes, there is no mistake – just pure data. Our task is to observe, collect, manipulate mathematically, etc. this data such that we can extract meaning from it i.e. to transform it in information. Keep in mind that “Performance Monitoring is a complex subject and in some ways more of an art than a science.”
Just for completeness I will add that you can check some of the available counters on your own system /they can differ depending on what have been installed/ from Control Panel ->Administrative Tools -> Performance. There – right click -> Add counter. The following box appears:



OK that’s enough knowledge for you to start observing some counter if you haven’t already in the past.

The counter which we are interested in today is connected with memory, so it should be in Memory performance object. The right counter is one of the following: Available Bytes, Available KBytes, Available MBytes.
"Available Bytes\KBytes\MBytes shows the amount of physical memory, in bytes\kilobytes\megabytes, available to processes running on the computer. It is calculated by adding the amount of space on the Zeroed, Free, and Standby memory lists. Free memory is ready for use; Zeroed memory consists of pages of memory filled with zeros to prevent subsequent processes from seeing data used by a previous process; Standby memory is memory that has been removed from a process' working set (its physical memory) on route to disk, but is still available to be recalled. This counter displays the last observed value only; it is not an average."

How to retrieve data from performance counters in C#? There is a namespace in .NET named System.Diagnostics . There are a bunch of classes which give us the power to play with these counters. It is very straight forward and easy. You can see the simplicity from my sample which is only 3-4 lines of code.



In this manner we can retrieve the free memory with C#.
There are a lot other useful counters out there in Windows such as these for the processor, disk usage, etc. Of course if you have installed .NET framework, there are a lot counters connected with the CLR as a whole.

In the future I am planning covering some of other performance counters and connected classes in .NET so stay turned. Hope this helps!

Something that amazed me - Stereograms

вторник, 18 март 2008 г.

Yes.. it really is true. Stereograms are something that made me feel really strange. First I will give you one of them. Your task is very simple - just stare at it.



Yes.. I know this is jsut a bunch of paper clips. I'll try to give you a hint how to see it. Go near your screen. Stare at it but do not harden your eyes. Just stare. Then move your face out of the screen slowly. After two or three (thousands) of times you will see it. And do not ask me when you will understand that you will see what is there. If you see it you will be sure.

I want to present you a short definiton from Wikipedia: A stereogram is an optical illusion of depth created from flat, two-dimensional image or images. Originally, stereogram referred to a pair of stereo images which could be viewed using stereoscope. Other types of stereograms include anaglyphs and autostereograms.

Here you can find a lot of other stereograms. It is very funny - really!

In some of my next posts I will try to cover the topic of creation of stereograms. You know me - I am a deep diver!

Thanks and do not take a long time staring!

My blog in YOUR language!

вторник, 5 февруари 2008 г.

Hi guys!
I know that there is a time in which you want to read something, which you do not completely understand because of the language in which it is written. As you may do not know I am a great fan of machine translation topic. This automatically leads to the fact that you can now read my blog in a language which you better understand or even in YOUR language. This cool functionality is produced because of who? Google of course :-). (Look under my profile information.)

So lets start blogging more frequently in YOUR language!

Thanks!

P.S. If you know me better you will already know that I will share how you can do this to your own blog/site. Just read the information from here

ScriptManager in a BasePage class.

вторник, 15 януари 2008 г.

Hi guys!
As I don't have much time I will go straight to the problem - how we can put ScriptManager in our BasePage class? You know that when you insert an UpdatePanel to a page and there isn't any ScriptManager it cries for one. When you insert more than one ScriptManager, you are said that there isn't any. As I have researched - there wasn't answer how you can put ScriptManager from a BasePage class and again we were alone ;).

OK here is the solution:



How you can come to this conclusion yourself?
When you open the code of the UpdatePanel you will see that the class has property ScriptManager, which internaly calls ScriptManager.GetCurrent(page) which internaly returns (page.Items[typeof(ScriptManager)] as ScriptManager);

So I had to do two things - first to lie the UpdatePanel that there is at least one ScriptMangaer, than I had to remove it because I want to add it as first control on the page.

Thats all folks! Hope this helps :-).

 
Vesko Kolev's Blog : IDeveloper -