DEV Community

Ben Halpern
Ben Halpern Subscriber

Posted on

What are the great function/method/etc. names in popular libs/languages?

Naming things is hard, but what are the ones that have stood out to you as great choices that have stood the test of time?

Latest comments (28)

Collapse
 
alshakero profile image
Omar Alshaker

I really like PHP's explode and implode couple. It's String.split and String.join for those who don't know.

Collapse
 
jesseditson profile image
Jesse Ditson

I always thought it was kind of brilliant of the react team to hijack the reader’s brain to create a fake protected member by naming it _SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED

Collapse
 
ben profile image
Ben Halpern

Functional propaganda

Collapse
 
galdin profile image
Galdin Raphael

Android's UserManager class has something called isUserAGoat().

Here's an interesting discussion on it 😁
stackoverflow.com/questions/133753...

Collapse
 
katafrakt profile image
PaweΕ‚ ŚwiΔ…tkowski

Not sure if this counts, but PHP's T_PAAMAYIM_NEKUDOTAYIM parser token is pretty rad yet savage :D

Collapse
 
katafrakt profile image
PaweΕ‚ ŚwiΔ…tkowski

Damn, I was going to post this when I saw this thread ;)

Collapse
 
rapidnerd profile image
George

From one of my most recent projects

void iDontKnowIfThisIsGoingToWorkSoImPuttingOffUsingThisMethodBecauseImScaredOfTheOutcome()
Collapse
 
aodev profile image
AoDev

The start of my journey as a programmer is a peculiar one in that regard.

As a non-native English speaker, when I started to code, a long time ago, I simply didn't understand anything. In fact, I thought that most reserved word of any language were just that: some "random strings" with no meaning outside of the programming language. It's later, when I had learned English that I got some Ah ah! moment.

Obviously for an English speaker: "if, case, switch, while, random" are just normal words. It wasn't for me. (I started to play around with code when I was a child, under MS-DOS 6)

So, talking about some great choices, my biggest and relatively recent "Ah ah! moment" has been with

Math.ceil
Math.floor

I could never remember which one would round up and which one would round down.
Until a day like any other day, my brain said: "hey, wait a minute: isn't "floor", because the floor is low and "ceil(ing)" is up?" Awesome. XD

Collapse
 
phortx profile image
Ben Klein • Edited

I really like the convention to name mixins with-something in react and Vue. Often this feels very elegant. Like with-captcha.js or with-user.js. There couldn't be any naming that feels any smoother 😍

Collapse
 
kip13 profile image
kip

A common problem in PHP (maybe in some other langs too) is the way to move between dates and get the incorrect value, for example when you decrease or increase a month(s):

>>> (new \DateTime('2017-01-31'))->add(new \DateInterval('P1M'))->format('Y-m-d')
=> "2017-03-03"

Carbon a good library offers some methods to avoid this behaivor and their names are really good:

>>> (new Carbon('2017-01-31'))->addMonthNoOverflow()->format('Y-m-d')
=> "2017-02-28"

If you wanna get the calculation with this behaivor, no problem:

>>> (new Carbon('2017-01-31'))->addMonthWithOverflow()->format('Y-m-d')
=> "2017-03-03"

Other methods are: createMidnightDate, localeHasDiffOneDayWords, createSafe...

Collapse
 
nimmo profile image
Nimmo

Maybe in Elm, not only because it's descriptive (Maybe it has a value, and Maybe it doesn't), but when it doesn't have a value, instead of null or undefined or whatever, it's Nothing.

Which makes me think of Nathan Explosion whenever I use it.

youtube.com/watch?v=o_PMab-SGgY