flat assembler
Message board for the users of flat assembler.

Index > Heap > C++ vs Object Pascal

Goto page 1, 2, 3  Next
Author
Thread Post new topic Reply to topic
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
I mainly use C++, so I'd like to know: How does Object Pascal TODAY compares to C++?

I've been looking recently at Free Pascal (and the Lazarus IDE). It's a very interesting project as it aims to compile Delphi apps and it supports multiple platforms.

If anyone here uses it, what are your thoughts?
Post 15 Jan 2013, 18:46
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Pascal rules! Smile Object Pascal is better language than C/C++ and generally all "curly bracket languages". As HaHaAnonymous already said - it is much more readable.
Of course, FASM is even better. That is why I abandoned Delphi programming at all.
Post 15 Jan 2013, 19:44
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Spool



Joined: 08 Jan 2013
Posts: 154
Spool
[ Post removed by author. ]


Last edited by Spool on 17 Mar 2013, 03:52; edited 1 time in total
Post 15 Jan 2013, 20:12
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Actually I am not sure C++ is faster than Pascal. And Pascal allows using inline assembly natively.
Post 15 Jan 2013, 20:20
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
I just saw there's Android support in Lazarus/fpc:
http://wiki.lazarus.freepascal.org/Custom_Drawn_Interface/Android

I'm downloading the VirtualMachine with the full development enviroment.

This looks very cool.
Post 15 Jan 2013, 23:45
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
OzzY wrote:
I mainly use C++, so I'd like to know: How does Object Pascal TODAY compares to C++?


I don't know much about Object Pascal.
C++ is still evolving, currently with C++11 (adding more complexity?)
Post 16 Jan 2013, 01:00
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
JohnFound wrote:
Actually I am not sure C++ is faster than Pascal. And Pascal allows using inline assembly natively.


This is an implementation issue, not a language design issue.
Comparing implementations can be tricky, I think, because it's possible that one compiler supports a certain optimization, while the others not.

That's why in the end we always have to take a look at the assembly output Smile
Post 16 Jan 2013, 01:05
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Comparing implementations is easy actually. It is enough to see how one particular feature is implemented:

First C++:
Code:
   int no = 100, val ;
        asm ("movl %1, %%ebx;"
             "movl %%ebx, %0;"
             : "=r" ( val )        /* output */
             : "r" ( no )         /* input */
             : "%ebx"         /* clobbered register */
         );   int no = 100, val ;
        asm ("movl %1, %%ebx;"
             "movl %%ebx, %0;"
             : "=r" ( val )        /* output */
             : "r" ( no )         /* input */
             : "%ebx"         /* clobbered register */
         );    


And Turbo Pascal:
Code:
procedure swap (var a, b : word); assembler;
asm
  les di,[a]
  mov ax,[es:di]
  les di,[b]
  mov bx,[es:di]
  mov [es:di],ax
  les di,[a]
  mov [es:di],bx
end;    
Post 16 Jan 2013, 04:44
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
TmX wrote:
C++ is still evolving, currently with C++11 (adding more complexity?)
More complexity, yes, but most at it in the compiler end - reducing the complexity for programmers. This is A Good Thing(TM). Autos (judiciously used!), ranged-based for and lambdas can really reduce your code complexity, and result in some pretty beautiful and easy to read code - with decent enough performance as well. Move semantics are wonderful for performance. Initializer lists + Uniform initialization are nice pieces of syntactic sugar.

And finaly there's core support for threading (more work than you might think, as it required not just library support but also memory model specificatiosn... and there's a lot more to threading than just CreateThread.) - there's improvements to the standard library as well. I'm a bit on the fence whether it was a good idea to include regex support, not having a huge base library is both an advantage and a curse of C++ and regex can definitely be handled platform-independently by 3rd party code... OTOH, regex is a core programming feature these days. Still, I'm on the fence. It's a shame TR2::filesystem didn't make it, since that's something you need for portable programmig - then again, there's plenty of C++ target platforms without filesystems, and you can drop in the Boost version Smile

I feel that C++11 is now a pretty comfortable language to work in, while still offering kick-ass performance. Granted, you won't be able to use it for ├╝ber-portable software (that needs to target very limited devices or derelict platforms with dusty compilers), and probably not for existing C++ legacy projects... but development of modern applications for capable systems? Not a bad choice. Not the best choice for any kind of system either, but right tool for the job and all that.


