Jump to content

Talk:Comparison of programming languages (basic instructions)/Archive 1

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Archive 1

Untitled

Why not just mark as stub? I'm sure it'll be a good article in a few time, when it will be expanded. Furthermore Wikipedia is full of comparison articles. Bh3u4m 17:34, 1 December 2007 (UTC)

I would like to show that once this page will be enlarged and completed, it might be very useful as a reference for people willing to learn a new programming language. Bh3u4m 18:14, 1 December 2007 (UTC)

Fortran

Any views on whether or not to add Fortran examples to this page? I know it's an old language, but it is still widely used in engineering and for scientific calculations. Murray Langton (talk) 09:13, 11 December 2007 (UTC)

Pascal is more old and out of date than Fortran, so Fortran is OK, every programming language is OK. Bh3u4m (talk) 10:28, 18 December 2007 (UTC)
Pascal dates from the late 60's/early 70's, while Fortran dates from the mid/late 50's, though Fortran is still being regularly updated. OK, I'll add some Fortran 77 examples to start with (which is what I'm familiar with) and then see about later versions of Fortran. Murray Langton (talk) 11:23, 18 December 2007 (UTC)
Note that Fortran versions up to and including FORTRAN 77 had the programming language name in capital letters, while versions from Fortran 90 on only capitalised the first letter. Also, up to and including FORTRAN 77, only one case (capitals) of letters was legal, though many compilers would accept lower case and quietly convert it to upper case. The examples I have provided (or will provide) are capitalised or not accordingly. Murray Langton (talk) 11:54, 18 December 2007 (UTC)

Also, FORTRAN 77 does have a while loop. Just go look at the article. --208.138.31.76 (talk) 18:29, 21 December 2007 (UTC)

The Fortran article points out that the while loop is part of MIL-STD-1753 defined in 1978, and is not part of the FORTRAN 77 standard (it is part of Fortran 90), even though it is in fact implemented by many FORTRAN 77 compilers. Murray Langton (talk) 21:29, 21 December 2007 (UTC)



Exception handling?

I was considering adding exception handlers to the Control flow section. Would this be a suitable addition? I appreciate everyone's contribution to this page. --208.138.31.76 (talk) 18:02, 21 December 2007 (UTC)

Exception handling is very important, more so IMO than some other things on this page. —Preceding unsigned comment added by Ty8inf (talkcontribs) 17:42, 17 January 2008 (UTC)
That would definitely be suitable but, we should divide the control flow section up so it doesn't get too wide. Mike92591 (talk) 01:33, 18 January 2008 (UTC)
Split control flow section. --208.138.31.76 (talk) 19:26, 25 January 2008 (UTC)
Added exceptions to the control flow section. Thanks ;) --208.138.31.76 (talk) 18:43, 29 January 2008 (UTC)

Standard Input and Standard Output: Client-Side JavaScript

alert () and promt () dialogs are not I/O streams, but they are standard input and output methods in Client-Side JavaScript. Alik Kirillovich (talk) 21:01, 31 March 2008 (UTC)

The Standard Input and Standard Output section only discusses I/O using the standard streams. Other forms of input or output are not discussed here. --72.252.194.115 (talk) 16:27, 2 April 2008 (UTC)

Array examples

I intended the array type table to show how to declare an EMPTY array because not all languages support pre-filled ones. --208.138.31.76 (talk) 18:29, 21 December 2007 (UTC)

by EMPTY, I presume that you mean an array who's elements do not have any particular defined values. In some contexts, 'EMPTY' can mean NULL or 0, while in other contexts it could mean an array with no elements. I have reworded the article to avoid the word 'EMPTY'. Murray Langton (talk) 21:38, 21 December 2007 (UTC)
Yes, that was what I intended. In addition, a pre-filled multidimensional array would probably require more than one statement to pull off. --208.138.31.76 (talk) 14:12, 27 December 2007 (UTC)
Why doesn't python have an example for array declaration, e.g. array = []. Technically, these are called 'list' types, but aren't they the same?
67.87.98.164 (talk) 03:29, 19 March 2008 (UTC)
Fixed that --Btx40 (talk) 21:00, 4 April 2008 (UTC)

