Been a long time since I wrote anything here.  It's a failure on a personal level.  There's been stuff to write about, I just haven't felt like writing about it.  On the programming front I'm still whacking away at it, though in small portions.  I recently rewrote our internal website at work.  It was an old dinosaur of a site, full of tables antiquated HTML tags.  There were even some old Frontpage extensions.  For a start I rewrote everything in proper HTML/CSS with PHP for ease of management stuff like including the navigation structure and some forms.  I've added a database with the intention of building in some management and automation tools.  Make it so I'm not the only one who can update the thing.  So far all I've done with it is an event calendar.  It's a simple afair, just a form for adding and editing events, and a page for displaying them.  The dates are saved as timestamps that the page will translate.  So far it's working fine, but I'm the only person to use it at this point, and I know how to behave with it.  We'll see what happens once a few others start using it.  I did add a simple log in case there are any shenanigans.  I also plan on adding an employee directory, maybe that classifieds page I've been tinkering with.  For any of the more complex stuff I've been doing object oriented PHP code.  I think I'm getting the hang of it, but I never know if I'm doing it "correctly".

On a more personal front, I've been playing a lot of videogames lately.  They're my preferred form of escape.  I never know how personal to get here.  Should I keep it light or unleash the abyss?  Suffice it to say I am and have been depressed for some time, and the games take my mind off things.  At least for a little while.  XCom 2 is my most recent focus.  It's odd, over the years the original X-Com, which I believe I had on Playstation, picked up from a discount bin at a game store that I can't even remember the name of, has been a lingering obsession.  Most people I have talked to about it have never heard of it, yet the remake and sequel are both very popular.  I must have been talking to the wrong people.

I was ecstatic when I found the original on Steam, and even more so when I found a mod for it (almost more of a complete rewrite) that fixed some of the technical limitations of the old ones.  Weird, old school PC game type problems, like item limits due to memory allocation.  It also made the AI even more deadly, as if that were necessary.  I think anyone who has played the original has had one of those missions where you lose 3 people as they're literally stepping off the ship to off-screen alien ambushes.  Anyway, it was remade a few years ago, and while it wasn't the same, it had enough of the old elements, and it was a ton of fun.  They recently released a sequel, where I believe they got just about everything right, and it's been a lot of fun playing it.  I think I may have had my all time nerdiest moment the other day when it released.  For my birthday my wife got me a shirt with the new XCom logo, complete with the Vigilo Confido slogan, and I wore it while playing XCom 2 on release day.  Shameful.

I've been enjoying it so much so that I stuck my toe in the modding water.  To be fair, what I made isn't really a mod.  They added a feature where you can create soldiers and export them to share with others.  Within days Nexus mods had a bunch of themed characters people had made.  A wide variety of alien killers, from the cast of the Alien movies (1 and 2, aka the good ones), Predator, even Duke Nukem.  But there was a glaring absence.  I'm of course talking about the protoganist of what may be the finest sci-fi horror movie ever made: The Thing.  1982 version, not that 2012 nonsense.  That's right, RJ MF'ing MacReady.  Here's the link to him on Nexus Mods

The makers actually released a full on SDK for the game, so I might dip my toe a little deeper.  I don't know squat about mod making, but I imagine it can only help sharpen my software development skills.  It's funny, I put very little actual work into the character, and yet I've already checked on the page activity about 4 times since posting it tonight.

I guess that's about it for right now


The Grind

As I write this, my latest project, the classified ads page for work, is incomplete but stable. The part of the page that will display ads is done, including pictures. When I first started this seemed like such a minor step to completing the project, but it turned into quite a milestone.

The reason the display page became so much more of a big deal is because I'm attempting to make it with objects. I'm relatively new to object oriented PHP. More accurately, I'm relatively new to object oriented programming altogether. Almost all of my previous PHP projects were all written procedurally. Back when I was first learning the language objects were weird and intimidating. I've gotten a lot more familiar with them lately, but it's been a slow process. Thus, the title of this post.

I think I can identify the source of many of my issues. I think it's safe to say that most of them are self-inflicted. For example, I noticed I have a tendency to get really focused on solving a problem without taking the time to think if I'm solving the right problem. There were many times where I would be chiseling away at a particular block of code. I would change this piece, refine that piece, inching closer to the expected result set when I tested it. And when I finally got there, I would sit and think "I can't use this at all". It's a great feeling to finally get something to work after struggling with it, but it's equally, if not more, deflating to realize you did all that for nothing.

Almost worse than that, I would occasionally stop what I was working on to inexplicably work on a different feature. Even at the time I thought it was odd. I was still working out the details of pulling in the pictures for each ad when I decided to stop in the middle of that and implement an image resizer, which I wouldn't actually need until WAAAAY later in the project.

One fun little problem I ran into was during that image resizer implementation. Up until that point I had avoided namespacing. I figured I was starting out, and namespacing was a layer of complexity that would cause more frustration than it would fix problems. Now maybe the problem I had was because I didn't include the namespacing from the beginning, but who knows? Basically, once I added the namespaces everything just stopped working. I kept getting errors that the files couldn't be found at the expected locations. I spent hours trying to troubleshoot this. Making all sorts of minor changes, looking up solutions from other people with these problems, trying those fixes, trying everything, all to no avail. And near the end, I figured something else must be going on because I've been at this enough that I can just tell I have it right. So I called it a night. The next day, without making any changes, I tried it again and it worked fine. I can only assume it was something in my test environment that needed to get reset.

I did notice that I found it more difficult to think out the logic with objects. I think it's a mixture of still being unfamiliar with some of the object syntax, and also that I'm generally trying to hold more code in my head when working with objects. With the procedural work I used to do, it seemed like I would only need to keep a few lines of code straight to get the next piece to work. With the objects it's more like I need to keep what the code is doing in my head. For example if I'm writing a class that will do something to an array, I need to remember how the array is coming in, what I need to do with it, and how I want it to leave. While that's not unreasonable or even difficult, it's different from what I used to do and takes some adjustment time.

On the plus side, I find it FAR simpler to refactor object code. While it was definitely a grind, it would have been a lot worse if not for using objects. I believe this is due to what I talked about earlier, where you have to know what is going into a class or object, and how it is expected to return. Everything is organized into little discrete chunks, which makes it far easier to identify and address a trouble spot. I found I was much more confident in the code I wrote and whether it would work than when I made everything in the procedural style.

It's funny, when I look at the last project I made with PHP compared to this one, it's like night and day. It was a database and website for tracking PC deployments at work. The way we were doing it just wasn't good enough anymore, so I put this thing together over a few days. It's...good enough...but I haven't touched it in a long time because the code is a mess. Looking back, it almost looks like I was trying to write one of those "Don't Do This" examples for a text book. I would love to expand on it, and use it in different ways, but I'm terrified to touch it at this point. It's so easy to break with just minor changes. It's a good lesson, and probably one that I had to learn the hard way.

I'm planning to get back to this classifieds project soon and finish it. I've been a little out of sorts lately, and the need to detach and zone out has outweighed the need to better myself through applied learning


Why "Remember This Choice" checkboxes are EVIL!!!!

I've noticed, both as a fledgling developer and seasoned IT support dude, that doing anything the first time sucks.  If whatever you're doing doesn't work as you thought it would that first time it throws everything into doubt.  Is there a flaw in what I did?  Does the component itself not work?  Did I forget to uncheck the "don't work" checkbox in settings?  The list goes on.  It's an awful feeling when this happens.  Best case scenario you're annoyed.  Worst case for me usually means I assume I'll be spending the next 4 hours of my life trying to get things working only to discover that whatever I'm trying to do is fundamentally broken, and will never be fixed, and everyone already knows about it.  Now this has never happened, but it's often how I've felt after the second or third attempt that doesn't work.

What does this have to do with checkboxes?  Relax, man, I'm getting there.

