11 ms·
How Developers Choose Names
- loloquwowndueo 6y agoNaming things - one of the four hardest problems in computing (the others are sorting and off-by-one errors) :)
- jwdunne 6y agoLooks like you need to invalidate your cache of hardest problems in computing ;)
- amelius 6y agoProper caching makes any problem 10x as hard.
- athrowaway3z 6y agoTwice as hard is a underestimate imo.
- GuB-42 6y agoTwice as hard? Or is it three times? Like they say, there are 10 kinds of people, those who understand ternary, those who don't, and those who mistake it for binary.
- froh 6y agofive... naming, sorting, of by one concurrency errors and.
- fiddlerwoaroof 6y agoI see a transaction rolled back, and the autoincrement id column no longer matches the row count.
- mod 6y agoWell, the app is broken now because we relied on the autoincrement id column never having a missing value and didn't handle the error when it has one missing.
- karmakaze 6y agoSorting actually isn't one, at least anymore. Exact once and in-order delivery although part of 'distributed' computing should be, since most computing is distributed, right down to our multicore processing hardware.
- loloquwowndueo 6y agoIt is - do your sorting, then show the results to stakeholders and you’ll see they all want different, mutually conflicting sort orders.
- ravenstine 6y agoDon't forget time comparison. Your unit test of a function comparing dates relies on server time and usually fails if run around 12pm. Whatever. Nobody uses this app around lunch time anyway. Just tell your teammates in the to ignore that. Wait, why is the test failing every time today?! Did we just switch to DST? Uh oh...
- papito 6y agoThis has to come with a trigger warning.
- fiddlerwoaroof 6y ago“Our JavaScript date library and the date library we’re using in Clojure disagree on the first day of the week. Elasticsearch disagrees with both too”
- emodendroket 6y agoYou can avoid this problem by always passing in either a time or a time provider and never just relying on Time.now or whatever it is your language provides.
- fiddlerwoaroof 6y agoThis. Nearly every date/time library comes with this sort of attractive nuisance that is just waiting for a chance to ruin your day.
- gavinflud 6y agoFunnily enough, I recently had to help with an issue where a company's payment screen was not loading correctly and instead displaying "Invalid session". They use a third-party vendor to handle payments and display their payment form in an iFrame on their website. There is an initial request to create a session that has to pass the desired expiration time of the session. Unfortunately, the vendor requires the time to be in Eastern Time. The poor, naive soul that originally implemented this just got the current date, added 15 minutes, and converted it to "EST". As soon as daylight savings hit a few weeks ago, the expiration time was automatically being set to 45 minutes in the past, the vendor was responding with "Invalid Session" and the company was unable to take payments from customers.
- netflixandkill 6y agoDiscussions about naming schemes make me think of the old joke "until I got married, I had no idea there was a wrong way to boil water" or other variations of banal tasks :) Perhaps there is an answer lurking out there in the universe, but it feels more likely it'll only be invalid pointer Aborted (core dumped)
- mmmd 6y agoHonorary mention: Copy/Pass by reference or value
- slver 6y agoOne of the most cruel things evolution did to us is that we constantly seek meaning, order, correctness, where there are none to speak of.
- cbcoutinho 6y agoI'd argue that the ability to unite people by assigning meaning onto things, places, and ideas is the single reason why humans have been so successful in advancing civilization to where it is today. Edit: eschew -> assign
- papito 6y agoSure, but now it's actually DE-volving our society in form of QAnon and religious "interpretations", and technology here is not blameless in the least.
- selfsimilar 6y agoPedant note: eschew means ‘to go without’. You probably meant ‘assigning’.
- cbcoutinho 6y agoWhoops, thanks
- slver 6y agoThat's precisely the problem. It's very useful, when it's useful. Which leaves us spinning in circles when it's not.
- 3grdlurker 6y agoIt would be impossible for you to say this (circular) sentence and call something a “problem” if you didn’t think that there was some basis of right/wrong, which contradicts your top-level comment.
- rileymat2 6y ago> Based on the results of this experiment we developed a 3-step model of how names are constructed: (1) selecting the concepts to include in the name, (2) choosing the words to represent each concept, and (3) creating a name from these words. This seems flawed, when I look to name something, one of the most key things is what other things are named in that context, and patterns and consistency between them. It appears the study described a problem, instead of putting them in preexisting code?
- karmakaze 6y agoThis is a actually the way I name important things. There's even a 4th step: Choose only a few of the important or distinguishing concepts to include in the name. For examples in a database model you end up with x_y_z_name_id because of relations on relations, that might get reduced to y_z_name or x_z_name, dropping the part that is of widest/implicit context.
- thom 6y agoI would be interested if any task-performance based studies had been run with different naming schemes and enough developers to see which naming conventions worked best. Some simple job like fixing a bug or a simple refactoring, judged on time to completion and correctness.
- hallway_monitor 6y agoThat would be great empirical data to see. However from anecdotal data across almost two decades, is extremely obvious to my case study that naming is second only to application architecture in its impact on ease or difficulty and risk of updating the code base in the future.
- zexodus 6y agoResearch like this could lead to IDE's suggesting names for some of our methods. Exciting!
- emodendroket 6y agoGiven how much it freaks the IDE out I can't imagine writing a method before naming it.
- adithyasrin 6y agoVariable names are alright, available domain names are a different beast
- slver 6y agoThe more shared a name is, the greater the pain in selecting it. Given domain names are worldwide, no wonder then.
- granshaw 6y agoI have a rule called “name it what it does, not how it’s used” which is a mistake I often see with junior developers and sacrifices information density Eg it’s more helpful for readability to do “onClick => updateDate()” rather than “onClick => handleClick()” (Not the best example and I’ve seen far more egregious, but those examples are escaping me now)
- 3grdlurker 6y agoI’m an engineering lead and I made a rule of using the handleClick() style instead of updateDate() in our codebase. The reasoning is that the latter sounds more like an atomic, standalone function, whereas handleClick() may have some internal checks that could eventually call something like updateDate(), but the internal checks are beyond the responsibility of the updateDate() function.
- granshaw 6y agoYes my example was if updateDate literally just updates the date - I take this a step further too, Eg if the function has some extra checks, I’ll name it maybeDoX(), which is a somewhat uncommon practice in common programming languages
- deleted 6y ago[deleted]
- hanniabu 6y agoPersonally I would have both and within the handleClick() function do whatever it needs to do and call an atomic updateDate() function (assuming it's updating the date globally). Although for anything generalized standalone function I like to put that in its own namespace, such as helper.updateDate().
- dapids 6y agoOr be explicit. Call it AtomicUpdateDate if such functionality is really desired. Nobody should assume any operation is atomic ... Unless it is explicitly stated to be so. EDIT: sorry meant to reply to the parent comment.
- jariel 6y agoThis is one of the most interesting artifacts of programming, and it's probably impossible to explain to people outside the field. How at the same time it's trivial and important, and a constant cause of neuroticism. It takes up far too much tought-space to the point I would gladly follow some ugly set of conventions merely to have to just never think about it.
- hallway_monitor 6y agoSure, following some guidelines and standards is helpful. But never having to think about naming is almost like never having to think about logic. What you name things dictates how future developers think about them. Just this week we had a feature that could belong in an existing module or it could require a new module all depending on how we define the domain and therefore the name of the existing module.
- jariel 6y ago"s almost like never having to think about logic. " Not really, because naming is 98% convention when it's done right. The challenge is establishing all the conventions for a project, and then sticking to them. If there are really good conventions in place, well known, then naming is considerably easier. In fact, even if the conventions are not super good - they can be powerful when they are very well adhered to. Example: recently broke a rule and decided to use a known naming anti-pattern by suffixing variable names with the system type. This is normally not good. But within this module, the meta typing was ambiguous - by adding the suffix, the code was magically more clear. That little convention, very easy to apply, solved a clarity problem far more so than any issues around what functions should be called. So we used it for the module and that module only. Apple has some pretty hardcore naming conventions that I don't really like, but what's more important then whether they are good or not, is that they are very consistently applied - in other words - a lot less to think about.
- anonu 6y agoI find that I am remarkably internally consistent with how I name things. I sometimes forget about a filename, class or function that I wrote months ago (thats another problem in itself). But when I go to name the new thing I am about to write I realize that it already exists. I then pat myself on the back.
- asddubs 6y agoi wish that was me, if I'm not vigilant about it I always end up choosing a synonym that I didn't previously use (e.g. pressed vs clicked vs activated)
- nicetryguy 6y agoI thought you just added "ly" and called it a day?
- bitwize 6y agoYou watch your program buzz, But don't know what anything does. How do you name things so they're obvious to the eye? Descriptively, descriptively, descriptive... L-Y!
- wolfgang42 6y agoFor those unfamiliar with the reference, Tom Lehrer did several songs for the educational TV program The Electric Company, including one on the use of the suffix -ly to produce adverbs: https://www.youtube.com/watch?v=dB2Ff8H7oVo https://www.youtube.com/watch?v=dB2Ff8H7oVo
- baby_wipe 6y agoMy process: (1) How would I explain face-to-face what this code does to another developer? (2) Use the key words from that explanation to make a name as short as possible without losing clarity. Example: Step 1: This class handles all the navigation work for the sign-up flow in our mobile app. Step 2: SignUpFlowNavigator
- ed25519FUUU 6y agoHow about numbering? I always use to get a sideways glance back in the day (before we all started using uuids) when starting the number for a server group at 0. You’ll only have 9 servers in the first group and 10 thereafter if you start at 1! Yet some people insisted.
- dw-im-here 6y agoSays in the paper they had 337 subjects, so we'll have to match them with 337 irrelevant anecdotes so that we too can be scientists
- anon_tor_12345 6y agoyou think that's bad? this paper http://pdinda.org/Papers/ipdps18.pdf http://pdinda.org/Papers/ipdps18.pdf surveyed ~150 and concluded therefrom. the more hilarious thing being that they drew conclusion completely unscientifically i.e. by just interpreting vague plots (i.e. without performing t-tests or anything like that).
- deleted 6y ago[deleted]
- nuclearnice1 6y ago“But choosing good meaningful names is hard. We perform a sequence of experiments in which a total of *334 subjects* are required to choose names in given programming scenarios.”
- efortis 6y agoIn this video [1] the developer uses the prefix *old* where I normally used *prev*. Today I renamed all those "previous in time" to "old" for distinguishing them from the previous or next of a list. [1] https://youtu.be/AQ0lcm2_skI?t=319 https://youtu.be/AQ0lcm2_skI?t=319
- ttiurani 6y agoWith naming what IMO matters more than choosing one name, is choosing a name that is consistent with other similar names in the codebase. A new developer will learn your project's specific convention in a few minutes, but will be completely lost if the convention is routinely violated here and there. This is especially important with what verbs to use in methods, and how to name interfaces/classes in a way that respects both the business domain and the techical use. I've seen way too many times how much confusion is created and time wasted when a developer not too familiar with the project comes up with a brand new verb for a common action, and couples it with a new synonym for an existing business domain entity – or worse still, uses the same name previously meant for a completely different domain entity. The unfortunate burden with this is that a new developer might be right that their name is better for their use case, which then leads to laboursome debates about which is more important: consistency or slightly crisper name for the one use case.
- vas1 6y agoCouldn’t agree more with this. Consistency is key even if the convention used is awkward
- jawns 6y agoThis goes double for APIs, and triple for externally facing APIs, where typically the people who are working with it aren't familiar with your code base or naming conventions. That's why good API design is so hard. Every name you assign to something becomes a convention by default.
- hinkley 6y agoYou have to be careful with your definitions. Don’t use different definitions of the same verb/noun in different places. You get one. If you need another definition elsewhere, use a synonym. It is not beneath you to hit thesaurus.com while picking a name.
- jeremydeanlakey 6y agoA thesaurus is one of my favorite dev tools.
- cconroy 6y agooh man; they should of selected 42 or 1337 study subjects!
- johnchristopher 6y agoAs a non native english speaker I have a recurring problem with this: > getInstances(); // ok, returns an array of instances > getInstanceId(); // ok, returns an id > getInstancesId(); // ??, returns an array of id > get InstancesIds(); // ?? returns an array of id > getIdsOfInstances(); // ?? returns an array of id > getAllInstancesId(); // ?? returns an array of id > getAllInstancesIds(); // ?? returns an array of id How do I conjugate that ? And what about the possessive `s` ?
- halfmatthalfcat 6y agogetInstanceIds
- resonantjacket5 6y agogetInstancesId() would usually mean a singular id corresponding to the group of instances. Only ones with an "s" at the end of the id should return an array if you have the existing "getInstanceId" either that or invert that function to be getIdOfInstance and subsequently getAllIdsOfInstance for the array version. Generally speaking don't use the possessive "s" it is implied by being next to it. Also I usually use "instance" in this case more like an adjective Edit: usually I think of it as (current subject) verb adjective object. So server get instance IDs becomes getInstanceIds() or zoo clean active dogs becomes cleanActiveDogs()
- crazygringo 6y agoAs a native English speaker (and former English teacher), hope this helps: > getInstances(); // ok, returns an array of instances Correct. > getInstanceId(); // ok, returns an id Correct. > getInstancesId(); // ??, returns an array of id Unusual, but would return a single ID referring to a collection of instances. > get InstancesIds(); // ?? returns an array of id Correct. Though more common would be getInstanceIds() since you don't need to pluralize twice. E.g. we don't say "blues shoes", we say "blue shoes", so these aren't "instances ID's" but "instance ID's". However, in naming functions or variables you'll sometimes see plurals repeated for clarity. E.g. getInstanceIds() is ambiguous because it could refer to the ID's of multiple instances, or multiple ID's of the same instance. While getInstancesIds() makes it clearer that it's the ID's of multiple instances, even though it's not actually grammatically correct. > getIdsOfInstances(); // ?? returns an array of id Same as getInstanceIds(). Both are correct, though getInstanceIds() would probably be more common -- most people wouldn't put in the extra word "of" simply because it's an extra word, but sometimes it might be clearer for consistency with other function names. > getAllInstancesId(); // ?? returns an array of id It would mean the ID for the collection of all instances, though that would seem very unusual. Perhaps if there were a global account ID for a service or API you used. > getAllInstancesIds(); // ?? returns an array of id Sams as getInstanceIds(), but "All" presumably means it doesn't include a parameter to filter -- so I'd assume this implied the existence of another function such as getCollectionInstanceIds() or similar that it was contrasted against. > How do I conjugate that ? And what about the possessive `s`? Obviously you can't or shouldn't use apostrophes in variable names, so people generally try to avoid the possessive s. That's why we generally change nouns to noun adjectives -- instead of "computer's ID" (computer = noun) we use "computer ID" (computer = noun adjective).
- amelius 6y agoSay what you want, but it's better than how mathematicians choose names imho.
- uyt 6y agoIn defense of mathematicians, having conventional single letter variable makes stuff a lot easier to read. For example in graph algorithms, I used to write descriptive names like: weight = adjacenyMatrix[node][neighbor] Nowadays I write it as: w = G[u][v] Because in graph theory, an edge is usually (u, v), weight is usually w, graph is usually G, etc. It's basically the same reason why people don't name their indices "index" and instead use "i", "j", "k". And instead of point.first and point.second, you use point.x and point.y. Naming conventions are awesome when people can agree on them.
- patrick451 6y agoWhen writing code that is mathematical, I firmly believe "descriptive" names are an anti-pattern. To figure out what anything complex is doing, I'm going to have write the equations on paper anyway, and a matrix called G instead of adjecencyMatrix speeds that process along greatly. Even better, if the variable names are sufficient short and mathy, I may not need to translate back to paper, since the equations become more recognizable in place. This zealotry a lot of devs have over descriptive names needs boundaries.
- Asraelite 6y agoIn maths, you usually write "where x is ..., y is ... etc." after equations where what the symbols represent isn't abundantly obvious anyway. Likewise, when programming, if I reuse some variable very often in a short space, I will temporarily rename it to something single-lettered, e.g. "s = volumeScalingFactor; x = s; y = s; z *= s". I think maths style vs. programming style is only one factor here, with the other simply being this application of DRY: describe one-off things well, but shorten their names if they're oft-repeated within a given context. Maths tends to reuse the same variable for a lot of different operations in a single context whereas programming doesn't as much, which naturally leads to this single-letter name vs. long name difference in styles.
- makach 6y agoThis reminds me of this old quote from qotd: We had fairly random naming for our servers, so I proposed we named them after planets - and the admin responded with "great idea, you mean like planet01, planet02, planet03.." It´s a funny story, but naming means ALOT when you are developing, or building systems or processes that requires a name or an identificator. Also don´t be afraid of changing the name if it no longer reflects on its purpose.
- spinny 6y agovery badly, sometimes randomly, magic 8 ball would not be surprised if some dev somewhere considered naming his/hers first born "/tmp/first_born" until coming up with a better name we can also add mathematicians and physicists to the group of people that are exceptionaly bad at naming stuff
- Smaug123 6y agoPrimo is an actual name in Italian; the others have fallen (more) out of fashion, but certainly Quintus, Septimus and so on used to be perfectly reasonable Latin names.
- swyx 6y agosharing a relevant bit of research I did collecting naming practices across a bunch of different languages and frameworks: https://www.swyx.io/how-to-name-things/ https://www.swyx.io/how-to-name-things/
- rickbad68 6y agoThis seems such a weird study. Names are important, but not so much as what is being named. In one sense, names become easy given a properly abstracted design. Further, it’s not names so much that are paramount to program comprehension, but more the quality of the design. With a bad design that doesn’t properly separate concerns it won’t be possible to come up with good names because functions/data structures will represent multiple concerns. Any time names are controversial it probably indicates a design problem, even for unique/complex abstractions, there is usually a name which everyone agrees is the perfect name for a thing..
- ineedasername 6y agoI just use a UUID for every variable name to make sure the codebase never has any ambiguity. No one is going to confuse e7693160-b5cf-4761-9202-de019cfd0fc9 with c3d8b9ac-d0da-4bbc-912b-025ce4e47f62
- whatshisface 6y agoA good name has maximal information density. If the string is compressible, you're wasting your reader's time. That's why I use all utf-8 glyphs to render my uniformly random and highly informative (from an information theory standpoint) variable names.
- uyt 6y agoYou joke but symbolic programming languages like APL are kinda neat. https://en.wikipedia.org/wiki/APL_syntax_and_symbols https://en.wikipedia.org/wiki/APL_syntax_and_symbols
- calvinmorrison 6y agoI do see this more often in UTF8 native platforms. arr1 and arr2 might use subscripts for 1 and 2 with no side effect on plan9. Why use "delta" when writing a delta symbol is so easy?
- dTal 6y agoJulia not only supports Unicode, but embraces it culturally. You indeed very often see Δ in Julia code.
- 174SIGSEGV 6y agoA good name is also memorable, consistent, easily decipherable, and works around namespace conflicts. Might be a best 2.7 out of 4 situation, I guess. Why 2.7/4 and not 3/4? Because the remainder was lost in translation to the ASCII gods.
- keanebean86 6y agoThis implies your code has fewer than 2¹²² variables. A real coder should have more than that in each method. Sounds like you're basically a glorified VB "dev."
- domador 6y agoThe following article has influenced my naming choices ever since I first read it: https://www.joelonsoftware.com/2005/05/11/making-wrong-code-look-wrong/ https://www.joelonsoftware.com/2005/05/11/making-wrong-code-...
- whatshisface 6y agoIt's interesting how programmers tend to reinvent the idea of type systems after enough experience. The us_ prefix is a manually checked Us(String) type. Fortunately in modern languages we can express that at the function signature level and we don't need to spend "three weeks" training our eyes!
- dragonwriter 6y agoRelying on naming discipline as opposed to the more reliable features available in a language with any of (1) static typing, or (2) class-based OOP, or (3) prototypical OOP, seems...unnecessarily error-prone.