some thoughts on php and oop

So, I was working on Znurt this morning (I woke up unusually early, and didn’t wanna go back to sleep).  I’m getting close to opening the codebase, but before doing that, there’s some really obvious glaring deficiencies that I want to clean up first.

The big thing I’ve been working on with the packages site now is making it more efficient.  The first step in that has been gathering some data on how often certain things are being called to see where optimizations are most needed.  So, the other day, I added a counter to the constructor of each class that would just tally each time the class was instantiated, and then I’d dump out the counter at the end of an import run.

One thing that surprised me is how often one particular class was being called — PortageTree.  It’s a really simple class, and all it does is set down some really simple variables that aren’t going to change at all once they are declared, such as the location of the portage tree and it’s metadata cache on the filesystem.  Pretty much used across the board on a lot of other classes that need to know the filesystem location of files (PortageCategory, PortagePackage, etc.).

Well, being still pretty new and fuzzy to the OOP approach, I thought it made sense to just extend the PortageTree class on PortageCategory and call the parent constructor to get the variables set.  That ended up in that class being created a huge magnitude of times,  all for the same pretty much unchanging variables.

So, I switched it this morning to use a singleton instance instead, so the class is only being created once and referenced thousands of times each import.  Much nicer already.

It’s stuff like that that makes me wish I knew more about OOP.  I am studying it on and off, but there’s still some concepts that I just can’t wrap my brain around at times, like exceptions.  In my procedurally-attuned programming frame of mind, every time someone explains them to me, I think … “Well, if something *breaks* why don’t you just work with the return codes and work around that?”  So, yah.  Some stuff is still lost on me.  I’m trying to figure it out though.  Maybe it’s one of those things that doesn’t make sense so much when you apply it to PHP and it’s general usage of websites.  A lot of the stuff I read about, I think how it would make much more sense if it were an actual application running.

Anyway.

On a totally different note, one thing I want to look at getting into the packages website is tracking a changelog of all the package’s keywording history.  Right now, the import process is pretty simple — if the content of the ebuild has changed, then the old one is marked for removal and an entirely new ebuild record is created in the database.  The reason for that is because that is far easier to do than it would be to examine all the myriad of data that is associated with one ebuild, track the changes, and then flag those.  Instead, I just dump the old one and treat the new one as a completely new record.

There’s a tradeoff in the compromise, though, because instead of tracking ebuild modifications, I have to do all this coding to flag packages and ebuilds that things have changed and to treat them as an update instead of a new one.  That was tricky to get setup right, and getting that stuff in there in fact was one of the main things that pushed the initial launch back.  It was just one of those things that I couldn’t run into the bugs until I started actually doing  a sequence of import runs, since they wouldn’t show up until then anyway.

But, I’d like to start at least tracking the ebuild keyword status changes.  The reason is because that is really valuable data that can provide an excellent set of reports.  For instance, we can see which categories / packages / herds are getting ignored historically as far as stabilization.  Plus you can do cool stuff like import results from a statistics tracker as far as what people have installed, and you can start to see where maybe the tree could use a little more love.  And, it would help contributors who want to help out, but are overwhelmed by the enormity of bugs and packages and issues that need to be addressed.  I could see it being helpful saying, “here’s an area that is suffering from neglect *and* is popular.”  That would be cool.  And that’s my goal.  In fact, that’s *been* my goal for years.  I’m just now getting to the point where it’s becoming possible, though.

Fun stuff.  I gotta hone my coding skills as I go, though.

skateboarding in winter … um, again

I must be out of my mind.  I went skating again tonight (the second time in a week), even though its like 30 degrees outside.  It’s freaking cold, man!  I dunno what came over me, though.  I just really wanted to go skating all of a sudden, so I called up Kevin and we went to Liberty Park and screwed around for a bit in the biting cold.  It was really fun, and I totally sucked at landing anything because I haven’t been in at least six months.

Then, tonight, it was equally cold, but I went to Fairmont and was just screwing around.  Good times.  I really wanted to get a picture of the skate park, since it’s half covered with snow, but there’s enough melted that you can actually go around it in places.  Instead of that, here’s a picture of me drawing pictures. :D

I think I learned a good trick though to skating tonight.  Just freaking relax.  I realized the other day that I get totally tense when I’m poised to ollie or shuvit and it’s totally working against me.  So, tonight I tried to just relax and try and pop it a couple dozen times no matter how poised or ready I felt.  It wasn’t very effective practice, but I did *try* a lot more, so that was good.  I landed one ollie, I think.  Barely.  I’m not sure I really went in the air, actually.  But who cares.  I went out, I had fun, it was worth it. :)

znurt hosting, bugs, code

I migrated the packages website to a new server this weekend, and so far I’m really glad with the setup. I originally planned on having the whole thing setup in a short time, but I went with a different web server setup this time around. Instead of using lighttpd for the server, I went back to apache, but this time with mod_fastcgi to run PHP. From what I’ve read, PHP doesn’t like threading too much, so running at as CGI instead should avoid any possible headaches. We’ll see. So far, the site is far more responsive than everything else I’ve tried, so I’m happy.

I feel bad about how things have gone so terrible since the initial launch of the site. I really was not ready for the massive load, and my interim solutions were just slow and clunky. Hopefully things should be much happier now.

There’s still a lot of silly bugs in the code that I need to fix. I just found another one this morning where the caching is breaking if you change your architecture selection around. Oy. I’d like to get to them, but I’ve been pretty swamped for time lately, between starting a new job this month and dividing my remaining time doing consulting work for two other companies.

Having a break from it though has been kind of good. I’ve already thought of a few optimizations that I can throw in there that are kind of like, “well, duh” type stuff I can’t believe I didn’t think of. For example, one way that I check to see if an ebuild is new is to see if the file mtime has changed. I don’t know why it never occurred to me to just read the Manifest file and see if any of the hash sums have changed. That’d save me a lot of time.

I’ve been poked a few times about getting the code in a live repo somewhere, too. I guess that’s coming soon, assuming I can get around to it. Personally, I don’t like the idea of doing it when I *know* my code is in some ugly stages, but whatever. I need to learn how to setup a git repo anyway.

Oh yes, that reminds me. I also moved all the Planet Larry stuff onto the same server. Everytime I poke at the site, all I can think about is how much of an overhaul the whole thing needs. I’m totally embarrassed that I haven’t even switched over to using Gravatar yet.

My goal is to ditch the planet software and write my own software to pull in the feeds, drop them in a database, and have the whole thing searchable. Then build a user admin section as well so users can manage their feeds themselves, and stop waiting on me. I’m planning on making that my next project, once Znurt gets to a better stage of stability.

Right now, though, I just did some minor tweaks. I got rid of the subdomains, and all the other projects on the site that I let atrophy, so planet is just available now at http://larrythecow.org/