Earlier quoted context omitted.
passive: He was told by a doctor to take a pill active: The doctor told him to take a pill
He provides examples `class PlanEvents`, `class EventPlanner`, `class Scheduler`. To me, they all seem to be active. Any thoughts?
How to name things in programming
171–177 of 177 posts
Re: How to name things in programming
#172Earlier quoted context omitted.
passive: He was told by a doctor to take a pill active: The doctor told him to take a pill
He provides examples `class PlanEvents`, `class EventPlanner`, `class Scheduler`. To me, they all seem to be active. Any thoughts?
What I also say in the talk is that this analogy is a stretch, but at least advice from writers about writing can inspire us to think about how we write code.
Re: How to name things in programming
#173An important rule is missing here: variables should be named with their scope in mind. So if a variable is longer lived and has larger scope its name should be that much more descriptive because when you're looking at it the only thing that will tie the value of the variable to the context within which it can be used is its name. So 'i' is fine for a loop control variable with a scope of five lines but totally inadeq…
True, but I have plenty of slides in my presentation without adding more :)
The 'small scope rule' is more of a situation when you can get away with names that are less good, because of the small scope. When I get into discussions about that, everyone agrees with each other, and it distracts from the issue of coming up with good names when the scope isn't tiny.
Also, 'i' for a loop control variable is a trick example: why aren't you using a language that loops over collections without using a loop index?
Re: How to name things in programming
#174This seems like its trying to force advice for one domain to another when its not appropriate. I disagree strongly with one or two of the rules. But an even bigger problem is that some (or even most) of the advice either has little value or doesn't really apply to programming. In english, shorter is better, but I'd much rather a longer class name that I can understand than one that's abbreviated to the point where I…
When I give this talk, I make this clear. I agree. The point is that there's a lot more good advice from writers over the fine details of prose than there is from coders about fine details of code, such as naming. In the talk, I conclude that the advice from writers is entertaining, but not really relevant, but that it can inspire us to try to come up with our own guidelines for naming.
> We have these rules in programming for how to write variable names
Not enough. Also, they tend to be badly written and lack humour. But please share your favourites.
> when writing a novel a writer should create living people; people not characters. A character is a caricature
This is a digression from coding to functional design, in which 'personas' can be a useful refinement of the concept of an anonymous 'user'.
Re: How to name things in programming
#175I agree with everything except abbreviations, but to be honest, I think my worst habit it just trying to use words with the same number of characters for different variables so they align well with monospace font. e.g. int num = 42; int acc = 0; instead of; int n = 42; int acc = 0; and it gets worse when things get complicated; vector dist; // stands for distances vector excs; // stands for excesses Does anyone else…
Yes, you have worse problems than ambiguous abbreviations :) That doesn't make the abbreviations okay, though.
Re: How to name things in programming
#176Thanks for the thorough write-up Peter! This pack of slides addresses "naming things" to depth that it could have been a little book... I miss a few things though. 1. Short functions can use abbrevs; because I can keep track of them. 2. "text_correction_by_editor" might convey a lot more info then "edit"; especially in code where "edit" (and derivative) are heavily overloaded. For instance I can imagine "text_correct…
In the talk I explain that this is a real example, from software for a publishing company in the Netherlands. The 'editor' is the person who edits the text. The problem was that the subject matter experts used two different Dutch words for two different kinds of text correction, depending on whether the original author or the editor made the correction.
This example is about the tradeoff between making the difference explicit (text_correction_by_author vs text_correction_by_editor), or agreeing on consistent translations for the two Dutch words (e.g. 'edit' and 'revision').
Re: How to name things in programming
#177An important rule is missing here: variables should be named with their scope in mind. So if a variable is longer lived and has larger scope its name should be that much more descriptive because when you're looking at it the only thing that will tie the value of the variable to the context within which it can be used is its name. So 'i' is fine for a loop control variable with a scope of five lines but totally inadeq…
> An important rule is missing here: variables should be named with their scope in mind True, but I have plenty of slides in my presentation without adding more :) The 'small scope rule' is more of a situation when you can get away with names that are less good, because of the small scope. When I get into discussions about that, everyone agrees with each other, and it distracts from the issue of coming up with good n…