/* attempt to deal with prototype, bootstrap, jquery conflicts */ /* for dropdown menus */

\$2

### Image of the Day Submit

IOTD | Top Screenshots

## Finding joy in coding Using Pascal programming language

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

44 replies to this topic

### #1Darkhog  Members

Posted 28 June 2013 - 04:45 PM

Don't get me wrong - C/C++ is great and has many uses, but using it can be sometimes a chore.

Why? Because of pointer hell. In C/C++ pointers are used literally everywhere, even where passing by value would be enough. Like here:

int WINAPI MessageBox(
_In_opt_  HWND hWnd,
_In_opt_  LPCTSTR lpText,
_In_opt_  LPCTSTR lpCaption,
_In_      UINT uType
);


That's right. This is WinAPI's message box function. LPCTSTR in case you don't have WinAPI experience, is pointer to string. WTF? This function doesn't even NEED pointer to where string is stored as it doesn't change it. It only show standard Windows message box.

Such quirks aren't even specific to WinAPI (which, admittedly, is poorly written). Most of C/C++ APIs I had even "pleasure" to work with are littered with things like that. Like Qt:

void QMessageBox::about(QWidget * parent, const QString & title, const QString & text)


Same sin as in case of WinAPI.

But we want to make games, don't we? Let look into some game API, say, SDL:

Synopsis

#include "SDL.h"

Description

Loads a surface from a named Windows BMP file.

Return Value

Returns the new surface, or NULL if there was an error.

SDL_SaveBMP

Why it even returns pointer, when returning value (SDL surface) would be enough?

Such approach results in things like memory leaks and other sort of "fun" stuff. Pointers should be only used when you need write access to variable you are passing and can't afford working on a copy (passing by value).

Finding joy

Above thing which I've dubbed "Pointer Hell" was thing that made me chose Pascal (Object Pascal specifically) as language of choice when developing games. In Pascal you only use pointers when you actually need them. Which is almost never as most things you can do without touching them.

Unless, of course, you are interfacing with some c/c++ library, like I'm doing with Allegro.

Pascal also provide syntax that any human (or non- human ;)) being who happen to know English can read and in many cases comments aren't even needed to understand what code does. Unless you reading code from some obfuscation contest or written by first-time programmer.

Also when coding in Pascal you can really enjoy this. You don't have to worry about memory leaks and for the most part logic bugs are easy to fix. There is also helpful community related to game making ready to help when you happen to have some issues. It's mostly because of them I could progress so far when writing Super Heli Land.

Notable games and software written with Pascal:

- Original Jazz Jackrabbit (Turbo Pascal 7.0)

- RPG Maker 2003 (Delphi, not sure about version)

- Resource Hacker

- Hedgewars, the Worms clone - freepascal (engine, rendering) plus some c++ bits mainly because there was no good Qt bindings for Pascal when project was started.

- This.

Edited by Darkhog, 28 June 2013 - 06:37 PM.

### #2Alpheus  GDNet+

Posted 28 June 2013 - 05:07 PM

Whatever programming language you are comfortable and productive in is a good language.

External Articulation of Concepts Materializes Innate Knowledge of One's Craft and Science

Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley

If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts

Spoiler

### #3Darkhog  Members

Posted 28 June 2013 - 05:08 PM

Now, where is up arrow when you need it?

### #4Olof Hedman  Members

Posted 28 June 2013 - 05:17 PM

That's right. This is WinAPI's message box function. LPCTSTR in case you don't have WinAPI experience, is pointer to string. WTF? This function doesn't even NEED pointer to where string is stored as it doesn't change it. It only show standard Windows message box.

I don't think you even know what the point of pointers are...

What has changing the string to do with anything?

Why should you copy the entire string around in the function call, and mess with dynamically sized data, when all the function need is a pointer to a string to use?

That would be a massive waste of time.

I'm pretty sure Object Pascal use pointers most of the time too, it just hides the fact better...

For c++, you can use references to get a bit nicer syntax, but they are still just pointers with some extra rules. (like inability to be un-initialized)

Why are you so scared of asterisks anyway?

Nothing wrong with pascal though, keep on using it.

I do wish C++ had some nicer syntax for smart pointers...

Still havn't really gotten used to using them. Probably because I'm too used to the simplicity of raw pointers...

Doesn't help that my debugger seem to have problems showing them correctly too...

Edited by Olof Hedman, 28 June 2013 - 05:24 PM.

### #5alnite  Members

Posted 28 June 2013 - 06:08 PM

Nothing wrong with pascal though, keep on using it.

:=

Edited by alnite, 28 June 2013 - 06:09 PM.

### #6Darkhog  Members

Posted 28 June 2013 - 06:30 PM

Nothing wrong with pascal though, keep on using it.

:=

==, ->

If you don't have any substantial things to say, don't post.

Edited by Darkhog, 28 June 2013 - 06:36 PM.

### #7TheChubu  Members

Posted 28 June 2013 - 07:37 PM

Nothing wrong with pascal though, keep on using it.

:=

That. And if begin end else begin end blocks. Which are madness. Then the "var" thing after procedures/functions, which is also madness. : before the type? Madness.

I also agree that -> operator is madness in C++ though.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

### #8Bacterius  Members

Posted 28 June 2013 - 08:53 PM

That. And if begin end else begin end blocks. Which are madness. Then the "var" thing after procedures/functions, which is also madness. : before the type? Madness.

You will enjoy Golang.

Object Pascal is the first language I learned. Say what you will, even if it may not have been the most trendy language ever conceived (though it is actually still quite popular in Europe and Russia) the reason I really like it is that it just works. Things are straightforward, there is no 1300-page standard to endlessly debate on, and heavy development has been put in creating the two main visual component libraries which now power basically all of its GUI applications (the VCL and the FCL, Delphi & Free Pascal respectively). The GUI builder integrated in the two main IDE's is wonderful and is perfect for utility/business applications (though not everyone will like it nor need it). It's fun and enjoyable to develop in this language. Programming is fun again!

Also, cross-compiling is very good (for FPC - it is nonexistent for Delphi, obviously), inline assembly support is generally flawless (and much more elegantly integrated than how C++ does it, or at least gcc/g++) and despite people claiming otherwise, it still performs quite well in terms of performance. And, yes, cross-compiling applies to the visual library too, so you won't need to mess around with half-baked cross-platform themed GUI libraries - it's already there.

Finally, the Pascal spirit of "doing things at as high a level as possible, but seamlessly dropping to a lower level when required, all the way down to inline assembly if necessary" has always appealed to me and you will find few languages which are capable of blending those different programming levels as elegantly and idiomatically (though this is arguably subjective).

Now I'm not crapping all over C++ here. Every language has its pros and cons. And while Pascal has never gained the traction and popularity of C++, Java, or even Python, just because it's a relatively obscure language today and has a syntax that (gasp) doesn't consist of curly braces and asterisks doesn't mean it cannot be used effectively.

So, no, you can't write embedded software in Pascal or some other stuff, but what it can do, it does it very well. The only thing missing is.. well.. support. Borland dropping Delphi was basically the nail in the coffin, it's pretty obvious the language is slowly going the way of the dodo but while it's there we can still use it.

To be frank I find the whole attitude towards Pascal rather close-minded.

Edited by Bacterius, 28 June 2013 - 09:33 PM.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

### #9Servant of the Lord  Members

Posted 28 June 2013 - 09:06 PM

Hey, just because you like to fly planes over mountain ranges doesn't mean we all want to. Some of us enjoy the lung-killing climb up Mount C++.

That said, SDL and Win32 are designed for 'C'. Despite the fact that people use it with C++, it must use C-only language features, hence the pointers.

You'll notice Qt (which is C++) uses const references where appropriate, which removes the so called 'pointer hell' you are talking about.

void QMessageBox::about(QWidget * parent, const QString & title, const QString & text)


The parameter 'parent' is optional, so it's a pointer - you can pass in nullptr if you just want a message box without attaching it to any other window.

It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

### #10Hodgman  Moderators

Posted 29 June 2013 - 12:15 AM

That's right. This is WinAPI's message box function. LPCTSTR in case you don't have WinAPI experience, is pointer to string. WTF? This function doesn't even NEED pointer to where string is stored as it doesn't change it. It only show standard Windows message box.

LPCSTR is not a pointer to a string. It is a string. It is an array of null-terminated characters.

C does not have a string type, so the standard way to represent a string is by using an array of characters, which decays to a pointer.

There's nothing wrong with QMessageBox::about. If the partent was passed by value, that would clone the parent and the message box would be attached to the clone instead of the original (desired) parent. The intention is to share a single object in multiple places, so a pointer is required.

The strings are passed by const-reference, which is the same as a pointer, but with the guarantee that they won't be modified, so it looks just like pass-by-value. The difference is that pass-by-value would create copies of the strings, which is a complete waste of time. If the API required that all string arguments be reallocated for no reason, it would be a bad API.

The SDL_Surface is allocated by the API and reference counted. The object that's pointed to by your return value is a shared object, more than one part of the code may be pointing to the same shared object. Returning by value would completely break this shared-asset design.

I appreciate your pascal joy and your dislike of C  ... but your critiques of "bad" C code above simply show that you haven't learnt C or C++ yet and aren't qualified to critique those APIs  Critique the language that results in these API designs, fine , but your supposed API flaws are not flaws.

P.S. I enjoyed using the "become equal to" / "assignment" / ":=" operator, rather than "=", which mathematically means equivalence, not assignment.

Edited by Hodgman, 29 June 2013 - 12:18 AM.

### #11Vortez  Members

Posted 29 June 2013 - 01:38 AM

LPCSTR is not a pointer to a string. It is a string. It is an array of null-terminated characters.

Dosen't LPCSTR mean Long pointer to const c-string? or do you mean delphi string?

Anyway, personally, i love both c++ and delphi equally, in fact, i love delphi way more than c# since it's more close "to the metal". All the stuffs you can do

in c++, you can do in delphi.

Most of the time when i need a complicated win32 application, i use both language. Delphi for the interface, and a c++ dll for the more complicated stuffs.

That way i have the best of both world. I even know a trick to use c++ class exported from dlls using pure virtual classes, and that is just awsome, albeit

it require a little more coding time since you need to provide an additionnal .pas file for the dlls declaration. Delphi is also freaking great for writting custom win32 components in a snap once you get the hang of it. And, Delphi programs runs natively, no need for the silly .net framework. I last but not the least, it's by far the fastest compiler know to man.

The only thing i hate in delphi is the stupid := operator.

Just my 2 cents.

Edit: I dunno why the guy removed the code of the pure virtual functions... it work flawlessly with like 20 different classes in my personal library. It also work for c++ builder...

And for the OP, pointers can look scary at first but it's a very important principle to understand in programming, and once you understand them,

you will say "Oh, it was not that complicated after all". I've explained them a little while ago here.

(Somehow the example i gave got wrapped on a single line... )

Edited by Vortez, 29 June 2013 - 02:19 AM.

### #12Hodgman  Moderators

Posted 29 June 2013 - 02:43 AM

Dosen't LPCSTR mean Long pointer to const c-string? or do you mean delphi string?
Yes, that's how you'd expand out the confusing microsoft abbreviation. It's a "string pointer", and it' usually just a typedef for "char*".

i.e. it's not actually a pointer to a string. It's a pointer to a character, because there is no string type. However, it's assumed that this character will be followed by followed by more and more characters until a null character is reached.

A null-terminated array of characters is a "C string". You can't pass it by value -- but an array can decay to a pointer, so you can pass a pointer to the first element in the array.

