Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Programming languages - what are the differences between them?

Comparing the programming languages ... the same program in 10 languages

How do I add one to a variable? Some languages have a ++ operator, other languages allow you to use +=, others have an incr command, and in some you have to write a long(er) assignment statement.

How do I set up a variable in the first place? In some languages, simply mention a variable and it will appear as if by magic, nicely initialised to zero or an empty string. In others you need to set an initial value. And in others you need to tell the computer the type of data it will contain as well as defining the type.

How do I output results? There are all sorts of puts and print statements, and even operators such as <<. And how you join values on the same line, and add the end of line character, is a further question.

I can teach you any of ten languages, and one of the big advantages I have of knowing so many is that I can compare and contrast for you if you're in the process of converting, or if you're learning anew and have vague recollections from School days. [Course Schedule]

The sample program I've written takes a variable up from nothing / zero to 7, displaying its value twice and incrementing it twice each time around a loop. Results - consistently in all the languages - look like this:
   wizard:incr graham$ ./incr.sh
   xxx 1
   yyy 1
   xxx 3
   yyy 3
   xxx 5
   yyy 5
   xxx 7
   yyy 7
   wizard:incr graham$


The programs differ - here are links to the code to do that in ... C C++ Java Lua PHP Perl Python Ruby Shell (Bash) and Tcl.

Let's look at just three examples within this main article. Here's the program in Perl:

  #!/usr/bin/env perl
  while ($n < 7) {
    print "xxx ",++$n,"\n";
    print "yyy ",$n++,"\n";
  }


in Tcl:

  #!/usr/bin/env tclsh
  set n 0
  while {$n < 7} {
    puts "xxx [incr n]"
    puts "yyy $n"
    incr n
  }


and in C++:

  #include <iostream>
  using namespace std;
  int main() {
    int n = 0;
    while (n < 7) {
      cout << "xxx " << ++n << endl;
      cout << "yyy " << n++ << endl;
    }
  }


In Perl, the variable is automatically created and assigned an empty value when first encountered, with Perl deciding it has to be a number when it's incremented. In Tcl, variable (almost) always need to be initialised, but you don't need to tell the system the type of data they will contain. And in C you must declare the type, and it's strongly recommended that you intiialise; if you don't, the variable takes the initial value form whatever was left in memory from the previous program.

Both Perl and C++ have the ++ operator to increment a variable. If the ++ is written before the variable name, then it's incremented before it's used for anything else in the context in which it's written. In Tcl, the incr command provides a shortand way of incrementing a variable.

C++ variable names never start with a $. Perl (scalar) variable names always start with a $. And in Tcl, you specify a $ in contexts where you are just using the existing contents of a variable, but never in the contexts where you are (or may be) setting the value.

Perl and Tcl programs start at the top of the file, whereas your C++ program starts at the function called main.

In all 3 of the example languages I have chosen, you indicate the scope of a loop using a {} block. But please note that differs when you look at other languages in other examples such as Ruby (the word end) and Python (where it's done by spacing)

C++ is a compiled language - you need extra instructions to convert the code above into a runnable program. Tcl is a pure interpretter language - each line is interpretted as the program runs (quick to start, slower to run if you have loops). Perl, and most of the other languages for which I've supplied examples, use a Virtual Machine approach which means that the source code is only interpretted once - a little slower to actually start the program than an intepretter, but then much faster to run, and without the hassle of C++'s extra instructions.

If you're unsure which language is right for you, and you're not too far from us, please let me know and we'll arrange for you to pop in for an evening to help you make a choice. There's a lot more to the choice than just the syntax of the source.
(written 2012-06-27, updated 2012-06-30)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Q102 - Choosing your language
  [76] Learning to program in - (2004-10-07)
  [1990] Speaking all the languages - (2009-01-12)
  [2001] I have not programmed before, and need to learn - (2009-01-19)
  [2048] Learning to program in PHP, Python, Java or Lua ... - (2009-02-19)
  [2507] Admission - (2009-11-19)
  [2535] When should I use Java, Perl, PHP, or Python? - (2009-12-13)
  [2536] All the Cs ... and Java too - (2009-12-13)
  [2700] The same very simple program in many different programming languages - (2010-03-31)
  [2866] Ruby - how does it compare and where is it the right language? - (2010-07-11)
  [3169] Rekeying a table - comparison in #Ruby #Perl and #Python - (2011-02-14)
  [3558] Python or Lua - which should I use / learn? - (2011-12-21)
  [3619] Ruby v Perl - a comparison example - (2012-02-21)
  [3764] Shell, Awk, Perl of Python? - (2012-06-14)

G908 - Well House Consultants - Language Comparisons
  [209] FAQ - Perl or PHP - (2005-02-11)
  [1582] Ruby, C, Java and more - getting out of loops - (2008-03-19)
  [1717] Q - Should I use Perl or Python? - (2008-07-23)
  [2755] Books in the store in the USA - still a portent of the UK market to come? - (2010-05-08)
  [2947] Teaching Lua to a Perl advocate - (2010-09-06)
  [3003] What will we be teaching in six years? - (2010-10-17)
  [3112] Public and private courses - subjects available for 2011 - (2010-12-29)


Back to
Steam train calls at Melksham - Pictures
Previous and next
or
Horse's mouth home
Forward to
Improving Wiltshire Rail Offer - it WILL be happening
Some other Articles
More than just matching with a regular expression in PHP
Getting more than a yes / no answer from a regular expression pattern match
Melksham Pride - the Chamber of Commerce, and the future
Improving Wiltshire Rail Offer - it WILL be happening
Programming languages - what are the differences between them?
Steam train calls at Melksham - Pictures
Load path, load and require in Ruby, and a change from 1.8 to 1.9
Standard methods available on all objects in Ruby
Private, Protected, Public in Ruby. What about interfaces and abstract classes in Ruby?
Ruby of Rails - cleanly displaying model data in the view
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3785_Pro ... them-.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb