May 31

How to be a Professional PHP Developer

A more apt title might be, “How Not To Suck At PHP”… but I digress.

php-developer

Want to know how to be a good PHP developer?  The secret to being good at PHP, and programming in general, is to know what you’re doing.  Seriously.

DISCLAIMER: If you think this song… er… blog is about you, you’re wrong.  I learned all these lessons the hard way.

Without further ado, here’s the list.  Feel free to skim.

#1: Learn HTML

You need to understand the heart of this markup language before you can write something that writes it.  That’s right, PHP writes HTML.  Whoa.

Part of this involves CSS and Javascript.  Maybe you don’t think it does, but it does.  Unless you’re trying to make one of those pages from the 1990’s.

#2: Don’t Repeat Yourself

D.R.Y. is a pretty powerful concept.  Writing the same thing over and over again is terrible.  “Didn’t I just fix this yesterday?”  It’s the stuff bugs come from.

Write stuff that’s reusable.  Or find frameworks that do it for you already.  Don’t copy & paste things!

#3: Avoid Spaghetti Code

Are you writing inline PHP?  You know.  Html, some code, some more html, with a little more code, interspersed with html and code.

If your IDE can’t figure out where one tag ends and another begins, you’ve got spaghetti code.  And if you think Dreamweaver is an IDE… just back away.  Slowly.  Or quickly, if I’m holding a spoon.

Reading elegant code is awesome.  Writing elegant code is even better.

#4: Use Version Control

“But I’m the only developer, I don’t need version control.”

Bullshit.  If you think you’re never going to have help, this is the sure-fire way to turn that into a self-fulfilling prophecy.  Lacking version control pretty much guarantees it.

Have you ever looked at a website (or maybe they/you called it an “app”) and wondered why there’s all those backup files?  And renamed folders?  And scripts that forcefully exit immediately?  Yep, I guarantee there wasn’t any sort of version control.

“Did you overwrite my file?  Oh man… do you have a backup?”

If you have version control, you wouldn’t have to deal with that.

#5: Separate Those Concerns

This kinda goes with #3: don’t mix HTML and PHP.  It’s gross.

HTML goes into a template.  PHP goes into a script.  Functions are there to be reused.  Classes hold business logic, and do the brunt of the work, including ALL of the database stuff (if you have SQL in your scripts… shame on you).

#6: Learn Context

Understand relative and absolute paths.  Your website/application should work even if the location on the server changes.

Variables can overwrite themselves if you don’t pay attention to scope.  Or they might not, for the exact same reason.

#7: Understand The Bits

Databases.  CSS.  Javascript.  AJAX.  File descriptors.  Paths in Linux (and how they work in Windows, I suppose).  Code dependencies, and how to use cool things like JQuery and Composer.  Protocols like HTTP.

A real web developer knows all these things.  They don’t use the “I’m not a _____!” excuse.

#8: Listen

If there’s somebody willing to explain stuff to you, listen to them.  Especially if they’re more experienced than you are, but even if they’re not: everyone knows different stuff, so even less-experienced people will occassionally show you something new.

Allowing them to explain things helps both: the best way to learn something isn’t to do it, but to teach it.  That’s right, a lot of teachers (at least the good ones) are learning more every time they teach.

Conclusion

Try to understand what you’re doing and why.  Ask questions.  Don’t be so afraid of being wrong, be afraid of creating unmaintainable garbage.

Category: Code, PHP, Rant, Software Development | Comments Off on How to be a Professional PHP Developer
April 26

Local Development, Made Easier

I finally have some local development going again after getting a new laptop.  Hooray!

With a new environment comes the opportunity for change.  Like setting up “wildcard subdomains” using dnsmasqnginx, and php.

I mostly followed the SitePoint tutorial.  It’s really nice to not have to create a pile of configuration files that differ only in the path.

As a side note, Heroku looks to be pretty amazing, theoretically.

UPDATE: so it seems like DNSMasq isn’t doing what I thought it was doing.  Like, at all.  This ICANN article explains why anything.dev always resolves to 127.0.53.53.

UPDATE2: Okay, so it looks like there was some local DNS caching, or something.  DNSMasq works just fine.  Hooray!

Category: Code, Living With Linux, Nginx, PHP, Software Development | Comments Off on Local Development, Made Easier
October 26

The Truth About Family

There’s two kinds of family. There’s the kind that you’re forced into at birth, and there’s the kind that forms out of close relationships.

Some people think that “real family” somehow are more important than anyone else. They believe that the family you’re bonded to through DNA–your blood relatives–should be held in the highest regard, forsaking everyone for them.

Sometimes blood relatives have a strange sense of entitlement.  They think that because DNA connects you, that somehow they’re automatically more privileged.  They deserve more from you, and should be given more slack.  That they automatically have a place in your inner circle.

But here’s the truth, at least the way I see it.

The family that has formed around you are sometimes more important.  They don’t have the same sense of entitlement: in order to get into your inner circle, they had to prove themselves.  They fought for you.  Bled for you.

So who is more important?  Hmm.

Category: Rant | Comments Off on The Truth About Family
October 5

