水曜日, 8月 31, 2011

Java and C++ Exception Handling

Java and C++ differs in how to handle exceptions. In Java, every possible exception must be handled. In C++, the exceptions handling can be omitted.

The demerit of not having to write exception handling procedure is not of optimization but in the safe programming practice. The exceptions readied for the methods will be thrown away, which might cause some fatal errors. Java has it that those have to be taken care of. Every method that throws exceptions must declare as "throws Exception" or any exception class. When the method is called, it must be in the try-catch block.

The counter argument is that when exception handling can be omitted, the code can be short as pointed out by this g++ user(s), the program size will not be affected unless the exceptions are explicitly stated to be thrown and handled in case of the g++ compiler. You can safely ignore any error message the original library writer tried to warn you in calling the methods. And those who use the method won't be warned as well.

There is no way to assume that any method won't throw exceptions, unless explicitly stated as in Java code, as throws Exception. Going through all the possibilities to make sure that the method that you are calling does not call just any method that throws exceptions, is if not an impossible task then tedious work. Therefore, this practice may leave the programmer unsafe and the products made from those libraries.

火曜日, 8月 16, 2011

Why, just why?


The Professional edition of Visual Studio 2010 C++ does not compile dependent projects right. 

It does not compile the static or dynamic libraries even when the configuration is set to compile them.  This bug is more annoying since it says Rebuild All Succeeded when it is set to be compiled from the main project.  This can be avoided if the project is compiled separately. 

This is such a major bug that it is rather puzzling it is not set in that way, particularly in C++.  Could there a way to compile them all together?

土曜日, 8月 13, 2011

Visual Studio: Refactoring

Microsoft's Visual Studio has a very nice feature called 'refactor'.  It replaces the names of a method or function to whatever you rename it.  It does contextual search and replace.  The same name used in other namespace or scope will not be affected.  It alleviates all the troubles associated with renaming.  In the end, the code would come up closer to the final products no matter how you change your course of programming.

Visual Studio's C# refactor, however, is not perfect.  It replaces the names even when there are the same names within the scope.  There is no way to distinguish the variables that has renamed and the existing variables with the same name.  That certainly is detectable.  As for C++ version of the IDE, there isn't such a function to rename methods and variables with contextual searches.

土曜日, 8月 06, 2011

C#の列挙型

C#の列挙型は特殊です。

列挙型は、Cなどでは定数程度としか使えませんが、C#では名前を取得したり、オブジェクトから列挙型の値を得ることができます。

FontStyle fontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), (string)obj);




「今までと違う」列挙型は、なにも嫌がらせのためにあるわけではなく、これこそはコンピュータ科学の成果であり、技術の進歩...と声を大にして言いたいところですが、あまり主張すると「シカト」などの憂き目にあうのでリーマン稼業の人間には注意が必要です。

改革は、草の根から...ですね。

Qt: 外部プログラムを起動する

  Qt/C++ のアプリは、外部へ直接アクセスできます。これはネットアプリでは不可能な Qt のメリットです。 外部プログラムを起動することもできます。QProcess::startDetached() を使うと独立したプロセスを立ち上げることができます。 この QProces...