How to name things in programming
slideshare.net
How to name things in programming
1–10 of 177 posts
Re: How to name things in programming
#2Re: How to name things in programming
#3My MacBook (with Chrome) does not like this site -- within 5 minutes of opening it and clicking through slides, it got very loud and hot and the battery went down by ~8%.
Re: How to name things in programming
#4However, when naming, my philosophy is always clarity over elegance.
for example (in python):
def reverseListAndAddOneToEachElement(input_list):
Ugly, but clear. I don't even need to write out the full definition you already know exactly what it does.Re: How to name things in programming
#5Re: How to name things in programming
#6My MacBook (with Chrome) does not like this site -- within 5 minutes of opening it and clicking through slides, it got very loud and hot and the battery went down by ~8%.
Re: How to name things in programming
#7When structuring code, elegance and efficiency always take top priority. However, when naming, my philosophy is always clarity over elegance. for example (in python): def reverseListAndAddOneToEachElement(input_list): Ugly, but clear. I don't even need to write out the full definition you already know exactly what it does.
Re: How to name things in programming
#8My MacBook (with Chrome) does not like this site -- within 5 minutes of opening it and clicking through slides, it got very loud and hot and the battery went down by ~8%.
Re: How to name things in programming
#9When structuring code, elegance and efficiency always take top priority. However, when naming, my philosophy is always clarity over elegance. for example (in python): def reverseListAndAddOneToEachElement(input_list): Ugly, but clear. I don't even need to write out the full definition you already know exactly what it does.
I like the logic of this, but it goes against all books that i've read to keep it short. Why do we need to keep it short?
Re: How to name things in programming
#10When structuring code, elegance and efficiency always take top priority. However, when naming, my philosophy is always clarity over elegance. for example (in python): def reverseListAndAddOneToEachElement(input_list): Ugly, but clear. I don't even need to write out the full definition you already know exactly what it does.
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 place" errors), but when function is named from its implementation instead of its purpose - it doesn't make much sense to change implementation anyway. The absolute worst thing is
def reverseListAndAddOneToEachElement(input_list):
#requirements changed
return [x+2 for x in input_list.reversed()]
So either I repeat myself by copy-pasting code, or I repeat myself by saying the same thing in implementation and in the name. It's the hardest problem in naming for me.