Ad
  • Custom User Avatar

    I arrived at a similar solution. Is it possible to pass a null string?

  • Custom User Avatar

    Hey, thanks for the feedback.

    While you are correct consider that there was no expected behaviour specified, e.g. should we return null oder string.Empty, which is the reason for me letting the method raise an exception in the case of the parameter being null.

  • Custom User Avatar

    I completly agree with that comment.

    Adding a null check will solve this at the start of the function. It isn't too clear what to do for error case. I suppose returning 'null' would be ok, but throwing a new ArgumentNullException works too.

  • Custom User Avatar
    • Maskify.Maskify(""); // should return ""

    Throwing an exception is not "change all but four chars.."

    And null is not "".

    In nearly all cases where you're passing null instead of a string, it is an error. IMO, it should cause an exception, unless you have a well-defined behavior for that case, as otherwise you're allowing bugs to propagate.

    And let the caller, who I assume have accee to user interface and such, to handle possible errors caused by a null string

    Except you're making it much more difficult to handle those errors at the source.

  • Custom User Avatar

    Most of the other solutions will fail if cc == null as well...and frankly, that's the right thing to do, unless the problem specifies a behavior for that case.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution