Thread: PHP Refugees
View Single Post
Old 09-10-2012, 07:41 PM  
edgeprod
Permanently Gone
 
Industry Role:
Join Date: Mar 2004
Posts: 10,019
Quote:
Originally Posted by brentbacardi View Post
No offence but a lot of coders do have sticks stuck so far up their ass. Just because code may be sloppy as fuck and far from elegant doesn't mean it sucks!
You're narrowly right, and widely wrong. When I'm doing rapid prototying (typically, with a client in an ICQ window waiting to see, or otherwise interactively), I only bother to indent. And I probably only indent because NOT doing so would take my brain LONGER at this point.

Once something moves beyond the prototype stage, however -- for example, if it even thinks about touching a production environment -- you'd better believe that it's done in Model/View/Controller style, and it's done right. Anything else would not only be irresponsible, it'd be borderline fraud when it comes to "work for hire," or anything you'd be selling.

I've committed the sin of sloppiness earlier in my career, but not learning from it would speak more about me as a person than me as a coder.

I think the "stick up the ass" grows over time, and is the result of people saying "close enough is good enough" and then guys like raymor, isteve, and myself having to clean up after them. It just grates on you after enough time.

It's actually to the point where if someone documents their code excessively, I look at them as a novice. See the "sample of my code" example on my blog for a great illustration of too much documentation, and sloppy code. It was written years ago, and I've evolved as a professional and as a programmer in the interim.

I'll give you an example: I'm working on some software right now to retrieve entries from a database. On the index page, I only need 8 pieces of data, so I query that specific data. The programmers we look down our noses at (or, I guess, get sticks up our butt about) will typically suck down all of the data, parse it in PHP, and spit out what they need to the page. Not only is this wasteful, sloppy, and a potential security risk, but it doesn't handle scale (read: additional traffic), and can actually bog down everything else that shares the MySQL server.

Another example ... inside of a search for a single data point, this is my query:

Code:
$this->set('models', $this->Vehicle->find('all', array('conditions' => array('make' => $value),
                                                       'fields' => array('DISTINCT (model)'))));
All I'm returning to the $models[] array is the distinct column names for 'model' where 'make' matches the $value I have passed to the method. In PHP's "amateur-hour-friendly" structure, I could have just as easily queried ALL of the data, then grabbed ALL of the values for 'model', then used PHP to sort by 'make' key, and finally grabbed the array_unique() of the resulting array.

Instead, I'm using a very narrow query to populate an array with ONLY what I need. Then, after checking if the array exists, I can build a search field with HTML form options that includes a list of the various models.

When I'm finished with it, the query will also include an 'order' parameter to return the results in alphabetical order, instead of using asort(), or a similar language-level sort. This is what separates those of us that SHOULD be doing your projects from the bargain-basement "code hackers" who put in penny-wise pound-foolish bids on jobs.

Sorry for the rant, but I wanted to make sure you understood, and that you weren't misleading people into thinking that sloppy is somehow "okay" because the end user doesn't "see" the code. That's like saying your mechanic can do a shitty job on your breaks because you don't ever have to look at them.

Great thread, Brujah. To answer YOUR question: Python (duh!), Ruby, Ruby on Rails, and I've extended the life of PHP somewhat by moving to the CakePHP framework for development (it makes it a lot like Rails for me).
edgeprod is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote