Entries in Programming (5)


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


Some Updates

Nothing too long-winded today.  The pants arrived safe and sound.  They fit and look work-appropriate enough, so this story had a happy ending.

The backup tracking app continues to plod along.  Currently one can view a table of backups, a table of hard drives used for backups, can add new hard drives, modify existing drives (not sure there's a lot of need for that, come to think of it), and add new backups.  Still need to add a page for modifying existing backups, and a way to delete entries.

I showed my wife the progress I had made a few days ago.  She did the best she could, but it's hard to get excited over something so simple as this tracking app.  I don't generally get any real feeling of accomplishment when I do things.  Usually the closest I get is relief that a particular task is over and I can move on to something else.  But this is different, somehow.  When I figure out a solution to a coding problem it's a genuine rush, if only for a moment.  It sucks that there's no way to convey that feeling when looking at the finished product.  She can't see the two hours of research, experimentation, and testing, she just sees a dropdown list that pre-selects the right entry when you hit Edit on the hard drive table.

I'm starting to update other areas of this site, slowly but surely.  Added a link to my Github profile.  I've updated LinkedIn and Google+, though I don't think they're linked here yet.  I still can't really bring myself to use all these social networking sites properly.  I think I just missed being part of the generation that cares about this stuff.  It's more than just the feeling of "who cares", it's the time.  Seems like there's precious little time to go around these days, and proper social networking seems like it would be a time sink.

Speaking of time sinks, Titanfall comes out on Tuesday.  I had a chance to play the demo a few weeks ago when they were stress-testing their servers, and I'm looking forward to getting my hands on the full thing. The link up there is to the ridiculous Collector's Edition, which clocks in at $250.  They're also selling "Professional Quality" branded headsets for $150, and even have Titanfall Xbox One console bundles.  This all seemed highly unusual for a new franchise until I did a little research and found this was being done by some of the original Call of Duty guys.  Some of the gameplay elements address some of the problems I have with these big multi-player shooters, plus it's got big-ass robots, so I'm in.  I'm sure I'll explore that in greater length in a future post.  This one has already gone on way longer than I intended.  Until next time!



Partial Pages in ASP

I wrote some code. Imagine that! If someone were familiar with this backup tracker project, but not with me or my family, it would appear that I started testing out partial pages, then fled in terror for 3 months. Not true! While the specific implementation of partial pages in ASP.NET is new to me, I understand the benefits.

The basic idea is to write a piece of a page that you can use multiple times in other pages. In this particular case, that's a form. Whether you want to add a backup/harddrive, modify an existing entry, or delete one, you need some kind of interface for entering that data. If you want to add a new entry, the form is blank. If you want to modify an entry, you pre-populate the form fields with the data about the harddrive or backup and allow the user to edit some or all the fields. If you want to delete, you pre-populate the form, restrict the ability to edit, and make it super-duper clear that you're deleting something. Partial pages lets you write the big chunk of that page -the form- once and use it in different contexts by inserting it in other pages.

This was a new way of thinking about this problem for me. I'm mostly self-taught, and I started with PHP. When I needed to do add/edit/delete forms for a project in PHP, it took a while to figure out how to do it. My first thought was to just write 3 pages, but I rejected that idea almost immediately. Copying code like that is a bad idea. What if the form has to change? What if something with the database changes? What if someone else has to change something, and doesn't know to change the other two?

So the next thing I thought of was to do all of them as a single page. This seems like a good idea until you try to do it. The hard part isn't really writing the code, it's trying to understand it later. Now I'll admit that I probably didn't hit upon the best way to do this particular idea, so maybe there are ways to do it that are easier to manage or make more sense. My pages were a mess. The problem is you need to account for 3 different complex tasks, all while trying to use the least possible amount of code. You want the add/edit/delete options to use the same form or you run into the problem of having 3 completely separate pages. The solution is to use variables in the form, and account for them in the code blocks for the 3 specific options.

So what I did was split the page into 3 parts. The first part was Setup, where there was some code to figure out what you want to do, and prepare the correct data for that option. If you wanted to add an entry, it would use blank variables so the form would be empty. If you wanted to edit it, then it would get the info from the database and put it in the variables to pre-populate the forms. The delete would do the same as modify, but also add a little piece to the form that made the fields uneditable. This section would also define the instructional text above the form, change the title of the page, etc.

The second part was the actual page. This was mostly variables, since the title should be different for each, and instructions. This is where the actual form code was written, but it was almost unreadable because of all the jumping in and out of PHP code, or using echo or HEREDOC statements to build the forms.

The third part was the Results section. This is where it would attempt to validate the data, and perform the final database option of adding, editing, or deleting, and display the results. Sometimes this section was bigger than the other two combined if a lot of work had to be done on the data before interacting with the database.

To make things more complicated, I usually did forms on a single page and split them up by how they interacted with the server. This is get and post. When you first request a page, you use GET to retrieve it from the server. When you're submitting data, you're using POST. So if the server got a GET request for the page, it would display the form. If it was POST, it would execute the form processing steps and then add it to the database. This meant my 3 part page was further split into 2 sections, with the Setup and Form parts in the GET section, and the Results part in the POST section.

The end result was a huge, complicated, almost unreadable page that worked, but god forbid I ever need to modify anything in it. It's ridiculous, I would be afraid to change anything because it was so hard to see what the results of that change would be. Would I break another part? How would I ever find that part again if it did break? What a mess!

Now using partial pages doesn't completely negate all that, but it does make it easier to manage. That changes the actual form from taking up easily 40+ lines for a simple form to a single line of code to render that as a partial page. This makes using separate pages for each action far more attractive. You still run into the problem of adjusting for a database change, but changing the form is simple. It's also easier to keep track of what you're doing when you don't have that big chunk of form code sitting in the middle of your work. It makes all the code (except the one line) for those pages only about the task of that page. It was also pointed out to me today that there are other options for doing the delete that don't require the form, so that makes things even easier.

Now the only trick is actually writing it. I'll report back on that later.


C#, ASP.NET, and Other Stuff. Mostly Other Stuff

I haven't written anything in a while.  Not intentionally, I just find that this blog is the first thing to go when I get busy with other things.  I also need to address something that I feel is weird. It involves the nature of this blog. I don't know if it's generational, or a personality thing, but I just have trouble with social networks.  Anytime I think about starting to use one, I can't help but ask "Who cares?"  To which I never have a satisfactory answer.  I don't own a business or have some cause that I'm promoting, and while I happen to think that I'm endlessly amusing, I'm also self-aware enough to know that very few (if any) share that opinion.  I have other ways to keep in touch with people I care about, so I can never muster a good reason to get involved with any of the networks beyond lurking.  But I know that anyone in a technology field looks like a weirdo without some kind of online presence, so I got this website.  I don't know why, but writing on here feels different.  I think it's because people have to seek it out.  Moving on, the weird thing that I referenced earlier is that anyone who is likely to read this is already very familiar with what's going on.  I guess I should approach this without an audience in mind, but I don't quite know how to do that.
So here's what's been going on during the writing break.  I have decided to become serious about programming, and have started down a path that will hopefully lead to a new career.  I've been flirting with this idea for years.  I got a Java programming book when I was in college, but never really had time for it.  Then I got into PHP after college, and started working on web apps that I would eventually deploy at work.  I can't remember how much of this I've talked about before, but I do IT support in Seattle, and there are many day-to-day tasks that I do manually that could be transitioned to a database with a web front-end.  So that was where I started.  I did all the work at home, and I thought I would write about my progress.  Now maybe this is just me being shy, or part of that "who cares" reaction I have to social networking, but I didn't really tell anyone about this.  My wife didn't even know I had started writing on here again.  After months and months of inactivity, I can't blame her for not checking.  Somewhere during this time, though, my sister found the blog and was probably horrified that her sweet, darling little brother had turned into a degenerate who rants about video games, scotch, and amateur web development.
Somewhere in the process, my sister tells me that her husband, Adam, would be willing to show me the ropes.  This is where talking about this stuff gets weird.  I knew Adam was a software developer from way back when we were all still living in NY and I was a smartass teenager needling both of them over any little thing, but it had never occurred to me to reach out about this.  I think part of it was because I wasn't 100% sure at that point if I really wanted to take programming past the hobby level.  The offer to teach me really made me start thinking more seriously about what I wanted to do.  I didn't want to waste Adam's time by jumping in and then deciding 3 months later that I didn't actually want to do this. So I decided that if I could make something reasonably complex (for my skill level at the time) and actually finish it, then I would take him up on it.  I know myself, and I know that I'm real good at planning and starting, but I tend to lose steam near the end.
The surgery tracker that I've written about in the past was borne from that test.  It's kind of crazy to look back at that, even as recently as I made it, and see how much I've changed.  There is some rough, ugly code in there.  That was written with PHP and first MySQL, then adapted for MS SQL Server.  One of the first things Adam did was introduce me to C#, and shortly after that ASP.NET.  My familiarity with object oriented languages was largely theoretical at that point, so it's been slow going, but I'm making progress.  Some of the other major changes that have come from this was Adam dragging me into modern day web programming practices.  Stuff like Github and Bootstrap, and using an actual IDE to write code in (I still love you Notepad++).  I learned HTML and CSS during the time (or from a book written during the time) somewhere between the utter chaos of early HTML, where tables and iframes reined supreme, but before the div tag became the standard structural element of all web pages.  I remember the book stressed the importance of separating the structure of the page from the appearance of the page, but it didn't really offer any suggestions on good ways to do that.  Just being exposed to some of these things has helped me tremendously.
Currently, I'm working on a tracker for hard drive based backups that I'll use at some point at work.  I'll write more about that at a later date.  I'm still getting used to ASP.NET, but I'm making progress.  Well, I haven't made much progress lately.  At work they decided to renovate the biggest clinic over the course of 2 months, and I'm playing Christmas elf at home.  We're having my wife's brothers up for Christmas, and it's the first time at least 2, if not all 3, have seen the house, so we want to make it special.  I'll take some pics and put them up here somewhere when it's done.  We keep adding or changing things, so it's a work in progress.  Isn't everything?

Hello World!

That feels like a suitably nerdy title for the first post on my first website.  That whole hello world as the first program that one writes when learning a new language seemed a little weird to me.  Is it just superstition, or is it that all the programming books teach that in the first chapter?  I took an introduction to Visual Basic course, and that was the first program taught in the book.  I think it'll be interesting to see if that holds true for other languages as I start to get deeper into programming.

It's strange to me to be writing something like this.  By nature, I'm basically a hermit.  I don't like crowds, I try to cover up whatever I'm doing if I think it might lead to a conversation that could be weird or awkward, I really just try to blend in.  It's bizarre to think that I'm going to write something that anyone could see, and just stick it out on the internet.  It's a little hard not to feel egomaniacal at the thought that anyone would be interested in this.

My goal in doing this is to help establish myself online, since it looks like this whole internet thing isn't going away.  Since I'm interested in pursuing a career in technology, I should probably embrace it.  It seems like it's getting to the point where not having an online presence will be perceived with the same instant confusion and distrust as someone who never drinks who isn't a recovering alcoholic.  Who knows, having a place to vent may even be healthy.  I'm sure my wife will appreciate it, because up until now, she's been the sole audience for my rants and pontifications on subjects I know she doesn't care about.

I'm really hoping that I have the hutzpah to stick with this.  It would be nice if people found this and read it, but I think it has a real value to me even if they don't.  It'll be interesting to see how this evolves as I get into it.  I think that's enough for now.  Until next time, world.