Programming Style, Code optimization and efficiency

Discussions about development of VICIDIAL and astGUIclient

Moderators: gerski, enjay, williamconley, Op3r, Staydog, gardo, mflorell, MJCoate, mcargile, Kumba, Michael_N

Programming Style, Code optimization and efficiency

Postby scottgutman » Mon Sep 07, 2009 10:42 am

Matt, this is for you(I know the stickies say not to do this). I would like to ask you about choices made in creating vicidial.

Has anyone suggested loading vicidial into a framework like Drupal? I know that CMS's have a heavy Overhead, so the answer seems obvious. I just wanted to know if there was more.

I am curious about some of the style of coding in the scripts and I wondered if this is just your style or if there is some performance enhancement.

1. Function Modules. I noticed that there is little use of functions in the scripts. I like to reuse code as much as possible, is that a mistake? The only problem I have with functions is passing all the Global Vars needed to make it work.
2. While loops on SQL with limit 1. Why not just test for a record and grab the array?
3. > or < instead of ==. I noticed that when checking flags, that the tendency is to see if the number is greater than 0.
4. When parsing the Get/Post variables, why not load them into any array? I use:
//Load all Data into an array
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$g = array_change_key_case($_GET,CASE_LOWER);
} else {
$g = array_change_key_case($_POST,CASE_LOWER);
}

I guess it is a little messy with $g['something'], but seems to limit my spelling mistakes and is a little easier to read???.
5. In vicidial.php why not seperate the javascript functions into a functions.js script and just include it?
6. I know that someone mentioned skinning and I think I saw a mockup that looked good. Has there been any interest or progress in this? This idea could also flow into the Drupal idea, at least for the admin section??

What kind of IDE software do you use to Code/Debug, Etc.? I am using Rapid PHP 2008 and notepad++ on a MS Vista Box. Is there something better that you like or recommend?

I hope non of this offends you. if yes, please delete this post.
Dialer-Vicidial 2.2.0-250_100116-0709, Asterisk 1.4.21.2, Intel Quad Q6600 2.4G x64/8G Ram
Web-Apache/2.2.3, PHP 5.2.10, eAccelerator v0.9.5.2, AMD 9950 Quad 2.6G x64/4G Ram
DB-MySQL 5.0.45, 2xAMD 2.6G i386/4G Ram
OS-CentOS 5.3-2.6.18-128.1.16.el5
scottgutman
 
Posts: 75
Joined: Mon Mar 23, 2009 4:17 pm

Re: Programming Style, Code optimization and efficiency

Postby mflorell » Mon Sep 07, 2009 8:20 pm

Has anyone suggested loading vicidial into a framework like Drupal? I know that CMS's have a heavy Overhead, so the answer seems obvious. I just wanted to know if there was more.


ViciDial is too complex for a CMS, none of them can handle nested AJAX, or some of the other complex multi-layered taskes without blowing up. Unfortunately this means that almost everything has to be hand-coded.

I am curious about some of the style of coding in the scripts and I wondered if this is just your style or if there is some performance enhancement.


Some of the style (or lack thereof) is because I started writing the code in 2003, and my coding has gotten better over the years.

1. Function Modules. I noticed that there is little use of functions in the scripts. I like to reuse code as much as possible, is that a mistake? The only problem I have with functions is passing all the Global Vars needed to make it work.


I've started to use some functions, but usually there are changes from one set of code to another which is why I haven't reused that as much.

2. While loops on SQL with limit 1. Why not just test for a record and grab the array?


In most places I do, and I've been changing to that as I see the limit-1-while-loops as I go through the code recently.

3. > or < instead of ==. I noticed that when checking flags, that the tendency is to see if the number is greater than 0.


depending on the history of a variable == will not always work(don't ask me why, but I've run into it several times before), yet < or > will always work.

