A few years ago, I programmed in Max/MSP (max4live, technically) for a while and one thing I found super-refreshing is the ease at which you could prototype and experiment your way to a solution just by not having to figure out what something should be called until you were good and ready. Ever since that time, I found that naming things is a big hindrance to evolving code from an experiment to a solution. Names get in the way until you're sure what the code is supposed to do (at which point, the above quote is true and you should be able to give it a descriptive name).
How to name things in programming
51–60 of 177 posts
Re: How to name things in programming
#52What did he mean by "never use passive when you can use the active (respect grammatical rules for identifiers)", on the slide 15?
He was told by a doctor to take a pill
active:
The doctor told him to take a pill
Re: How to name things in programming
#53Thanks 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…
Java class names are like Haskell function types. In fact, there are libraries that can autogenerate implementations for database logic by the name of the interface and methods alone, much like you can guess what the function does just by the types it operates on.
They are conventions (like Haskell types) but they lack the laws.
Re: How to name things in programming
#54Earlier quoted context omitted.
I am suspicious of names containing "and". I agree about clarity over everything else, but then why even make a function if all it does is calling 2 functions in sequence, and you can't name it on higher level of abstraction? In this case wouldn't [x+1 for x in input_list.reversed()] be even clearer? True, functions allow you to change code in one place and affect many places (so they prevent "forgot to update one pl…
> but then why even make a function if all it does is calling 2 functions in sequence How else would you execute the functions? What initiates them?
Re: How to name things in programming
#55Slide 41: "If you don't know what a thing should be called, you cannot know what it is. If you don't know what it is, you cannot sit down and write the code." A few years ago, I programmed in Max/MSP (max4live, technically) for a while and one thing I found super-refreshing is the ease at which you could prototype and experiment your way to a solution just by not having to figure out what something should be called u…
Re: How to name things in programming
#56Earlier quoted context omitted.
Here is where "first write good code" applies, at the design level. This function is begging to be two separate, composable functions that each only do one thing. reverse(addToEach(input_list, 1))
But what calls "reverse(addToEach(input_list, 1))" if not another function?
Re: How to name things in programming
#57I 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…
Re: How to name things in programming
#58Re: How to name things in programming
#59Earlier quoted context omitted.
Which, when you add a third variable "stuff", will require you to go back and add a space for both n and acc, pollutting both the diffs themselves (making reviews harder) and the git-blame (making pinpointing bugs harder).
git diff -w