Is anybody else using ridiculously long variable names?
I've seen our own codebase end up employing rather long names pretty much everywhere, things like:
val documentAndPdfSavedOnDiskJsonStates = ... val resumeAndPortfolioThumbnailsJsonStates = ...
Is this worth debating? Good idea/non-issue/binary size issues maybe?
Best regards!
50 comments
[ 3.0 ms ] story [ 104 ms ] threadIn this case, it was necessary because the code would have to be reviewed by others to pass QC.
Just my two cents, added to yours, to make four.
Its not just for other developers (when I revisit something I've written months/years ago). But yeah, when I have to review code with Testing/QA, who aren't full time developers, it makes it much easier to step them through what is being done.
-- ps: especially since I'm always sparse on comments...
In Rust I've even started doing something additional which is use the shadowing feature. This was always a big no-no in other languages, some don't allow it, others do something different, but in Rust it can be used safely to reduce the explosion of variables in certain contexts. This helps reduce the need for distinctions between variables, allowing for shorter names.
So you csn have saved_state.tracked_picture.
Makes it clear what group something is in and what the name of that data is meant to be.
Much easier to parse.
Really long names in functions just make reading harder. I am not sure it makes things actually clearer. Can someone understand the code without actually understanding the function? Can they make an edit?
(Although I wouldn't use `xn`, I'd use `node`. `e` for `event` is fine.)
[1]: http://martinfowler.com/bliki/BoundedContext.html
So, for a short lived variable, I'm personally ok with it being short, as in, some random bit of python:
IMHO, I don't really think it matters what 's' is here, and I don't think it would would be that helpful if given a more meaningful name. The cognitive load is small.Conversely, variables that live a long time and/or operate globally are better off with a longer name.
However, I would observe that your example might suggest a coding issue, the tipoff being 'and'. If a single variable is handling two chunks of state, then perhaps it's doing too much and you might be better off with something like:
Not huge savings there, but perhaps also things might get clearer encapsulating these things in a class, with methods like (just making stuff up): Not saying that this is always the correct approach or valid in your particular case, just making the general observation that IME highly modular code tends to require fewer really long names.(any type of)documentAnd(convert success)PDFState(categoric variable)JsonStates(chunks of json states).
It's part of an Akka Streams well, stream :) (i/o -> content transform)
But: the broader the fame/notoriety of the entity, the shorter the name!
Just like in human culture.
Among your friends or family, you have a nickname. In a broader situation, you might go by your first name, and in a broader one still, by your full name.
But: if you're stinkin' famous, then you might get a nickname again, and everyone knows it.
I'm not going to give the Lisp cons function a seventeen letter name just because it is global.
Because autocomplete.
Really don't understand the binaries implication.
However, if a method/function is too long (i.e. too many lines in that single method/function) then it is very likely to have longer variable names within the scope and that method itself is likely to be a good candidate for refactoring. Sometimes the same applies to configuration variables (for example- stuff you read from a json config)
I'm skeptical `documentAndPdfSavedOnDiskJsonStates` is a useful variable name. Without context it's hard to say. It sounds like you have a couple of collections of states (state names?) for various document types.
PDFs are already documents, so that seems redundant. It already sounds like `savedDocumentStates` and `thumbnailStates` would be adequate--but again, without any context, it's impossible to know if that would be adequate.
(Personally I'd have a type => state mapping and skip them altogether, and use a different form of classification altogether.)
You can find a list of examples here: https://github.com/Quotation/LongestCocoa
Edit: I just had to quote the longest one: "outputImageProviderFromBufferWithPixelFormat:pixelsWide:pixelsHigh:baseAddress:bytesPerRow:releaseCallback:releaseContext:colorSpace:shouldColorMatch:"
Aww, looks like someone renamed it a decade later: https://lists.freebsd.org/pipermail/svn-src-head/2013-Februa....
http://journal.stuffwithstuff.com/2016/06/16/long-names-are-...
https://a-nickels-worth.blogspot.ie/2016/04/a-guide-to-namin...
- high coupling
- lack of encapsulation
- action at a distance
- wrong level of detail
Therefore it's a code smell. Imagine we referred to each other as "multicellular organism from the kingdom animalia phylum chordata clade synapsida class mammalia order primates suborder haplohrini family hominidae genus homo species homo sapiens sapiens".
1. Why is it the document and the PDF? Are they the same thing? if so, pick one term and use it consistently.
> SavedOnDisk
2. Disk is the default place to save things.
> Json
3. JSON isn't an interesting label, as it gives you no ides of the data structure. If this is a hashmap with a bunch of document titles and booleans with their save status, then that should be obvious.
This thing seems to be save state for multiple documents, right?
So I'd replace:
> documentAndPdfSavedOnDiskJsonStates
with
orThank you.