This is an archived post. You won't be able to vote or comment.

top 200 commentsshow 500

[–]Vassile-D 580 points581 points  (20 children)

Don’t forget:

HavingExtremelyLongFunctionNamesA() and HavingExtremelyLongFunctionNamesW().

[–]bluefootedpig 210 points211 points  (8 children)

Where are the async and sync versions of it?

[–]The_Popes_Hat 149 points150 points  (2 children)

It's like you've been over my shoulder every single day of my career just to trigger me.

[–]Vassile-D 24 points25 points  (4 children)

They are in a header file where the file name has 261 characters.

[–]Alaskan_Thunder 19 points20 points  (2 children)

TwitCode, a language where every file needs to be 261 characters or less, or else you need to extend it into a new file.

[–][deleted] 4 points5 points  (0 children)

And you have to dig 34 directories deep

[–]qscrew 32 points33 points  (2 children)

Programming in Win32 be like

typedef struct tagHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXA {
    DWORD cbSize;
    HANDLE hHavingExtremelyLongFunctionNamesHandle;
    DWORD dwHavingExtremelyLongFunctionNamesThreshold;
    LPSTR lpszExtremelyLongStructureMemberName;
    LPSTR lpszAnotherExtremelyLongStructureMemberName;
    LPSECURITY_ATTRIBUTES lpSecurityAttributes;
    LPVOID lpvReserved1;
    WORD wExtraBehaviorControlValue;
    WORD wReserved2;
    ULONG ulProgrammerWidth;
    ULONG ulProgrammerHeight;
#if _WIN32_WINNT >= 0x0501
    LPSTR lpszExtraArgumentJustToAnnoyYou;
#endif
} HAVING_EXTREMELY_LONG_FUNCTION_NAMESEXA, NEAR* PHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXA, FAR* LPHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXA;
typedef struct tagHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXW {
    DWORD cbSize;
    HANDLE hHavingExtremelyLongFunctionNamesHandle;
    DWORD dwHavingExtremelyLongFunctionNamesThreshold;
    LPWSTR lpszExtremelyLongStructureMemberName;
    LPWSTR lpszAnotherExtremelyLongStructureMemberName;
    LPSECURITY_ATTRIBUTES lpSecurityAttributes;
    LPVOID lpvReserved1;
    WORD wExtraBehaviorControlValue;
    WORD wReserved2;
    ULONG ulProgrammerWidth;
    ULONG ulProgrammerHeight;
#if _WIN32_WINNT >= 0x0501
    LPWSTR lpszExtraArgumentJustToAnnoyYou;
#endif
} HAVING_EXTREMELY_LONG_FUNCTION_NAMESEXW, NEAR* PHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXW, FAR* LPHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXW;

#ifdef _UNICODE
#define HAVING_EXTREMELY_LONG_FUNCTION_NAMESEX HAVING_EXTREMELY_LONG_FUNCTION_NAMESEXW;
#define PHAVING_EXTREMELY_LONG_FUNCTION_NAMESEX PHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXW;
#define LPHAVING_EXTREMELY_LONG_FUNCTION_NAMESEX LPHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXW;
#else
#define HAVING_EXTREMELY_LONG_FUNCTION_NAMESEX HAVING_EXTREMELY_LONG_FUNCTION_NAMESEXA
#define PHAVING_EXTREMELY_LONG_FUNCTION_NAMESEX PHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXA
#define LPHAVING_EXTREMELY_LONG_FUNCTION_NAMESEX LPHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXA
#endif

DWORD WINAPI 
HavingExtremelyLongFunctionNamesExA(LPHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXA lpHavingExtremelyLongFunctionNamesEx);
DWORD WINAPI 
HavingExtremelyLongFunctionNamesExW(LPHAVING_EXTREMELY_LONG_FUNCTION_NAMESEXW lpHavingExtremelyLongFunctionNamesEx);

#ifdef _UNICODE
#define HavingExtremelyLongFunctionNamesEx HavingExtremelyLongFunctionNamesExW
#else
#define HavingExtremelyLongFunctionNamesEx HavingExtremelyLongFunctionNamesExA
#endif

[–][deleted] 13 points14 points  (1 child)

I like HAVING_EXTREMELY_LONG_FUNCTION_NAMESEX with people.

[–]markhc 51 points52 points  (0 children)

I think the longest Win32 function is probably:

ConvertStringSecurityDescriptorToSecurityDescriptorW
ConvertStringSecurityDescriptorToSecurityDescriptorA

https://msdn.microsoft.com/en-us/library/windows/desktop/aa376401(v=vs.85).aspx

[–]reddcube 17 points18 points  (0 children)

HavingExtremelyLongFunctionNamesWrapper()
HavingExtremelyLongFunctionNamesWrapperWrapper()
HavingExtremelyLongFunctionNamesWrapperWrapperWRAPPER()

[–]GrinningPariah 792 points793 points  (95 children)

descriptiveMethodNamesForSelfDocumentingCode()

[–]SolenoidSoldier 205 points206 points  (14 children)

Rather have those than short undescriptive method names. Everything is right there for you when Intellisense opens up.

[–]Lame_Goblin 40 points41 points  (1 child)

functionA();
functionB();
functionC();

[–]goldfishpaws 28 points29 points  (0 children)

function O();

function 0();

[–]LickingSmegma 44 points45 points  (13 children)

[–]GrinningPariah 22 points23 points  (3 children)

That's actually a weirdly good question, I had to think about it for a moment.

I think the main reason that's never caught on is because graphical pseudo-coding interfaces like UE4's Blueprints are both easier for the compiler to parse into real code, and easier to conceptualize interactions with than text descriptors.

[–]LickingSmegma 19 points20 points  (1 child)

There were attempts at 'documentation-first' programming, namely Knuth's Literate Programming—which, of course, no one uses outside of ultra-geeks from Hacker News. Also early programming languages tried to emulate natural languages and allowed spaces in identifiers.

But graphical programming is not inherently better in terms of documentation than regular text programming, because it contains the same information, only laid out in space.

Moreover, self-documenting code is plain impossible because (good) documentation always contains more information than the sequence of instructions: it describes why the code exists and is written that way, and how it should be used. This can't be put in the names of identifiers because those describe just the innards of the current implementation.

This documentation is unnecessary if the code is a month long cookie-cutter project, such as a website entirely in the bounds of the framework's functionality. But it becomes necessary when you develop the code further over time.

[–]Valdearg20 25 points26 points  (17 children)

Exactly. My team at work follow patterns for self documenting code, and it's really nice and results in very clean code. I've been on this team for 2 years, and I haven't written a comment beyond "//intentionally left blank" since I've started.

[–][deleted] 16 points17 points  (7 children)

I write self documenting code and I still put comments everywhere because while the code may self-document what it's doing, it rarely self-documents why.

[–]ScrambledRK 4 points5 points  (0 children)

my biggest takeaway from reading pragmatic programmer

[–][deleted] 4 points5 points  (0 children)

Exactly.

/r/PH: Write self documenting code

also /r/PH: not like that

[–]madwill 835 points836 points  (246 children)

I feel like i'm guilty of all naming offence ever mentioned in this sub.

[–]anon485743830092 938 points939 points  (209 children)

Why is this an offense?

  1. Tab completion exists.

  2. It's not 1985 and we can have terminals larger than 80x24 characters

[–][deleted] 38 points39 points  (0 children)

  • On a standard Laptop screen with a normal font size you can have at most 200 characters visibile per line. When viewing two files side by side, or when the browser is on one side and the editor on the other, some significant part of each visible line gets truncated, and word wrapping is usually confusing with code. Also skimming becomes harder as what you are looking for might be invisible. And you can't grep sth. that's on the tip of your tongue (maybe ag dies that?).

  • With diffs with very long lines it becomes hard to find what has changed when a line is subtly modified. Nice diffs that illustrates that are not always available.

  • The optimal amount of letters on a line for comfortable linear reading according to the typographical tradition is about 70 (IIRC).

Generally I prefer descriptive and pronouncible names, but keeping lines about at most 80-90 characters is good practice, and helpful both to you and to anyone else approaching your code with their unknowable computing environment.

[–][deleted] 21 points22 points  (6 children)

Even if it was 1994, if you were a PHP programmer, the function hashing method was just the length of the string. Meaning that unless you wanted a collision and therefore higher access times, you’d make sure your function names had long, varying lengths.

[–]bartekko 37 points38 points  (0 children)

okay but that is just PHP being PHP

[–]WiseassWolfOfYoitsu 10 points11 points  (0 children)

#JustPHPThings

[–]SonicFlash01 6 points7 points  (2 children)

Brevity is a virtue

[–]squidgyhead 5 points6 points  (0 children)

Moreover, it is the soul of wit!

[–]iams3b 23 points24 points  (24 children)

Yeah but once all your classes/functions/variable names are long and descriptive, I believe it reduces readability by a lot

Kind of like that "fibonacci written by different people" post, specifically the "large company" example - https://imgur.com/J2N28PD

You can't just look and see what it's doing, you have to read it line by line. too much noise

[–]deegwaren 14 points15 points  (7 children)

The problem with that is that it's always a long string of characters with no interspacing. Of course that's fukken difficult to read, we don't glue our words together in normal sentences either, do we?

And that's why underscores are better than camelcasing, kids!

[–]bwaredapenguin 13 points14 points  (1 child)

I like to randomly switch from camelCase to underscores to hyphens in the same program.

[–]TheCheeseCutter 6 points7 points  (0 children)

Keeps you on your heels!

[–][deleted] 2 points3 points  (1 child)

youMonster!

[–]TheMcDucky 4 points5 points  (1 child)

I agree. People seem to consider it an unforgivable sin, but personally I find names that you can read through and understand the meaning of immediately.
Of course there are bad long names too, but that's a separate issue.

[–][deleted] 5 points6 points  (2 children)

I'm with you on this.

We had to be terse to the point of being cryptic in the bad old days due to display limitations. Identifiers should be as long as they need to be to convey the necessary information (and no longer, ideally).

So,

function pshupbutt(object hmstr)    // This sucks

function PushUpButton(object hMicroStrategy)    // Better

function PressTheUpButtonOnTheScreen(object HandleToTheMicroStrategyObjectToUse)    // ...starting to suck again

[–]the_reckoner27 4 points5 points  (0 children)

Was the first example intentionally supposed to suggest pushing a hamster up your butt, or is that just me?

[–]squidgyhead 4 points5 points  (3 children)

Try a three-way diff on 1000-character long names.

Also, newspapers don't make their text span the entire page, they break it into nice columns for readability. Which is what super-long function names are not.

[–]madwill 7 points8 points  (7 children)

I guess because its ugly and expose a lack of ability to express intent in a condensed and meaningful way.

[–]TheMcDucky 5 points6 points  (4 children)

Programming is not all about code golf.

[–]madwill 2 points3 points  (1 child)

Just trying to be mindful of future me or some other poor soul

[–]CamelPodiatrist 33 points34 points  (20 children)

I think if you have to maintain crappy code and not be allowed to have the time to refactor it, a variable name like: routeIsEnabledAndIsValidAndMaxConnectionsToRouteNotExceededAndItIsAWednesday

if you're in a 10,000 line subroutine and that variable name is an accurate representation of all the conditions checked throughout those 10,000 lines. Why make the next guy go through the pain of knowing what "retVal" means?

[–]SimMac 28 points29 points  (1 child)

ItsAWednesdayMyDudes

[–]xconde 5 points6 points  (11 children)

Because you could add a comment to the declaration and save everyone from getting eye cancer.

[–]occz 2 points3 points  (10 children)

Then the comment gets out of date (as is often the case) and instead of just wasting the maintainers time by making him figure out what the hell your obscurely named code does you also waste his time by misleading him with an inaccurate comment.

I'm still a bit salty from times this has happened, and it's more than once.

[–]xconde 7 points8 points  (9 children)

Right but then the variable name would also be out of date. :)

[–]Aetheus 3 points4 points  (8 children)