4. When parsing the Get/Post variables, why not load them into any array? I use:
//Load all Data into an array
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$g = array_change_key_case($_GET,CASE_LOWER);
} else {
$g = array_change_key_case($_POST,CASE_LOWER);
}
I guess it is a little messy with $g['something'], but seems to limit my spelling mistakes and is a little easier to read???.


I used to do that actually, until a security expert yelled at me for it(in TEXT of course). He said it opens up too many possibilities for exploitation, and that specifying only the exact variable you want is safer.

5. In vicidial.php why not seperate the javascript functions into a functions.js script and just include it?


Because there is a lot of that javascript that is dynamically generated by the PHP, and understanding the flow of the code is easier(to me at least) if it is not separated.

6. I know that someone mentioned skinning and I think I saw a mockup that looked good. Has there been any interest or progress in this? This idea could also flow into the Drupal idea, at least for the admin section??


There has been interest, and I've seen a few versions of it, but they can never seem to keep up with the rapid development pace of the project and they usually end up forking or abandoning their efforts. As for the agent interface, I'm sure you could surround it in a CMS, but there would still need to be thousands of lines of custom code needed to actually make it work.

What kind of IDE software do you use to Code/Debug, Etc.? I am using Rapid PHP 2008 and notepad++ on a MS Vista Box. Is there something better that you like or recommend?


vi or Emacs(when on Linux), Editplus(when on Windows). I've used them for years, it's just what I'm most comfortable with for now.

I hope non of this offends you. if yes, please delete this post.


Of course not, I like open discussion like this :)
mflorell
Site Admin
 
Posts: 18341
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Postby scottgutman » Mon Sep 07, 2009 8:40 pm

Thank you.


I appreciate the answers. They do help :)
Dialer-Vicidial 2.2.0-250_100116-0709, Asterisk 1.4.21.2, Intel Quad Q6600 2.4G x64/8G Ram
Web-Apache/2.2.3, PHP 5.2.10, eAccelerator v0.9.5.2, AMD 9950 Quad 2.6G x64/4G Ram
DB-MySQL 5.0.45, 2xAMD 2.6G i386/4G Ram
OS-CentOS 5.3-2.6.18-128.1.16.el5
scottgutman
 
Posts: 75
Joined: Mon Mar 23, 2009 4:17 pm

Postby scottgutman » Tue Sep 08, 2009 7:52 am

2 More Q's
1. Comments. I heavily comment my code(I got lowsy memory,Need an upgrade), but I use syntax highlighting to make it easier to read. I noticed that it is not as "pretty" in black and white(vi). Is there any advantage to not having them?

2. Security Question.
I used to do that actually, until a security expert yelled at me for it(in TEXT of course). He said it opens up too many possibilities for exploitation, and that specifying only the exact variable you want is safer.

So, after we explicitly get the variable from $_POST/$_GET, can we then load it into an array and still be secure?
Dialer-Vicidial 2.2.0-250_100116-0709, Asterisk 1.4.21.2, Intel Quad Q6600 2.4G x64/8G Ram
Web-Apache/2.2.3, PHP 5.2.10, eAccelerator v0.9.5.2, AMD 9950 Quad 2.6G x64/4G Ram
DB-MySQL 5.0.45, 2xAMD 2.6G i386/4G Ram
OS-CentOS 5.3-2.6.18-128.1.16.el5
scottgutman
 
Posts: 75
Joined: Mon Mar 23, 2009 4:17 pm

Postby mflorell » Tue Sep 08, 2009 5:19 pm

Please show an example of how you do syntax highlighting.

As for loading variables into an array, sure you could do that, but at this point I don't really want to spend the time to convert everything.
mflorell
Site Admin
 
Posts: 18341
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Postby scottgutman » Tue Sep 08, 2009 10:24 pm

Syntax highlighting is actually part of the program I use. I have 3 that I use.

Notepad++ is a nice program for syntax highlighting. It's open source and you can download it at http://notepad-plus.sourceforge.net/uk/site.htm

just install it and load a script. it usually can tell the syntax from extension. For .agi scripts, change the lang to perl and poof it works.

