Thursday, September 22, 2011

C++ part 2 returning an object

The following code in C++ is not the same.

Fraction multiply(Fraction * f2) {
        return Fraction (m_Numer*f2->m_Numer, m_Denom*f2->m_Denom);
}
 
    Fraction multiply1(Fraction * f2) {
        Fraction a(m_Numer*f2->m_Numer, m_Denom*f2->m_Denom);
        return a;
    }


The first one return an actual object. And second is returning a local object which will be invalid after the method returns. Therefore the second method call will cause run-time error.

Wednesday, September 21, 2011

c++

After spending so many years programming in C#, I really appreciate how life make it so simple by language designers. Consider the following code written in c++:


Fraction a = b;

vs.

Fraction a;
a=b;

In C#, these 2 blocks of code are saying the same thing. It declares a variable and assigns it value b (i.e. a and b now pointing to the same object).

However, in C++, it is totally different. The first code block is to create an object of class Fraction by calling constructor(const & Fraction). The second block is to create an object with default constructor, and call the operator=(const Franction &). Depends on how you write your member functions of the class, the code might or might not work the way it looks.

I like C#'s version, since the code worked exactly it is read. Whereas, in C++, errors might be introduced.



dl

Friday, September 05, 2008

Error with Nant

It seems that the following error message can be fixed by create a new registry entry. I am not sure why it is missing.

Solution:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"sdkInstallRootv2.0"="C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727"


Error message:
C:\wiki>c:\nant\bin\NAnt.exe svn.build
NAnt 0.86 (Build 0.86.2898.0; beta1; 12/8/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net


BUILD FAILED

Failed to initialize the 'Microsoft .NET Framework 2.0' (net-2.0) target framewo
rk.

    Property evaluation failed.
Expression: ${path::combine(sdkInstallRoot, 'bin')}
                            ^^^^^^^^^^^^^^

        Property 'sdkInstallRoot' has not been set.

For more information regarding the cause of the build failure, run the build aga
in in debug mode.

Try 'nant -help' for more information



Monday, August 25, 2008

LizardTF : a much better alternative than Visual Studio TFS client

I highly recommend anyone whom works with TFS as his/her primary source control tool to give LizardTF a try. I especially likes the review sub-menu, 10 times better than TFS, since I sometimes making changes of a couple of hundreds files and can view the check-in items in a hierarchical view. Another reason is it categorized the items into 4 categories. IMHO Microsoft should hire the guy if they want to improve the usability of the product. :)

Personally, I use GIT while work offline to keep track of intermediate changes and update the TFS while a work item is done.

Tuesday, August 12, 2008

things that I do like in TFS

1. No shell integration. I do not understand why it is not a priority. I spend lots of time in Windows Explorer for adding, moving, deleting, and copying files. It is just impossible after I re-arrange a couple of folders and try to check-in the changes. No easy way to identify which files are added, moved, and deleted.

2. Bad integration with VS 2008. For example, it does not tell you if the file under the folder is modified until you expand the folder. Same apply for the project, you won't know if any file gets modified after you open/expand the project. It is not difficult thing to do, why it worked this way. No drag and drop support is another example. Lack of unified diff. I am not a mouse-clicker. I know I can get it from view pending change menu option. But what if I made 20 small changes to 20 files, I have to click through these 20 files to find out the changes I made.

3. No disconnect mode. I could not work offline, check-in the changes, and later synchronize with main server. Every operation needs to contact server. That explains why the performance is so slow and inconsistent via VPN. Sometimes it takes 15 seconds to open the property page of a project. It is extremely slow comparing VS 2008 without TFS installed. Luckly I have GIT installed on my local machine and used it keep intermediate changes and only update it when it is done.

I moved from SVN+TortoisesSVN+AnkhSVN, I felt the difference is day and night. In everyway, I felt the TFS is working against you not for you.

Things that so simple with SVN become impossible to do it or at least 10 times more difficult to do in TFS. Here is another example, I used a code generation tools that creates about 200+ .cs files which is part of the c# project. In SVN, every time I need to refresh the generated code, I just need to generate the code and refresh project by clicking the refresh icon under the Solution Explorer. Then I can then visually tell what files have changed since last check-out and I can do unified diff to find out all the updates. I do not think it is possible at all in TFS. What a shame!!!



