잊지 않겠습니다.

In C++ or No GC enviroment, we have two serious problems in windows programming.

  • deletes other objects to which the object holds pointers
  • closes handles to resource

And .NET cannot release unmanaged resource automatically. so .NET prepared Finalize() method to dipose unmanaged resource.

In VB.NET : actually write the Finalize() method

In C# : pseudo-destructor with the ~NameOfYourClass() -> C# Compiler creates the Finalized() method using the code when we write in the specialized pesudo-destructor.

 

Writing Finalize() is rarely a good idea

if you don't use unmanaged resource, Don't write the Finalize() method. It make inaccessible instances and delay the cleanup.

 

Releasing managed resources in Finalize() can wreak havoc

Don't access managed resources with in the Finalize() method. If you access managed resource, it cannot be predicted.

Also, don't call any methods on other objects, or even set their reference to null/Nothing.

 

Rules to invoke base.Finalize() aren't consistent

In VB.NET, you write Finalize() method as a protect method but you only write pseudo-destructor in C#.

so you don't invoke the base class's Finalize() method in C# but you must invoke the base class's Finalize() method in VB.NET.

 

Depending on the Finalize() can tie up critical resources

.NET provides a mechanism to support synchronous cleanup fo resource used by object. : IDisposable interface

If you want to clean up your unmanaged resource synchronously, you can write Dispose() method used IDisposable interface.

 

Using Finalize() on disposed objects is costly

It's better to Dispose() an object than to depend on Finalize() method because Dispose() let you control the clean up of an object.

and Dispose() should have already taken care of its resources, both managed and unmanaged resources.

Calling Finalize() on an object involves overhead. This should be avoided as mush as possible. From within your Dispose() method, call GC.SuppressFinalize().

Posted by Y2K
,

What are the things you need to remember to make your code interoperable between language?

Common language specification complicance isn't the default

Operation overload : not Common Language Specification(CLS)

CLS-Compliant : add [Assembly:system.CLSCompliant(true)] 를 넣어줘야지 된다.

이는 Language가 다를때, 서로간에 CLS에 대해서 명확한 정의를 따르는지에 대한 Compiler level에서의 정의가 될 수 있다.

 

Optional parameters break interoperability

VB.NET에서 허용되는 option parameter의 경우에는 C#에서는 허용되지 않기 때문에, 반드시 그 값을 적어줘야지 된다.

 

Mixing case between class members breaks interoperability

VB.NET에서는 각 값의 case에 따라서 다른 Property, member, method를 가질 수 있다. 이는 VB.NET과 C#을 섞어서 사용하는 경우에 CLS를 위반하게 된다.

 

Name collision with keywords breaks interoperability

VB.NET에서 사용되는 Stop()의 경우에는 code break로 사용되기 때문에, 이름에 의한 충돌이 일어날 수 있다. 언어의 종류에 따라 method의 이름을 명명할 때 주의해야지 된다. 

 

Defining an array isn't interoperability

VB에서 자주 일어나던 문제. VB의 경우에는 Array의 크기의 선언이 아닌 Array의 max index의 선언이기 때문에 발생

int[] intDatas = new int[3]; <- size : 3
Dim intDatas() As Integer = new Integer(3) {} <- size : 4


Posted by Y2K
,

Singleton is't guaranteed process-wide

Singletone으로 만들어주는 static method의 경우에는 Process에 귀속되지 않는다.

.NET에서는 Singleton은 AppDomain에 유일한 존재로 staic 을 생성하게 된다.

   

Default performance of Data.ReadXML is poor

ReadXML의 경우에는 xsd 파일이 지정되어있지 않는 경우에는 매우 속도가 느리게 된다.

Data.ReadXML을 사용하는 경우에는 반드시 xsd 파일을 지정해줘야지 된다.

   

enum lacks type-safety

enum 형태는 int 형태에 의미를 부여할 수 있는 형태로, 사용이 매우 편한 형태이지만, int의 casting을 시켜줄때는 type-safety가 이루어지지 않기 때문에 사용에 주의를 해줘야지 된다.

   

Copy constructor hampers exensibility

Constructor에서 다른 객체의 copy를 만드는 형태의 경우에는 모든 객체의 값들을 같이 참조하는 형태로 만들어지게 된다. 따라서 하나의 객체의 값이 바뀌게 되면, 다른 객체의 값까지 바뀌게 되는 형태로 만들어지기 때문에 피하는 것이 좋다.

이러한 copy constructor의 문제는 C++, Java, .NET에서 모두 같이 발생하는 문제가 된다.

   

Clon() has limitations

"copy constructor hampers exensibility"와 동일한 문제가 발생한다.

MemberwiseClone()의 경우에도 역시 마찬가지로, 같은 문제가 발생하기 때문에, 두개의 각각 다른 id를 갖지만 같은 객체의 값을 갖는 copy본을 만들어주고 싶을 때는 주의가 필요하다.

   

Object initialization sequence isn't consistent

C#과 VB.NET에서의 Initialization sequence가 각각 다르다.

Base Class에서 someClass1을 선언과 동시에 초기화 시키고, Base Class를 상속받는 Derived Class가 someClass2를 선언과 동시에 초기화 시킬때,

C#
  1. someClass2 초기화
  2. someClass1 초기화
  3. BaseClass 초기화
  4. DerivedClass 초기화
VB.NET
  1. someClass1 초기화
  2. BaseClass 초기화
  3. someClass2 초기화
  4. DerivedClass 초기화

  

Polymorphism kicks in prematurely

Constructor에서 override가 될 수 있는 virtual 함수의 호출은 하지 않는다.

virtual 함수의 호출을 Constructor에서 시켜줄 경우에는 Derived Class에서의 초기화는 항시 Base Class의 virtual 함수를 호출하게 된다. override 된 자신의 함수를 호출하는 형태가 될 수 없다.

Posted by Y2K
,