Using a programming language of your choice, write the
code to reverse each word in the email message. (e.g.
'programming' becomes 'gnimmargorp').
What is the most important aspect of coding (e.g.
simple to understand, efficiency, elegance, etc.) to you?
How is that aspect demonstrated in your code example
above?
I have been an independent software consultant for the
past several years. I feel that the most important aspect of
programming is to meet the requirements of my customer in a timely
fashion. Elegance in coding is lost upon the client or end user; they
simply want the software to work.
Poorly written code has a tendency to haunt the writer, or worse yet,
the person who takes over the project. I feel that all code should be
written from the standpoint of maintenance by being consistent, having
intelligent variable & function names, proper error checking with clear
error messages, and liberal use of comments and whitespace.
Looking at my code:
[1] This is a fairly simple script written in the perl programming
language. Perl is a strong language for string manipulation because of
its regular expression and handy built-in functions like the "replace()"
function that reverses the letters in a string. It is also useful from
the standpoint of portability, i.e. this same script, with only minor
modifications, will run on my Linux box.
[2] Note the comment section at the top that tells the script name, what
the script does, and assumptions made when writing the code. I also add
a "Change Log" depicting date, my initials, and description of the
change.
[3] The script uses tab indentation where tabs are set to 4 spaces. I
have run into code that uses tabs or spaces indifferently making the
code difficult to follow in another editor. This script consistently
uses only tabs for indentation.
[4] Variable names use a composite of a three letter identifier of what
the expected type will be, in this case 'str' suggests that the
variables will hold strings. Types are not as important in perl, but it
can be handy to the programmer to know what the variable expects.
[5] Comments are used liberally throughout the code to describe what is
going on in that block or line. Years down the road it will be much
easier/faster to understand the English comments than the actual code.
This is especially true in perl when using robust regular expressions.
[6] The variable $strReversedWord did not need to be defined; I could
have simply printed the result rather than storing it in a variable.
However, the variable is named such that it aids in clarification of
what the code is doing. Also, any future changes to this script that
require manipulation of the reversed word will be implemented more
easily.
|