New article

I am planning to start a compaison article for object-oriented programming features. I will use these languages and features to start the comparson tables.

Languages Features
C++ Object creation
C# Constructors and destructors
Java Class declaration
Visual Basic .NET Fields
Python Properties
Windows PowerShell Inheritance

Any suggestions for other languages or features are happily accepted --Btx40 (talk) 15:35, 7 April 2008 (UTC)

Article started --Btx40 (talk) 15:38, 8 April 2008 (UTC)

Loop statements

I don't think the recent changes to the foreach column are an improvement. Using language specific comment syntax like /*do something to item */ instead of the generic instructions makes this column harder to read and inconsistent with the other loop statement examples. Suggestions? Ghettoblaster (talk) 17:19, 17 April 2008 (UTC)

Python Indentation

We should use a consistent way of expressing Python indentation, either '\t', 'tab' or '    '. There is a mix of both '\t' and 'tab' in the current article, but I suggest using four spaces instead, as specified by the Python style guide PEP 8. 124.169.94.84 (talk) 01:05, 20 April 2008 (UTC)

I think so too, but with non-breaking spaces (&nbsp). Word wrap may cause problems (like with the VB examples). I am also thinking of a way to mark optional elements, such as else and finally blocks, without using square brackets. --Btx40 (talk) 03:42, 20 April 2008 (UTC)
That's what I use strike-through text for. Mike92591 (talk) 16:13, 20 April 2008 (UTC)
That's fine but, that means we definitely should change how it looks, it's not a good idea for one to stick out. Mike92591 (talk) 16:13, 20 April 2008 (UTC)
1 2 3
if condition:
    instructions
else:
    instructions
if (condition) {instructions} else {instructions}
if (condition) {instructions} else {instructions}
I strongly agree that there need to be changes made so that the formatting of all examples on this page is consistent and easy to read. Maybe I'm the only one here, but I don't like any of the recent changes using Bold and Strike-through. Using italics for the placeholder text seems more appropriate to me. I'm not sure what might be the best way to mark optional elements, though. Maybe we should try colors? I don't know. For Python indentation I would suggest using <tab>. Ghettoblaster (talk) 16:17, 20 April 2008 (UTC)
I'm not a big fan of it either but italics and colors are problematic. Italics are more difficult to distinguish. Different hues aren't helpful for some color blind people (depends on the type), however we could probably use a different shade like gray. It may also help to use guillemets or something. Mike92591 (talk) 22:06, 20 April 2008 (UTC)
Ok, I can accept the point regarding different hues and color blind people, but Strike-through is definitely hard to read for non-color blind people and for color blind people as well. Another issue is that optional elements cannot be nested this way while this was possible using square brackets. IMHO this is just wrong. Ghettoblaster (talk) 19:57, 22 April 2008 (UTC)
I personally didn't find that hard to read at all but it was more of a test anyway. The only problem with brackets is it collides with something that is often used, I think there would more confusion in that case. Although strike through has problems too. I think guillemets would be better although not by much. Mike92591 (talk) 00:05, 23 April 2008 (UTC)
1 2
if condition:
    instructions
«else:
    instructions»
if (condition) {instructions} «else {instructions}»
Guillemets sound OK, but they are not on a standard US-English keyboard, which is both an advantage and a disadvantage. Most programming languages only use standard ASCII symbols found on the US-English layout. Until this article expands to include ALGOL or something similar, that could be a viable solution. --Btx40 (talk) 14:16, 23 April 2008 (UTC)
I agree. Your example already looks much better. While working on some other articles I found Microsoft's TechNet formatting legend [1](at the bottom of the page). They use bold for non-optional elements and they also use italics for user supplied elements. I think this is a good idea, because italics are used for user supplied elements in many code examples throughout Wikipedia. The fact that guillemets are usually not used in programming languages is a big advantage here. Maybe we should also avoid the typewriter font, because bold letters don't look much different than non-bold letters in this font. Here is my suggestion. I use wikisyntax for indentation etc. Ghettoblaster (talk) 14:59, 23 April 2008 (UTC)
1 2