Fixing Pidgin’s Missing System Tray in Linux+Cinnamon

I love using Pidgin for… well, pretty much all my IM’ing needs.  And I’ve come to depend on the little icon in the system tray to show me what’s going on.

For a long time, though, the icon has only sporadically worked.  To “fix” it, I killed & restarted it a bunch of times until the icon finally showed (or until I finally gave up).

Well, here’s the real fix, from an old post I found:

As root (or via sudo):

root@laptop:~$ cd /usr/share/pixmaps/pidgin/tray/hicolor/
root@laptop:/usr/share/pixmaps/pidgin/tray/hicolor$ mv 16x16/ _OLD_16x16
root@laptop:/usr/share/pixmaps/pidgin/tray/hicolor$ ln -s 22x22 16x16
root@laptop:/usr/share/pixmaps/pidgin/tray/hicolor$

Boom.

UPDATE [October 6th, 2015]: Halt the presses.  This doesn’t seem to work all the time, at least not on an alternative machine… I should have known not to publish based on a single success.

Category: Living With Linux | Comments Off on Fixing Pidgin’s Missing System Tray in Linux+Cinnamon
September 30

How I Got Here…

I posted something on Facebook the other day, with a couple of pictures (last year vs this year) and a brief statement that I’d gone from 324 lbs to 287 (37 pounds lost). A co-worker asked me how I’d done it, and I gave a short answer… which later I realized was far too short.

So what has changed?  What did I do to get here?

That’s a good question.  And there’s a lot to think about, and I probably won’t give credit where it’s due, but I’ll try.

First, I drew my line in the sand.  I was in the fight of my life, for my life, a fight just to survive.  My health was spiraling out of control, and I needed to do something, not just plan and think, but DO something.

I started going to the gym.  I got a membership at the YMCA, went there with a buddy (thanks, Prophet), and put my nose to the grindstone.

I logged every trip to the gym, with very few exceptions.  The only way you can see change is if you track it.

I started seeing some changes, added some muscle and lost some weight…. but I needed more.

I added racquetball to the mix, because it was fun and got me moving.  Even though Prophet (and later my son) kicked the snot out of me, I had fun.

I learned to sweat, and to enjoy sweating.  I learned that it was okay to huff and puff, to have to stop to catch my breath, because that pounding in my chest was my heart telling me I was still alive.

Nerd Fitness - Join the Rebellion
Nerd Fitness – Join the Rebellion

I found this awesome website jam-packed with information, called Nerd Fitness.  No pushy sales, no need to buy anything to get help.  It actually took me a while to figure out what there was to buy.

I started investing in my health: I gave up going out to eat every morning so I could afford a gym membership.  I asked for–and received–a membership to the “Nerd Fitness Academy”, a one-time fee that’s turned into the best investment I’ve made.

Logging stuff was a huge thing, so I finally took an interest in an awesome little app called My Fitness Pal.  I used it to track food intake, and to track carbohydrates, so I knew how much insulin to take.  Insulin and blood sugar levels have all been logged religiously in a cool little app called OnTrack by Medivo.

gallery_5603_173_202964 gallery_5603_173_125417

The graphs above show what tracking progress really means.  The one on the left has all the individual readings, while the one on the right uses daily averages.  They cover slightly different time frames, but that little gap–the funny little line between October & January–is when I started caring.  When things started turning around.  That was the end of 2013, into the beginning of 2014.

 

I started walking more.  I embraced the Walk to Mordor challenge, going so far as to start work on my own app to track it (yeah, it’s still in the works).

When my knees started giving me problems from walking too much (especially with stairs), I got myself a bike.  When I started, I could barely get around the block… now I feel like I’m slacking if I only get 15 miles a week.  I only feel really accomplished when I hit the 4 mile mark on a single ride, though I generally limit myself to an hour a night.

So that’s what I’ve got so far.

It wasn’t a simple thing.  It wasn’t some crash diet.  No “juicing” or 90-day crash diets.

I hope you enjoyed reading about it.  Feel free to ask questions or whatever in the comments below.

Category: Health, Rant | Comments Off on How I Got Here…
September 16

So Far Behind…

I think I’ve over-committed myself.

It’s not abnormal for me to be lagging behind updates by a day or two.  I don’t check social media on my phone–Facebook Messenger slipped through the cracks, but it hasn’t gone off more than once every few weeks–so I usually don’t know if Stan Lee posted something about me (yeah right) or if there’s some crazy new Mime-related humor.

I’m having a hard time keeping up on the things that matter.  Coding projects.  Paying attention to my wife.  Beating the kids on a regular basis.  Keeping bills in line.

Bear with me.  I’m going to spend some time re-organizing things over the coming days and weeks, hopefully to get a better line on the top priorities.  I’d like to get Project Hobbit Walk to a better place.  I’ve got doodles to upload to Deviant Art.  I’ve got pictures to force upon the world (or at least my friends).  And TTORP needs to get to a better place (the website blows).

TL;DR:  Stay tuned.

Category: Uncategorized | Comments Off on So Far Behind…
September 1

Spaghetti Code