Tuesday, July 15, 2008

How to extending default MSBuild script for Teambuild

I have been configuring and using Cruise Control .NET and NANT combination for my last project in my company. Everyone loves it, it takes only 10 minutes from the code check-in to generate the final deployable binaries. I even setup the an auto-deploy project so that when the latest code is generated, it will automatically deploy under the IIS. Everyone can monitor the project status via the little green icon in the system tray.

Since I was the person who was most familiar with compile/build process in the team, I undertook the task to setup a new build system and convert all existing projects into Team Foundation Server (TFS). Since I do not like hybrid solution, I set out to just use the MSBuild functionality. It was quite easy to configure the MSBuild agent. I did it with the following steps:

1. Install the Team Foundation Build from the TFS CD.
2. Make sure that you are granted access rights to Build Services via the Project Security dialog box.
3. Right-mouse click on the Builds and select Manage Build Agents and add a build agent that setup in step 1.
4. Right-mouse click on the Builds and select Add new Build Definition.
5. Under the Project File menu, you can have the TFS to create a default build file.
6. Complete the rest of menu options and click OK to save the changes.

Now you have a newly created build definition and you can launch it by right-mouse clicking and selecting Queue New Build. You should have the compiled binary files in the drop location in 5 minutes if your project is not too big.

The next thing comes is how to further configure it. Specifically there are 2 things I would like to do:

1. replace some place holder in the source files before compile
2. run the WISE setup module to create  final MSI files for distribution.

After a little bit digging in the Microsoft.TeamFoundation.Build.targets file, I found all the extension points that are available as the following. By create 2 targets (AfterGet and PackageBinaries) in the newly-created build definition file, I could archieve what I what to do here.



  <!-- Override this target to execute custom tasks before EndToEndIteration -->
  <Target Name="BeforeEndToEndIteration" />

  <!--
       Override this target to execute a task for customizing the build number and/or drop location.
       Make sure that the task outputs properties with the names 'BuildNumber' and/or 'DropLocation'.
    -->
  <Target Name="BuildNumberOverrideTarget" />

  <!--
       Override this target to execute a task for customizing the build number and/or drop location.
       Make sure that the task outputs properties with the names 'BuildNumber' and/or 'DropLocation'.
    -->
  <Target Name="BuildNumberOverrideTarget" />

  <!-- Override this target to execute custom tasks before clean -->
  <Target Name="BeforeClean" />

  <!-- Override this target to execute custom tasks after clean -->
  <Target Name="AfterClean" />

  <Target Name="BeforeCleanConfiguration" />
  <Target Name="AfterCleanConfiguration" />

  <!-- Override this target to execute custom tasks before cleaning an individual solution -->
  <Target Name="BeforeCleanSolution" />

  <!-- Override this target to execute custom tasks after cleaning an individual solution -->
  <Target Name="AfterCleanSolution" />

  <!-- Override this target to execute custom tasks before workspace initialization -->
  <Target Name="BeforeInitializeWorkspace" />

  <!-- Override this target to execute custom tasks after workspace initialization  -->
  <Target Name="AfterInitializeWorkspace" />

  <!-- Override this target to execute custom tasks before getting sources -->
  <Target Name="BeforeGet" />

  <!-- Override this target to execute custom tasks after getting sources -->
  <Target Name="AfterGet" />

  <!-- Override this target to execute custom tasks before labeling sources -->
  <Target Name="BeforeLabel" />


  <!-- Override this target to execute custom tasks after labeling sources -->
  <Target Name="AfterLabel" />


  <!-- Override this target to execute custom tasks before compilation -->
  <Target Name="BeforeCompile" />

  <!-- Override this target to execute custom tasks after compilation -->
  <Target Name="AfterCompile" />

  <!-- Override this target to execute custom tasks before the compilation of an individual configuration -->
  <Target Name="BeforeCompileConfiguration" />

  <!-- Override this target to execute custom tasks after the compilation of an individual configuration -->
  <Target Name="AfterCompileConfiguration" />

  <!-- Override this target to execute custom tasks before the compilation of an individual solution -->
  <Target Name="BeforeCompileSolution" />


  <!-- Override this target to execute custom tasks after the compilation of an individual solution -->
  <Target Name="AfterCompileSolution" />

  <!-- Override this target to execute custom tasks before associating changesets and updating work items -->
  <Target Name="BeforeGetChangesetsAndUpdateWorkItems" />

  <!-- Override this target to execute custom tasks after associating changesets and updating work items -->
  <Target Name="AfterGetChangesetsAndUpdateWorkItems" />


  <!-- Override this target to execute custom tasks before running tests -->
  <Target Name="BeforeTest" />


  <!-- Override this target to execute custom tasks after running tests -->
  <Target Name="AfterTest" />

  <!-- Override this target to execute custom tasks before the testing of an individual configuration -->
  <Target Name="BeforeTestConfiguration" />

 <!-- Override this target to execute custom tasks after the testing of an individual configuration -->
  <Target Name="AfterTestConfiguration" />

  <!-- Override this target to generate documentation. -->
  <Target Name="GenerateDocumentation" />

  <!-- Override this target to package all binaries for deployment. -->
  <Target Name="PackageBinaries" />

  <!-- Override this target to execute custom tasks before copying files to the drop location -->
  <Target Name="BeforeDropBuild" />

  <!-- Override this target to execute custom tasks after copying files to the drop location -->
  <Target Name="AfterDropBuild" />

  <!-- Override this target to execute custom tasks before the BuildBreak target -->
  <Target Name="BeforeOnBuildBreak" />

  <!-- Override the target to execute custom tasks after associating changesets on a build break -->
  <Target Name="AfterGetChangesetsOnBuildBreak" />

  <!-- Override the target to execute custom tasks before associating changesets on a build break -->
  <Target Name="BeforeGetChangesetsOnBuildBreak" />

  <!-- Override the target to execute custom tasks after associating changesets on a build break -->
  <Target Name="AfterGetChangesetsOnBuildBreak" />

  <!-- Override this target to execute custom tasks before work item creation -->
  <Target Name="BeforeCreateWorkItem" />

  <!-- Override this target to execute custom tasks after work item creation-->
  <Target Name="AfterCreateWorkItem" />



