Web Analytics Made Easy -
StatCounter JavaScript/DHTML newbiew -- general questions - CodingForum

Announcement

Collapse
No announcement yet.

JavaScript/DHTML newbiew -- general questions

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

  • JavaScript/DHTML newbiew -- general questions

    Hi all,

    I am new to Web programming, most of the time have done GUI development in C++/MFC and played a bit with Java/Swing.
    I have read about DHTML and its ability to enable interactive Web applications.
    Before delving into DHTML programming I would like to know what are the surprises; people in my group ask the following questions:

    1. Why do we need this DHTML stuff? (after all, we already have Java)
    2. Does it work across browsers?
    3. Are there any development tools that support DHTML programming?
    4. Can we use DHTML to develop GUI applications like we do with Java?

    Thanks for your time,
    Sergiu.

  • #2
    DHTML is just Javascript + HTML + CSS.
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

    Comment


    • #3
      DHTML is more a way to use both javascript (in fact ECMAScript +DOM) and CSS. DHTML has nothing to do with java.

      Now the responses to your question

      1. Javascript is a client-side language. Java is a server-side language. They have nothing at all in common (javascript resembles rather with C++ or php) except the name, which, at a time, was a "brand" affair (Netscape - the LiveScript owner - joined in mid 90's it's efforts with Sun - the Java owner - to stop Microsoft monopoly, and renamed their client script language javascript in order to emphasize this partnership).

      Javascript is a powerfull object-oriented-on language. It uses functions, methods and operators to create/modify/remove web page's objects(elements) and their attributes. Javascript does not uses classes, but it may create a sort of "pseudoclasses" if needed. It is a very flexible language.

      Javascript is an open-language. It cooperates quite well with other languages oriented on DB admin (XML, php, asp...) or "active" objects (ActiveX, XMLHttp)

      So that the dilema javascript/java is a nonsense, as they are and they do totally different things.

      2. Yes, but there are small (but sometimes important) differences between, mainly, IE and Mozilla. There was made a somehow succesfull effort to standardize the language (ECMAScript- by ECMA - and DOM- by W3C ), but still Microsoft and Netscape/Mozilla use sometimes different methods. That is not a major problem, as there are always possibilities to find cross-browser solution.

      3. Not really. javascript does not need a compiler. Codes may be done using Notepad, for instance. There are some editors (Macromedia has some) which might build some popular javascript applications (rollover, drop menus) but it is not recomanded to use them. The so-built codes are clumsy, redundant, and hard to modify/debug.

      4. Javascript can do a lot of things at the GUI level, same as Java applets. The only difference is that javascript can not create vectorial design. Anyway, in that case Flash is to be prefered, not Java. Java have lost it's mid 90's popularity at GUI level. Drop menus, object movement, and stuff like that are easy to be done with DHTML or, sometimes, with Flash. Java remains only a powerful server-side language.

      So... What you have in mind? We might tell you if javascript can or can not do that.
      Last edited by Kor; Jul 29, 2005, 06:39 AM.
      KOR
      Offshore programming
      -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

      Comment


      • #4
        Hi Kor,

        Your answer is very helpful!
        Still, I need some clarifications.

        1. Javascript is a client-side language. Java is a server-side language.
        What about Java applets?

        So that the dilema javascript/java is a nonsense, as they are and they do totally different things.
        Applets run at client-side and they are written in Java. So JavaScript+DHTML and Java do seem comparable -- what do you think?
        So I am asking again: why choose JavaScript+DHTML instead of Java applets?

        2. Yes, but there are small (but sometimes important) differences between, mainly, IE and Mozilla. .... That is not a major problem, as there are always possibilities to find cross-browser solution.
        Does it mean that I will have to maintain one code base for each kind of supported browser?

        3. Not really. javascript does not need a compiler.
        That is a very important point!
        Languages such as Fortran, COBOL, Pascal, C, C++, Java, Ada, C# all have compilers -- how JavaScript programmers can live without a compiler?

        BTW, is there a debugger for JavaScript?

        4. Javascript can do a lot of things at the GUI level, same as Java applets.
        So JavaScript+DHTML does support menus, toolbars, trees, panels, etc; but it does not support vectorial graphics -- is that true?


        Thanks for your patience,
        Sergiu.

        Comment


        • #5
          Applets are not the way to go unless nothing else will do. I do not run applets and will never run them, no matter the circumstance...
          Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

          Comment


          • #6
            Client-side languages need not a compiler. A compiler should conver the code into a .exe file (or similar) which contains the binary data.

            Instead of a compiler, client-side languages use an interpretor. Interpretor is a part of browser's construction. The interpretor is looking for the language and type of code (HTML, CSS, Javascript, VB Script...) and runs the code lines according to the specification.

            So that DHTML applications and Java applets are not compatible (from this point of view). Java applets are executable files, so that, following the continous growth of the viruses thread, most of the users (me included) block the java applets when browsing.

            If no compiler, that means there is no real de-bugger. But there are "javascript consoles" - Mozilla has the best- included in browser, which will signal the javascript errors. Errors, like the code in itself, are to be corrected mainly "by hand".

            Regarding the way code is interpreted, javascript resambles HTML. There is no compiler, there might be editors which help you to gain time when coding, the may signal possible errors while coding (by using code coloring) but a good knowledge of the language is indispensable.

            In other words, one must know the javascript language to build javascript codes.

            As I said, DHTML does not support real vectorial graphics. In the present web design, vectorial graphic, if needed, are made mainly by using Flash applications. Flash has a good communication interface to dialogue with javascript, if needed. Ussualy it is used a common application Flash-Javascript to use both's advantages.
            Last edited by Kor; Aug 1, 2005, 03:22 AM.
            KOR
            Offshore programming
            -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

            Comment


            • #7
              Originally posted by Kor
              Client-side languages need not a compiler. A compiler should conver the code into a .exe file (or similar) which contains the binary data.
              Your statement sounds bizarre to me.

              Besides converting into executable code, compilers also do a static analysis. The static analysis aims to find various coding errors, from syntactic errors, through type errors, till coding style errors. This means that entire classes of bugs can be caught before running the program.

              Comment


              • #8
                As I said... Javascript don't use a compiler, it uses an interpretor, the browser's interpretor. The interprator "decript" the code lines and run them meanwhile. If an error ocurres, the interpretor stops the running of the code and usually sends an error message somewhere in the browser. Everything which was correct before the error isrun.

                This is the reason why for fast debuging we use mainly alert() messages. We insert them here and there to check where the program stopped, or to check the existance of an element or of attribute and so on.

                The interpretor error messages only points out to the line where the error occured, but it can not do as a compiler, so that it can not repair the wrong code lines. Well, hm... I have notice that both Moz and IE claimed to have build a sort of an incorporated "debugger", but, according to the present browsers general performance I have not even the curiosity to check what's all about
                KOR
                Offshore programming
                -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

                Comment


                • #9
                  don't confound the compiler with an edit tool. There are tools which might help you to code faster or which can automatically build a custom code for usual purposes but they are not trusty. As long as the interpretor is an internal tool of the browser, and all the browsers' producers woun't agree to use a standard language (we are talking about HTML and CSS and Javascript and requesting object - ActiveX, XMLHttp), there is no chance to have a good tool to debug/create/help creating crossbrowser codes.
                  KOR
                  Offshore programming
                  -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

                  Comment


                  • #10
                    Hi Kor,

                    Suppose the following JavaScript code:

                    Code:
                    function doMorningGreet() {
                      window.alert( "Good morning!" );
                    }
                    
                    function greet() {
                      var date;
                    
                      date = new Date();
                    
                      if( date.getHours() < 12 ) {
                        doMorningGreet();
                      }
                      else {
                        doAfternoonGreet();
                      }
                    }
                    Now, suppose we are testing the "greet" function before 12:00 -- everything will function properly.
                    But when the "greet" function will run after 12:00, it will generate a run-time error since no "doAfternoonGreet" function is defined!
                    Such kind of errors (reference errors) could be detected by a static code analyzer before the program is run.

                    Now, imagine a JavaScript program with thousands of functions and variables and with many more references -- what a mess!

                    Sergiu.

                    Comment


                    • #11
                      Originally posted by sergiu
                      Now, imagine a JavaScript program with thousands of functions and variables and with many more references -- what a mess!
                      Imagine how long it would take to load all these functions and how much cpu power you would need to run such a script monster..

                      Sorry mate, but JavaScript is _DEFINITELY_ not the right language for something complex like that.

                      Normaly a script doesn't has that many functions and is relatively easy to understand, so it's not as bad as it seems.

                      Of course, if you choose inappropriate variable/function names and make no comments.. well, good luck with debugging!

                      Anyway, no one forbids you to make test case.

                      E.G.:
                      Code:
                      var debug = true;
                      function greet(hour) {
                        if(debug) writeToTestCaseResult('greet called with ' + hour);
                        if( hour < 12 ) {
                           if(debug) ...
                          doMorningGreet();
                        }
                        else {
                          if(debug) ...
                          doAfternoonGreet();
                        }
                        if(debug) ...
                      }
                      function writeToTestCaseResult(msg) {
                        ...
                      }
                      function displayTestCaseResult() {
                        ...
                      }
                      for(var i = 0; i < 26; i++) {
                        greet(i);
                      }
                      greet(3.55);
                      greet('hello world');
                      greet(true);
                      displayTestCaseResult();
                      dumpfi
                      "Failure is not an option. It comes bundled with the software."
                      ....../)/)..(\__/).(\(\................../)_/)......
                      .....(-.-).(='.'=).(-.-)................(o.O)...../<)
                      ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
                      ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
                      Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

                      Comment


                      • #12
                        Now, imagine a JavaScript program with thousands of functions and variables and with many more references -- what a mess!
                        - usually, as dumpfi well said, you don't need a great number of functions or variables for nomatter you may have to do

                        - as any other language, javascript may use loops and "soub-routines" functions to shorten the code

                        - unlike some other languages, in javascript there is no need to declare all the variables (if they are local) from the begining. The order in which you write your functions or global variables is not important.

                        - you may split the code in separate external js files, so that the variables which might be important or frequently updated (menus...) may be placed separately, for a better view. That means you may use modules.

                        - there are some, let's say, "self-methods" to check the results of the code (I have mentioned alert() but frequently it is used innerHTML to check what elements/attributes were created/changed/removed. Further more, there is an event called onerror, it is a window's event, which may help you to check errors as well

                        - Modern javascript (Ecmascript +DOM) is strongly oriented to the objects, thus it is easy to verify the effect of the code, as most of the objects are in fact visible elements of the web page

                        Well, hm This is the reason for a good DHTML coder should be paid much more that he actually is. We have no compiler, there is no perfect standard language for the momemnt, we are dealing with several different types of browsers... Yet, when we succede in doing a good cross-browser job, the result is better than in any other languages' similar applications...
                        Last edited by Kor; Aug 2, 2005, 12:21 PM.
                        KOR
                        Offshore programming
                        -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

                        Comment


                        • #13
                          I'll just add that there are reasonable debugging tools in Opera, Safari, Firefox, and Explorer 6/Win. They're called Javascript Consoles, and they'll tell you that doAfternoonGreet() is not defined. The firefox one is located under Tools.
                          Jalenack.com .:. YWDA Founder .:. Rounded Corners Maker 1.1! .:. My Blog
                          The hardest thing about teaching is not knowing the right answers, but knowing the right questions - Elisabeth Klein
                          Pretty buttons does not a great website make.

                          Comment


                          • #14
                            Hi dumpfi,

                            Great points!

                            Originally posted by dumpfi
                            Imagine how long it would take to load all these functions and how much cpu power you would need to run such a script monster...
                            Suppose having an application with several thousands of functions. Also suppose that at run-time only few percents of these functions are used most of the time. Why should all of these functions be loaded ahead?!

                            About the CPU power -- I presume that coding exponential algorithms in assembly language will also require a lot of CPU power...

                            Originally posted by dumpfi
                            Anyway, no one forbids you to make test case.
                            Let's look to your example test case. You are calling the "greet" function three times
                            Code:
                            greet(3.55);
                            greet('hello world');
                            greet(true);
                            each time with a different parameter type.
                            You may have type related errors in your programs as well in your test cases.
                            You may have reference related errors in your programs as well in your test cases.
                            Still, a static code analyzer will be able to reduce those kinds of errors to zero -- i.e. less debugging!

                            Originally posted by dumpfi
                            Normaly a script doesn't has that many functions and is relatively easy to understand, so it's not as bad as it seems.
                            Agree. But I am looking for ways (technologies & tools) to write GUI applications that depend only on Web technologies at client-side. GUI applications and their libraries tend to have hundreds or even thousands of functions.

                            Sergiu.

                            Comment


                            • #15
                              Agree. But I am looking for ways (technologies & tools) to write GUI applications that depend only on Web technologies at client-side.
                              That means there will be limited things you want to do... Or you intend to compile codes and let them be executed at local level by the client? Javascript can not do that. Javascript is a client-side direct language. You write it in web page and it will do something. That is all.

                              What exactly have you in mind?
                              KOR
                              Offshore programming
                              -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

                              Comment

                              Working...
                              X