So, the LPCSTR is actually a pointer to the first character in the string (not a pointer to a string), and that pointer actually represents the string itself. When you pass the LPCSTR by value, you're passing the string by pointer.

### #13Darkhog  Members

Posted 29 June 2013 - 04:42 AM

That. And if begin end else begin end blocks. Which are madness. Then the "var" thing after procedures/functions, which is also madness. : before the type? Madness.

You will enjoy Golang.

Object Pascal is the first language I learned. Say what you will, even if it may not have been the most trendy language ever conceived (though it is actually still quite popular in Europe and Russia) the reason I really like it is that it just works. Things are straightforward, there is no 1300-page standard to endlessly debate on, and heavy development has been put in creating the two main visual component libraries which now power basically all of its GUI applications (the VCL and the FCL, Delphi & Free Pascal respectively). The GUI builder integrated in the two main IDE's is wonderful and is perfect for utility/business applications (though not everyone will like it nor need it). It's fun and enjoyable to develop in this language. Programming is fun again!

Also, cross-compiling is very good (for FPC - it is nonexistent for Delphi, obviously), inline assembly support is generally flawless (and much more elegantly integrated than how C++ does it, or at least gcc/g++) and despite people claiming otherwise, it still performs quite well in terms of performance. And, yes, cross-compiling applies to the visual library too, so you won't need to mess around with half-baked cross-platform themed GUI libraries - it's already there.

Finally, the Pascal spirit of "doing things at as high a level as possible, but seamlessly dropping to a lower level when required, all the way down to inline assembly if necessary" has always appealed to me and you will find few languages which are capable of blending those different programming levels as elegantly and idiomatically (though this is arguably subjective).

Now I'm not crapping all over C++ here. Every language has its pros and cons. And while Pascal has never gained the traction and popularity of C++, Java, or even Python, just because it's a relatively obscure language today and has a syntax that (gasp) doesn't consist of curly braces and asterisks doesn't mean it cannot be used effectively.

So, no, you can't write embedded software in Pascal or some other stuff, but what it can do, it does it very well. The only thing missing is.. well.. support. Borland dropping Delphi was basically the nail in the coffin, it's pretty obvious the language is slowly going the way of the dodo but while it's there we can still use it.

To be frank I find the whole attitude towards Pascal rather close-minded.

So true.

Also there are in fact THREE component libraries for Pascal. VCL, which is Delphi-specific, FCL which is Freepascal's one and LCL which stands for Lazarus Component Library and is for Lazarus IDE (Delphi clone - if you used Delphi 7 or earlier, you'll feel right at home). True, VCL and LCL share many things in common, but some VCL components cannot be ported to LCL without rewriting whole thing and vice versa. So please don't confuse them.

Another thing... Yes, you can write embedded software in Pascal. FPC (Free Pascal compiler) has ARM target and it is possible to write software for GBA or NDS (!) using it. And what is GBA or NDS if not specific kind of embedded device designed to play games?

Also since it support ARM as target, you could, in theory, write software for any ARM device.

There are also Pascal compilers that translate pascal into JS and thus make possible to develop HTML5 apps using it. One such compiler is Smart Mobile Studio. There is Oxygene for Java, which can take Pascal code and transform it into JVM byte code (Lazarus can even use it by selecting jvm compiler target, though from I've gathered this feature is still experimental).

Another thing:

Nothing wrong with pascal though, keep on using it.

:=

That. And if begin end else begin end blocks. Which are madness. Then the "var" thing after procedures/functions, which is also madness. : before the type? Madness.

I also agree that -> operator is madness in C++ though.

Now, take those two codes to some friend who isn't programmer. First show it this:

for (i=0;i<15;i++) {
Car[i]->Ignite
}

then this:

for i:=0 to 14 do
begin
Car[i].Ignite
end;

and tell them to decipher where code actually begins and what it really does (ask also him how many cars it would actually ignite). He won't have any problems with Pascal one, but c++ one... Well, if he deciphers it he lied to you when he said he isn't programmer. That's the power of pascal - ANYONE can program with it and code still will be readable unless you read code from obfuscation contest or made by first-time programmer (and even in last case, you'll find out you can decipher it after few minutes).