Tuesday, March 18, 2008

GWT(google Web Toolkit)

Recently I was doing feasibility study of implementation GWT for our next project.

The tool kit allows programmers write plain Java which be compiled into JavaScript for rich web front-end application. There is a Java to JavaScript compiler will compile the Java code to JavaScript while the library that comes with the tool kit will hide the any browser quicks for you. The resulting JavaScript code will only be load once on the client and only the data will be dynamically requested by the JavaScript code. I think it is wonderful programming model.

The issue I am running into is that since Javascript has so called Same Origin Policy . It prevents any scripts that try to request data from any servers other than the server that the scripts are loaded.

It is not much a problem for the GWT, the front-end development server happens to be the same back-end server if you are using built-in RPC calls. For me, I was going to use Microsoft IIS as my development back-end server. Since I am going to use Eclipse with GWT plugin as my front-end development environment, the JavaScript will be loaded from my front-end development server and will not be able to request any data from back-end server on a different port (it will violate the Same Origin Policy).

To work around the problem, I use a tool called Fiddler which allows you to modify the request on the fly. What you need to do it just download and install the software from the web site. Upon launching the Fiddler UI, press CTRL-R to open customized script editor (it can also be open via menu Rules | Customize Rules... ). Locate a function call OnBeforeRequest and insert the following lines:

        if (oSession.HostnameIs("MYAPP")) {
            if (oSession.PathAndQuery.StartsWith("/search")){
                oSession.host = "www.google.ca";
            }
            else {
                oSession.host = "127.0.0.1:8888";
            }
       
        }

It is quite self-explanatory. It basically says that if the host name is MYAPP, then rewrite the host name based on the requesting URL. In the example, if the URL is starting with "/search", it will send the request to "www.google.ca" otherwise it will send requests to localhost port 8888. It needs to customized to suit your needs.

After you set it up, you can now requesting paging via Internet Explorer (unfortunately it works only on IE). Try the following:


This will overcome the Same Origin Policy restriction for you since your JavaScript and back-end server will all appear as it originated from the same server.

It has the following drawbacks.
1. It does not work on Firefox.
2. The breakpoint has no effect if you invoking the page via the proxy. (I do not know why?)