2

I have a C# application that is developed with VS 2010 pro. The ultimate version would have a sequence diagram feature.

Since I will "create" my sequence diagram manually, how do I deal with quite long method names?

object.createPathForCustomerIDblablablabla_click()

Do I just use the method names as they are already given? Use a shorter name in the sequence diagram?

I would like it to fit on a A4 page.

4

Aside:
Contrary to popular belief, long names are not always a bad thing. Used in moderation, they can be helpful. For example, if a method returns a boolean value that indicates that the application startup should be aborted if the execution fails while the application is starting up then one of these is more clear than the other:

  • getTerminateDuringStartup
  • getHaltApplicationStartupIfExecutionFailsDuringStartupFlag

On to the Question:
If the names are too long to conveniently fit in a diagram, consider creating short names in the diagram only and map them to the full method name.

For example: Use createPFCIDbbbbc in the diagram and include a page that maps the short name to the long name. Consider flagging the short names; one way is to add an asterisk to the front of shortened names. In that case, *createPFCIDbbbbc would indicate that it is a shortened name and createBlammyQ would indicate that it is not a shortened names.

On the map page, start with a statement like "Some method names are too long to conveniently fit in the diagrams that follow. In these cases the method name will start with an asterisk to indicate that it is a shortened name. The list below maps between the shortened names and the actual method name in code". Then have a simple table like this:

Shortened Name         Actual Method Name
createPFCIDbbbbc       createPathForCustomerIDblablablabla_click
3

Since you already have code and you are reverse engineering it into a UML model, I would highly recommend keeping the method and attribute names as they are in the code. This will make it easier for someone to go between the code and the model. However, using exact function names aren't required in a sequence diagram. Typically, I've seen this earlier on in the design process when activity, sequence, and communication diagrams are being used to describe a use case. The breakdown of the classes and functions may change, but the general approach is described using names that may or may not become the names of the methods.

Stylistically, though, long method names may be considered a code smell (see this C2 Wiki article on code smells, this C2 Wiki article on using good naming, and this Stack Overflow question about long variable and function names). You may not want to refactor it now, but perhaps make a note of it somehow to revisit the next time you're working with that code. As you can tell, long method names can make documentation difficult to create and read in the future, so that's another good argument for choosing good names in the future or refactoring existing code.

  • FWIW the first C2 Wiki says "if it's long, it might mean the method should be moved to another class" The SO link "well, it may or may not be a code smell, but it might imply the method is doing too much" FWIW – rogerdpack Jan 25 '18 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.