[Lazarus] 'with' is evil, isn't it?

Michael Van Canneyt michael at freepascal.org
Wed Aug 3 16:36:02 CEST 2011



On Wed, 3 Aug 2011, Mark Morgan Lloyd wrote:

> Michael Van Canneyt wrote:
>> On Wed, 3 Aug 2011, Graeme Geldenhuys wrote:
>> 
>>> On 08/03/2011 02:00 PM, Alexander Klenin wrote:
>>>> Anyway, my preferred solution would be to allow aliases in 'with' 
>>>> statement,
>>>> which would improve readability even further while sacrificing only a
>>>> few characters:
>>>> 
>>>> with a := MyCompomentList[0] do begin
>>>>   Rectangle(0, 0, a.Width, a.Height);
>>>> end;
>>> 
>>> 
>>> A simple solution to something which I don't think is a problem either.
>>> [I fully agree with Michael van Canneyt here]
>> 
>> I agree the above is indeed an acceptable solution.
>> 
>> But I do think it is a corner case, because it goes against pascal 
>> philosophy which says that all identifiers must be declared prior to being 
>> used.
>
> How about
>
> with const a = MyCompomentList[0] do begin
>  Rectangle(0, 0, a.Width, a.Height);
> end;
>
> a is, after all, a constant: it can't be changed and doesn't occupy any 
> storage.

Sorry, but that's even more ugly.

My point was that in pascal, you explicitly separate declaration blocks from code blocks.
The above construct does away with that by putting the 'declaration' in the code itself.
Personally, I do not welcome such a change. There is a reason for this separation.

Due to circumstances, I program a lot of Javascript these days. 
It's totally unreadable because it is littered with such 'easy-going' constructs.
You can do some nice tricks with it, but at the same time, it's much more error 
prone than Pascal.

So, any attempt to introduce such 'features' will never be met with applause from me.
(and that's putting it mildly ;))

I often wonder why people keep asking for such things in Pascal.

To me, introduction of features found in other languages make it less Object Pascal,
when bringing in fact very little gain. I've seen many 'features' added, I even use them. 
But none of them have made me more productive or made it easier to debug my code.

I like to compare it with the game of chess:
It's not like the chess community introduces new moves every year to make it interesting or cool.

If you don't like the strict rules of chess, go play something else. 
For example, "Magic: the gathering". They introduce new cards all the time:
have fun, knock yourself out ! (I don't know if it still exists, at that)

Michael.




More information about the Lazarus mailing list