Sunday, March 25, 2007

Hey guys how are you?

I wanted to share you with nice dillema that was raised by one of our team leaders, called: Boaz Davidoff.
He encountered with a situation that he wanted to create new instance of an object that inherits from a parent object (which is no problem right...?), BUT firstly he wanted to initiate some members in the child object before of creating the parent object and just after it to call the parent object constructor.

It turns out that this situation is quite impossible in .NET, because by default, you must call the base ctor firstly and just after it to do your stuff, for an example:

public class A
{
    int a1, a2;

    public A(int a1, int a2)
    {
        this.a1 = a1;
        this.a2 = a2;

        // Do your stuff
    }
}

public class B : A
{
    public B(int b1, int b2) : base(b1, b2)
    {
        // Do your stuff
    }
}

I wanted here, by calling B ctor, to make some manipulations over b1 and b2 (before calling the base ctor), but encountered with a PROBLEM.

So, take a look on this solution:

public static B CreateBObject(int c1, int c2)
{
    // Do some manipulation over c1 and c2

    return new B(c1, c2);
}

private B(int b1, int b2) : base(b1, b2)
{
    // Do the rest of your stuff
}

Some explanations:
I created again B ctor, which the only different from the other B ctor is by that it is private (in other words: this object cannot be initialize from outside this class).
Now, the addition... I added a static method called CreateBObject, which receives the same params, does some manipulation over them, after it calls the B's private ctor and returns B object like we wanted in the first time.

Nice, huhh? I would like to have some comments

p.s.
Thanks Boaz

Posted by: Eran Nachum (c)
Post Date: 3/25/2007 5:33:02 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | Comments [3] | Trackback   #
 Monday, March 19, 2007

Hello guys, how are you?

In this post I wanted to talk about some code managing. As we all know (the Microsoft environment developers of course...) the 'natural' way, that Microsoft pushes into, that exists (if you are working with Visual Studio) is to work against Visual Source Safe. In all my (3 years) career progress I was working against this tool, which was not so bad, but in fact, it has some disadvantages and problems (do not mention the incidents of code losting and lack of doing merging between code files).

So, let's talk about the SubVersion control system and give some overview about this open source and free product.
'The goal of the Subversion project is to build a version control system that is a compelling replacement for CVS in the open source community. The software is released under an Apache/BSD-style open source license.' (taken from the SubVersion site).

OK, some basics facts:

  1. FREE FREE FREE - As they claims (in the above paragraph) this product is free to use, so you don't need to buy this kind of a tool (if you are lack of money... :))
  2. Directories, renames, and file meta-data are versioned. Lack of these features is one of the most common complaints against each source control. Subversion versions not only file contents and file existence, but also directories, copies, and renames. It also allows arbitrary metadata ("properties") to be versioned along with any file or directory, and provides a mechanism for versioning the `execute' permission flag on files.
  3. Apache network server option, with WebDAV/DeltaV protocol. Subversion can use the HTTP-based WebDAV/DeltaV protocol for network communications, and the Apache web server to provide repository-side network service. This gives Subversion an advantage over CVS in interoperability, and provides various key features for free: authentication, wire compression, and basic repository browsing.

and more...

I found this tool best to use now, because in the existing project that I am working on, the work is also overseas (I am working commonly with developers in the US), and the only tool that provides that is the SubVersion.
Another good thing is that I can get as much as I want a file to work on, and even if another developer is working on it in the same time, at the end of the work SubVersion will know to merge the code in a smart way, which Visual Source Safe run into problems occasionally.

So, if you want to explore some more details about it and download it you can go to the SubVersion site at: http://subversion.tigris.org/

Comments will be appriciated.

Posted by: Eran Nachum (c)
Post Date: 3/19/2007 10:57:22 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | Comments [0] | Trackback   #