Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Many thanks to you for putting it together and to the forum members for taking the time to post their replies and give their time to help others. Their isn't another site that can touch it..."

Geography

Where in the world do Tek-Tips members come from?

Advice: Simplify your code

ndogg (Programmer)
14 Feb 00 16:36
I have seen lots of code for lots of different things. Much of what I've seen has lots of redundancy and in some languages can actually slow the program down. This redundancy also has a tendancy to make code harder to read. Take for example the following two (they're not language specific, they just take attributes almost universal to any language (these "//" are comments):
<pre>
function DoThis(n) // creates a function called DoThis with n parameters
if n = 0
then print "apples"
// print to the screen the word "apples"
else
if n = 1
then print "oranges"
// same as above except prints "oranges" instead
if n = 2
then print "pears"
else
if n = 3
then print "peaches"
end DoThis(n)
</pre>
the same code, simplified:
<pre>
function DoThis(n) // creates a function called DoThis with n parameters
array x[] = {"apples","oranges","pears","peaches"} // initializes the array x
print array[n] // prints the value of the array
end DoThis(n)
</pre>
Now tell me which code is easier to read.

REH
hawkdogg@crosswinds.net
Powered by Linux
Learn Linux and Leave out the Windows :)

MikeLacey (MIS)
16 Feb 00 10:04
REH,

With respect - could I suggest that you may be confusing conciseness with readability? My position would be that for all but the most trivial of cases future maintainability is key - rather than speed of execution or brevity of code.

With regard to your hypothetical function DoThis you are quite correct; the second example is easier to read. As a general principle however you are quite (IMHO) wrong. The more english-like your code (the more verbose) the easier it will be to read and maintain.

Regards

Mike

Mike Lacey
Mike_Lacey@Cargill.Com
Cargill's Corporate Web Site

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close