In this particular case, I spent the better part of at least an hour (probably more) trying to figure out why I couldn't ignore anything from version control in my classifieds project.  I'm using a new (to me) IDE that integrates with git (another technology relatively new to me).  I thought it might be prudent to leave the file with the database username and password out of version tracking.  Realistically, I'd say it's a low risk in this case, but I want to do things right.  So I make an ignore file for git, add that file name, and do a test push.  Oops, there's my settings file, sitting up on gitub.  Fortunately, I had the foresight to test this with a blank file.

I'm not in full despair at this point.  I need to research it a bit first, find out everything is set up correctly, yet it doesn't work.  Now the despair is starting to creep in.  After much testing and experimentation, I figure out gitignore will work if i add the file name to it BEFORE making the file.  So now I know something's wrong.  Chances are it's not with git, since the whole damn world seems to be using it just fine.  So it's either the IDE or some bug in the git integration.  Now I'm cursing the developers, their mothers, it gets ugly for a little while.  A bit more digging and experimentation soon reveals the true culprit:  ME!  When I first started on this project it would prompt me for every new file if I wanted to add it to git, with a checkbox to remember that decision.  Dumb ol' me thought "why wouldn't I want to add any new files to version control automatically?", so I clicked the checkbox and said yes.  I remembered that only AFTER finding the setting for how to handle new files.  I will gladly go back to being nagged to avoid something like this happening again.

What surprises me the most is that I almost never use those checkboxes.  I have no scientific proof of this, but I'm pretty sure something bad happens everytime one of those is used.  The important thing is that I ultimately have it working.  Gopod times, huh?


Classified Thoughts

I find myself stalled on what should be a fairly simple project, and I think the reason is I don't quite have the structure of everything where I want it.

Part of the problem is I don't want to do things "the wrong way".  Intellectually, I know there's a lot of wiggle room when it comes to the "right way", and for this project in particular speed is probably preferable to doing everything proper.

For example, my original plan called for having 2 contact fields in the ClassifiedAds class.  But I don't want to put that in the database.  I know that's a no-no, but my reasoning was that this will never be a huge public site where things like that can really cause trouble.  It's an informal classified ads page on our internal network.  But still, why not do it right?

Why not?  Because it's going to take a lot longer to write everything to support a variable number of contact fields,  It also makes the form a little more complicated, and if I want it to look and behave nicely, I'll need to incorporate javascript to dynamically add the extra fields as they're needed.

My brain keeps telling me that this is unnecessary, but my gut keeps saying to do it right.  My gut is bigger than my head (by quite a margin), so I'm going to stick with doing things correctly for the moment.  Or at least as correctly as I can with the knowledge and skill that I have.

I'm working on the database at the moment.  I know what tables I want and how they'll all fit together, the issue right now is getting comfortable with using MySql again.  Thankfully XAMPP comes with phpmyAdmin, which makes things so much easier. I enjoy the command line as much as the next guy (maybe more), but I figure this isn't the time or place.  Maybe next project.


New Project

Just a quick one to mention that I'm working on a new project.  It's a simple classifieds page for work.  Someone had the idea to have an internal classifieds page a few years ago, and at the time I volunteered to make and maintain it (mostly because no one else knew how).  This thing has become the bane of my existence.  

"I am Rich's reckoning"

The code is simple enough to write, but it's just time consuming.  Everyone has different ideas about how their ad should read, so it often requires some editing to make them fit the template I use.  Even then they're different enough that I can't even make a decent macro for most of the code.  Correction, I probably could, but it doesn't seem worth the time.  They're infrequent enough that it always seems a better use of my time to just handcode it and be done than to make something to fix it.

I know this is mostly griping, but it's why I wanted to make something that could automate as much of this as possible.  The first round is going to be a simple page to show the ads, and an admin page to manage them, including a form for adding and editing ads.  Eventually I would like to add a built-in resizing feature.  I'm making this a longer term goal because while I'm confident it can be done, I don't know how to do it yet or how much research it may require.  I want to get this thing done and deployed quickly, and I know I can teach someone to resize the images.  Here's the link on Github