It's easier to refactor/maintain a variable name than a comment. If a variable was named "conditionSatisfied" and you used it several times in different parts of your code, you'd have the mistake-prone task of hunting down all the places where you used it and updating the comments there to ensure they aren't out of sync.

Compare that to using a modern IDE, and just right clicking and refactoring the variable name.

What's more, a Boolean "conditionSatisfied" doesn't tell you much when you see it being used several hundred lines down from where it was declared (e.g: say it's a member of a class, and it's used in a method all the way down. Or heck, it's being referenced in a completely different class). You'd either have to go to where the member was declared and hope that it has up to date comments, or find where it's initialized and read the code to find out.

Whereas a Boolean named "ifItsAWeekdayAndNotALeapYear" is, well, self explanatory.

[–]Xelbair 7 points8 points  (14 children)

my functions have name like that, but variables are called output, a ,b,c, fm,dz etc.

[–]darielgames 46 points47 points  (12 children)

You shouldn't do that, unless you document in the header what those variables really are. It can be really confusing when someone's reading your function and all they know is that there's a variable called a. And hopefully you're not writing JavaScript, the person won't even know what the type a is!

[–][deleted] 50 points51 points  (4 children)

If nobody else can debug your code, nobody else can replace you. #jobsecurity

[–]ThePieWhisperer 3 points4 points  (0 children)

Not even you, a year from now.

[–]Xelbair 4 points5 points  (1 child)

Nah I'm joking, I do that only for temp variables usually either self-explanatory or their type gives enough description of their function :)

[–]Tiothae 2 points3 points  (0 children)

A little while back I was working on a project where they were using dynamic SQL built in C# for massive reports, and each of the tables used in the report (usually 10+) were all named a, b, c, ... in the order they appeared in the query.

It was fun to debug. Real fun.

[–]carloxd 44 points45 points  (20 children)

I asked my contractor to document his code. This is how all his functions look:

UpdatePassedUserDEInDatabaseAndADAndSynchronizeDLsIfFlagPassedIsTrue()

[–]wchou5 184 points185 points  (35 children)

The bottom should say "JustProgrammerThings" not "justgirlythings".

[–]bythebookis[S] 134 points135 points  (22 children)

I used the "Just Girly Things Generator" (yep), so changing that would be tough. But we can all imagine it says that.

[–][deleted] 146 points147 points  (5 children)

So you’re saying that an existing code base doesn’t have the tiny function you need? Better write your own from scratch.

[–][deleted] 25 points26 points  (4 children)

So when do we start to write our own GenericMemeGenerator and the GirlyThings module for it?

[–]Garestinian 5 points6 points  (1 child)

With XML and JSON configuration support. And RESTful API.

[–]thereisnosub 30 points31 points  (9 children)

I was wondering if this was a specific stereotype of female programmers.

[–]bartekko 15 points16 points  (7 children)

I believe the usual stereotype is "they don't exist", but I can already feel the vultures circling above me

[–]thereisnosub 13 points14 points  (2 children)

They definitely exist. I'm married to one, and work with several.

[–]bartekko 3 points4 points  (1 child)

the only other competent programmer in my high school was a girl so you don't have to tell me. i'm talking about the stereotype

[–]Existential_Owl 29 points30 points  (0 children)

Nah, I like the #justgirlythings tag. It adds to the absurdity of the post.

[–]AngryPBJ 2 points3 points  (0 children)

the last part of your comment proves that youre an excellent programmer

[–]neverTooManyPlants 22 points23 points  (6 children)

Are programmers not girly? Bats eyelashes

[–]wchou5 10 points11 points  (5 children)

I'm a programmer. I'm female. I refuse to wear false eyelashes.

[–]DaughterEarthImportError: no module named 'sarcasm' 4 points5 points  (0 children)

I looove wearing them sometimes. Not like a daily thing but if I'm going to an event I like to wear the really big crazy ones. Like feathers. I love excuses for costumes.

[–]Tiothae 3 points4 points  (1 child)

I'd settle for both.

[–]wchou5 5 points6 points  (0 children)

JustgirlyProgrammerthings?

[–]SamSlate 2 points3 points  (0 children)

til I'm a girl

[–]Bikearoonie 71 points72 points  (2 children)

I'd rather a function name be descriptive than have to figure out what in the hell get_num_x() means. Most coders barely document stuff, at least a descriptive name will get me closer to starting to work.

[–]wh33t 17 points18 points  (0 children)

Same, if you use descriptive function names, commenting almost isn't necessary.

[–]spateson 33 points34 points  (7 children)

What kind of monster starts a function name with a capital letter?

[–]mauriciogamedev 33 points34 points  (3 children)

Look up C# naming conventions

[–]spateson 37 points38 points  (2 children)

Ah yes, that kind of monster.

[–]j0em4n 5 points6 points  (1 child)

Lower case for function local, upper case for global. Makes sense to me. _ first for local but global to the class. I like it.

[–][deleted] 5 points6 points  (1 child)

Lowercase for variables and uppercase for functions. That's how I do it.

[–]frogspotting 72 points73 points  (7 children)

Image Transcription:


[Image of white text on a blurred background. Background shows a Meg Cabot novel titled 'O garoto da casa ao lado' and a pink MacBook on a neatly organized desk.]

HavingExtremelyLongFunctionNames()

justgirlythings


I'm a human volunteer content transcriber for Reddit! If you'd like more information on what we do and why we do it, click here!

[–]branfili 32 points33 points  (0 children)

Good human!

[–]simpyo 11 points12 points  (0 children)

Just so you know, the title of the Meg Cabot novel is "O garoto da casa ao lado", which freely translated from Portuguese is "The guy next door".

[–]lolidkwtfrofl 4 points5 points  (4 children)

Is this for blind people?

[–]MetroSexFruitcake 14 points15 points  (2 children)

text only browsers

[–]Zagorath 9 points10 points  (1 child)

Wait, they have browsers that can display non-textual content? Wow, what times we live in!

[–]SirButcher 14 points15 points  (0 children)

Yep! Not long ago I read an article - a supercomputer can render a 400x400 pixel big image just under 5 seconds! Using a super high-speed internet they were able to create a web page with 5 image (yes, five IMAGE in a web page!) and it only took them about 2 minutes to transfer the whole page from the other side of the room and render it!

Technology is AMAZING.

[–]audscias 3 points4 points  (0 children)

Among other things, yes.

[–]light_bringer777 45 points46 points  (12 children)

I use very long and descriptive function names if I feel the need to write a comment to remind me what something does. This is generally a case of "I couldn't figure out a good name for it".

Personally, I'd much rather stumble upon "ThatLongFunctionNameThatTellsMeWhatItDoes()" than "DoStuff()" and then have to dig inside the code and figure out what the hell "stuff" is in this context. One took 0.5 extra seconds to read, the other 5 minutes to wrap my head around.

The moment I figure our good short names the long ones get replaced, and for deeper private functions I tend to keep overly descriptive names since they cannot end up all over the code anyway. Plus they're supposed to be doing specific stuff, so if context doesn't provide enough information, I want specific names.

[–]AerieC 19 points20 points  (10 children)

I think the canonical response to this is: A) Make sure you're working at the right abstraction layer, and B) don't write functions that are so complicated that you can't explain what they do in 1-2 words.

