Gym? I Hardly Know Him

April 10th, 2008

24HourFitnessIf the definition of “computer specialist” can be stretched to include software engineers, then software engineering qualifies for Heather Boerner’s list of America’s Surprisingly Unhealthy Jobs. Though Boerner states that computer specialist jobs are associated with issues of ergonomics and her article appears to equate unhealthiness merely with injury, it is worth considering a sedentary work environment as a source of other health issues.

I have been developing software for more than full-time over the past two years. My day typically consists of working in front of a computer with some breaks for personal upkeep, which includes things like eating and sleeping. Unfortunately, physical activity was not included in my upkeep. It can be said that I’ve consumed a lot of calories or energy units without actually using them, and my body has been storing them daily in its own way.

I was looking to join a gym at the start of the year. The prices at that time were very high. The gym that is most convenient to me was charging and continues to charge above 50USD per month. That’s about 600USD per year, with some of it due at initiation. People can debate the value of my health and assign it a worth greater than 600USD per year, but I really could not make such a big financial commitment. The expense was just not financially feasible. So, I fished for a deal. I monitored the 24 Hour Fitness site on Mondays for the deals that they make available for only four hours, and I snapped up a deal for a year of membership at 200USD. That’s just about 17USD per month and is about the same amount that I would have paid at initiation for the club’s normal membership pricing.

I go to the gym every other day on average over the week. My workouts are fairly consistent. As it is early in my membership, I may decide to vary my routine at a later time. The current goal is to raise my heart rate and keep it high for a set period of time, and maybe burn some calories. I want to be able to eat what pleases me, but with some exercise, I hope to be able to slow the rate that my body stores the unused energy that I consume.

Trade Secret Protection

March 14th, 2008
Posted in Legal | 1 Comment

According to Classen’s A Practical Guide to Software Licensing for Licensees and Licensors, the following phrase may be helpful in marking an item as subject to contractual proprietary information clauses and agreements:

Proprietary and Confidential, © Copyright [Company Name] all rights reserved. (Classen 141)

Data Hiding in C

March 2nd, 2008

Object-oriented programming languages are described as supporting encapsulation, polymorphism, and data hiding. They provide powerful features that allow software components to be designed and implemented for change.

Observing the mechanisms in an object-oriented programming language can potentially lead to a parallel implementation in a procedural language. This allows some object-oriented design knowledge that has been refined through study and experience to be implemented in procedural languages such as C.

A Circle type is a typical classroom example of a user-defined data type. Getting an area or circumference are common operations performed on instances of a Circle type. In C++, a Circle type may be defined as follows:

class Circle
{
  double radius;

  public:
    Circle()
    {
      // not using init list here to make parallelism
      // with example C code more easily seen
      this->radius = 0;
    }

    void setRadius( double r )
    {
       this->radius = r;
    }

    double getRadius()
    {
       return this->radius;
    }

    double getCircumference()
    {
       return 2 * PI * this->radius;
    }

    double getArea()
    {
       return PI * pow( this->radius, 2 );
    }
};

Member functions, which are functions that are called to operate on objects, in object-oriented languages tend to have a reference or pointer, which may be implicit or explicit, to the object on which the function operates. The use of a struct and functions that accept a pointer to the struct instances provides similar behavior in C. C code that mimics the example C++ code is presented here:

typedef struct
{
   double radius;
} Circle;

void circle_construct( Circle *c )
{
  c->radius = 0;
}

void circle_setRadius( Circle *c, unsigned r )
{
  c->radius = r;
}

double circle_getRadius( Circle *c )
{
  return c->radius;
}

double circle_getCircumference( Circle *c )
{
  return 2 * PI * this->radius;
}

double circle_getArea( Circle *c )
{
  return PI * pow( this->radius, 2 );
}

An association between the functions and the data, which is accomplished through encapsulation in the C++ code, is made in the C code through a coding convention. The convention here directs the form of the function signature to be as follows:

returnType typeName_operationName( params )

Data hiding is accomplished by another coding convention. Instead of dependents on Circle objects operating directly on the Circle objects’ fields, the dependents shall only call functions that manipulate the object on behalf of the dependents.

Code that is dependent on Circle objects as implemented in C is presented below:

Circle c;

circle_init( &c );
circle_setRadius( &c, 3 );
printf( "%f", circle_getRadius( &c ) ); /* "3.0" */
printf( "%f", circle_getCircumference( &c ) ); /* "18.85" */
printf( "%f", circle_getArea( &c ) ); /* "28.27" */

circle_setRadius( &c, 4 );
printf( "%f", circle_getRadius( &c ) ); /* "4.0"  */
printf( "%f", circle_getCircumference( &c ) ); /* "25.13" */
printf( "%f", circle_getArea( &c ) ); /* "50.26" */

The above code is more insulated from change than code that accesses the Circle fields directly. A field for the circle’s color and functions that operate on that field can be introduced, for example, and the above code has a good chance of not requiring modification while having its behavior remain unchanged. Ignoring the possibility of floating-point approximation errors, as another example, the internal representation of the Circle type can be overhauled completely by changing the radius field into a field containing the circumference of a circle and modifying the associated functions appropriately, and a necessity of change in the above code remains unlikely. The ability to change the representation of a data type without modification to dependent code evidences this technique’s effectiveness in making code resilient to change.

