[fpc-pascal] Scoped enums and inferred types

Ryan Joseph ryan at thealchemistguild.com
Wed Feb 21 09:58:12 CET 2018



> On Feb 21, 2018, at 3:45 PM, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
> 
> I think this would be confusing:
> 
> {$scopedenums on}
> type
> 	TMyType = (A, B, C);
> {$scopedenums off}
> var
>  A: integer;
> 
> procedure DoThis (t: TMyType; i: integer);
> begin
> end;
> 
> DoThis(A,A);

yes it would be. :) Swift lets you opt out if you want so you can still do DoThis(TMyType.A, A) in that case but more specifically Swift keeps the . prefix so it would be DoThis(.A, A). Not always what you want but in some cases it’s really handy. In many API’s there’s a constant plague of long enum names all starting with the same prefix so shortening them to the logical suffix when possible just make sense. 

Here’s something that’s all too common in code. There’s obviously some redundancy here we could optimize out. The only reason we keep the prefix is for name space integrity but logically in code what I’m really thinking about is the suffix so it makes sense that if the compiler could infer this it would save me time.

type
	TTileSortingFlag = (	kTileSortingStatic, 
				kTileSortingRamp, 
				kTileSortingIgnore,
				kTileSortingParticle,
				kTileSortingFloor,
				kTileSortingFlat,
				kTileSortingContainer,
				kTileSortingOnRamp,
				kTileSortingBufferStatic,
				kTileSortingBufferDynamic
				);


Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list