[fpc-pascal] Pascal is alive!!??
Matt Emson
memsom at interalpha.co.uk
Mon Feb 26 13:07:11 CET 2007
> Well, let's do the standard:
>
> Pascal:
>
> program
> Hello_World;
>
> begin
> WriteLn ('Hello world.');
> end.
Class: What does program mean? Does the name matter? Does it have to be the
same as the executable? Why is there a colon at the end of the line - isn't
the begin end at the bottom part of it - like with for or while loops or
procedure and functions? Why is there a dot/fullstop/period at the end? What
does begin and end mean? Where does "writeln" come from? Why is the System
unit hidden?
> Ada:
>
> with Ada.Text_IO;
>
> procedure Hello_World is
> begin
> Ada.Text_IO.Put_Line ("Hello World.");
> end Hello_World;
Wow.. I forgot how horrible ADA was ;-)
Class: "is" what? Why do I need to repeat the name of the procedure? If I
use "with" why do I need to put the whole line in again? Why can't I leave
out "with" but can leave out "uses"? Where does the "put" put it? - plus
some similar ones from the Pascal above.
> Java:
>
> public class HelloWorld {
> public static void main(string[] args) {
> System.out.println ("Hello World.");
> }
> }
Thins that are simpler to explain:
1) "void" - the procedure and function paradimn often confuses students.
With Java/C./C++/C# the syntax is completely consistent.
2) "public" - try explaining unit syntax to a beginner. The difference
between "interface" and "implementation" and the argument for "public" and
"private" are already on a par.
3) "static", easily glossed over as a "feature you will find useful later
on". No more complex than explaining the entry point in a pascal "program"
or how on earth ADA works out what the entry point is in the firtst place.
4) "System.out" how is this any more complex than the Ada example. In fact,
if you imported "System.out" it would actually be *simpler* than the ADA
example.
5) The string[] array of arguments.. again, it's a fairly simple "you'll
find this useful in the future", but it's simply and array of the parameters
passen on the command line. The way Pascal handles this is far, far more
complicated to explain that the, quite frankly up front, way Java does.
ParamStr(), ParamCount and all that business... is not intuitive at all.
> Java in that respect is definitely harder to grasp. You learn a lot of
> keywords in one lesson, though.
Not really. The syntax is different, it's not that you learn anything more
or less.
> So, it isn't? A full bunch of keywords wrapped inside a class to make it
> OOP and it's not even close to *any* OOP is *easy*?
No, you can write seriously non OOP code in Java if you treat a class as a
"unit". You could even write inline classes if you so wished.
> Well, at that point programming ends and software engineering starts to
> emerge. The latter Java already lacks by mixing interface and
> implementation into one holy mess.
Java does nothing of the sort. It mixes nothing.. it actually forces the
programmer to think about the scope of a routine rather than leaving it up
to the luck of the draw, And when it comes to units and classes in Object
Pascal - well that's one holy big mess in itself.
> > Pointers - no, no, no. Java passes by reference. This is not anything
> > to do with "pointers"
>
> That's why it's called "NullPointerException" instead of
> "NoneReferenceException", I'd suppose?
Historical.
> Well, it's a minor technicality, if you call it pointer or reference.
A reference contains much more information.
> > different to Java? If you wish to pass integral types by reference,
> > box them. It's not exactly rocket science ;-)
>
> It's damn hard rocket science, because even if you do that it's still
> not clear, what sort of parameter mode it is supposed to have. :P
Not really... Objects are passed by reference. That's the only rule you need
to remember ;-)
double is a simple type, Double is a class.
double dd = 3.142;
Double dD = new Double(d); //boxed..
More information about the fpc-pascal
mailing list