Parallels to the idioms and adages of languages like C++ can be implemented in C. By mimicking the natural mechanisms of object-oriented languages. the benefits of those features can be introduced in procedural languages where such mechanisms are neither directly supported nor idiomatic.

Weekend Tech Supporter

February 12th, 2008

I spent the weekend by hunting down the reason a computer was running sluggishly. I noticed that the system would wait at the Microsoft Windows XP splash screen for a couple of minutes while starting up. I activated the task manager just as the desktop was being displayed. According to the information that it provided, a process was responsible for 99% of the processor load.

I deduced that the problem was spyware. I believed it would require some modification to the system. Because the system’s owner expressed concerns about data retention, I decided to perform a raw backup before I took corrective action. I rebooted the computer into a LiveCD version of CentOS 4.4, mounted an SMB share, and used the following command from linuxquestions.org:

dd if=/dev/hda | gzip -c \
| split -b 2000m - /mnt/smb/backup.img.gz.

A write back to the hard drive is performed with the following:

cat /mnt/smb/backup.img.gz.* | gzip -dc | dd of=/dev/hda

I thought that in order to improve performance, I would need to address the offensive process. I uninstalled a program called “Spyware Terminator,” the probable owner of the process that was eating up processor resources. I have known that AVG can consume 99% of the processing power at times as Spyware Terminator did, but I did not remove AVG, because of simple brand recognition. Perhaps due to my lack of IT work experience, I have never heard of Spyware Terminator, and it was one of my first targets for removal. It may be an excellent program from what I do not know.

The system seemed to perform better than it did before Spyware Terminator was removed, though it continued to stall on the Microsoft Windows splash screen. A friend suggested that I run AVG in safe mode. I did not think about doing that, because of my past failed attempts to install AVG in safe mode. I observed the computer stall as the listing of files that were being loaded during boot into safe mode was displayed. It seemed to stall on the same file, hup.sys, so I did a lookup on Google and found something about hanging on hup.sys and possible hardware faults.

While booting up the CentOS LiveCD earlier, I noticed messages regarding an inability to read hard drive sectors. The requests were timing out. I did not think much of it at the time. After all, GNU/Linux is a bit more verbose about problems than Microsoft Windows. I checked the event logger in Microsoft Windows, and it indicated a problem with the hard drive as well. I downloaded a hard drive test utility from the system’s hard drive manufacturer. The short self-test passed, but the long self-test failed.

The culprit of the computer’s degraded performance was isolated to a failing hard drive. Microsoft Window’s drive manager may report the drive as healthy, but a number of tools indicate that the problem is with the hard drive. I swapped out the hard drive, loaded the CentOS LiveCD, used dd to write the backup image of the original hard drive to the new hard drive, and rebooted into Windows.

Success was very apparent upon boot. The splash screen was displayed for seven seconds as opposed to the minute or two that it was displayed when the computer was first brought to me. With a sense of accomplishment, I polished up my work by applying updates, setting up auto-updates, and scheduling virus scans. I used ScanDisk and the disk defragmentation tool, and it was ready for release to the computer’s owner.

I believed that I eliminated the problem by removing Spyware Terminator, but I was not satisfied with the slight increase in performance. If it were my computer, I would investigate the problem further, and I did for this computer. Taking ownership in the technical tasks that I perform has helped me bring about quality in my work and satisfaction for the people who use the product of my work. As I take on jobs, I think about how I would want other people to do things for me. I also think about how I would want to do things for myself and apply those thoughts to tasks that are done for others. Not being satisfied with marginally acceptable results lead to the diagnosis of a problem that allowed for a significant increase in performance when resolved.

Functions, Parameters, and Global Variables in C

February 4th, 2008

When I define interfaces to the functions that I implement, I try to be explicit about the variables that the functions will examine and modify. From time to time, a global variable is necessary, and I typically employ intermediary functions for accessing such a variable. Avoiding the direct use of global variables within functions is a sound software implementation principle.

An ideal function under the functional programming paradigm operates only on its parameters and returns a single value. Functions that possess these attributes along with good function names are coherent and cohesive. The function is dependent entirely on its parameters. There are no implicit dependencies. As opposed to a function that operates on a global variable, for example, a function that operates only on its parameters can accept different parameters from its caller.

There are times when a global variable is required, and introducing accessor functions to provide access to these variables is highly recommended. One benefit that accessor functions provide is the possibility of implementing state validation. In general, using accessor functions allows for preprocessing before access to the global variable is provided. Using an accessor function, even if such a function simply returns the global variable, introduces another level of indirection. It effectively provides an interface to the global variable.

Like the good practice of keeping member fields of objects in C++ non-public and preventing dependents of those objects from acting on those objects’ data fields, a level of indirection should be introduced between a global variable and the code that depends on the global variable.