if condition:

instructions

«else:

instructions»
if ( condition ) { instructions } «else { instructions }»
BTW <tab> is not a valid HTML tag (I tried it on the sandbox). Did you mean Ctrl+Tab ↹ (which does not work in IE7)? --Btx40 (talk) 15:25, 24 April 2008 (UTC)
I know that '<tab>' is not a valid HTML tag. I suggested it as an alternative placeholder similar to '\t', 'tab'. I thought it would be easy to identify, but on the other hand angle brackets are also already used in programming languages. I think a better solution is using wiki-style indentation colons as I tested in my table example here. This will only work at the beginning of a line, but AFAIK the tab is only used at the beginning of a line anyway (at least in Python). However, I did not test how this will affect word wrapping in lager examples.
I also think that the keypress template you suggested is an even better idea. Also, we don't need Ctrl. All we need here is the Tab ↹. I tested it and it works fine in IE8 beta. I suppose it is safe to use it here, since it is already in use in other Wikipedia articles. Ghettoblaster (talk) 16:08, 24 April 2008 (UTC)
Are you sure it does not work in IE7? It does work with IE7 emulation mode in IE8. Ghettoblaster (talk) 22:04, 24 April 2008 (UTC)
When editing, Ctrl+Tab ↹ inserted a literal tab character on IE6. The shortcut changed to switching between tabbed browsing windows in IE7 (and maybe IE8, who knows). --Btx40 (talk) 13:23, 25 April 2008 (UTC)
Oh, I see what you mean. I did not know about this feature. I thought you suggested using Tab ↹ as a graphical representation for the tab character in the code examples. Ghettoblaster (talk) 12:05, 28 April 2008 (UTC)
I'm not to crazy about using the colon. It looks bad. The keypress thing is okay I guess. Mike92591 (talk) 23:11, 26 April 2008 (UTC)
Ok, so everybody agree on using something like this then? Ghettoblaster (talk) 12:08, 28 April 2008 (UTC)
1 2

if condition:
Tab ↹instructions
«else:
Tab ↹instructions»

if ( condition ) { instructions } «else { instructions }»
I agree, it's good enough. Mike92591 (talk) 19:10, 29 April 2008 (UTC) Never mind, the gray looks horrible.Mike92591 (talk) 22:10, 29 April 2008 (UTC)

Unlimited precision in Python

A dip into the article was interesting, but one thing stood out for its absence. Python automatically and transparently converts an overflowing integer to an L integer, which has unlimited precision. This makes life easier for many programmers. But, I don't want ot derange the tables, so have kept free of the. They're fascinating and I don't want to gum them up. Perhaps someone who does table might make the necessary changes? ww (talk) 09:13, 29 May 2008 (UTC)

Named constants

Some programming languages (e.g. C++ but not C) make provision for named constants. Should this feature be added as a separate section, or as another column to some existing section? Murray Langton (talk) 16:20, 14 February 2008 (UTC)

I'm not sure about that. Not only do languages differ on the keyword used to declare a constant (C# uses const while Java uses final) but on the meaning of "constant" e.g. final variables can be modified by mutators while const variables can't be modified afer they are declared (ever). There is also the issue of some languages offering constants as the only type of variable *coughMLcough*.
That sort of thing is a bit too much for this page. --Btx40 (talk) 19:29, 20 June 2008 (UTC)

Retrieving variables

