Aah.. naming things. A developer's favorite brain sport, nestled somewhere between attending endless meetings and refactoring code. As developers, ...
For further actions, you may consider blocking this person and/or reporting abuse
I think
ensureMinusAtStart
would be a clearer name for the conditional version ofaddMinusAtStart
.You're right! I wasn't sure if "ensure" was clear enough but hearing it from an independent source.. imma change it 👍
ensureMinusAtStart()
is semantically correct if you are doing that, i.e. if you are adding a minus only if there is not one already there. In the case of:I would be inclined to retain an
addMinusAtStart()
function such that you have something like this (C++ kind of thing) :Just a thought though.
having learned more about the importance of idempotency (aka desired state pattern) in (distributed) information systems, I use "ensure" all the time now. For example instead of delete(x), we might even write ensureDoesntExist(x).
You need to review your use of
if (!valueOfOtherField)
if you're targeting clarity. There's no evidence in your code thatvalueOfOtherField
is a boolean type, but (based on C-type-derived languages) the!
operator takes a boolean as input and produces a boolean output.It looks like you're relying on either an overload of the boolean
!
operator, or an implicit cast ofvalueOfOtherField
to a boolean type. Either case is not clear. I have no idea of the type returned byrow.doc[otherField]
so I would hope that a conditional that used that returned value would be a proper value comparison retuning a boolean (e.g., where the return type us a string,if (valueOfOtherField.isEmpty())
.Naming event listeners in particular, which can be asynchronously managed and therefore trickier to debug within context, is a great exercise. "on[Before|After][state][change]" is a good template here.
Great, haven't thought of that one 👍 Thanks for sharing
Good references/examples in the careful thought put into the VS Code extensions API:
vscode-docs.readthedocs.io/en/stab...
German "Gründlichkeit" at its finest. Very good!
Using logical scheme-based, objective descriptions saves lots of time and effort all around. This is especially helpful in large or long-lived projects, but, honestly, once you get used to naming things like this, you wouldn't have it any other way even in small one-off personal projects, either.
Love the intro, more true words were never spoken xD
how to name a array which will hold two different data let say town data and city data based on condition.
I have named it cityTownData is there any better way to do that
I did something similar a few weeks ago and needed to change it back. If you can, make them two seperate arrays as this becomes easier to scale and work with in the future. But if not, you could name it cityAndTownData to avoid confusion that "city" is just a descriptor for "town" and "cityTown" is one thing. The condition you can add at the end like this:
cityAndTownDataWithLargePopulation
or even bettercityAndTownArrayWithLargePopulation
orcitiesAndTownsWithLargePopulation
. "data" is too general and could be anything, so replacing it with "array" you give developers a better idea of the type. So final answer would be:citiesAndTownsWithLargePopulation
as it will be either city or town data so can i make it cityOrTownArray or should i keep them seprate ?
Don't overengineer your variables and spend too much time thinking about one. The core purpose of good naming is so your code can be easily read by others and yourself without feeling stupid. If you feel stupid reading other peoples code its most likely their fault. Just check your entire function and ask yourself the question. Is the code as a whole clear and understandable? If yes youre fine.
PS: If cities and towns are two different things in your code, seperate them. If they are pretty much the same, just use one word, or a generalization word like "settlement".
ठीक है
This post inspired our weekly #DEVDiscuss! Check it out and join the convo:
#DEVDiscuss: Naming Things
Erin Bensinger for The DEV Team ・ Apr 25 ・ 1 min read
Great article of a fundamental subject.
This certainly makes sense to me. Naming is hard and having this pattern as a guide is really useful.
Excellent points raised!
Your tips are fantastic, thank you!
Сongratulations 🥳! Your article hit the top posts for the week - dev.to/fruntend/top-10-posts-for-f...
Keep it up 👍
ChatGPT is my new best friend for naming things, no human can compare with all the (in)sanities it provides me!
Why is naming hard? Because it is the abstraction itself.