开发者

How to do OOP with Pascal?

开发者 https://www.devze.com 2022-12-10 06:25 出处:网络
I am learning OOP with the pascal programming language.After googling the Internet, I found the OOP --开发者_开发百科 The GNU Pascal Manaul.

I am learning OOP with the pascal programming language.After googling the Internet, I found the OOP --开发者_开发百科 The GNU Pascal Manaul.

What does this function declaration mean?

function Baz (b, a, z: Char) = s: Str100; { not virtual }

I have never seen = xx before, and it seems that the pascal syntax does not have it.


That appears to be some nonstandard extension. The implementation of the function in question is:

function FooParent.Baz (b, a, z: Char) = s: Str100;
begin
  WriteStr (s, 'FooParent.Baz (', b, ', ', a, ', ', z, ')')
end;

Normally in Pascal, the name of the function is used as the function return variable, so the above function would be written like this:

function FooParent.Baz (b, a, z: Char): Str100;
begin
  WriteStr (Baz, 'FooParent.Baz (', b, ', ', a, ', ', z, ')')
end;

It appears that the = s syntax indicates that the return value of the function is stored in the variable s inside the function body. I'm not sure why that would need to be exposed in the object interface, though.


I can't answer your question but I suggest to learn OOP with a language like Python or Groovy. Pascal isn't really something on which you'll be able to build a career. I'd rather suggest that as a third or fourth language to give you some ideas how other languages work but not as your first/main language.

Both offer an interactive console (for Python, I suggest iPython) where you can do small experiments.

Note: Some people attack me on the grounds that I don't know much about Pascal. I'm not sure where you get that idea. I have over 200K points on SO, I know 30 programming languages (know == written large amounts of code in it), I've written code in Pascal at the beginning of my career.

I understand it hurts when your beloved programming language doesn't get the recognition you feel it deserves. A no brainer: You made the decision to use that language, so it must be the best one - otherwise your decision would be wrong.

But when I compare code written in all the languages that I know, Pascal/Delphi/Modula/Oberon are among those which I don't recommend for various reasons. Delphi got some traction because of Borland but that's over. I've seen the code which good Delphi programmers wrote and my first thought was: Maintenance cost.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号