Go Premium for a chance to win a PS4. Enter to Win


a general code/script question

Posted on 2014-09-24
Medium Priority
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
  • 2
  • 2
  • 2
LVL 85

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 111

Accepted Solution

Ray Paseur earned 1000 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.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 85

Assisted Solution

ozo earned 1000 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 111

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

926 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