What comments do you write in your check-ins/commits?

That’s how Linus Torvalds does it. I like his style. Here’s one example:

Import: always open and read the file before checking the filename ex…
…tension

Most of the parsers will want the content in memory,
so keep them simple. The fact that the Suunto parser
uses "libzip" that has to re-open the file is annoying
and causes us to re-open the file etc.
But it's the odd man out, so don't design the
"open_by_filename()" function around it. Pretty much
everybody else will want to avoid having to cook up
their own IO routines.

Also, when reading the file, NUL-terminate the buffer.
This allows us to just treat text files as large strings
if we want to, and doesn't matter for binary files (we
still pass in the length explicitly).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

 

Note the use of present tense, e.g. “Import..”, rather than past tense, “Imported”. Present tense better applies to Git workflow, where all check-ins can be “replayed” many times for many different repositories. If you want to replay a check-in (or “pull” in Git’s terminology), the heading tells you what it does (rather than what it did).

A more formal definition for the comment would be:

  1. Heading – a short one-line explanation of the commit. Limit to 72 characters. Use present tense.
  2. Empty line – to separate the body, unless your source control system provides a separate field for the heading.
  3. Body – one or several paragraphs of details:
    1. Wrap paragraphs at 72 characters.
    2. Separate paragraphs with empty lines.

“Singed-off-by” may not necessary for commercial projects. It’s used by some open-source projects to confirm the copyrights and transfer them from developers to projects.

Merging .NET assemblies into one executable with ILMerge

Splitting code into assemblies in .NET is a useful technique that enables building scalable applications. But, it produces an executable with a number of satellite assembles. All of them need to be deployed to the target system for the app to work. Most of the time installers (MSI-packages) handle this task. But, sometimes it would be very convenient to have one self-contained executable file to share with someone for quick testing by e-mail or Dropbox (or any other service).

I looked at several tools including SmartAssembly from Red Gate and ILMerge from Microsoft. SmartAssembly has a nice GUI and works fine, but pricey at > $795. ILMerge, on the other hand, is a command line tool, is free and works just as fine. The syntax is simple:

ilmerge /target:winexe /out:SelfContainedProgram.exe Program.exe ClassLibrary1.dll ClassLibrary2.dll

ILMerge doesn’t come with Visual Studio or an SDK, so you have to download and install it. For a more detailed description of ILMerge I also recommend this article on Code Project.

 

Distilled : A Visual Guide To Internal Innovation

An excellent visual guide on innovation process was posted by Distilled, a London-based SEO agency. I’ve pasted a one-image summary below, but I strongly recommend reading the entire post.

Connecting applications with PubNub

PubNub offers a seamless way to connect web (and other) applications. In the simplest scenario you’d write a couple of lines of code in both applications and PubNub will take care of the rest of communication:

Example of the code:

More on their website.

Jettison – auto-ejecting external drives for Mac

I’ve been using my Macbook for a few years with external USB hard-drives – for backup and just to have extra storage. The problem with this setup is whenever I grab the laptop to go I end up with the “The disk was not ejected properly” message:

The disk was not ejected properly Mac OS X error message

Manually ejecting external drives every time just was not compelling. For a while I ignored the message (and the fearful consequences it promised) but it just annoyed me too much. Eventually I gave up and manually connected an external drive when I needed it. A less than seamless solution.

Then I stumbled on Jettison, which solves this very problem. Jettison auto-ejects all external drives (configurable) whenever your Mac goes to sleep. So, just close the Mac’s lid while Jettison is running and in a couple of seconds you’re good to go (there’ll be a beep). Nice solution.

Conditional compilation in AS3

Starting with SDK 3 Flex ActionScript compiler supports conditional compilation that can be used similarly to #if/#else pragmas in C# or C++. It works somewhat differently, but it’s pretty close.

To use it define a compile-time constant in your debug build, e.g.

–define=BUILD::DEBUG,”true”.

In Flash Builder it’s done in “Flex Compiler” tab of the project properties. Alternatively, you can define it in the command line:

mxmlc -define=BUILD::DEBUG,”true”,

or in your ANT build (if you use it):

<mxmlc … >
<define name=”BUILD::DEBUG” value=”true”/>
</mxmlc>

In your release build define the same constant as

–define=BUILD::DEBUG,”false”.

Then you can use it in the code like this:

public class Debug
{
    public function assert(condition : Boolean) : void
    {
        BUILD::DEBUG
        {
             if (!condition)
             {
                throw new Error("Assertion failed");
             }
        }
    }
}

 

This function will behave similarly to Debug.Assert() in C# or assert() in C++. It’ll throw an exception in the debug build, but will do nothing in the release. If you’re not familiar with assertions, this Wikipedia article can get you started.

You can also include/exclude entire methods and classes. Check out Adobe’s documentation (PDF) for more details and examples.