[fpc-pascal] Illogical automatic dereferencing

Aleksa Todorovic alexione at gmail.com
Mon Oct 12 13:21:37 CEST 2009


On Mon, Oct 12, 2009 at 12:47, Jürgen Hestermann
<juergen.hestermann at gmx.de> wrote:
>>>>> No, it happens with static arrays,  if you set pia := @ia, ia[x] and
>>>>> pia[x] will give you the same result (in delphi mode, at least).
>>>>
>>>> It's simply more readable and a shortcut.
>>>
>>> It's definitely the opposite: It is *less* readable
>>
>> This is your opinion :) To my experience faking arrays with dyn. size by
>> using array declarations with infinite size (else you get in trouble
>> with range checking) are much more error prone and unreadable than using
>> pointers with an implicit dereference operator as arrays. As soon as you
>> start using them like normal arrays (new, high, sizeof, passing them to
>> open array parameters, no range checking) you get burned as well, even
>> not taking care the extra declarations you need.
>
> What has the one thing to do with the other? It would have been easy to
> introduce dynamic arrays without hiding away its nature from the user.
>
>> E.g. ansi- and widestrings or classes use implicit dereferencing as well
>> and they proved to work very well. If someone uses low level operations
>> like Move he should know what he does.
>
> That's just the point: Most users are left unclear about the nature of data
> structures and they start doing an trial and error approach (changing syntax
> as long as it is compiled). Then hope it will do what they intented. That's
> exactly C-style! Of course, there are some that look under the hood and know
> about the details and only these people are able to avoid such things as
> memory leaks or pointers pointing to freed memory and so on. The others
> stumble through it praying that it runs and as long as 80% procent works
> they are already satisfied. That's not the spirit of Pascal. The language
> should be clear and predictable from the start.


I like the fact that Pascal introduced high level data structures
(like dynamic arrays, automatic reference counting on string, etc),
because they make your life much easier. It is true that you have to
be careful when you mix these high level data structures with low
level data structures (pointers) and low level functions (Move), but
once you _learn_ and understand the nature of these structures, you
get used them.

You could equally say that we don't need arrays at all, because they
could be represented as record of pointer to the the first byte of
array, number of elements in array and size of one array element, but
that's exactly what arrays are during compile time :-) Plus, you get
type checking. See? When you really need some feature so much that you
start coding it over and over (like dynamic arrays based on pointer to
array), it makes sense to improve the language and the compiler.


-- 
Aleksa Todorovic - Lead Programmer
Eipix Entertainment
http://www.eipix.com/



More information about the fpc-pascal mailing list