Skip to main content
  • Home
  • Womblog
  • Contact
  • Login
By Wombats logo By Wombats
You should see them code...
Home

Programming

Defining Classes in Modules "Leanly"

In:
  • Drupal
  • Programming
  • Ubercart
29Sep2008

Through some personal development efforts and work on Ubercart, I've been confronted lately with how to best use classes in my Drupal modules. For this post, I'm really just curious how others are defining and using classes in their modules and if the "lean" approach I've outlined below is reasonable. (i.e. Is what I'm doing to ensure Drupal loads less code even worthwhile?)

The general idea I'm following is that I want as little unnecessary code to be in my .module file as possible. To that end, I'm following Drupal's core practice of using .admin.inc and .pages.inc files to hold page callbacks. I believe Views does something similar (coupled with some auto-inclusion), and we're using this in some places in Ubercart.

Now I'm doing some experimental development on making something like a shopping cart a class. I've used a method in my FreshBooks module (w.i.p.) where I define the class in a .class.inc. So, in the module I obviously can't use $object = new ClassName();, but instead I create a small function in the .module that includes the .class.inc and passes the arguments on to the constructor when it creates and returns the object. From there on out it's using an object like normal.

This means I can have a thousand lines of code tucked neatly into a .class.inc file that needn't be loaded and parsed on every page request... just those where the class is actually needed. It also helps me personally to isolate all this code in a single file when developing/debugging. It seems like this segmentation would provide a performance boost, but I don't know what sort of tests to do to establish that. Should I just assume less code loaded is better? What about the require_once() bits from Rasmus' Drupalcon session?

What about possible pitfalls? Another module can't simply extend my class right off, but it could just as easily include the .class.inc before trying to do so. Would the hassle and file access outweigh the memory difference? Thoughts?

  • 10 comments

A Procedural ASCII Universe

In:
  • FreeBASIC
  • Programming
12Sep2008

I've always been a big fan of ASCII based games. If I sit down to toy with a project, more often than not I'm doing something ASCII. I was never a great artist, but I loved Roguelikes (ADOM being my favorite) and had a mind to write a multi-player Roguelike back in the day.

Anyways, I just wanted to post about one of the coolest ASCII apps I've seen in a while. The name is Project Infiniverse. It procedurally generates universes with star maps and nebulae or planet surfaces with climate regions, vegetation, etc. It's pretty awesome to check out if you have the time and are on Windows.

The apps are programmed in my compiled language of choice, FreeBASIC. I'd love to be able to write algorithms like that. (There's the geek in me speaking. Laughing out loud)

  • Add new comment

Legitimating the Developer's "Groove"

In:
  • Programming
  • Work
14Aug2008

I'm not the only one who knows about it...

"It is clear that interruptions are a major cause of low productivity among programmers. Why? The problem is not the time needed to handle the interruptions themselves, but the time needed to get back into the programming problem. Everybody, no matter what they do, face a reorientation time when they return to their work after an interruption. When you are reading a magazine article and look up to answer a question, it takes you longer to read the next paragraph than if you had been reading continuously."

From Are developers people? by Jakob Nielsen.

It was quite an enjoyable little read. I recommend it, even if you just wanna know a little more about how I think. Eye

  • 1 comment

SECTOR SHOCK

In:
  • FreeBASIC
  • Games
  • Programming
19Nov2007
Well, for the last several weeks, there has been a FreeBASIC game programming competition in the forums at FB.net (view thread). I pleaded with my wife and was allowed to work on and submit an entry. I've sacrificed plenty of sleep to work on the project after she's gone to bed and ended up with what I feel is a solid, enjoyable arcade game with enough bonuses and gameplay strategies to provide some replay value. The title is SECTOR SHOCK, and it is your next favorite pasttime.
  • 2 comments
  • Read more
Entries (RSS)

About Ryan

Ryan Szrama is a Drupal e-commerce developer for Commerce Guys, focusing on Drupal Commerce. Aside from his work, he loves his wife, his daughter, his church, and a good book over a white mocha.

You can find him elsewhere online at:

Commerce Guys logo Druplicon Twitter

Find me at these upcoming events...

I'll be presenting Drupal Commerce at the following events and sponsoring some with Commerce Guys. Be sure to say hi!

Come to the 2010 CMS Expo

Bible Books Christianity Drupal Drupalcon drupalconszeged2008 Family Food Homeownership Marriage Ministry Music Programming Space Ubercamp Ubercart Vacation Work
more tags
Creative Commons License © 2009 Ryan Szrama

Drupal port by 3rdWorld : Created by Design Disease