6

I have a Java class that handles import and export of data. It started out as a simple

private void export() {
}
private void import() {
}

Of course, I wrote the export first, committed it, and then went on to write the import. But import is a keyword in Java - I can't use that as a function name. So I go back and rename both methods. I usually end up with

private void doExport() {
}
private void doImport() {
}

which is both ugly and feels contrived. What do you think of these names? Got any better suggestions?

Note: I'm asking now, because it's now happened thrice and that keyword is getting quite annoying.

4
  • I realize this method is quite subjective. I hope it's not off-topic here. Sep 29, 2010 at 23:48
  • This might be subjective, but it's still directly programming related, so I'd argue it belongs on StackOverflow and not here. Sep 29, 2010 at 23:56
  • 2
    I don't think SO would appreciate this kind of question. Sep 30, 2010 at 0:01
  • See meta.programmers.stackexchange.com/questions/350/…. You could change your question to match 1, your question might meet 2, I guess it will meet 3; it meets 4, 5 and 6... Sep 30, 2010 at 1:03

2 Answers 2

4

I would prefer something like this:

private void importData(){}
private void exportData(){}

If you now would use this Class as an API you can do something like this:

dataUtil.importData();

With the CodeCompletion of the IDE, the differences are more visible if this methods wouldn't start the same way.

1
  • I agree, this is much better than doImport/doExport for most cases. Good answer! Oct 5, 2010 at 23:28
1

This is the same problem as with all keywords in programming languages. But the problem is easy, just chose another name.

How about this?

private void dataExport() {
}
private void dataImport() {
}

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