JohnFound wrote:
Pascal rules! Smile Object Pascal is better language than C/C++ and generally all "curly bracket languages". As HaHaAnonymous already said - it is much more readable.

Can you quantify some reasons why it's a better language? Or is that simply a subjective feeling? Also, is your "much more readable" based solely on BEGIN/END vs. {}, or other language aspects as well? (I hope it's not based on the curlies alone - that's purely a matter of (very short) language exposure... and it's less visual clutter than BEGIN/END).


JohnFound wrote:
Comparing implementations is easy actually. It is enough to see how one particular feature is implemented:

First C++:

"C++" has no notion of inline assembly, that's an implementation detail. But from the code snippet, I'm guessing GCC. Which is kinda ugly (one thing is AT&T style vs. Intel, but that's a matter of taste - and afaik you can switch to .intel_syntax, at least you can for pure GAS) - and then there's the rest of how it's represented.

It does, however, allow for a lot more optimization than the "dumb" Pascal inline assembly - for code that doesn't depend on specific registers, you can work with the compiler's register allocation instead of against it.

If you're going to limit yourself to "dumb" WYWIWYG assembly code, you're better suited writing an external module in an assembly flavor that's portable between compilers, instead of locking yourself into one compiler's inline-assembly syntax. If you're going to claim "but my asm snippets are too small to warrant call/ret overhead!", then You're Doing Things Wrong(TM).

_________________
Image - carpe noctem
Post 16 Jan 2013, 09:38
View user's profile Send private message Visit poster's website Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
f0dder wrote:
More complexity, yes, but most at it in the compiler end - reducing the complexity for programmers. This is A Good Thing(TM). Autos (judiciously used!), ranged-based for and lambdas can really reduce your code complexity, and result in some pretty beautiful and easy to read code - with decent enough performance as well. Move semantics are wonderful for performance. Initializer lists + Uniform initialization are nice pieces of syntactic sugar.


Well it has been my long impression that Object Pascal is a less complex language compared to C++.
And I must admit I haven't read about C++11 throughly. On a glance, it do looks nice.

And of course, only hardcore UNIX geeks who insist to write everything in C.

Very Happy
Post 16 Jan 2013, 10:44
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
f0dder, Pascal is better (more readable) language because of its origin. It was planned to be readable, because it was created for teaching purposes.
Only the effort of Borland turned Pascal to be suitable for professional programming.

Anyway, it is true that the curly brackets produce "less visual clutter" than begin/end, but is it an advantage? I don't think so! Actually "less clutter" means exactly "less noticeable".
But the brackets are not something insignificant in the source code!
They specify the structure of the program and they must be noticeable. Less visible == less readable.

Another bad side of C/C++ are the augmented assignments and the unary operators - all these += ++ --. They are implemented in the language with the sole purpose to be used with less type effort and in order to optimize the generated code. But they really make the source less readable. (Pascal implements some of these, but in better way - not as unary operators, but as functions inc(some_var) and dec(some_var)Wink. IMO, the optimization of the arithmetic expressions is a compiler's task, not programmer's.

Another good Pascal side are the units - they are so better than the C/C++ header and source files. The units solve the namespaces conflicts in really elegant way.

I will not write much about the OOP syntax. The C++ one looks like a dirty hack compared with the carefully planned OOP syntax of Object Pascal. Smile
Post 16 Jan 2013, 11:56
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
JohnFound: well, I disagree on the curlies - I'd say it's a matter of personal preference and exposure to the language. Perhaps I'll change my mind when I get old and get very bad eyesight, but I don't the curlies any less visible - just less cluttered. To me, Pascal's IF-THEN/BEGIN/END is overly verbose and the curlies are succinct.

Same goes for for assignment and operators. If you see C code for the first time without any previous experience with the language, sure thing, some of the operators are not immediately obvious. But outside of teaching languages, I find that a language should be written with daily usage in mind. (Well, there's a balance to be found. I personally do find that for most normal code, C++ hits the balance relatively well - some of the academic languages are overly terse and look like symbol soup).

You could argue that PRED/SUCC has some merit, but that's only really if you follow functional programming style, and if PRED/SUCC can be extended to support UDTs (I'm not sure if that's the case with today's Pascal compilers?). But instead INC/DEC I'll take my unary -- and ++ operator any day, pre- as well as postfix. Not for "optimization" reasons, but because of code style Smile

JohnFound wrote:
Another good Pascal side are the units - they are so better than the C/C++ header and source files. The units solve the namespaces conflicts in really elegant way.

Hell yes, that's one of the few things I missed (and kept on missing) after moving from Pascal. Includes are a nice feature to have, but it should be in addition to a proper module system, not in place of it. It's really a much cleaner way to organize things, and has the benefit of beeing oodles of times faster as well.

JohnFound wrote:
I will not write much about the OOP syntax. The C++ one looks like a dirty hack compared with the carefully planned OOP syntax of Object Pascal. Smile

Dunno about that - and I guess it also depends on what exactly you mean by "Object Pascal"? Is there a formalized standard for it now? The dialect in Delphi definitely has some extensions to the dialect in TP6 Smile. It's been ages since I did any Pascal OOP, but as far as I recall the concepts are pretty much the same - or do you have any specific examples?

Only things that really spring to mind would be that templates can get extremely hairy, but that's a bit to the side of "just" OO. And one could argue that "!" should have been used instead of "~" for specifying destructors ;p.

Btw, I'm not asking to turn this to a flamewar or "my language is bigger than yours", but since I moved from pascal and would consider it mostly a setback (though Object Pascal certainly has evolved since I used it last, and I definitely wouldn't mind modules or properties in C++!), I'm interested in hearing other people's opinions. Who knows, I might come out wiser Smile

Btw, one thing that Pascal does elegantly are subranges for numeric types - there's not really any super clean and nifty way to do that in C++.

_________________
Image - carpe noctem
Post 16 Jan 2013, 12:48
View user's profile Send private message Visit poster's website Reply with quote
asmhack



Joined: 01 Feb 2008
Posts: 431
asmhack
It's personal preference after all. For me the best language for rapid windows application dev remains visualbasic Twisted Evil

Code:
me.caption = app.exename
    


Still tho I don't see the reason using pascal over C++. Or delphi.


Last edited by asmhack on 16 Jan 2013, 14:29; edited 1 time in total
Post 16 Jan 2013, 14:23
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
f0dder, I also moved from Pascal.
But to FASM, not to C/C++. Wink
Post 16 Jan 2013, 14:53
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
HaHaAnonymous wrote:
Microsoft wants monopoly (which is not good).


You don't have to use MS compilers, if you don't want to.


Unless you are forced to use it for work Wink
Post 16 Jan 2013, 15:26
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
f0dder, JohnFound, just to keep the "fighting" going Razz : What do you think about pointer syntax for both declaration and dereference on things like pointers to functions/procedures, variables, double indirection (anything else?).
Post 16 Jan 2013, 16:26
View user's profile Send private message Reply with quote
Spool



Joined: 08 Jan 2013
Posts: 154
Spool
[ Post removed by author. ]


Last edited by Spool on 17 Mar 2013, 04:18; edited 1 time in total
Post 16 Jan 2013, 16:44
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Spool, actually not so much in the case of Pascal (or at least TP, Delphi, FreePascal as I remember). I don't remember how Pascal handled pointer arithmetic though, I remember it was possible, but can't recall whether adding one advanced the pointer by one byte or one data unit.

I would enter the discussion, but unfortunately I remember too little Sad (other than liking Pascal syntax over C in this regard)
Post 16 Jan 2013, 17:08
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Pascal handles pointers in pretty readable manner. "&Something" is the address of the something. And "SomePointer^" is the object (variable, etc.) pointed by SomePointer. The pointers are typed, so the language always knows what type is the variable. For example "type MyPointerType = ^integer" or "var MyPointer: pointer to integer". There are type casting of course and other extras as well.
In the OOP, the objects are actually pointers to the object instance. But the syntax mimics normal variables, which is really useful, because it makes the syntax very clean. For example if you have some TMemo object (multiline editor) you can do:
Code:
var MyMemo: TMemo;
MyMemo = TMemo.Create(MainForm);
MyMemo.text = "My little novel.";
MyMemo.Visible = true;    
Post 16 Jan 2013, 17:57
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Spool



Joined: 08 Jan 2013
Posts: 154
Spool
[ Post removed by author. ]


Last edited by Spool on 17 Mar 2013, 03:52; edited 1 time in total
Post 16 Jan 2013, 18:10
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.