Showing posts with label brain. Show all posts
Showing posts with label brain. Show all posts

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.

Wednesday, 3 July 2013

Programming Brain Farts

I have a long and annoying habit of getting the smallest thing lodged in my code, many years ago a famous one was whilst programming the N-Queens problem in Java, it simply would not work, myself and my house mates were pulling our hair out... Until one of us solved it, and I have the ignominy of my mate walking in pointing at my screen and going... "That [int] should be a long"... DOH.

And the same has just happened now, in some byte wise encryption and transcription code, I could not get the C# port to work, I'd looked at it, printed it out, I'd stared long into the evening... no dice.

I noticed a senior manager earlier twiddling his thumbs, so I asked what he was up so - not that I have remit to do so - he said nothing... So I palmed this task off to him....

Five minutes, most of which was his printing out the function, it took him... "That byte there is in Hex on the spec, but you got it as decimal in the code"... ARGH... ARGH... ARGH... GAH....

"Thanks!"....

FUCK another one for my list of Brain Farts.