What's the longest pre-name definer?

I know, I know “pre-name definer” is not a proper definition.

For my purposes I’ve managed to struck a fairly “long boi”:

public static readonly string myVar(params object[ ] data)

But just how longer can it get?
Note that adding more and more parameters doesn’t count, obviously you can just keep on adding those.

This seemed like such an odd question I had to answer it. I thought it’d be a completely arbitrary ‘How long is a piece of string?’ type question, but there’s a bit of a caveat to it.

So the first part of the declaration is the Access Modifier. The longest variation on this is (as far as I’m aware) would be

protected internal readonly

Next up is the type declaration. If we’re using built in types, the longest named type is decimal. However, if we’re using anything other than built-in C# types, we can create a class with a ridiculously long name. I took the limit to be what will actually compile. According to this post on stackexchange, the longest compile-able name in Visual C# is 511 characters. This is longer than you think.

RidiculouslyLongVariableOrClassNameNoSeriouslyItsLikeSoLongYouGuys_AccordingToStackExchangeIts511CharactersInCSharp_IGotBoredAboutThisFarInSoIllJustPasteLoremIpsumDolorSitAmetConsecteturAdipiscingElitSedDoEiusmodTemporIncididuntUtLaboreEtDoloreMagnaAliquaUtEnimAdMinimVeniamQuisNostrudExercitationUllamcoLaborisNisiUtAliquipExEaCommodoConsequatDuisAuteIrureDolorInReprehenderitInVoluptateVelitEsseCillumDoloreEuFugiatNullaPariaturExcepteurSintOccaecatCupidatatNonProidentSuntInCulpaQuiOfficiaDeseruntMollitAnimI

But that’s just the class name. The variable name can also be the same length. Adding this to what we’ve got so far gives us:

protected internal readonly RidiculouslyLongVariableOrClassNameNoSeriouslyItsLikeSoLongYouGuys_AccordingToStackExchangeIts511CharactersInCSharp_IGotBoredAboutThisFarInSoIllJustPasteLoremIpsumDolorSitAmetConsecteturAdipiscingElitSedDoEiusmodTemporIncididuntUtLaboreEtDoloreMagnaAliquaUtEnimAdMinimVeniamQuisNostrudExercitationUllamcoLaborisNisiUtAliquipExEaCommodoConsequatDuisAuteIrureDolorInReprehenderitInVoluptateVelitEsseCillumDoloreEuFugiatNullaPariaturExcepteurSintOccaecatCupidatatNonProidentSuntInCulpaQuiOfficiaDeseruntMollitAnimI myRidiculouslyLongVariableOrClassNameNoSeriouslyItsLikeSoLongYouGuys_AccordingToStackExchangeIts511CharactersInCSharp_IGotBoredAboutThisFarInSoIllJustPasteLoremIpsumDolorSitAmetConsecteturAdipiscingElitSedDoEiusmodTemporIncididuntUtLaboreEtDoloreMagnaAliquaUtEnimAdMinimVeniamQuisNostrudExercitationUllamcoLaborisNisiUtAliquipExEaCommodoConsequatDuisAuteIrureDolorInReprehenderitInVoluptateVelitEsseCillumDoloreEuFugiatNullaPariaturExcepteurSintOccaecatCupidatatNonProidentSuntInCulpaQuiOfficiaDeseruntMollitAni;

Now we could have a method that takes this class as a bunch of inputs, but that violates the stipulation that paramenters don’t count. However, we can also give this a default value. Which lets us use the class name again.

public class RidiculouslyLongVariableOrClassNameNoSeriouslyItsLikeSoLongYouGuys_AccordingToStackExchangeIts511CharactersInCSharp_IGotBoredAboutThisFarInSoIllJustPasteLoremIpsumDolorSitAmetConsecteturAdipiscingElitSedDoEiusmodTemporIncididuntUtLaboreEtDoloreMagnaAliquaUtEnimAdMinimVeniamQuisNostrudExercitationUllamcoLaborisNisiUtAliquipExEaCommodoConsequatDuisAuteIrureDolorInReprehenderitInVoluptateVelitEsseCillumDoloreEuFugiatNullaPariaturExcepteurSintOccaecatCupidatatNonProidentSuntInCulpaQuiOfficiaDeseruntMollitAnimI
    {

    }

    protected internal readonly RidiculouslyLongVariableOrClassNameNoSeriouslyItsLikeSoLongYouGuys_AccordingToStackExchangeIts511CharactersInCSharp_IGotBoredAboutThisFarInSoIllJustPasteLoremIpsumDolorSitAmetConsecteturAdipiscingElitSedDoEiusmodTemporIncididuntUtLaboreEtDoloreMagnaAliquaUtEnimAdMinimVeniamQuisNostrudExercitationUllamcoLaborisNisiUtAliquipExEaCommodoConsequatDuisAuteIrureDolorInReprehenderitInVoluptateVelitEsseCillumDoloreEuFugiatNullaPariaturExcepteurSintOccaecatCupidatatNonProidentSuntInCulpaQuiOfficiaDeseruntMollitAnimI myRidiculouslyLongVariableOrClassNameNoSeriouslyItsLikeSoLongYouGuys_AccordingToStackExchangeIts511CharactersInCSharp_IGotBoredAboutThisFarInSoIllJustPasteLoremIpsumDolorSitAmetConsecteturAdipiscingElitSedDoEiusmodTemporIncididuntUtLaboreEtDoloreMagnaAliquaUtEnimAdMinimVeniamQuisNostrudExercitationUllamcoLaborisNisiUtAliquipExEaCommodoConsequatDuisAuteIrureDolorInReprehenderitInVoluptateVelitEsseCillumDoloreEuFugiatNullaPariaturExcepteurSintOccaecatCupidatatNonProidentSuntInCulpaQuiOfficiaDeseruntMollitAni = default(RidiculouslyLongVariableOrClassNameNoSeriouslyItsLikeSoLongYouGuys_AccordingToStackExchangeIts511CharactersInCSharp_IGotBoredAboutThisFarInSoIllJustPasteLoremIpsumDolorSitAmetConsecteturAdipiscingElitSedDoEiusmodTemporIncididuntUtLaboreEtDoloreMagnaAliquaUtEnimAdMinimVeniamQuisNostrudExercitationUllamcoLaborisNisiUtAliquipExEaCommodoConsequatDuisAuteIrureDolorInReprehenderitInVoluptateVelitEsseCillumDoloreEuFugiatNullaPariaturExcepteurSintOccaecatCupidatatNonProidentSuntInCulpaQuiOfficiaDeseruntMollitAnimI);

All in all, that gives us a single-line declaration that’s 1575 characters long. I’m sure there are other ways of extending this without parameters, though!

3 Likes

This is valid C# and isn’t just some long named method or parameter. It’s the best I could come up with though it could get quite long if you included attributes.

protected internal unsafe sealed override ref readonly Task<dynamic> m<T>(params object[] p)

Alternatively the base method with generic constraints could be longer.

protected internal unsafe virtual ref readonly Task<dynamic> m<T>(params object[] p)
            where T : class, new()

There is some use of C# language preview features here though. I opted for readonly ref instead of async since it’s longer.

4 Likes

You should be able to throw in volatile keyword there too :slight_smile:

#bringBackBoo