Tuesday 28 January 2014

String Replace in C# & Java

I hate the way an object orientated language like C# can completely ignore object orientation...

My example for the day... The Replace function in the String object....

string l_name = "Job";
l_name.Replace ("b", "g");

I don't know if it's just my Pascal lathered mind, or today in general, but this got really on my manboobs, that it did nothing... Because instead of the Replace function acting on the "l_name" object, it acted like a static function outside the string... Meaning I had to do this:

l_name = l_name.Replace("b", "g");

So I may as well have used C notation...

Replace (&l_name, "b", "g");

It's Functional rather than object orientated, I wanted "Replace" just to act on the object it was pointing at, to do "this->Replace" and not need to assign back to anything... That's how I'd have designed this function.  And yes, if people wanted to assign a Replace leaving the original alone I'd have let them, like this:

class string
{
  public:
    void Replace (string& p_What, string& p_With);
    static string Replace (string& p_Source, string& p_What, string& p_With);
};

Gah, object orientation is the point of C# existing... I note Java handles its string class the same way, and I find it so very very annoying...

And worse than finding it annoying me, I don't know quite why its annoying me so much, I think today I feel on the whole to be totally out of control of my own life... Not least because I note the company has docked £372 off of my pay for the xmas break, new rules in my new position... So already earning a pittence and running around after everyone else, I'm getting docked cash for time off at Christmas... Thanks Scrooge... Thanks.

No comments:

Post a Comment