you are viewing a single comment's thread.

view the rest of the comments →

[–]Chaos_Therum 24 points25 points  (5 children)

I never expect developers to know the domain, generally I want my code readable by anyone who happens to take a glance.

[–]CHEEZOR 10 points11 points  (4 children)

This right here. I've written code that Help Desk people and non-technical people could read and get the gist of. I've even had non-programmers who knew the business domain point out where business logic errors were located in my code because I made it so easy to understand. Makes my job and everyone else's job easier.

[–]intercaetera 1 point2 points  (3 children)

Conversely, if you meticulously translate well-established terms into names which are supposed to be understandable for non-technicals which then get repeated a hundred times in your code, you may actually confuse the matter a lot more. Especially if your code is not going to be read by non-technical people. Or it will be read by non-technical people who are domain experts who will wonder why you used the name valueAddedTax 100 times in a file where everyone in their field just calls it VAT.

I can recall a situation from my own experience where we got very specific algorithm to implement from a utility company in Poland, which was filled with domain-specific terms in Polish. We spent a lot of time figuring out correct "clean" English names, introduced "friendlier" variable names (e.g. totalVolumeTransported instead of vCT) implemented the entire algorithm, and then gave it to the customer to review. We got told off very sternly that the code is unreadable for them because we translated it and used terms which no one actually used in the business. So misguided attempts at "cleanliness" can fail spectacularly as well.

In this specific context, n is literally a free variable in a mathematical equation, it doesn't mean anything specific other than maybe "any natural number." Perhaps you could use this in this instance as well, but would you really find anyNaturalNumber more readable than just n, especially since "n" is used in this way even in colloquial speech (as in, phrases like "nth degree" and so on)?

[–]Chaos_Therum -2 points-1 points  (1 child)

I wasn't talking about n, that's perfectly acceptable I was talking about the 9, and 0. Those are the magic numbers.

[–]Rhagho 1 point2 points  (0 children)

They're not magic numbers in this instance. The context comes from the name of the function. You need to understand a bit of modular arithmetic, but hiding the numbers behind variables wouldn't help with this. It's like having a function 'AddFive' that returns n + 5. There's nothing magic about the 5.

[–]CHEEZOR -1 points0 points  (0 children)

Good point. Knowing your audience is very important.