Category: Programming

Mar 27 2010

Life in JQuery

JQLife

JQLife

I mentioned a couple weeks ago that since getting the hang of CSS and discovering jQuery (a Javascript framework that’s a huge improvement on a language that feels like it was created by government committee) I was starting to enjoy web programming again.  Several nights ago, I woke up and couldn’t get back to sleep, so I thought I’d take the opportunity to work on something new.   In about three hours, I threw together a little game based on something I played once on the Commodore 64, and got it functioning. Read more »

GD Star Rating
loading...
Feb 08 2010

Programming Is Fun Again

Unlike a lot of the people of my generation who got into computers and programming, I didn’t grow up with one.  Home computers were still kind of an oddity then, and the price tags made them seem about as accessible to me as having my own jet plane.  So my first programming experiences were fairly short and pointless: some character graphics stuff on Apple systems at College for Kids at QU; fiddling with Pascal on a visit to Purdue when I was 16; and finally some real Z-80 programming on the Sanyo CP/M machines we got at St. Thomas in my senior year.  Computer class focused on word processing in Wordstar and saving our work to disk, but somewhere I managed to run down some info on the Z-80s registers and assembly language, and did some simple programming like a tic-tac-toe game.  I even remember programming on paper, writing out the lists of instructions that I’d type in later when I got access to the systems again. Read more »

GD Star Rating
loading...
Jan 22 2010

My Simple Twitter Program

One thing that’s kept me from diving into the social networking systems like Twitter and Facebook is their ephemeral nature.  Twitter saves posts for maybe two weeks, and that time frame is getting shorter as the service gets busier.  I don’t know how long Facebook saves things, but I don’t think there’s any easy way to search back through them anyway. Read more »

GD Star Rating
loading...
Aug 14 2009

Leaving the Daemon

(Despite the title, this is a technical screed, not a religious one.  You have been warned.)

I started using FreeBSD about ten years ago.  A new client had it on his web servers, and I was impressed enough by it to start running it on my own machines, including my desktop.  In the late 1990s, the various Linux distributions were like fraternities making floats for a Homecoming parade: they turned out some impressive work, but you had to put up with a lot of drunken brawling to get there.  I bounced from one Linux distro to another, never really satisfied with any of them.  The BSD community seemed more mature (I saw a poll once that said FreeBSD developers were ten years older on average than Linux developers)  and it showed in the software.  I liked the stability of the software and the release process and the way it was all designed.  It just seemed like the free Unix operating system (OS) for grown-ups.

Read more »

GD Star Rating
loading...
Dec 30 2008

Perl Rules

This strip from the excellent XKCD.com pretty well sums up my thoughts on both schools and the perl programming language, so I had to share it:

11th Grade Activities

11th Grade Activities

GD Star Rating
loading...
Dec 03 2008

Actionscript: Not Actually a Script, and Very Poor Action

Learning a new programming language is never exactly easy, but it’s like learning a new spoken language: once you know a few, it’s easier to pick up the next one. They all share things in common, so you don’t have to learn everything from the ground up. It’s become a routine: I go find a tutorial or a very simple “Hello, World!” program written in the language, and start looking for things I recognize. “Ok, it has C-style syntax, OO like Java, and a regex package like perl’s.” With those basic impressions, a few examples, and a function library, I’m ready to start writing or fixing programs in that language. Proficiency takes time, but I can get started right away.

Or, that’s how it usually works. Not so much with Actionscript, the language Flash programs are “written” in. Those are sarcasm quotes around “written,” because apparently most Flash programs aren’t written, they’re designed or “staged.” Now I know why Flash became so popular so fast: you didn’t have to use the keyboard to make Flash doohickeys. Making most Flash programs is like making a movie or an animated drawing. You load up the Flash builder program, insert a movie or draw some stuff on the “stage,” and tell it where you want things to move and what you want to happen if someone clicks on something.