There is so much in there, that I find a new toy to play with every week. But, you can still use it right out of the box with delay.
The only thing that I don't like is that it is not logic aware, it won't help you debug by checking the syntax or list the functions in the code. It just changes the color and highlighting of the test. Now that I think about it, we could probably make a highlighting profile for Asterisk conf files. hmm.
Another cool feature is RegEx Find and Replace.

Another is RapidPHP 2008. This is good for php, html, js combo scripts and is Logic aware. it will let you know if your missing a ";" and you can load the PHP debug program into it to debug directly. Again good highlighting.

And an old favorite is primalscript. I think this is better suited for M$ but can do alot.

As far as loading the variables, I am working on a way for us to have our cake and eat it too. hopefully the variables will be loaded with a single line of code, to 1 function that will create backward compatible vars and a global array while doing the security check for non alpha-numeric symbols. It might even work:)

I am thinking to create a lib_func.php and load it similarly like db_connect.php.

I need to get it done asap, or my users will fry me:)
Dialer-Vicidial 2.2.0-250_100116-0709, Asterisk 1.4.21.2, Intel Quad Q6600 2.4G x64/8G Ram
Web-Apache/2.2.3, PHP 5.2.10, eAccelerator v0.9.5.2, AMD 9950 Quad 2.6G x64/4G Ram
DB-MySQL 5.0.45, 2xAMD 2.6G i386/4G Ram
OS-CentOS 5.3-2.6.18-128.1.16.el5
scottgutman
 
Posts: 75
Joined: Mon Mar 23, 2009 4:17 pm

Postby mflorell » Wed Sep 09, 2009 9:18 pm

There is already a functions.php in SVN trunk that you can start working from, which is where you should be doing all development in anyway.

2.0.5 is basically a dead branch that will be unsupported in a few months after 2.2.0 is released later this year.
mflorell
Site Admin
 
Posts: 18341
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Postby scottgutman » Thu Sep 10, 2009 10:46 am

I was thinking about that. Are there any pitfalls to upgrading to the SVN? Things are working well on the floor and I would hate to ruin that.
Dialer-Vicidial 2.2.0-250_100116-0709, Asterisk 1.4.21.2, Intel Quad Q6600 2.4G x64/8G Ram
Web-Apache/2.2.3, PHP 5.2.10, eAccelerator v0.9.5.2, AMD 9950 Quad 2.6G x64/4G Ram
DB-MySQL 5.0.45, 2xAMD 2.6G i386/4G Ram
OS-CentOS 5.3-2.6.18-128.1.16.el5
scottgutman
 
Posts: 75
Joined: Mon Mar 23, 2009 4:17 pm

Postby mflorell » Thu Sep 10, 2009 9:04 pm

I don't know of any pitfalls, we are running recent SVN trunk versions at all of our maintained client sites without any major issues.
mflorell
Site Admin
 
Posts: 18341
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Postby scottgutman » Thu Sep 10, 2009 9:19 pm

ok, once more into the breach--

See you on the other side.
Dialer-Vicidial 2.2.0-250_100116-0709, Asterisk 1.4.21.2, Intel Quad Q6600 2.4G x64/8G Ram
Web-Apache/2.2.3, PHP 5.2.10, eAccelerator v0.9.5.2, AMD 9950 Quad 2.6G x64/4G Ram
DB-MySQL 5.0.45, 2xAMD 2.6G i386/4G Ram
OS-CentOS 5.3-2.6.18-128.1.16.el5
scottgutman
 
Posts: 75
Joined: Mon Mar 23, 2009 4:17 pm

Postby mflorell » Thu Sep 10, 2009 9:28 pm

Make sure you read and follow ALL of the UPGRADE document change points when you upgrade from 2.0.5 to SVN trunk
mflorell
Site Admin
 
Posts: 18341
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida


Return to Development

Who is online

Users browsing this forum: No registered users and 18 guests