debuggable

 
Contact Us
 
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26

30 days later

Posted on 19/9/08 by Felix Geisendörfer

Hey folks,

My 30 day challenge is officially over today. I set out to do a blog post every day before 9am for thirty consecutive days and had 28 successes and 2 failures.

The first time I missed to post due to the all-nighter Garrett, Nate and I did before the workshop. Corey, one of the attendees noticed and was rewarded with 50 Euros as promised instantly. The second failure was yesterday. I was on the plane from NYC to Berlin and published a post right after I got back in. However, I could have pre-written the post at the airport where I had plenty of time. I just got totally sucked into a new side project (soon to be announced) and only noticed my mistake by the time the final boarding call was made ; ).

Overall I feel the challenge was a huge success, yet something I won't continue with or do again. During the challenge I was able to release two behaviors, one datasource, one cli shell, a jquery plugin and a a php code generator that were created as part of projects Tim and I worked on. I also published a few thoughts on programmings I meant to share for a while and a whole stack of code snippets, ideas and pictures.

So why wouldn't I do it again? Mostly because not all blog posts are created equal. There is stuff that takes me days to write and that deserves far more thought and research than what can be accomplished in an hour or less. This is the type of posts I want to do more and that cannot be done in the way I've been blogging for the past 30 days. I also realized I don't feel like blogging every day and it shines through when I write something just for the sake of a challenge. Nevertheless, a little discipline in regular blogging sometimes can't hurt and this exercise is probably going to be very beneficial for my future writings.

Now it is time to take on new challenges. I already set one. However, I won't share it. This time the only person I am accountable to is going to be myself which will require an even higher amount of discipline. How will you know what the new goal is? Well if there isn't a major announcement here 30 days from now you'll know it was not achieved ; ).

-- Felix Geisendörfer aka the_undefined

 

PHP code generator

Posted on 18/9/08 by Felix Geisendörfer

Hey folks,

this is post #29 of my 30 day challenge. Yes, I know its a little late, but I just got out of the plane from NYC to Berlin. Turns out nobody asked for the 50 EUR so far, too bad ; ).

Anyway, if you find yourself writing PHP code that writes PHP code, you might appreciate a little class I just wrote. You can use it like this:

$Code = new PhpCode();
$Code->write('$foo = array(%d, %d, %d);', 1, 2, 3);
$Code->open('foreach ($foo as $bar) {');
$Code->write('echo $bar');
$Code->close('}');
echo $Code->compile();

And in return you will get

$foo = array(1, 2, 3);
foreach ($foo as $bar) {
  echo $bar;
}

So what it does it essentially provides you with a wrapper for sprintf and also automatically does all the code indention for you so you don't have to go crazy with putting "\t"'s everywhere.

Anyway here is the code of the class:

class PhpCode{
  var $lines = array();
  var $mode = 'append';

  public function compile() {
    $out = array();
    $depths = 0;
    foreach ($this->lines as $line) {
      if ($line['block'] == 'close') {
        $depths--;
      }
      $out[] = str_repeat("\t", $depths).$line['code'];
      if ($line['block'] == 'open') {
        $depths++;
      }
    }
    return join("\n", $out);
  }

  public function write($code) {
    $args = func_get_args();
    $this->inject(array(
      'code' => vsprintf($code, array_slice($args, 1)),
      'block' => false,
    ));
  }

  public function newLine() {
    $this->inject(array(
      'code' => '',
      'block' => 'open',
    ));
  }
 
  public function open($code) {
    $args = func_get_args();
    $this->inject(array(
      'code' => vsprintf($code, array_slice($args, 1)),
      'block' => 'open',
    ));
  }
 
  public function close($code) {
    $args = func_get_args();
    $this->inject(array(
      'code' => vsprintf($code, array_slice($args, 1)),
      'block' => 'close',
    ));
  }

  public function prepend() {
    $this->mode = 'prepend-once';
    return $this;
  }

  public function inject($line) {
    switch ($this->mode) {
      case 'append':
        array_push($this->lines, $line);
        break;
      case 'prepend':
      case 'prepend-once':
        array_unshift($this->lines, $line);
        break;
    }
 
    if ($this->mode == 'prepend-once') {
      $this->mode = 'append';
    }
  }
}

Let me know what you think, suggestions are more than welcome!

-- Felix Geisendörfer aka the_undefined

 

Comment feed

Posted on 17/9/08 by Felix Geisendörfer

Many people have asked for it, we added it.

Subscribe to the new comment feed of the debuggable.com blog.

-- Felix Geisendörfer aka the_undefined

 

Installing PHP5.3 via MacPorts

Posted on 17/9/08 by Felix Geisendörfer

Hey folks,

this is post #28 of my 30 day challenge.

I originally wanted to continue my post on the linguistics of programming
today, but I was simply unwilling to publish what I have so far as it will require much more research to be of any significance.

So instead I'll share an easy way to play around with PHP5.3 if you're on a Mac. First of all install MacPorts (don't forget to install XCode before). Then run:

sudo port install php5-devel +apache2 +mysql5 +pear

To verify it worked run:

php --version

You should see:

PHP 5.3.0alpha1 (cli) (built: Sep 16 2008 16:03:17)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2008 Zend Technologies

After that, follow the instructions that from this general PHP5 via macports tutorial to get your new PHP5.3 configured with an Apache2 server.

Have fun with the new PHP : ).

-- Felix Geisendörfer aka the_undefined

 

The Linguistics of Programming

Posted on 16/9/08 by Felix Geisendörfer

Hey folks,

this is post #27 of my 30 day challenge.

When we think about programming languages, we often times think of them in terms of features, limitations, performance, syntax and other aspects.

Being asked how many "languages" we speak we might joke around, saying half a dozen not including a bunch of dialects of basic.

But really? How often do you really think of your programming languages just as you would of human languages? Lately I've been given the concept a lot more thought. And it is quite surprising how many parallels you can find.

It probably all started with the idea of having a dictionary for computer languages. For human languages we are very much used to the concept of using a dictionary that translates between a language we already know and the new language we want to learn. Why doesn't there seem to be books or sites out there that pick up on the idea for computer languages?

I mean, somebody's previous language skills seem to be just such an important aspect when learning a new language. Depending on the vocabulary (commands), syntax (~alphabet), grammar, philosophy (history) and features (expressions / idioms / constructs) people just come in with all kinds of assumptions when learning a new language. How can this be ignored in all of the learning material out there?

A follow up to this post will come tomorrow, but meanwhile I'd like to hear a little from you guys and what concepts you think are important in the human / computer language comparison.

-- Felix Geisendörfer aka the_undefined

 
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26