Finding joy in coding Using Pascal programming language

This topic is 1657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Of course, but can we get back to the topic?

IMO C/C++ is like cleaning your apartment after large party. Pascal is like party itself - you can get things done quickly while enjoying yourself without shooting yourself in the foot.

Also great quote from David Keppel:

C++ provides a remarkable facility for concealing the trivial details of a program - such as where its bugs are.

Edited by Darkhog

Share on other sites
*shrugs* If I want to get something done quickly I'll go grab C#

Share on other sites

*shrugs* If I want to get something done quickly I'll go grab C#

Or python

Share on other sites

Pascal was actually the first programming language I used. It was before internet, and a friend had lots of patience for my endless questions by phone :)

I remember my first program, a small "piano" in text-mode "graphics", with lots of copy-paste, because I hadn't grasped the concept of "functions" yet.

Then I moved on to assembler, z80 and 68000 for TI calculators.

After a few years of that, transitioning into C and C++ felt very natural, "to get things done quickly" :)

Share on other sites

Of course, but can we get back to the topic?

IMO C/C++ is like cleaning your apartment after large party. Pascal is like party itself - you can get things done quickly while enjoying yourself without shooting yourself in the foot.

While I could agree with your conclusions.. the points you are making in this thread to prove your positions are just highlighting your total ignorance about C++ and C and absolute lack of understanding of programming in general.

It would be interesting to see how you propose to pass a string to a C function then... that'll be really entertaining or how useful would be to pass a copy of a Widget that I want to set the text on.. amaze me.

Share on other sites

*shrugs* If I want to get something done quickly I'll go grab C#

If all I care about, is how fast I can bang out code, I use Python 2.7
- It's so much faster to type than C# or Ruby

Share on other sites

Correct me if I'm wrong, but I'm sure I remember pascal having something to do with the Win32 API?

Share on other sites

*shrugs* If I want to get something done quickly I'll go grab C#

If all I care about, is how fast I can bang out code, I use Python 2.7
- It's so much faster to type than C# or Ruby

How exactly is it faster to type?

Share on other sites

*shrugs* If I want to get something done quickly I'll go grab C#

If all I care about, is how fast I can bang out code, I use Python 2.7
- It's so much faster to type than C# or Ruby

How exactly is it faster to type?

Syntax of Python is shorter than most languages

Share on other sites

Syntax of Python is shorter than most languages

CodeGolf would disagree. Python usually ranks about the same as PHP, significantly behind Ruby, which is behind perl. It's hard to compare C# in those scenarios due to the boilerplate that gets generated for you (so you don't have to type it) but with ScriptCS getting more popular, I wonder how it would fare.

Share on other sites

Syntax of Python is shorter than most languages

CodeGolf would disagree. Python usually ranks about the same as PHP, significantly behind Ruby, which is behind perl. It's hard to compare C# in those scenarios due to the boilerplate that gets generated for you (so you don't have to type it) but with ScriptCS getting more popular, I wonder how it would fare.

Since when is Ruby fast to type out ?

I always end up getting a little confused with it's mix-and-match syntax style.

Share on other sites

Since when is Ruby fast to type out ?

I always end up getting a little confused with it's mix-and-match syntax style.

Whatever you're most familiar with is going to be what you're fastest with. But with the codegolf example, the measurement is based on number of characters typed to provide a solution.

Share on other sites

Pascal was actually the first programming language I used. It was before internet, and a friend had lots of patience for my endless questions by phone

I remember my first program, a small "piano" in text-mode "graphics", with lots of copy-paste, because I hadn't grasped the concept of "functions" yet.

Then I moved on to assembler, z80 and 68000 for TI calculators.

After a few years of that, transitioning into C and C++ felt very natural, "to get things done quickly"

