Web Hosting How-Tos

  Home arrow Web Hosting How-Tos arrow Page 3 - Learning a New Programming Language Pa...
Web Hosting Articles  
Web Hosting FAQs  
Web Hosting How-Tos  
Web Hosting News  
Web Hosting Reviews  
Web Hosting Security  
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WEB HOSTING HOW-TOS

Learning a New Programming Language Part 3: Syntax Differences
By: Chris Root
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2005-05-11

    Table of Contents:
  • Learning a New Programming Language Part 3: Syntax Differences
  • Defining Variables
  • Variable Syntax
  • Defining Functions
  • A Few Words About C and C related languages
  • Let the Parrot Speak
  • A Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     

    SEARCH WEB HOSTERS

    TOOLS YOU CAN USE

    advertisement

    Learning a New Programming Language Part 3: Syntax Differences - Variable Syntax


    (Page 3 of 7 )

    Another minor difference in syntax can be found in the way you reference a variable in a particular language. For instance, when you declare a variable in Visual Basic you use the keyword "Dim" (meaning dimension).

    Dim mynumber as integer

    Javascript, on the other hand, uses the keyword "var" when declaring a variable. The var keyword shows up in PHP as well. The difference is that it is only used to declare properties in a class definition.

    class myclass

    {

    var $size = 0;

    var $weight = 0;

    }

    Notice also the dollar sign before each property name. This is used for variables in PHP, Perl and Ruby (only for global variables). In Perl the dollar sign is used for scalar variables (single values) and an "@" symbol is used in front of array names. If you are addressing an element of an array, however, you use the dollar sign, as this element carries a single value.

    @simpsons = (Homer, Marge, Bart, Lisa, Maggy);

    print "Doh! $simpsons[2] !";

    Something to note about the last line of the above example is that the variable is included in the double quoted string. This is an alternate method for concatenating strings. Both Perl and PHP support this method. In Javascript this isn't possible because variables are not denoted by a preceding character, and therefore could not be distinguished from any other word in the string. In this situation an operator character is used to join strings together. Javascript and Java use the "+" operator.

    var tagbegin;

    var message;

    var tagend;

    tagbegin = "<strong>";

    message = "Give me all your lupins!";

    tagend = "</strong>";

    alert(tagbegin + message + tagend);

    /* Output would be <strong>

    Give me all your lupins!</strong>*/

    Ruby and Python use the "+" operator as well. Ruby can also repeat a string by using other operators.

    str = "baby" * 3

    # Would output baby baby baby

    In PHP and Perl the operator used to concatenate strings is a period or "dot". If you are concatenating values returned from function calls with strings or variables, using the "dot" syntax in both languages is the way to go rather than putting things inside strings. Below is an example in PHP.

    function identify()

    {

    return "We are the knights who say NEE!"

    }

    $tagbegin = "<strong>";

    $message = "and we want a shrubbery!";

    $tagend = "</strong>";

    print($tagbegin.indentify().$message.$tagend);

    One thing to note is that when someone is talking about the "dot syntax" in Java and Javascript, they are talking about the use of a period to separate names when addressing object properties and methods.

    myObject.myMethod(otherObject.aProperty);

    The TCL language uses a procedure (function) call to tcl_concat to concatenate strings. The arguments are the strings to concatenate.

    More Web Hosting How-Tos Articles
    More By Chris Root

    WEB HOSTING HOW-TOS ARTICLES

    - Phishing Scams: An Overview and How to Detec...
    - Tips for Safe Downloading Online
    - How To Avoid Spam
    - How to Get Into Ethical Hacking
    - How to Prevent Drive-by Downloads
    - Facebook Timeline Tips and Tricks
    - How to Keep Up with Facebook`s Changes
    - Wi-Fi Network Security Tips
    - Tips for Safe Online Holiday Shopping
    - Facebook Privacy: Keeping Up with the Const...
    - Tips for Facebook Privacy
    - How to Cover Your Tracks on the Web
    - SSH Keys for FileZilla and Putty in Cpanel
    - How to Create a Filezilla FTP User
    - How to Install FileZilla Server

    Developer Shed Affiliates

     




    © 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap