English 中文(简体)
Why does pascal forbid same identifier name for method s parameter and class s data member?
原标题:
type
    TPerson = class(TObject)
        name : string;
        constructor create(name : string);
    end;

would trigger compiler error.

I think a self or this pointer/reference is good enough,for its clarity. So, what are the advantages of doing so?

EDIT: One more question, could you show what are the other languages that deploy this policy?

最佳回答

To prevent name clashes where the parameter name would shadow the class member. It just can t happen this way and every name is unambiguous.

Remember that Pascal is a bondage-and-discipline language; those are designed to try to prevent common errors.

Another option to prevent the perceived problem is what Python does: mandate the qualification of instance members with this or self so that you have to prefix every instance member access with self.

I don t know of any other language with that restriction, though. But some language features are indeed unique; checked exceptions for example are, too.

问题回答

暂无回答




相关问题
Summing Numerical Character String

I m having an issue with my programming assignment where I cycle through a string and sum the integer value of character. As the following code states. Now I pass a string into this subroutine. For ...

What is the best way to join 2 records in Pascal?

I ve a little problem with records in Pascal. I m writting a program where I ve got two lists of records: one with patients and second with diseases but I don t have idea how to join it. I was trying ...

Untyped Pointer in Pascal

What can I do with untyped pointers in Pascal? (Why untyped pointers are good?)

Tutorial for Pascal/Delphi for C++-Coders

I m a C++-Programmer. But now i have to learn Pascal/Pascal. Are there any websites, documents around that can teach someone with my knowledge the difference?

热门标签