Shouldn't there be a section on how each language retrieves a variable's data? In C/C++, it is referenced by name, but other languages differ (Logo, a variant of Lisp, uses THING "<name> or :<name> to retrieve a defined variable). Graham (talk, contrib, SIGN HERE!!!) 16:28, 20 July 2008 (UTC)

Logo isn't mentioned here. Most, if not all of the languages mentioned in this article reference variables by name. --Btx40 (talk) 15:17, 21 July 2008 (UTC)

Pointers

Some languages support pointers. Shouldn't this be included in, say, other types of variables? Also, can a pointer be considered a declaration of an object in C++? The two are closely related. Graham (talk, contrib, SIGN HERE!!!) 16:31, 20 July 2008 (UTC)

If you are talking about memory address pointers, then I'm not so sure.
As far as I know, only 4 of the 18 languages described support pointers namely C, C++, C#, and Pascal, so it looks like quite a minority. Also C# code using pointers has to be placed in an unsafe block; compiling code with unsafe blocks requires the use of an extra compiler option - hardly "basic". That and pointers would probably require their own section because of the need to compare reference/dereference operations.
As for C++, void* could be considered a "variant" type because a void pointer can point to any type of variable, so it could be mentioned. --Btx40 (talk) 15:12, 21 July 2008 (UTC)
One big problem with this article is the meanings. C and C++'s, C#'s, Pascal's, and Fortran's pointers are all quite different; It depends on where you draw the line. Mike92591 (talk) 22:25, 24 August 2008 (UTC)

Declaration vs. type name

It seems that for the languages that have declarations (like C, Java, etc.), the "declaration" sections mainly only serve to tell you the name of the type. But many other languages don't have declarations (mostly scripting languages like Python, Ruby, etc.), and for those languages the "declaration" section currently basically does not give any useful information (it just says "x = value" for all types, without saying what the "value" has to be). Yet languages like Python do have runtime types, and, for purposes of comparison with the languages that do have declarations, it might be informative to just list the names of the types. For example, for Python we can have like "int", "float", "long", "char", "string", "bool", etc., so that someone can come to this page, and say, I know I would use "double" or whatever in this language for this variable, but now I want it in Python instead, and I would use "float". How to actually use "float" they can figure out for themselves from the language (it's not like the page currently gives any useful information in that regard anyway.) That way, it serves better as a "comparison" between languages that have declarations and ones that don't. --Spoon! (talk) 02:16, 23 January 2009 (UTC)

It's probably a good idea but, it might cause some inconveniences. I guess it's worth a try. Mike92591 (talk) 00:37, 24 January 2009 (UTC)

Enumerations

From what types do they derive from? In C and Pascal, they do not seem to be from any other type. Mike92591 (talk) 00:51, 28 June 2009 (UTC)

Also, why are enumerations listed under "simple composite types"? They are definitely not composite types. --76.91.63.71 (talk) 07:28, 28 June 2009 (UTC)

Common Lisp

I guess a functional language example was needed here. --Btx40 (talk) 18:32, 24 April 2008 (UTC)

CL is a littile confusing, could someone help out? --Btx40 (talk) 20:54, 24 April 2008 (UTC)

Other Types

I would like to see a comparison of Associative Arrays. Would like to see in Basic Instructions/Other Types.

Perl has its Hashes
Python has its Dictionaries
Any other languages? —Preceding unsigned comment added by Rlrandallx (talkcontribs) 22:28, 14 April 2010 (UTC)

C use of logical operators as conditionals

In the control flow section I think we should include the use of C logical operators as conditionals, as in: if(condition)do_stuff();/*effect equivalent to*/ condition && do_stuff();/*and*/ if(!condition)do_stuff();/*is equivalent to*/ condition || do_stuff(); --70.26.87.79 (talk) 03:01, 2 June 2010 (UTC)

Nice idea, but wouldn't those examples using logical operators fail if the return type of do_stuff is void? --Btx40 (talk) 15:21, 2 June 2010 (UTC)

Complex Number Types?

A number of languages provide native support for complex numbers. It would be nice to see this added to the data-type table. —Preceding unsigned comment added by Ty8inf (talkcontribs) 19:23, 19 January 2008 (UTC)

