SolvedPrivate

a general code/script question

Posted on 2014-09-24
6
37 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
  • 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 108

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 108

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Salesforce.com is a cloud-based customer relationship management (CRM) system. In this article, you will learn how to add and map custom lead and contact fields to your Salesforce instance.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now