General Programming Practices
When I learned to program in the 1980's, It was in BASIC, and everything was sequential (unless you used goto) and procedural. I don't even think it had functions. Later versions of BASIC at least had GOSUB/RETURN, but still, you were pretty much stuck with this mindset. Add to this that for 10 years or more I did very little programming, and the programming world left me in the dust.
I've been coding in PHP for a few years now. PHP is at it's root a procedural language, but it has some Object capabilities. I am beginning to learn them but my mindset is still procedural. How have you (that's the general "you" as in "you-all") made the mental jump from sequential/procedural mindset to the OOP mindset?
Do you write/use any OO code currently? Are you looking for an OOP tutorial? Or are you looking for some sort of rationale [or something] for using an OOP solution over a purely procedural one?
My mindset is this: I know what the keywords do, stop trying to confuse me.
Altair Basic for the 6800?
... things have changed. Just program in a way that's fun, there is no "best" (esp. not with PHP). If I use objects, it's only because its more fun than not. It processes so fast that no one cares how many extra MB of memory you consumed.
If you're loading BASIC from paper tape, be sure your serial I/O is strapped for 8 data bits and no parity bit.
Facebook and Google would probably disagree ...
Originally Posted by eval(BadCode)
I disagree with both of them on a lot more than just programming practices.
Originally Posted by svidgen
They saved quite a few bytes by cutting back on privacy.
Last edited by eval(BadCode); 12-23-2010 at 01:12 PM.
In the normal case you're [almost] absolutely right: performance and scalability are negligible items, provided that you're not doing something that performs in exponential time or something.
Originally Posted by eval(BadCode)
If you're looking to keep your clients (or your job) when your sites get slashdotted or dugg, you'd better have efficiency and scalability in mind. And no matter what, you ought to have "best practice" in mind. If you've been told otherwise, you've been misinformed.
I doubt anyone could maintain their employment at a long-standing highly trafficked site without attention to best practice. Amazon, Facebook, Yahoo, Google, LinkedIn, etc. ... they don't hire PhD's to let their subordinates "do what feels right." They could hire kindergarteners for that.
But again. For most websites, you can certainly be a little careless and it won't cost you a thing. (other than the ability to more effortlessly produce the "best" solution.)
To attach an anecdote to my above response, when I started working in my current position, I was effectively hired to evaluate an outside firm's code. They were charging a hella lotta money to outsource the code to Russians. And the solutions were actually fairly fancy looking on the front end. But, the code was a mess, and it wasn't built to scale well.
I told them that we'd have to abandon the code at some point because it would break (not scale). And break, it did.
After the first 3 or 4 thousand orders were in the system, reports were no longer runnable, and AJAX requests were useless -- not because they were doing anything horrible uncommon. But, it wasn't "best." And, the tragedy is that the "best" alternatives wouldn't have been all that difficult had they been worked into the foundation from the start. They were simply unconcerned with what was "best" ... we lost money paying for bad code. And they lost us as a client.
If you ever want to get a "real" programming job where you will be part of a team, you better learn OOP whether you personally like it or not, as that will 99% likely be required to get the job. If you are programming for personal hobby enjoyment or are a 1-person "team" doing freelance work, it may not be required -- but why not learn it anyway and find out what you're missing?
The thing is, though, that just learning OOP syntax is not enough. You need to really get a decent handle on the underlying concepts and rationales for it. This may mean reading some books and/or taking some classes -- watching a couple web videos and reading a short on-line tutorial probably will not cut the mustard. Without that understanding, you'll likely end up writing what is essentially just procedural code wrapped up in some classes.
One resource I found particularly enlightening was PHP 5 Objects, Patterns, and Practice by Matt Zandstra. A caveat is that I had been working at learning OOP for some time before reading that book, so I cannot say that by itself it may be all you need to ignite the light bulb, but in my case it really helped me "get it".
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Agreed w/ nogdog. Though, that's not to say OOP is always the "best" choice. There are notable folks out there who claim the OO foundations inhibit good coders from writing "excellent" code to accommodate the average programmers whom we need to protect ourselves from
Also, there's usually additional overhead in using objects versus structures, methods, and ideally conditionals and loops in place of either. (ideal from a performance standpoint, not from a code readability standpoint)
My first CS professor made it very clear though: "best" is subjective. "Best" is defined by your (your boss/company/client's) goals. For small scale sites, the "best" code is the code that is most readable -- follows common conventions. For larger scale sites (or sites that intend to be large), "best" is most (or more) efficient and scales well.
My monkey avatar still doesn't work. I tried saving the file as gif, jpg, bmp, and png.
Once you get it fixed up we'll have a monkey war.
Profile image not saved.
Icon not saved.
Then I'll get the book NogDog is talking about.
lol ... yeah, I created a "Test Monkey" to see about the icon uploading issue. Permission issue that occurred after I migrated to a new VPS. Of course, there's also a cron job that's supposed to run nightly to distribute coconuts and bananas and degrade ferocity and agility -- pretty sure that's not running either.
Originally Posted by eval(BadCode)
And there are actually 100-some "expired" users in the database ... I'll fix the permission issue, because it's simple enough to do ... but, the monkey war is sort of dead until I can get it rewritten. I really don't have time to add features to it -- so I want to rewrite it with really stripped down, core features that won't require any maintenance or explanation ...
ADDENDUM: it's also notable that I never put version numbers on the images -- they just use user ID's ... so if you upload a new image, browser might not notice right away ...
Last edited by svidgen; 12-23-2010 at 02:42 PM.
I hope it helps me govern the spatial arrangement and orientation of PHP 5 objects in relation to patterns of yin and yang and the flow of energy.
Thanks for all the replies.
I work for a small web design company as the lead (basically only) web developer.
I may have mentioned that my only formal training was BASIC in junior high and AP computer science (PASCAL) in my junior year. I have some bad habits I picked up because, for example, I read early on that GET and POST variables were automatically available and that the short php tag works just fine. (I am getting over those in a hurry.)
Some of the answers went off into whether or not one SHOULD learn OOP. Let's go with the fact that I've already decided that I SHOULD, and now it's on to HOW. I think nogdog's suggestion of PHP 5 Objects, Patterns, and Practice by Matt Zandstra is probably where I need to look to next.
If you've already decided to learn OOP then I recommend you give the book a read. I'm not finished with it yet, but it's excellent to say the least.
I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)