Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nice write-up. But there's not a single slide about usability and how it affects naming.

If your library exposes 'getCurrentRuntimeContext' which is going to be used in every other line of user's code, name it 'ctx'.

It's ambiguous, but it saves the user 3 seconds per 2 lines of code.

As for the readability, when the reader encounteres 'ctx' for the third time (at line 6 of the source file) they will already know what it is supposed to mean by heart.



I'm not so sure that is good advice, and I come from C programming so we love to do that.

With autocompletion in most code editors saving the user typing time is not a valid argument anymore, and I would rather prefer comprehensible if slightly more verbose code than accronyms everywhere.

What is obviously ctx -> getCurrentRuntimeContext for you is completely foreign to the next guy. And sometimes you don't spend a large amount of time in a specific part of a code base, such as when debugging and then figuring out what ctx means is a real PITA.


Imagine Ritchie & Thompson would have taken the above advice and named ++ operator "increment(x)".

That would suck in a big way.


I know you jest but I can actually see some advantages to not even having a ++ (and a --) operator.

You already have '+1' and '-1' so it's not even shorter (and those can't be sneakily inserted into expressions leading to side effects of the expression other than the value computed) and the post and pre-decrement versions of that can lead to very subtle bugs.


It's shorter because with +1 you need to write the variable twice. That said, I do prefer Python's += operator over ++.


Someone reading your comment might be left with the false impression that C does not have the += operator.


Fair enough, I meant Python uses += in lieu of ++, since it doesn't have the latter.


You are assuming that every one can recall 25+ letter names - dyslectics have problems with this sort of short term memory.


That is a very weak argument. Is there anything that suggests letter count is a barrier to dyslexics, and not, say, word count or number of obscure abbreviations?


Yes short term memory tests are one of the primary diagnostic tests for dyslexia. Ie how many consecutive numbers/letters you can recall.

Long Names like SomeRealyLongNameFunctionThing and SomeRealySimialrLongFunctionNameThing are both hard to work with and confusing to me.


I agree with your point that long names can be a problem by itself. Names should be kept as short as possible.

But not any shorter. "ctx" is just a bad name for a library to expose. Do rename it at those local contexts it'll be on every other line, but do not export it from a global library.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: