KBD

Keith Devens .com

Sunday, October 12, 2008 Flag waving
Mistakes are as serious as the results they cause. – House (The Mistake – ep 30)

Archive: June 12, 2003

← June 11, 2003June 13, 2003 →

Daily link icon Thursday, June 12, 2003

Python rocks, yet again

I'm converting that Perl code I've been writing to Python, since I'm writing a library I want to be available in lots of languages. Python is such a joy. It's so funny because most of the conversion from Perl to Python is simply removing things.

For instance, I just converted:

$self->{line_count} = scalar(@{$self->{lines}});

into:

self.line_count = len(self.lines)

Look how much nicer that is Smiley

And again...

#key
$_[1] = $self->trim(substr($_[0], 0, $n));

#value
$_[2] = $self->trim(substr($_[0], $n+1, $len-($n+1)));

turned into:

key   = str[:n].strip()
value = str[n+1:].strip()

(I think that's right). And trim was defined to be this:

sub trim{
    shift;
    my $string = shift;
    for ($string){
        s/^\s+//;
        s/\s+$//;
    }
    return $string;
}

Ok, well I finished converting that code. I haven't run it yet, so there are definitely errors, but I don't think it would significantly affect the fact that just after doing a braindead simple port of the code from Perl to Python I went from 287 lines to 225 lines.

Ok, take it back. I thought you could do more inline in Python than you can actually do. So, that expanded it to 235 lines, and now it compiles Smiley Still a big improvement.

Perl is difficult to program correctly in

While Perl has a lot of stuff built in to make a programmer's job easier (such as automatic memory management, etc.), for some reason I find it extremely hard to program correctly in Perl. It seems like, for me, it's much harder to get things right in Perl than in PHP or Python.

God, and I'm having to cut and paste large sections of code just so I can replace braces {} with brackets [] because Perl's syntax changes based upon the type of a variable, which is just wrong.

Well, it seems that judicious use of references can alleviate that particular problem...

Evolution

Answers in Genesis: Anthrax and antibiotics: Is evolution relevant?.

Worth a read. Obviously its focus is on bacterial resistance to antibiotics, but the article contains lots of info that is relevant to the discussion of evolution in general.

Unifying Tables, Objects, and Documents

I've seen this in a bunch of places, and I first came across it a relatively long while ago, but I didn't blog it because I wanted to read it first to see if it's worthwhile. I haven't finished it, but from what I've read it's definitely worthwhile, at least because it'll make you think about the issues the paper raises.

From Microsoft Research: Unifying Tables, Objects and Documents (PDF)

The most important current open problem in programming
language research is to increase programmers productivity,
that is to make it easier and faster to write correct programs[36].
The integration of data access in mainstream
programming languages is of particular importance - millions
of programmers struggle with this every day. Data
sources and sinks are typically XML documents and SQL
tables, but they don't merge nicely into a statically typed
object-oriented setting in which most programs are written.
This paper addresses how to integrate tables and documents
into modern object-oriented languages by providing a
novel type-system and corresponding language extensions.

← June 11, 2003June 13, 2003 →
October 2008
SunMonTueWedThuFriSat
 1234
567891011
12131415161718
19202122232425
262728293031 



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

Recent comments XML

I hate PHP

Elliot Anderson,

Dude!! You the​man! The reverse replacement for​array_u...

Alex Ndungu: Oct 11, 1:35am

Call a function from a string in Python

?!code:
some_object.__getattribute​__('method_name')()
?!/code

is​the s...

Patrick Corcoran: Oct 8, 3:53pm

Spider solitaire

I have won 185 games of Spider​Solitaire at the "Difficult" level.​ What is...

75.179.28.113: Oct 8, 12:42pm

Sed one-liners

Hi.

I wanted to let you know​that I wrote an article "Famous Sed​One-Lin...

Peteris Krumins: Oct 8, 3:05am

Timesheet Calculator

Hadn't seen it before now, but my​company already uses a time​tracking prog...

Keith: Oct 7, 10:44am

Girls, please don't get breast implants

Hey everyone, 

I am new to this​blog and I have enjoyed reading all​your...

Sarah.M.: Oct 6, 9:45am

Generated in about 0.052s.

(Used 7 db queries)

mobile phone