It was pretty much the same for me, allthough i dabbled with basic first and started my assembly journey with the inline assembler in pascal, my jump to "C++" wasn't all that smooth though (that damn rule of three caused me some major headaches tracking down memory leaks and wierd bugs due to shallow copies since i didn't write any copy constructors for my classes) (My C++ has gotten alot better though, mainly because i've picked up other languages SML and Java are probably the ones that have had the biggest impact on how i write code, allthough python is starting to leave a mark aswell now)

Share on other sites

Correct me if I'm wrong, but I'm sure I remember pascal having something to do with the Win32 API?

IIRC, some compilers used the "pascal" modifier for Win16 API functions.

in this case, AFAICT, it was pretty similar to "stdcall" used in the Win32 API.

both use callee stack clean-up, but the pascal pushed arguments from left-to-right, whereas stdcall pushes them from right to left (like cdecl).

beyond this? AFAIK, most of the core parts of early Windows were written in assembler, but later on (generally by Win9x and WinNT), most things were generally written in C and C++.

as for the Pascal vs C and C++ thing:

I mostly prefer C and C++ style syntax.

"var x:type;" and similar are passable IMO, partly as they are a bit more convenient from a parsing perspective (*1), and after exposure to a few languages which do things this way, one gets used to it. "type x;" is a little more convenient and cleaner looking though.

people often hate on the C-style "for()" loop for some reason, but it works.

it doesn't seem entirely unreasonably though that a language could support something like:

"for(i in 1 to 15) { ... }"

but this seems like a minor issue once a person understands what a "for()" loop in C is actually doing.

*1: a few common syntax elements in C-family syntax do tend to be a little troublesome to parse unambiguously, namely:

declarations; casts; templates / generics; ...

explicit keywords in these cases can make parsing these things a little easier, along with avoiding both possibly syntactic ambiguity as well as the problem of placing restrictions on various constructs.

as for "." vs "->", almost may as well make "." the default and otherwise treat them as analogous (with the compiler sorting out the rest).

as for ":=", "=", and "==".

I prefer "=" for assignment and "==" for comparison.

FWIW, the mathematical concept of "=" doesn't really exist in programming anyways, so really it can go either way.

it just so happens that variable assignment is a very common operation.

one frequent annoyance from a syntax design POV is the lack of more brace characters, hence the sometimes needed use of trickery to get more types of braces (sometimes context, sometimes ugly hacks).

granted, sometimes it may make sense to just use a few rarely used characters to stretch it out:

#(...), #[...], #{...}, $(...),$[...], \${...}, ...

along with some other options being double-braces and mismatched braces.

...

of course, potentially, many people might balk at something like:

"somegeneric#(T)" rather than the more usual and expected "somegeneric<T>" even if the latter makes more of a mess out of the parser.

then again, if the language has already gone as far as using "x:type" declarations, the designer may well be justified in being like "just deal with it".

Share on other sites

The reason for the pascal calling convention for most functions of the Win32 API is to save memory (when Windows 3.1 was out memory was limited in PCs). The called function cleans up the stack (since it knows how many arguments and how much stack space they require), this is done at the end of the function just before the RET.

With the C calling convention the stack is cleaned up by the caller after the function returns (the caller knows how many arguments were passed to the function). This means there are extra instructions following a return from a function, rather than the extra instructions being at the end of each function with the pascal calling convention, so more memory is used for the program with the C calling convention.

Since the caller knows how many arguments are passed to a function (and the function does not have to know), C calling convention supports variable length argument lists (like printf), whereas pascal calling convention does not. You will notice that Win32 functions which take a variable number of arguments do not use the pascal calling convention.

Share on other sites

PASCAL writeln() procedure uses variable argument lists.

Share on other sites

Presumably it must use a C-style calling convention for that then? (Another possibility is that the number/size of arguments is passed as a hidden parameter so that the called function can clean up the stack rather than the callee). EDIT: I'd have to look at the disassembly of the call to see what is going on in that case.

Anyway, that's the difference between pascal and C calling conventions (apart from the left to right parameter passing, again, it is easier to pass right to left if you use variable length argument lists, since the first argument is always bottom of the stack frame), and the reason for use in Win32 API was originally to save memory.

Share on other sites

There is no such language as C/C++ - yes, I know this point is sometimes pedantic, but it's important to distinguish when discussing something like pointers.

Can the OP clarify what he means by passing by value? I mean, passing strings and SDL_Surfaces by value would have the problem in C of copying large amounts of data - that's why C uses pointers.

C++ can do this by references - are you arguing against references and pointers? It can also handle this by copy-on-write, so passing by value doesn't necessarily copy data until required, but it's up to the classes/library to implement this.

How does Pascal pass information like strings around, or information to external libraries?

The SDL and WinAPI examples are C interfaces, not C++ ones. I guess it is a valid complaint that people often don't bother to write C++ interfaces, so you're still forced to deal with C-style interfaces and pointers in C++, but then I thought that it's harder to find out-of-the-box support for Pascal too? What do the same APIs for Pascal look like?

For the Qt example, the strings are passed by reference.

Share on other sites

Pass parameters by reference as C++ mention is a language construct. But normaly is implemented with pointers. Pointers are references too.

Niklaus Wirth, the founder of PASCAL, defined the two possibilities to pass parameter by value, logicaly copying them onto the stack, or passing them by reference. He uses these two mechanisms for to (dis-)allow a function/procedure to change the passed parameters on the callers side. This behaviour of passing parameters by reference and this way makeing the changes to the parameter within a function/procedure visible to the caller has introduced the "side-effect".

Using pointers and their description as something that describe the location where the value resides makes it easier to understand side-effects. For the C-Language using pointers was the only way of change a value within  a function and make it visible to the caller.

C++ introduced the reference with the same meaning and implementation but with the benefit not to stumble upon pointer arithmetics or with very unclean access to arrays of elements where only a single parameter was passed.

I do understand the reference in C++ but mostly use pointers because I am very familiar with that concept and always think in pointers.

AFAIK ANSI PASCAL has no modules concept. All code is put into a single file. And so you need no external libraries. Passing a string by value means copying to the stack. Needs a bit room on it.

Share on other sites

I know some grey hairs that still use Delphi 7.

A few years ago you might envy the built-in extended real data type (10 bytes), and the progs always seemed to run faster than what you could get from msvc with similar effort.