That’s right, there’s an actual, honest-to-goodness technical term called “Spaghetti Code.”  Basically, it’s code that’s all tangled up in itself, not elegant at all.  It does not look or smell tasty… imagine the worst experience you’ve had with that stuff they served back in school.  You know, with the green “meat.”

I avoid that shit like crazy.

I’ve written some of that shit.  Somebody smarter than me once said, “in order to make good choices, you must first have made plenty of bad ones.”  And I’ve made plenty of those.

In fact, since I have so much code that’s open source, pretty much all my mistakes are out there for people to see.

Anyway, down to the point.  As a programmer, every time you build something with spaghetti code, or in some way that is ugly and difficult to maintain, you acrue technical debt.  And that adds up FAST.

So, for PHP, you should separate code from HTML–you can use a Templating engine to do that.  Or a framework like CS-Content, or CakePHP, or a myriad of others.  Test on different servers, different versions of PHP, and/or do the continuous integration thing.

Category: Uncategorized | Comments Off on Spaghetti Code
August 21

Hobbit Walk: Tests are Passing

A quick update on the Project Hobbit Walk status.

I’m in the midst of a fairly large code refactoring–which basically means that I’m changing some of the code and cleaning it up.  A lot of the changes are done so that I can get unit testing done, including some automated testing.

The idea is that, whenever I make a change to the code, there will be an automated process happening that ensures nothing broke.

The major part of that is done.  I’ve still got some updating to do, but a major milestone is out of the way.

Category: Code, Hobbit Walk, PHP, Software Development | Comments Off on Hobbit Walk: Tests are Passing
August 18

Solving the Puzzle

Sometimes a puzzle presents itself to you. Sometimes you’re aware of the puzzle, of it’s nature, and sometimes you just have this little… thing, this irritating little itch that you can’t seem to scratch.

Solving the puzzle can be straightforward.  The answer comes to you in a moment, in a flash of brilliance–or common sense–and then you move on.  But then there are those puzzles that take longer.  Hours.  Days.  Weeks.  Months.  Even years.

“What the hell are you talking about?”

I solved one of those puzzles.  It was a puzzle I’d been working on for years, one that I was only casually aware of, but it was really digging at my (crazed)sanity.

This particular puzzle was one whose nature was in programming.

“I’m not a programmer.  This is gonna suck.”

I won’t get into the details; hell, that would bore the crap out of me.  And I’m the one that’s excited about it.

With programming puzzles, you’re almost never sure if it’s truly complete.  With a real puzzle, you’re told straight out of the box that there’s 250 pieces and it’s 15″ x 15″.  With programming, it might be five pieces, and be 50′ x 50′.  Or it could be 50,000 pieces, but only be a few inches wide and a few feet long… it’s just impossible to know.  And when you get to a point where you think, “gosh, I think it’s done,” you realize there’s a whole bunch more pieces that suddenly showed up.

And the other thing is, sometimes there are pieces of the puzzle that you don’t even realize are pieces.  You hold onto this little bit of information, because you know it’s important, but it just doesn’t seem to have correlation… until all of a sudden, you go, “holy crap, this thing here hooks onto this other thing…”

Yep.  It’s like that.

Category: Code, Living With Linux, PHP, Rant, Software Development | Comments Off on Solving the Puzzle
June 12

Mechanics and Painters, Programmers and Designers

Have you ever gone to your car mechanic and thought, “hey, Mike here is good with cars.  He can probably paint my car a different color and save me a boatload of money!”

Probably not.  And we both know why: it’s stupid.  And if another mechanic hears this question, they’ll laugh at you until you leave in embarrassment.

Your mechanic fixes your car.  He replaces parts in the engine when there’s something faulty.  Replaces fluids when they’re low.  Maybe even changes some parts out for you, if you’re lucky.

But your mechanic is not a painter.  Sure, Mike can weild a can of spray paint and cover a surface with it until it has become another color.  But you’re going to regret those couple of bucks you saved when you notice the drops of paint all over your windshield and seats.

This scenario is akin to asking a programmer to design/create a pretty webpage.

Them: “Can you make this webpage look like this image that our designer created in Photoshop?”

Me: “Uh… sure, probably.  I’m not very good at that sort of thing, though.  I’m probably going to need some help from your designer.”

Them: “Awesome!”

(days go by)

Them: “Have you completed that webpage yet?”

Me: “Uh, mostly.  It isn’t pretty, but I’m sure the designer could finish it off.”

Them: “Holy shit!  That page looks like somebody threw a firecracker into a dictionary and then shot it with paintball guns to put out the fire!”

If you happen to get a nice product, it will probably only look nice if you cross your eyes and unfocus them… and maybe point your head at something else entirely.  In most instances, mechanics are not also painters; just as programmers are generally not also designers.

If you manage to find a programmer that is also legitimately good at design, AND still legitimately good at programming, keep ’em on speed dial.

Author’s Note: my current workplace has actually done a fair bit to show this mechanic how to do a good job of painting.  This isn’t back-pedaling: it’s a shout-out to the awesomeness which it is.  I’m not even sure what to refer to it as… how can something so fun be called “work”?

Category: Code, Rant, Software Development | Comments Off on Mechanics and Painters, Programmers and Designers