The 'Data Types' section is getting quite wide. To make room for 'complex' etc., would it be helpful to split this into two subsections (Numeric and Non-numeric)? Murray Langton (talk) 21:24, 21 January 2008 (UTC)
I split the Data types section. I am not so sure that complex numbers are a suitable addition because they are complex, and only basic instructions are dealt with here. --208.138.31.76 (talk) 15:17, 25 January 2008 (UTC)
Well, in FORTRAN (66 onwards), COMPLEX data types are actually just as simple as floating point data types; such an addition would show an area in which FORTRAN is probably better than most of the other languages mentioned. Murray Langton (talk) 20:19, 25 January 2008 (UTC)
Don't see any .NET support, but C++ STL has a <complex> header. I might just add this after all. --208.138.31.76 (talk) 17:21, 29 January 2008 (UTC)
What is the meaning of the integer column in this table? If it means an integer-valued complex number, then the S-Lang entry should be blank because S-Lang provides no support for complex integers. --Ty8inf (talk) 17:57, 29 January 2008 (UTC)
Unsupported features are ref-ed instead of being blank. A blank cell indicates that the information has not yet been contributed. The integer column was added for those programming languages that make the difference between complex integer and complex floating point (such as C++). --208.138.31.76 (talk) 18:06, 29 January 2008 (UTC)
Python can handle complex numbers. Let's see who else can. —Preceding unsigned comment added by Rlrandallx (talkcontribs) 22:24, 14 April 2010 (UTC)
Does any language support cmplex integers? After reading the C++ spec which stated that C++'s complex template parameter was not unrestricted, but is limited to floating-point types, I considered deleting the integer column. --Btx40 (talk) 15:52, 2 February 2011 (UTC)

Tuple is not a type

Tuple is listed as a type, but all data structures capable of storing an ordered list of arbitrary, but finite length are, by definition, tuples in the mathematical sense. What's interesting about Python's tuple type, for example, is that it's a read-only, ordered list. This has many useful properties for optimization and debugging, but it's just a read-only, ordered list.

I think what's unique about Python is that it provides not only a data type, but syntax for defining a specifically read-only, ordered list of this sort, inline without having to translate for another form of list (e.g. (1,2,3) in Python is a tuple while [1,2,3] is a list).

Then there's Lisp, where "tuple" means something very, very different, and should not be conflated with the Pythonic tuple at all. It is, instead, a two-element association (a "pair"). Languages like Python have no direct equivalent of the Lisp tuple, and must rely on a list or tuple which is set to a length of 2.

I think it would be useful to change the wording of the chart to "read-only, ordered list" as the heading and then for python, the text should be "tuple: «(»val1, val2, ... «)»".

Additionally, there should be a "Pair" type listed for which the ones I know of are:

Lisp
tuple: (cons a b)
Perl 6
Pair: a => b
C++
std::pair
C#
KeyValuePair
JavaScript/JSON
pair: a:b (left side must be a string value)

That's as much as I can think of off the top of my head. -Miskaton (talk) 22:04, 4 March 2012 (UTC)

Foreach in Pascal?

The article Foreach#Pascal says "The ISO 10206:1990 standard introduced iteration over set types in Pascal", while in Comparison_of_programming_languages_(basic_instructions)#Loop_statements there is a "N/A" in the foreach column. I think, this is an inconsistency. Jochen Burghardt (talk) 18:39, 10 September 2013 (UTC)

Fixed. Rwessel (talk) 00:08, 13 September 2013 (UTC)

Change of tt's to template:mono by Bgwhite

User:Bgwhite has changed the many <tt>'s to use {{mono}} instead. Should this not be using <code>...</code> instead? Rwessel (talk) 22:00, 3 December 2014 (UTC)

fyi... <tt> is not part of HTML5. Changing tt to use mono renders the same, but now is HTML5 complaint. <code> should replace <tt> for computer code. I wasn't sure what to do with this page. Some of the tt's are not computer code, but others could be. When in doubt, I default to render it the same. Bgwhite (talk) 22:23, 3 December 2014 (UTC)
Yes, I know why we're moving away from <tt>, it's that usually <code> should get used for in-line bits of code. OTOH, I forgot about the box which <code> puts around the code block, which would be inappropriate for this table. So... Nevermind! Rwessel (talk) 22:40, 3 December 2014 (UTC)