0
$\begingroup$

This is a really basic question. Consider a statement:

A painted line is increased by length $x$

Can $x$ be a negative number just by the wording of the question? What would be a better way of rephrasing the question, to make it clear that $x$ can be negative?

(The reason I'm asking is that I'm programming and a method name needs to indicate that the parameter can be negative or positive, in order to decrease or increase a size)

Basically I'm looking for a generic term for decrease and increase.

  • 0
    Can't you just say "x may be negative" in a comment?2011-02-04
  • 0
    I have but it would be better for it to be part of the method name, which is currently increaseLengthBy:2011-02-04
  • 4
    @Jonathan: Well, if want to allow x to be either positive or negative (or 0), why not say "The length of a painted line changes by x"? Then the method could be `changeLengthBy`. The generic term is "change".2011-02-04
  • 1
    Or, "adjusted" so that the method could be `adjustLenthBy`. One of the guidelines in Microsoft's opus Code Complete is to use strong verbs in function names. Actually I like the use of negative arguments with `increaseLengthBy`. I should think it would make perfect sense to any mathematician who programs.2011-02-05
  • 0
    @hardmath, could you put that as an answer?2011-02-09
  • 0
    I suppose what you want to do is for the user to have the ability to increase or decrease by a certain amount. You then want to interpret the number as a positive or negative number accordingly. Moreover, I suppose that if your program has to be userfriendly, you have to assume he might not know about negative numbers (unless you have a specific type of user in mind). I'd say introduce an extra option where he can choose "increase" or "decrease" and then specify an amount and let the program do the transforming into positive or negative numbers.2011-02-09
  • 0
    @Raskolnikov; I had thought of that but it would make it a lot more code needed to implement, on my side and another developer's side. Because the adjust is more than likely to be dynamically calculated2011-02-09
  • 1
    @hardmath As a mathematician who programs, I agree that negative arguments with `increaseLengthBy` make perfect sense. Unfortunately when I did this once it was very confusing to non-mathematicians who needed to use the code.2011-07-06

2 Answers 2

2

As a "neutral" verb regarding increase or decrease, I propose "adjust" so that the method would be adjustLengthBy. This is concise but conforms to the MS Code Complete dictum to use strong verbs in function names.

0

I'd say that "A painted line is changed by length $x$." The use of 'increased' implies the change is positive and it sends a confusing mixed message.