SolvedPrivate

a general code/script question

Posted on 2014-09-24
6
33 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 84

Assisted Solution

by:ozo
ozo earned 250 total points
Comment Utility
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
Comment Utility
Great thank you for the insight!
0
 
LVL 108

Expert Comment

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now