### #14Olof Hedman  Members

Posted 29 June 2013 - 05:19 AM

I think the non-programmer would incorrectly say "That pascal code ignites 14 cars", when it in fact ignites 15 cars, which is more clear in the C++-code.

But I guess you made a typo, and intended to write  "for i:=1 to 15 do", since it seems many pascal programmers prefer to let their array indices start at 1, and then the pascal syntax is a tiny bit clearer.

Edited by Olof Hedman, 29 June 2013 - 05:25 AM.

Posted 29 June 2013 - 05:38 AM

I think you've forgotten the first piece of code your ever saw, waaaay back before you could program.  Without prompting, it's not particularly obvious to the uninitiated that either of those code samples represents looping through a series of cars and igniting each -- I'm sure some people would figure it out, but without any programming background they're really just guessing, with either version.

Just tried it on my wife, and she guessed that "it has something to do with igniting cars... maybe after 14 seconds, or the 14th car, or something?".

### #16Darkhog  Members

Posted 29 June 2013 - 05:41 AM

Dunno about other coders, Olof, but I use 0-indexed arrays.

And @jbadams, maybe you're right. My first program I ever written )in Turbo Pascal) was when I was 9 years old and it was simple program asking for name and then printing Hi, (name). And now I'm 23 years old, so you're probably right.

Posted 29 June 2013 - 05:46 AM

It's a trap most people fall into eventually -- as you learn more and more advanced topics, more basic things become so utterly trivial that it's hard to remember they were ever difficult -- as an adult most people are only tripped up when trying to read longer more complicated words, or foreign languages, but as my 6-month-old daughter has been reminding me, it's initially very difficult to reliably get out even a single syllable let alone short words.

There's no question that some syntax is easier to read than others, but in many cases it just comes down to personal preference as well as your existing bank of knowledge -- unless you're actually using plain English the nicest syntax in the world doesn't help someone unfamiliar with the concept of iterating through a collection.

Posted 29 June 2013 - 05:58 AM

Nothing wrong with pascal though, keep on using it.

:=

==, ->

If you don't have any substantial things to say, don't post.

However, == has a reason behind it, they (K&R) had a choice between := or = for assignment and = or == for equality. They analysed a load of programs and found assignment was at least 3 times more common than checking for equality, so they made it a single character rather than 2.

Edited by Paradigm Shifter, 29 June 2013 - 05:59 AM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #19Code Fox  GDNet+

Posted 29 June 2013 - 07:44 AM

If your dealing with Windows API, wouldn't it be a lot easier to use one of the "Visual Studio" suites ?

msgbox("Can't we all just get along?")


I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

### #20Darkhog  Members

Posted 29 June 2013 - 10:25 AM

If your dealing with Windows API, wouldn't it be a lot easier to use one of the "Visual Studio" suites ?

msgbox("Can't we all just get along?")

Unfortunately not everyone uses Visual Studio (especially if they want to make game/software that is actually portable). Also in most cases people seem to want to reinvent the wheel, like here: http://thedailywtf.com/Articles/A-First-Date.aspx.

Anyway from C-Like languages I particularly like Java and C#. First because of its clean, object-oriented syntax (though getters/setters gets to me and I don't use them in my own classes) and latter maybe because it was designed by guy who worked on Delphi (though I felt in love with C# thanks to Unity and learned about that same guy who worked on Delphi worked on C# also just recently). I kinda like Ruby too, but since it is only used in RPG Maker series and I rarely use RPG Maker, I don't have any occasions to practice it.

Edited by Darkhog, 29 June 2013 - 10:25 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.