Finding joy in coding Using Pascal programming language

Started by
43 comments, last by jms bc 10 years, 10 months ago

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... ph34r.png )

Advertisement


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.


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).

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.

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?".

- Jason Astle-Adams

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.

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. smile.png

- Jason Astle-Adams


Nothing wrong with pascal though, keep on using it.

:=

==, ->

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

I agree about ->

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.

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

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

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.

This topic is closed to new replies.

Advertisement