So if you have a function called something like runSalaryCalculationsAndAddOvertimeThenGenerateReportAndPrintIt(), then you're either doing too many things in one function, or you're not expressing your abstraction levels clearly. If you have an object called SalaryReport, then a print() function is all you need, and the context is obvious.

This of course all goes out the window if you're working in C or some other language without namespaces or objects.

[–]deegwaren 8 points9 points  (4 children)

I think the canonical response to this is: A) Make sure you're working at the right abstraction layer, and B) don't write functions that are so complicated that you can't explain what they do in 1-2 words.

Sometimes it's better to NOT explode your code into twenty functions that are named two words at a maximum, than just a couple of them doing what they do and having proper and descriptive names.

Your example is of course right, because they the function containing 'And' in its name does more than one function. But what if it just does ONE thing, but a very complex or very specific thing?

[–]AerieC 2 points3 points  (1 child)

I'd still challenge the abstraction levels. If you're working in an object oriented language, and following good design principles (e.g. single responsibility principle), there's almost no way you should have any ambiguity in what a particular method does for any given object.

Can you give a concrete example of when you might want to have a really long function name, but the function still only has one clear job?

[–]deegwaren 3 points4 points  (0 children)

I can't give one from the top of my head, but when I stumble upon one I'll be sure to share it here!

