Browsing articles tagged with " Ray Mitchell"

Prefix vs. Postfix Increment and Decrement Operators in C++

Mar 23, 2012   //   by Ray Mitchell   //   Blog  //  2 Comments

Here is how most programmers new to C-based languages are taught to write for a loop:

for (int i = 0; i < someValue; i++) {
    // Do something
}

Unfortunately this starts programmers off on the wrong foot by teaching them the bad habit of using i++ (postfix increment) as the default way to increment a value.  Using ++i (prefix increment) would work just as well since the result of the increment expression is not used by the containing expression (the for loop).  Here is the equivalent code using ++i1:

for (int i = 0; i < someValue; ++i) {
    // Do something
}

It’s preferable to use prefix increment when the result of the increment is not used by the containing expression.  To see why, let’s first take a look at what the compiler generates when it encounters i++ and ++i.
Read more >>

Reference vs. pointer parameters in C++

Mar 2, 2012   //   by Ray Mitchell   //   Blog  //  No Comments

Reference and Pointer Parameters

A question that often arises when working with C++ is whether it’s better to use references or pointers for function parameters.  Both types of parameters provide the ability for a function to indirectly access an object in the calling environment.  This indirect access provides several benefits:

  1. The object referred/pointed to by the argument does not need to be copied in order for the function to have access to that object’s value
  2. The function can directly modify the object referred/pointed to by the argument
  3. The function can take parameters of types that do not allow copying

Read more >>

Generating Software Diagrams

Jan 13, 2012   //   by Ray Mitchell   //   Blog  //  No Comments

Introduction

In this post I’m going to describe how to automatically generate diagrams from source code.  I’ve found that diagrams provide the quickest path to understanding how a piece of software works.  Diagrams also provide a great means to discuss software at a high level.  They’ve proven invaluable in the software development and software consulting work I’ve done.

Often diagrams are created by hand.  Unfortunately hand-crafted diagrams are prone to manual mistakes and falling out-of-sync as the source code changes.  Many IDE’s can automatically generate diagrams from source code on the fly, but sometimes your IDE doesn’t provide the diagrams or options you want.  Being able to generate your own diagrams will give you the ability to create exactly what you need when you need it. Read more >>

Recent Posts