KBD

Keith Devens .com

Wednesday, December 3, 2008 Flag waving
real software ships. – John Gruber
← HopeHey! →

Daily link icon Monday, September 16, 2002

Angry code comments

This is the comment I just wrote to myself to remind me what I have to write next time I pick up the code. If you've been paying attention, I've been working on some Java code Smiley... Sorry about the foul language.

// FUCKING LOOPING, INDEX KEEPING, TEDIOUS ASS CODE i'M GOING TO HAVE TO WRITE
// FOR THIS SHIT THAT TAKES ME TWO LINES IN A SCRIPTING LANGUAGE!!!

All to do some simple string manipulations.

Hey, look at that - it wasn't too bad Smiley All I really needed was a version of strtr that had the limitation that the "from" characters could only be one character long. It worked the first time too.

    public static String strtr(String str, char[] from, String[] to){
        StringBuffer sb = new StringBuffer(str);
        int n,m;
        for(n = 0; n < sb.length(); n++){
            for(m = 0; m < from.length; m++){
                if(from[m] == sb.charAt(n)){
                    sb.replace(n, n+1, to[m]);
                    n = n + (to[m].length() - 1);
                    break;
                }
            }
        }
        return sb.toString();
    }

Oh, and since I don't know how expensive the .length() function on Strings or StringBuffers is, I may replace that and pre-cache it (adjusting it for when I lengthen the string, of course).

Also note that the above code example is an excellent demonstration of how Java does not support the Uniform Reference Principle. .length for an array is different than .length() for a String.

← HopeHey! →

Comments XML gif

Keith Gaughan (http://hereticmessiah.weblogs.com/) wrote:

Next time you're doing string manipulation, just remember that you could be doing it in fscking slow-ass VB. Grrr!

Oh, and I'm back at college again. I notice you sent me some emails that I haven't been able to see and I'll get to them as soon as I can. Sorry, dude!

∴ Keith Gaughan | 16-Sep-2002 8:29am est | http://hereticmessiah.weblogs.com/ | #799

Keith (http://www.keithdevens.com/) wrote:

Hey, at least VB has basic shit like ltrim! Grr! Smiley

Keith | 16-Sep-2002 9:19am est | http://www.keithdevens.com/ | #800

Keith Gaughan (http://hereticmessiah.weblogs.com/) wrote:

I've no idea how expensive it is on strings, but length() is pretty darn cheap on StringBuffer. Even then, it's just good practice to cache it anyway. After all, if you can move a call outside a loop, it's a good thing.

What's really sucky about Java strings is that they're declared as final so you can't create extended versions of them with your own extra stuff. Now that sucks.

∴ Keith Gaughan | 16-Sep-2002 12:01pm est | http://hereticmessiah.weblogs.com/ | #802

Dean Peters (http://www.HealYourChurchWebsite.com) wrote:

Actually, VB.Net has some rather nice string capabilities via the .Net Framework ... provided you know what you're doing with regular expressions.

∴ Dean Peters | 18-Sep-2002 10:09am est | http://www.HealYourChurchWebsite.com | #803

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

December 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 5 posts

Recent comments XML

new⇒Girls, please don't get breast implants

I have 34 A breast but at 22 years​old they seem to be growing again​which ...

76.64.120.153: Dec 3, 10:00am

Perl 6 1.0 in March?

Doh, my mistake. I'm aware of the​relation between Parrot and Rakudo​but I'...

Keith: Dec 2, 1:03am

Free image hosting sites

Well, TinyPic has this in its​FAQ:

> Images and videos is in​your accoun...

Keith: Dec 1, 1:13am

Join a NameValueCollection into a querystring in C#

Well with a lamba expression, this​is what I came up​with:

?!code:csharp...

Gustaf Lindqvist: Nov 30, 4:38pm

Why no generic OrderedDictionary?

Check​http://www.codeproject.com/KB/recip​es/GenericOrderedDictionary.aspx?d...

Gabrielk: Nov 27, 6:57am

Generated in about 0.193s.

(Used 8 db queries)

mobile phone