a general code/script question

Posted on 2014-09-24
Last Modified: 2016-02-17
I'm  working on a project that happens to be using AMPScript in ExactTarget / SalesForce.

The project involves getting a bunch (about 65 values) from various columns in a table (in their lingo a "data extension") and displaying the values in the html body of a email (basically an html page).  This is done using AMPScript which is their in house scripting language for doing this kind of stuff.  It's all done within the document body and there are no external include files etc.  So with about 65 values should I make a block at the top of the document assigning each value or should I just assign the value inline in each instance.  It's on a cloud service and I don't expect any performance constraints with using variables.

For example:

<doc start>
var thing1 = go get the value from the data extension;
var thing2 = go get the value from the data extension;
var thing3= go get the value from the data extension;
var thing4 = go get the value from the data extension;
var thing5 = go get the value from the data extension;
etc etc etc 65 times

Here is the value of thing1= %%thing1%%

Here is the value of thing2= %%thing2%%

Here is the value of thing3= %%thing3%%

OR shoud I use this approach?

Here is the value of thing1= %%go get the value from the data extension;%%

Here is the value of thing2= %%go get the value from the data extension;%%

Here is the value of thing3= %%go get the value from the data extension;%%
etc etc 65 times

I would say the first approach is cleaner and more professional but in the real world which is the best practice?
Question by:tf2012
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 84

Expert Comment

ID: 40341513
If your in house scripting language  supports any kind of arrays or loops, I would not want to write essentially the same code 65 times.

Author Comment

ID: 40341586
Good point, but the variable names do differ quite a bit, there isn't any real pattern in the variable names that would support the use of a loop unfortunately.
LVL 110

Accepted Solution

Ray Paseur earned 250 total points
ID: 40341722
Having assigned variables (#1 approach) can make the coding easier when you need to extend the logic.  Having these assigned variables in an array or JSON object can help keep the code cleaner with less risk of variable name collisions.
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

LVL 84

Assisted Solution

ozo earned 250 total points
ID: 40341775
If the syntax is literally as presented in the example, then I don't see how #1 makes extending the logic any easier.  Rather it seems to double the opportunities to make a mistake.

If the names without any real pattern can be listed in one place where the part of the code that stays the same can loop over them, that would seem to minimise opportunities for mistakes and interdependancies between different parts of the code.

Author Closing Comment

ID: 40341889
Great thank you for the insight!
LVL 110

Expert Comment

by:Ray Paseur
ID: 40341894
seems to double the opportunities to make a mistake
That's why I also wrote the second sentence!

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question