Live data from Hacker News

How to name things in programming

slideshare.net

1–10 of 177 posts

Re: How to name things in programming

#4
When 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

#5
I clicked through the first twenty or so slides, but really I find myself disagreeing completely with him. When you write don't use cliches but the meaning of AbstractConfigProxyFactory is clear and convey more information than anything else.

Re: How to name things in programming

#6

My 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%.

Here's a link with just the slideshow: http://www.slideshare.net/slideshow/embed_code/key/qnND7jVVQ...

Re: How to name things in programming

#7

When 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

#8

My 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%.

For a long time I just used Chrome - because why not? It's an awesome browser, especially when you are a web developer. But I was always annoyed about the fan on my MacBook Air mid 2011 spinning all the time - but I didn't connect the dots. At some point though it must have dawned on me and I tried an experiment where I switched 100% to Safari. Now my fan NEVER spins and I get up to two hours more battery life out of my MacBook Air. (yes I know it's a really bad browser on almost all counts - but they do know how to code in an energy efficient way)

Re: How to name things in programming

#9
post #7

When 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?

You shouldn't try to make it short on purpose because that will obscure the meaning of the variable. But long name by itself could be systematic error in abstraction (BananaSingletonFactoryFactoryCacheFactory comes to mind). At the very least, reading long name will also take a lot more mental power to understand.

Re: How to name things in programming

#10

When 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 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 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.
Post reply on HN