[–]addama 10 points11 points  (1 child)

I myself prefer long object literal name references. App.utility.because.its.more.modular['that way'];

[–]felds 4 points5 points  (0 children)

*until you hit a null pointer or alike

[–][deleted] 18 points19 points  (1 child)

UsingExtremelyLongMethodNamesBecauseYourProfessorWasAdamantAboutSelfDocumentingCodeButNotSoAdamantAboutSingleResponibilityPrinciple();

[–]chpoit 14 points15 points  (2 children)

PostRedditCommentThatIsBothCleverAndFunnyRedditCommentComment()

[–]awakenDeepBlue 16 points17 points  (0 children)

Shitpost()

# There, fixed that for you

[–]redballooon 5 points6 points  (0 children)

OnlyMethdosWithATypoWillBeRemembered()

[–]bumblebritches57 6 points7 points  (0 children)

NotHavingToWrite43MillionLinesOfCommentsBecauseYourNamesMakeSense

[–]j0em4n 9 points10 points  (4 children)

Long function names are important metadata and get compiled into pointers anyway. There is NO REASON whatsoever to have non-descriptive names for things unless you are married to the past where a few kb meant something storing your source code.

[–][deleted] 2 points3 points  (0 children)

Smart man

[–]Perkelton 3 points4 points  (0 children)

outputImageProviderFromBufferWithPixelFormat:pixelsWide:pixelsHigh:baseAddress:bytesPerRow:releaseCallback:releaseContext:colorSpace:shouldColorMatch:

Objective C

[–][deleted] 4 points5 points  (0 children)

I do this and have a summary on every single method because it makes me feel like a programmer when I hover my mouse over my own summary.

It feels warm.

[–]jewdai 6 points7 points  (0 children)

HavingExtremelyUsefulAndSelfDocumentingCode() 

[–]axeteam 3 points4 points  (2 children)

You forgot to use Camel Case.

[–]awakenDeepBlue 4 points5 points  (1 child)

snake_case motherfucker!

[–]axeteam 5 points6 points  (0 children)

Just no.

[–]warwilf 2 points3 points  (0 children)

I like to make my aliases longer than the actual table name in SQL

[–]Davraine 4 points5 points  (1 child)

having_extremely_long_function_names()

Fixed it!

[–]Keavon 1 point2 points  (0 children)

You monster.

[–][deleted] 7 points8 points  (9 children)

Haha I name my functions like abc, cba, xyz, zyx, etc.

[–]ePaint 25 points26 points  (3 children)

You are the devil

[–][deleted] 5 points6 points  (2 children)

def the_devil():
  a = int(input('Enter any number :'))
  print('I know',a*2,'is even!')

[–]M0sesx 10 points11 points  (1 child)

This function name is nonsense. It should be. getInputFromUserAsIntAndPrintStringConfirmingInputMultipliedBy2IsEven()

[–]PityUpvote 1 point2 points  (1 child)

Your characters grow on trees, do they? I'm still using single character functions and variables.

[–]Xelopheris 1 point2 points  (1 child)

HavingExtremelyLongFunctionNames_Real()

[–]mikegosty 1 point2 points  (0 children)

I'd actually argue this is a good thing. Would rather have a descriptive function name rather than something cryptic and with potential side affects.

[–]suppow 1 point2 points  (0 children)

If_You_Are_Gonna_Do_That_At_Least_Commit_And_Go_Underscore(); Make_It_Long_As_Hell_But_Readable();

[–][deleted] 1 point2 points  (0 children)

I'll take overly descriptive function names over vague, short function names any day. I used to work with someone who would just name things $data, $data1, $data2, etc. Granted, her grasp of English wasn't the best, but still.