2

I might be having a dumb day but today after looking over my code I ran into a meaning issue with my own syntax, and the comments explaining that syntax...something I've never actually thought about until I decided I need to be clearer to myself, as this application gets larger and larger and I'm the only maintainer on this project...so here is the question.

If I were to say merge hash1 with hash2 what would that mean to you? Would it be more proper to simply say "merge hash2 into hash1" since this is what I actually mean? I'm not the the only one reading this so I want to be as clear as possible to people who aren't programmers what exactly is going on.

For anyone who wants elaboration on entities:
hash1 = {a: "default", b: "default", c: "default"}
hash2 = {a: "new", b: "new"}
Where in this case hash2 is being merged into hash1 so that hash2 overrides hash1.
For anyone who doesn't program, think of it as two lists, list2 merging into list1.

2
  • 1
    You might benefit from elaborating on the context of use, e.g. what are the entities that are being merged?
    – N.N.
    Oct 7, 2011 at 12:05
  • I've elaborated it for you. Oct 7, 2011 at 12:12

4 Answers 4

4

As a programmer (American) I agree you need to clarify your comments in the code. When I can't understand my own comments (and it has happened), I'm in big trouble.

I would expect merge A with B to give a result that contains all the elements of both A and B, but it doesn't tell me if the result is in A, B, or C. Merge A into B tells me that B will end up gaining anything from A that wasn't already in B.

In your specific case, I would say update hash1 with hash2 because you are modifying hash1 by ensuring that it contains the data from hash2.

It would probably be beneficial to use more than four words because someone else may eventually maintain the code and explicit comments will be greatly appreciated.

1
  • This is what I was thinking too. I should clarify it the way you're thinking and state "merge hash2 into hash1" because it's in-place so there is never going to be a c and even though a programmer would see that right off the bat, average-Joe wouldn't... so it sounds like this is what I should do, use into rather than with so it implies that b is going into a. Oct 8, 2011 at 7:22
2

You've answered your own question. When something you're not saying is "what you actually mean", you should say that instead!

"Merge hash2 into hash1".

1

When you say merge with I imagine that to mean that there will be portions of each input in the output. When you say merge into it suggests that the output will be very similar to one of the inputs, with some differences that were inserted from the other input.

1

In the context of your question, it would be (at least to my logic) merge hash2 into hash1. When you start with hash1 as the base, merge hash2 into that then hash2's entries take precedence should there be a duplicate.

This is a slightly different process from concatenation, which describes end-to-end linking — so hash2 would follow directly after the end of hash1.

Or perhaps this is actually what you have in mind? Given if you were merging hash1 and hash2 lists it's probably programatically simpler to concatenate multiple hash*n* files then parse the whole thing linearly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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