That’s all fine if you’re making a simple movie with a little interactivity, which seems to be what the language was originally designed for. But they’ve extended it with a full slate of classes and features to make it a full-featured programming language capable of doing anything. Problem is, 99% of the tutorials on the net assume you want to make a movie, not write a program. If you want to make anything more complicated than Duck Hunt, finding out how is tough. Adobe rivals Cisco in providing reams and reams of documentation that make it impossible to figure out how to do step one. I literally spent a couple hours figuring out how to compile my first program, since I wasn’t using the GUI builder. Then I had to learn this unholy combination of Actionscript and MXML that you have to feed the compiler to build the simplest program in the first place. I never found a straightforward “my first program” tutorial that said: install this program, put these lines in a file, and run this compiler command to create your first program. That’s insane.

Then there’s the language itself. Maybe it was a scripting language at version 0.1, but it’s not now, so the name doesn’t even make sense. Version 3.0 looks so much like Java I don’t know why they bothered coming up with it. Both languages are (or soon will be) open-source, so we’ll have two almost identical free languages battling for….bragging rights for Sun and Adobe, I guess. It’ll be like watching the Cowboys play the Raiders—can they both lose somehow?

An assortment of functions and classes shouldn’t be able to call itself a programming language unless it has a “sleep” function. The setInterval() and setTimeout() functions are useful for certain types of timing, but what about when you just want to delay the program a second and continue where you left off? No, can’t do that; it’d violate someone’s notion of good OO programming practice or something. But what if I have a 3D array (maybe a 3D chessboard) and I want to go through it space by space, doing something to each one and pausing a second between them? In perl, it couldn’t be easier:

for $x (0..7){
  for $y (0..7){
    for $z (0..7){
       do_stuff_to($array, $x, $y, $z);
       sleep 1;
    }
  }
}

That’s so simple I bet a non-programmer could understand it without much explanation. It loops through the variables $x, $y, and $z, and for each combination of those three, it calls the function do_stuff_to with those values and then pauses a second. Simple and intuitive. It keeps my looping variables inside the loops where they belong, so when the loops are over, they wink out of existence and stop using up resources. It matches the way I picture it in my head: start down the first row of the first column, then the next, etc., pausing a second between each space.

Not so simple or intuitive in Actionscript. You have to do something like this:

var x:int = 0;
var y:int = 0;
var z:int = 0;
var intervalID:uint;
function sillyLoopTimer():void{
    if(x>7){
        x=0
        y++;
        if(y>7){
            x=0;
            y=0;
            z++;
            if(z>7){
                return;
            }
        }
    }
    x++;
    do_stuff_to(array, x, y, z);
    clearTimeout(intervalID);
    intervalID = setTimeout(sillyLoopTimer,1000);
}
sillyLoopTimer();

Granted, this probably isn’t the most elegant code because I’m new at this way of doing it, but it’s how the examples I’ve seen do it. Now we’ve got a function that simulates the loops by incrementing the variables and checking bounds as it goes along. The variables have to be defined outside the function so they maintain their values between calls, so they won’t die off when the looping is done. (The compiler might be smart enough to figure out they won’t be used anymore, but you can’t count on it.) It’s not intuitive anymore, because now it says, “Ok, go do stuff to the first space, then set a timer for one second to go do stuff to whatever space these variables are pointing to a second from now.” Since the variables exist outside the function, if I forget and reuse them somewhere else, who knows what space I’ll be doing stuff to the next time the timer fires.

I’m sure this all makes sense in Computer Science 302, but it’s not much for practical programming. These new languages all seem to be designed to be used by committees of people with as little programming skill as possible but fancy GUI builders. (Judging by online examples, that function above really should have been named mySillyTimerLoopWithTheLongName(), and the looping variables should have been loopVarX, loopVarY, and loopVarZ. These languages seem to encourage ridiculously long names for everything.) Why, oh why, couldn’t PerlTk have been the one to take over the web applet market way back when? I guess all the perl programmers were too busy writing server-side code and getting actual work done.

I’ll keep plugging away at this (or switch to Java, which at least has Timer.sleep()), since I need it for a game I want to write. I’m sure once I learn some more of these workarounds and idiosyncrasies, I’ll be able to make some progress without tearing my hair out, but I don’t know if I’ll ever like it.

GD Star Rating
loading...

WordPress Themes