Home | Login | Recent Changes | Search | All Pages | Help
SemiColonsOnTheHeadOfaPinThis page is reserved for arguement examples about the relative merits of different languages. At the syntax level, How many semi colons can dance on the head of a pin? Comparing languages... There's a good comparison at <http://www.ipd.uka.de/~prechelt/Biblio/jccpprtTR.pdf> While somewhat flawed because some of the programmers were new to the languages, and the problem being implemented didn't require an object oriented design to solve. Various other comparisons are at <> and Also, <> and <>. This page compares Java and Smalltalk, by someone who has worked in both languages... It has a good example of the "hoops"... Smalltalk code to print the contents of a collection forwards and backwards:
Python (this isn't exactly the same, since it changes the list's order.)
Java code to do the same thing:
List list = new ArrayList();
C++ code to do the same thing (I wrote this, haven't tested it. It might need a correction in the reverse-iteration...)
--KeithRay 2002.07.12 Keith, are you using initializers on the smalltalk collection object? If so, in either C++ or Java:
#include "MyList.h" // or import MyList.* } Or, bypassing the collection - since we KNOW everything: } }
But, that's the trouble with apples & oranges. My concerns in languages presume a reasonable amount of structured syntax. The concerns that bite harder are things that trip-up teams or surprise individuals. For example, what does it take to safely print the content of a collection when multiple threads act on it? What are the synchronizing, threading and sharing/hiding mechanisms? BobLee 2002.07.21 Examples of gotchas: In C/C++/Objective C the declaration "int a, b, c;" declares three variables, each of type int. The declaration "int * a, b, c;" declares three variables, the first is a pointer to int, the other two are ints. The following code declares in int pointer type... and the three int pointer variables,
typedef int * IntPtr; The next piece of code "almost" declares an int pointer type, but not really. It actually declares one int pointer variable, and two int variables.
#define INTPTR int * Java doesn't have pointers, nor #define macros, but otherwise has the same gotcha for array types. "int[] a, b, c;" declares one int array variable and two int variables. Pascal [still alive as Borland's Delphi] is more verbose but has less tricky syntax. This declares three ints: "var a, b , c : integer;" and this declares three int pointers: "var a , b , c : pointer to integer;" --KeithRay 2002.07.21 Another version of the C++ example... one that only people knowledgable in the STL would write... Notice how it implements "operator () " ! Blech.
#include "stdafx.h" }; //Get the code into a container } Two implementations in Ruby. Apparently 'p' and 'puts' are both output functions... the second example is probably not putting the output on separate lines.
The previous Ruby implementation didn't follow the spec. Here's one that output one word per line.
An implemention in Objective C, using the classes provided by Cocoa / OpenStep / NextStep... object - method invocations go inside [ brackets ]. "@" tells the compiler to make string objects instead of char arrays.
--KeithRay 2002.07.22 More succinct Objective C implementation
Are we heading for a bout of examples implemented in the most painful language? I might have to dig up RPG or something like that from the past. I recall that there were some horribly obtuse languages, but mercifully I've forgotten them fo the most part. Perhaps we should perform the example in DOS's .BAT file syntax? Nah... LOGO? Nah... How about MVS JCL: COND=(....) steps to print one line... --BobLee 2002.07.22 The .NET versions, for what its worth. Both versions use arrays, because the initilization code is easy, but the iteration would work for at least some other collection types. VB.NET
C#
I find both C# and VB.NET to be very similar, and question the need for two new languages. (I think VB.NET is closer to C# than it is to the previous Visual Basics.) - ShannonSeverance LISP
Lest we forget how many parens can dance on the head of a pin! -- BobLee 2002.07.24 More semicolons can fit on a pin than parens, holding the size of the pin and font constant. The not causing a lot of nostalgia version, in Commodore 64 Basic V2:
It's all upper case, because that is the way the Commodore displays it. Most painful part of this program, is the emulator duplicates, as closely as possible, the C=64's layout. Ugh. 2 years on, I just read the 'Blech' comment. #include <algorithm> template< typename Type > cout << t << endl; } int main(int argc, char* argv[]) //Get the code into a container }
If you know the language well enough, you can use it elegantly. Notice also that this solution is no longer entirely OO, it uses 'generic programming'. --HuwLloyd 2004.08.25
Updated: Wednesday, August 25, 2004 |