SolvedPrivate

a general code/script question

Posted on 2014-09-24
6
51 Views
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?
0
Comment
Question by:tf2012
[X]
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
6 Comments
 
LVL 84

Expert Comment

by:ozo
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.
0
 
LVL 1

Author Comment

by:tf2012
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.
0
 
LVL 110

Accepted Solution

by:
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.
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 84

Assisted Solution

by:ozo
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.
0
 
LVL 1

Author Closing Comment

by:tf2012
ID: 40341889
Great thank you for the insight!
0
 
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!
0

Featured Post

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!

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

735 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