Announcement

Collapse
No announcement yet.

why is premain() executed twice?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • why is premain() executed twice?

    Can someone tell me why sss is printed twice on Formulat oupput window, which means premain() is executed twice? I tested it on (SPY, D)?


    var sss = 0;
    function preMain() {

    sss = sss + 1;
    debugPrintln("sss = " + sss);

    }


    function main() {


    }

  • #2
    Hi,

    I know this is an obvious question...but is there any chance you have it loaded more than once on the chart?

    I have never seen PreMain() executed more than once (unless I reload).

    Garth
    Garth

    Comment


    • #3
      No. I only had one chart running while I tested it. Another strange thing I found out today is that premain() is never executed while using reloadEFS() to reload the EFS. There are too many undocumented details on how and when premain() and main() are called. For ordinary users, maybe the current discription in the help file is enough. However when someone is serious about doing something truely complicated, it is almost guaranteed that he will encounter one undocumented mysterious behavior ( not necessarily bug ) or bug in eSignal EFS every week.


      Originally posted by gspiker
      Hi,

      I know this is an obvious question...but is there any chance you have it loaded more than once on the chart?

      I have never seen PreMain() executed more than once (unless I reload).

      Garth

      Comment


      • #4
        Another strange thing I found out today is that premain() is never executed while using reloadEFS() to reload the EFS.
        This isn't strange, it is very deliberate, as is the fact that local globals are not reset when reloadEFS is run. It allows a wider range of options on how to implement things. Of the small number of formula's that are out there that use reloadEFS(), many of those would not work if it wasn't handled this way.

        There are too many undocumented details on how and when premain() and main() are called. For ordinary users, maybe the current discription in the help file is enough. However when someone is serious about doing something truely complicated, it is almost guaranteed that he will encounter one undocumented mysterious behavior ( not necessarily bug ) or bug in eSignal EFS every week.
        Yes, but this is true of ANY large piece of software. Does this justify it - well as long as consumers don't complain too loudly I guess it does. Like corruption in politic's, it will not go away as long as the average joe doesn't complain and fight against it.

        The big problem in this case wrt documentation on the mechanic's of execution is that while most programmers are very used to playing with code to figure out how things work (because it is usually not well documented) - most of the people coding EFS are programmers...they are traders. They don't want to have to "play with the code" at all. They just want to get it done.

        The good news is that things are being worked on to make the programic interface simpler and easy to use.

        BTW, feel free to post up the code with the issue...I will take a look at it and try to see why it does what it does.

        Garth
        Garth

        Comment


        • #5
          most of the people coding EFS are programmers...they are traders
          This of course, should say that they are NOT programmers...
          Garth

          Comment


          • #6
            Hello Clearpicks,

            I've tested your code example and I'm only getting one execution of preMain(). I'm not sure what could be causing this on your end. If this behavior you're experiencing is causing a problem with a formula you're working on may I suggest using a global flag to prevent the second execution. Try the following:

            PHP Code:
            var sss 0;
            var 
            vFlag false;

            function 
            preMain() {
                if (
            vFlag == false) {
                    
            sss sss 1;
                    
            debugPrintln("sss = " sss);
                    
            vFlag true;
                }
            }


            function 
            main() {



            Jason K.
            Project Manager
            eSignal - an Interactive Data company

            EFS KnowledgeBase
            JavaScript for EFS Video Series
            EFS Beginner Tutorial Series
            EFS Glossary
            Custom EFS Development Policy

            New User Orientation

            Comment


            • #7
              Thanks. I know how to work arround this kind of issues. I am not sure what caused it either. Maybe it is because yesterday was Sunday. I will test it again next weekend.



              Originally posted by JasonK
              Hello Clearpicks,

              I've tested your code example and I'm only getting one execution of preMain(). I'm not sure what could be causing this on your end. If this behavior you're experiencing is causing a problem with a formula you're working on may I suggest using a global flag to prevent the second execution. Try the following:

              PHP Code:
              var sss 0;
              var 
              vFlag false;

              function 
              preMain() {
                  if (
              vFlag == false) {
                      
              sss sss 1;
                      
              debugPrintln("sss = " sss);
                      
              vFlag true;
                  }
              }


              function 
              main() {



              Comment

              Working...
              X