[fpc-pascal] Name collisions in scoped enums

Ryan Joseph genericptr at gmail.com
Tue May 5 04:16:30 CEST 2020


	

> On May 4, 2020, at 10:44 PM, Michael Van Canneyt <michael at freepascal.org> wrote:
> 
> That is how enums work by default in Pascal.
> 
> If you don't force scoped enums, you can still scope them.
> 
> if you use
> $scopedenums on then you simply force the use instead of having it optional.

But the names collide then, that's the whole point. We want to protect against name collisions and we don't want to type long prefix names every time. Scoped enums fixes half of that by formalizing the prefix syntax but you still need to type it even when it could be inferred by context.

Swift figured out how to do this and so should Pascal imo.


From https://docs.swift.org/swift-book/LanguageGuide/Enumerations.html:

Each enumeration definition defines a new type. Like other types in Swift, their names (such as CompassPoint and Planet) start with a capital letter. Give enumeration types singular rather than plural names, so that they read as self-evident:

	• var directionToHead = CompassPoint.west

The type of directionToHead is inferred when it’s initialized with one of the possible values of CompassPoint. Once directionToHead is declared as a CompassPoint, you can set it to a different CompassPoint value using a shorter dot syntax:

	• directionToHead = .east

Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list