SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 42
  1. #1
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    What wastes your time as a PHP'er?

    A little survey:
    As a PHP developer, what typically wastes your time? That is, what is stopping you writing features 100% of your day?

    To be a little more objective, and avoid the thread becoming a rant, there are three actual questions:

    1) What is the last non-feature thing you did? Could be right now, ten minutes ago or whatever. However small.

    2) What was the biggest hold up so far this week? Something where you were out of action for 2 hours plus. A bad rollout, difficult bug, training, working around a framework, figuring out how something poorly documented worked, a long meeting. Anything you want, but at least a couple of hours of delay. Name and shame dud libraries.

    3) What typically wases your time? You can rant on this one.

    Please answer all three before adding comments of your own (preferably in a separate follow on post). If you think too long about it, then you are probably getting too subjective. Try to add your reply before reading other peoples, as reading first will bias things.

    I'm going to compile them at the end of the thread. I'll add my answers later so as not to bias anything. I have a deeper discussion point to bring up, but I'll do that later.

    yours, Marcus

    Note to moderators: I'm after PHP answers here as I want to relate it to code later. Please don't move the thread out of the advanced PHP forum.
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2009
    Location
    Bristol
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) Evaluating 3rd party code for use in projects
    2) Lack of solid versioning/deployment process
    3) Feature creep from the client disrupting iterative development process. Important schedule hours dedicated to maintenance/testing/profiling replaced with introduction of hacks and last minute feature requests which then get cemented into the project.

  3. #3
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    1: Strangely familiar. How many pieces of 3rd party code are you evaluating and how many of those will you eventually use? What stops you making a rapid assessment?

    2: Rails/Ruby has Capistrano/Vlad/Rake. Does the PHP world need something similar?

    3: Log your time fixing stuff then moan about it somewhere. "I spent 2 hours fing XXX 'cos it broke yet again". Eventually 2 days of refactoring will seem cheap. It's a long haul though.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  4. #4
    SitePoint Addict webaddictz's Avatar
    Join Date
    Feb 2006
    Location
    Netherlands
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft View Post
    1) What is the last non-feature thing you did? Could be right now, ten minutes ago or whatever. However small.
    System documentation. Just finished, decided I should get a reward in the form of coffee and a read-up on Sitepoint. Before writing the documentation, I had a meeting with a customer to determine what should be in the next version of the application we've built (prioritizing). In the rest, today was about adding features.

    Quote Originally Posted by lastcraft View Post
    2) What was the biggest hold up so far this week? Something where you were out of action for 2 hours plus. A bad rollout, difficult bug, training, working around a framework, figuring out how something poorly documented worked, a long meeting. Anything you want, but at least a couple of hours of delay. Name and shame dud libraries.
    Todo-lists. Mondays are my set time to plan features, bug-fixes, and other related tasks, such as setting up the project's environment. Creating the todo list generally does take me a while, but it does give me the benefit of knowing where my team stands in every given project, and I know if I'm going to deliver the software on time.

    The second most time consuming non-coding activity has to be reading code. Although my current code seems to be pure logic to me now, the 5 years younger version of me wasn't that keen on writing documentation, doing proper normalisation, keeping code DRY and readable, refactoring or having decent and up to date specifications.

    I've learned a lot over the last five years, and the thing I've learned the hard way is that there is a huge difference between writing software and writing decent software, in terms of readability, but documentation just as well. I now wish I knew this five years ago.

    Quote Originally Posted by lastcraft View Post
    3) What typically wases your time? You can rant on this one.
    Phone calls, customers, co-workers, but mostly: me. I know, this all sounds very self-critic, but to be fair, it's me who usually busts out of the coding spree to do something else, just to crystallise my thoughts or to relax a little. You know, have some coffee, a smoke, a walk around the neighbourhood.

    More than 5% of my day is not spent on "pure coding", but doing things that aren't entirely related, such as reading blogs, and taking breaks. I don't necessarily think that is a bad thing though, quite the opposite. I think it helps me keep up with current developments and broadens my view on programming and problem-solving on a whole.

    It also helps me relax, which is also a very real requirement to write decent code, at least to me. If you're not relaxed enough (maybe even a little stressed), you'll feel pushed to write code. Just writing code without thinking about it ends up in tragic code that makes no sense, you might as well take a little time off and write decent code that does make sense. The overall cost will be lower in the future.

    That's not all though. Unexpected interruptions are extremely annoying and usually bust my coding-spree. If I take a little time for myself, I stop coding at a point where it makes sense: when feature X is tested, built, and documented. Customers, co-workers and telemarketers unfortunately don't have the gift of sensing whether or not I'm at a "save point" at that time, which means that once the nuisance is gone, I'll have to get back in the coding-spree, which takes a lot of time.

    I'll edit this post, probably, I might have to think this over a bit more. I'm interested to see what my fellow-PHP'ers have to say about this topic.
    Yes, I blog, too.

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft View Post
    1) What is the last non-feature thing you did? Could be right now, ten minutes ago or whatever. However small.
    I just finished salvaging some data from a log file that should have been sent to an external service. Since said external service fails randomly and gives very poor feedback, it's pretty much hit-and-miss. Luckily I was foreseeing enough to log each call.

    Quote Originally Posted by lastcraft View Post
    2) What was the biggest hold up so far this week? Something where you were out of action for 2 hours plus. A bad rollout, difficult bug, training, working around a framework, figuring out how something poorly documented worked, a long meeting. Anything you want, but at least a couple of hours of delay. Name and shame dud libraries.
    Waiting for external service provider to implement and roll-out a couple of extra fields for a data structure. Then asking him to fix it so it conforms to the specification. Which should be simple, as JSON is fairly bare-bones.

    Quote Originally Posted by lastcraft View Post
    3) What typically wases your time? You can rant on this one.
    Agreeing with people about who does what and what exactly we're trying to accomplish. So, in short - People.

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2009
    Location
    Bristol
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft View Post
    1: Strangely familiar. How many pieces of 3rd party code are you evaluating and how many of those will you eventually use? What stops you making a rapid assessment?
    Checking out various PHP Orm tools, suffers from same syndrome as "make a blog in 5 minutes" syndrome - the examples designed to give an overview of the capabilities each Orm's capability rarely provide the necessary insight into the implications of utilising the proprietors solution. Been looking at Redbean, PhpDataMapper, Outlet and CoughPHP. They all have really interesting features - but I've noticed a lack of an Identity Map (or have failed to find how they implement it).
    Quote Originally Posted by lastcraft View Post
    Rails/Ruby has Capistrano/Vlad/Rake. Does the PHP world need something similar?

    3: Log your time fixing stuff then moan about it somewhere. "I spent 2 hours fing XXX 'cos it broke yet again". Eventually 2 days of refactoring will seem cheap. It's a long haul though.
    Company is in a transition phase, working on increasingly complex and development heavy projects - current paradigm not evolved enough to cater for common/contemporary development practices. Problem 2 and 3 kind of related.

  7. #7
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    989
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    1) Refactoring our "page template" class (though I kept it backwards compatible ) and how it interracts with the controller for the current request.The code was about 3 years old and had grown horribly because it wasn't flexible enough. Still missing a few minor features but the code base is now about a fifth of the previous size and much easier to understand. It now initiates a proper MVC stack rather than trying to do everything in one class. Was something on my to-do list for quite a while. Finally had some spare time.


    2) Well this is entirely non-php related but required my expertise (nobody else would have any idea how to do it ), luckly I don't have an awful lot of work at the moment. Our designers use a NAS drive to store all their library images, psds, illustrator files and whatever is they work with over the weekend we had a power cut which killed the motherboard on it. I ended up taking it apart and plugging the drive into a pc only to find out it was using the XFS file system. Our only linux box is a fairly old machine we use as a development server, it doesn't have SATA. I ended up downloading knoppix, plugging the drive into another PC and sorting it out that way. Fun stuff! Now they have a UPS and a RAID1 NAS


    3) This might need context: I work in a very small team whos work mainly consists of many small-medium sized sites. Some of these were developed years ago (the company has been going 15 years and we have a few sites around that age) by people who no longer work here (and left before I started!). Many of these sites use some rather horrible bespoke frameworks that I despise working on. There's no documentation, of course, and I'm constantly left wondering whether any thought at all went into them. Funnily enough, some of the newer ones (~2006+) are the biggest causes of my frustration. I mentally mark them down every time I have to use print_r(get_included_files()); or debug_print_backtrace(); to work out where something is happening.

  8. #8
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by webaddictz View Post
    ... there is a huge difference between writing software and writing decent software, in terms of readability, but documentation just as well. I now wish I knew this five years ago.
    What concrete differences are there? If you look back at your old code, what were you doing wrong?

    It sounds like you have everything mostly under control, process wise. Hats off to you for being 95% productive!

    I'm going to press though .

    In a perfect world you'd write just a single line of code to add a feature (kind of). What causes you to write more? What caused you to need the documentation? You demand readability, so you are spending a lot of time reading old code, yes? What proportion are you spending reading to writing? Do you grep much, read logs, write tests?

    I've just moved from a super productive environment (it took 8 years to get it there) to one...er...less supportive.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  9. #9
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by sunwukung View Post
    ... - the examples designed to give an overview of the capabilities each Orm's capability rarely provide the necessary insight into the implications of utilising the proprietors solution. ... - but I've noticed a lack of an Identity Map (or have failed to find how they implement it).
    Both points completely chime with me. I spent two days retrofitting an identity map into a migration script. In this case it was Solar that was deficient. This thing has been in PoEAA since 2003ish for goodness sake. Do people like rolling dice when they save data?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  10. #10
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by kyberfabrikken View Post
    I just finished salvaging some data from a log file that should have been sent to an external service.
    Have you tried buffering with a message queue? Did you know beforehand that this service was flakey? Is there any way you could have found out?

    Quote Originally Posted by kyberfabrikken View Post
    Waiting for external service provider to implement and roll-out a couple of extra fields for a data structure.
    Why weren't they present to start with? Could you not have scheduled this fix ahead of time so tat it would be ready now?

    Quote Originally Posted by kyberfabrikken View Post
    Agreeing with people about who does what and what exactly we're trying to accomplish. So, in short - People.
    Do they know what they want? Should developers be bought in later once they sort this stuff out? Or should a developer have been involved earlier, while they were sketching the idea on a napkin in a cafe?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  11. #11
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by TomB View Post
    1) Refactoring our "page template" class ... Finally had some spare time.
    What % of your time is spent refactoring? What do you think the payback time will be in this particular case?

    Quote Originally Posted by TomB View Post
    2) Well this is entirely non-php related
    Nice, but too off topic. Sorry. Please try again.

    Quote Originally Posted by TomB View Post
    ...Many of these sites use some rather horrible bespoke frameworks that I despise working on. There's no documentation, of course, and I'm constantly left wondering whether any thought at all went into them.
    Aha! What is causing you difficulty understanding them? Conventions or the lack? Poor APIs? Surprises?

    This is the stuff I'm after. Can you post some snippets of stuff that has caused you some head scratching?

    Quote Originally Posted by TomB View Post
    Funnily enough, some of the newer ones (~2006+) are the biggest causes of my frustration. I mentally mark them down every time I have to use print_r(get_included_files()); or debug_print_backtrace(); to work out where something is happening.
    So stack traces and the included files are important sources of information. I do the same thing.

    My first problem is to find the file where the code is. That shouldn't be a problem, yet framework authors can find all sorts of clever ways to obfuscate this basic starting point

    A bad stack trace and a bad print_r() can stop me in my tracks as well. To me stack traces and dump-able objects are part of the API.

    It strikes me that good software has easy to find code (however badly written) - is this the advantage of older dummer frameworks? Or are you having trouble with mainly other things? Or is this one problem of many?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  12. #12
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    989
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by lastcraft View Post
    Hi...



    What % of your time is spent refactoring? What do you think the payback time will be in this particular case?
    Took me about 3 or 4 hours in total. Time which otherwise would have been spent not doing anything nearly as productive. It will allow sites to far more easily control the elements that go into the site template. Previously it was all a bit messy essentially, it was a class which initialised a template, accessed datamappers directly and passed values to the template. Messy and non-=eusable code. Admittedly, in most cases not an issue but for those edge cases, especially where the template is not the same every time, it was always a bit hacky getting everything working as it should.


    Aha! What is causing you difficulty understanding them? Conventions or the lack? Poor APIs? Surprises?

    This is the stuff I'm after. Can you post some snippets of stuff that has caused you some head scratching?
    All of the above :P


    Thought I'd post something quite basic. Here's a login script: http://pastebin.com/SWnRj5Vj

    -Non-descriptive variable names
    -Horrible template engine requiring lots of binding logic
    -developer kills me every time by renaming arbitrary variables during bindings $_SESSION['user_id'] = $s_rec['cid']; In another script he actually does this: $t_values['_email'] = $s_rec['email']; for about 20 fields... *mostly* just adding an _ but arbitrarily renaming enough fields to make it so I cant replace the whole block with a function that automatically prefixes an underscore to all the array keys.
    -the if-else nesting is annoying to follow. In the shopping basket page ther are eight levels of nesting and nothing is broken up into functions.

    Guess when this code was written... go on.. guess. I'll tell you: 2008. It was written by a freelance developer the company hired about 6 months before I started here.

    Of course, this is just a classic example of spaghetti procedural code.

    Guess what directory that's in? /uplds/php/login.php

    The login.php which is actually accessed by the browser looks like this:

    PHP Code:
    <?
    include 'config/config.php';
    include 
    'config/include.php';

    $page_name basename($_SERVER['PHP_SELF']);

    if(isset(
    $_GET)){
        
    $gtp $_GET['gtp'];
        
    $_SESSION['cfp'] = $_GET['cfp'];
        
    header('Location: ' $gtp);
    } else {
        
    header('Location: index.php');
    }
    ?>
    That's it! The entire thing. There is a page like this, which does nothing for everything.

    For *every* php page there is a file which looks like:

    PHP Code:
    include 'config/config.php';
    include 
    'config/include.php';

    $page_name basename($_SERVER['PHP_SELF']);

    include 
    'inc/std_page_prep.php';

    echo 
    $page->output
    It's identical. Exactly this, in 50+ files.


    Heh, that's just one I'll post about a slightly better one later.

    edit: i just came across this gem and had to post it:

    PHP Code:

     mysql_query 
    (sprintf ("INSERT INTO drivers
                                 SET firstName='%s', lastName='%s', nationality='%s', dateOfBirth='%s', birthplace='%s',
                                 residence='%s', profession='%s', maritalStatus='%s', hobbies='%s', favouriteTrack='%s',
                                 website='%s', sponsorText1=%s, sponsorLink1=%s, sponsorText2=%s, sponsorLink2=%s,
                                 sponsorText3=%s, sponsorLink3=%s, sponsorText4=%s, sponsorLink4=%s, sponsorText5=%s,
                                 sponsorLink5=%s"
    ,
                                 
    htmlentities (addslashes ($this->data->fields->firstName->value)),
                                 
    htmlentities (addslashes ($this->data->fields->lastName->value)),
                                 
    htmlentities (addslashes ($this->data->fields->nationality->value)),
                                 
    $this->data->fields->dateOfBirth->value,
                                 
    htmlentities (addslashes ($this->data->fields->birthplace->value)),
                                 
    htmlentities (addslashes ($this->data->fields->residence->value)),
                                 
    htmlentities (addslashes ($this->data->fields->profession->value)),
                                 
    htmlentities (addslashes ($this->data->fields->maritalStatus->value)),
                                 
    htmlentities (addslashes ($this->data->fields->hobbies->value)),
                                 
    htmlentities (addslashes ($this->data->fields->favouriteTrack->value)),
                                 
    htmlentities (addslashes ($this->data->fields->website->value)),
                                 (
    strlen($this->data->fields->sponsorText1->value) ? sprintf("'%s'",htmlentities (addslashes ($this->data->fields->sponsorText1->value))) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorLink1->value) ? sprintf("'%s'",addslashes ($this->data->fields->sponsorLink1->value)) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorText2->value) ? sprintf("'%s'",htmlentities (addslashes ($this->data->fields->sponsorText2->value))) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorLink2->value) ? sprintf("'%s'",addslashes ($this->data->fields->sponsorLink2->value)) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorText3->value) ? sprintf("'%s'",htmlentities (addslashes ($this->data->fields->sponsorText3->value))) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorLink3->value) ? sprintf("'%s'",addslashes ($this->data->fields->sponsorLink3->value)) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorText4->value) ? sprintf("'%s'",htmlentities (addslashes ($this->data->fields->sponsorText4->value))) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorLink4->value) ? sprintf("'%s'",addslashes ($this->data->fields->sponsorLink4->value)) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorText5->value) ? sprintf("'%s'",htmlentities (addslashes ($this->data->fields->sponsorText5->value))) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorLink5->value) ? sprintf("'%s'",addslashes ($this->data->fields->sponsorLink5->value)) : 'NULL'))); 
    of course later in the page he does this:

    PHP Code:
     mysql_query (sprintf ("UPDATE drivers
                                 SET firstName='%s', lastName='%s', nationality='%s', dateOfBirth='%s', birthplace='%s',
                                 residence='%s', profession='%s', maritalStatus='%s', hobbies='%s', favouriteTrack='%s',
                                 website='%s', sponsorText1=%s, sponsorLink1=%s, sponsorText2=%s, sponsorLink2=%s,
                                 sponsorText3=%s, sponsorLink3=%s, sponsorText4=%s, sponsorLink4=%s,
                                 sponsorText5=%s, sponsorLink5=%s
                                 WHERE id=%s"
    ,
                                 
    htmlentities (addslashes ($this->data->fields->firstName->value)),
                                 
    htmlentities (addslashes ($this->data->fields->lastName->value)),
                                 
    htmlentities (addslashes ($this->data->fields->nationality->value)),
                                 
    $this->data->fields->dateOfBirth->value,
                                 
    htmlentities (addslashes ($this->data->fields->birthplace->value)),
                                 
    htmlentities (addslashes ($this->data->fields->residence->value)),
                                 
    htmlentities (addslashes ($this->data->fields->profession->value)),
                                 
    htmlentities (addslashes ($this->data->fields->maritalStatus->value)),
                                 
    htmlentities (addslashes ($this->data->fields->hobbies->value)),
                                 
    htmlentities (addslashes ($this->data->fields->favouriteTrack->value)),
                                 
    htmlentities (addslashes ($this->data->fields->website->value)),
                                 (
    strlen($this->data->fields->sponsorText1->value) ? sprintf("'%s'",htmlentities (addslashes ($this->data->fields->sponsorText1->value))) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorLink1->value) ? sprintf("'%s'",addslashes ($this->data->fields->sponsorLink1->value)) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorText2->value) ? sprintf("'%s'",htmlentities (addslashes ($this->data->fields->sponsorText2->value))) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorLink2->value) ? sprintf("'%s'",addslashes ($this->data->fields->sponsorLink2->value)) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorText3->value) ? sprintf("'%s'",htmlentities (addslashes ($this->data->fields->sponsorText3->value))) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorLink3->value) ? sprintf("'%s'",addslashes ($this->data->fields->sponsorLink3->value)) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorText4->value) ? sprintf("'%s'",htmlentities (addslashes ($this->data->fields->sponsorText4->value))) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorLink4->value) ? sprintf("'%s'",addslashes ($this->data->fields->sponsorLink4->value)) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorText5->value) ? sprintf("'%s'",htmlentities (addslashes ($this->data->fields->sponsorText5->value))) : 'NULL'),
                                 (
    strlen($this->data->fields->sponsorLink5->value) ? sprintf("'%s'",addslashes ($this->data->fields->sponsorLink5->value)) : 'NULL'),
                                 
    $this->data->fields->id->value)); 

    ahhh the code i have to work with.

  13. #13
    Spirit Coder allspiritseve's Avatar
    Join Date
    Dec 2002
    Location
    Ann Arbor, MI (USA)
    Posts
    648
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft View Post
    1) What is the last non-feature thing you did? Could be right now, ten minutes ago or whatever. However small.
    Reorganized my file structure, experimented with namespaces and dependency injection.

    Quote Originally Posted by lastcraft View Post
    2) What was the biggest hold up so far this week? Something where you were out of action for 2 hours plus. A bad rollout, difficult bug, training, working around a framework, figuring out how something poorly documented worked, a long meeting. Anything you want, but at least a couple of hours of delay. Name and shame dud libraries.
    We don't have version control on a large e-commerce site we're doing (yes, you read that right). In order to start working on a task, I had to download the entire site via FTP, which overwrote some local changes I had made and forgotten about. Also exported the DB, dropped my local version, and imported the latest which overwrote some fields I had added. Luckily I had a backup from reinstalling my OS last week.

    Quote Originally Posted by lastcraft View Post
    3) What typically wases your time? You can rant on this one.
    I have ADD, so I could go on all day (and do) but here are a few: trying to find naming conventions, directory structures, controller method organizations, etc. that I like and can work with (and changing my mind constantly).

    Trying to write functionality from scratch that has already been written because I hate using code I haven't written or because my boss is paranoid about open source software being insecure.

    Trying to convince my coworkers to use version control, OOP, the latest stable version of PHP, automatic deployment, automatic testing, open source frameworks or CMSs, open source project management/invoicing software, etc.

    Trying to rewrite our 10-year old procedural "codebase" that is crusty as hell.

    Trying to figure out what clients want when they don't know what they want.

    Trying to implement things in PHP that Ruby on Rails has built in.

    Reading forums and blog posts about design patterns, DDD, TDD, ORMs, productivity, etc. and trying to implement enterprise-level solutions for mom and pop businesses.

    Trying to implement "perfect" solutions when they don't exist.

    That's probably a good start.

  14. #14
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi Tom...

    In summary then...

    1) Bad naming. I can't fathom what all those prefixes mean (s_ for session?).
    2) Pointless marshalling.
    3) DRY is an alien concept.

    All very obvious.

    Mainly though it's the very large number of beginner coders within the PHP community. In this case a Zend certification might have actually helped.

    What would you do different next time? A code sample from the dev beforehand? The dev had a plan (however deranged), so they would probably have talked a good game over the phone.

    How do we help businesses to recognise bad code? assessthiscode.com? An online script that can calculate some simple code quality metrics. Hm...that's an idea actually .

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  15. #15
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft View Post
    Have you tried buffering with a message queue? Did you know beforehand that this service was flakey? Is there any way you could have found out?
    I could have, but for some reason I didn't here. I probably should, in retrospect.

    Quote Originally Posted by lastcraft View Post
    Why weren't they present to start with? Could you not have scheduled this fix ahead of time so tat it would be ready now?
    Not really. We found out that there needed to be a new field of data, so we couldn't have known in advance. The problem here though, is that each time a task "changes hands", there is an overhead of ensuring everything is taken care of, that the quality is acceptable etc. Things get mighty complicated when there are multiple providers involved in a solution.

    Quote Originally Posted by lastcraft View Post
    Do they know what they want? Should developers be bought in later once they sort this stuff out? Or should a developer have been involved earlier, while they were sketching the idea on a napkin in a cafe?
    Well, in all fairness, these things should probably not be perceived as obstacles to being productive. Defining what has to be done is often part of the process. In fact, I would probably find my job a lot less interesting if it weren't.

  16. #16
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    989
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by lastcraft View Post
    Hi Tom...

    In summary then...

    1) Bad naming. I can't fathom what all those prefixes mean (s_ for session?).
    2) Pointless marshalling.
    3) DRY is an alien concept.

    All very obvious.

    Mainly though it's the very large number of beginner coders within the PHP community. In this case a Zend certification might have actually helped.

    What would you do different next time? A code sample from the dev beforehand? The dev had a plan (however deranged), so they would probably have talked a good game over the phone.

    How do we help businesses to recognise bad code? assessthiscode.com? An online script that can calculate some simple code quality metrics. Hm...that's an idea actually .

    yours, Marcus
    Well that was just one example. There are some much better thought out, mvc type frameworks which still contain several gotchas. Changing session variables at random points, header redirects to success pages with no error checking. Having to trace through function calls to find the entry point and file being used to do the part I want. All this stuff costs me time. Usually more than it takes to fix the often trivial thing the client wants changing.

    In my case, the problem is, for a long time the business had only one developer. As you said, how is my boss (who knows little more than HTML) supposed to know? The company started off as a print design business, went into web design and the next logical step was web development.

    As you said, there's no way for people who have less knowledge to tell.

    And of course:



    I think a better question is, what can we really do about poor quality legacy code? Nobody has time to re-write it."If it ain't broke don't fix it" the code works, it's just a nightmare to modify and extend. You could hack some better code into it but that's not great. The next person who looks at the code will be even more confused!

  17. #17
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by kyberfabrikken View Post
    I could have, but for some reason I didn't here. I probably should, in retrospect.
    How would you have found out?

    Quote Originally Posted by kyberfabrikken View Post
    ... each time a task "changes hands", there is an overhead of ensuring everything is taken care of, that the quality is acceptable etc.
    What sort of things take time? What was the last thing specifically?

    Quote Originally Posted by kyberfabrikken View Post
    Well, in all fairness, these things should probably not be perceived as obstacles to being productive.
    Yes. Unless you get something systemic, such as a constant stream of unrealistic features.

    OK, so what wastes your time, or are you in one of the super productive teams?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  18. #18
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by TomB View Post
    ...mvc type frameworks which still contain several gotchas.
    Any specific gotchas?

    Quote Originally Posted by TomB View Post
    Having to trace through function calls to find the entry point and file being used to do the part I want.
    That's begging for a code snippet.

    Quote Originally Posted by TomB View Post
    I think a better question is, what can we really do about poor quality legacy code?
    That's a different thread. What I want to know is what makes something legacy code.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  19. #19
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    OK, here's mine:

    1) Someone wrote a validator to an ORM field that prevented my script running. A lack of unit tests allowed my colleague to put in a default field that was invalid. Not just me that got broken by this.

    I was able to get the Locale tag from the error message easy enough, but then couldn't find it in the code. Turns out that in Solar the error message ERROR_MY_MESSAGE is automatically assigned to a validator called validateMyMessage(). How about that for a grep beating piece of magic?

    I never figured that one out. Another colleague that worked on Solar itself told me that's how it works. Now I also grep for "yMessage" too.

    2) I could put the same again, as it was a 2+ hour delay. As I have so many at the moment, I can add another.

    I'm trying to write a bunch of migrations that work transactionally. This is a foreign concept to the Solar ORM. A colleague wrote a UnitOfWork add on, and I added an IdentityMap. All this should be built in of course, but that's just the start of the problem.

    Solar overrides everything, including having special exception classes that display differently, weird conventions for storing up error messages in an insanely nested array structure and then dumping them into the stack trace, etc, etc. It takes control of the stack traces. The stack traces are even upside down. To make matters worse, our version of Solar is an old one that has been forked in-house.

    This combination makes it a nightmare to find out what actually caused a transaction to fail. I can spend several hours chasing this down at a time and often have to edit our fork to extract errors.

    Leave the PHP error mechanism alone. "Just say throw".

    3) Rant time. I have to grep. I have to grep a lot. A mixture of autoload, weird half baked service locators, factory pluggable registries and other bloated bits of confusion mean that I can never ever find the files that a piece of code depends on. PluggableRegistry is not a pattern. Patterns are solutions that *work*.

    Grepping is labour intensive, skilled work. It's expensive. If I have to grep the source, that source is a mess. Lately the search space is the entire app and the entire framework too. require_once() is simple and works. There has to be a damn good reason to replace it.

    And while I'm on the subject...

    Why is it the framework authors seem to think they are going to tell the poor little pleb application developers how to code? They create conventions where perfectly good PHP mechanisms already exist (PEAR::Error anyone?), force the creation of entire classes for trivial validation tests, make everything extend the framework base class, insist on their own configuration system and factories...grrr.

    Listen Mr. Framework author - the reason I don't publish an OS framework is because I am gainfully employed. The reason you can write one is because obviously you are not. Don't tell me how to code. Don't be clever (you aren't), dump the magic and keep out of my way.

    Well, I feel better now .

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  20. #20
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    989
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by lastcraft View Post
    Hi...
    Any specific gotchas?
    I mentioned a couple. I'll dig out some specifics tomorrow at work but there are a few general ones I come across

    -Having 2 controller functions doing pretty much identical things to cater for insert/update and containing lots of repeated code. Any change in the logic needs to be made twice. Adding a field? Add it twice.

    -As an extension, having multiple similar update functions which are used on a switch()/if() depending on a specific type. Polymorphism obviously isn't liked by some people.

    These aren't a fault with the MVC implementations themselves (though I have an issue with that by php developers as a whole, see links in sig /plug) but by (trying to...) deploying MVC some people seem to then loose sight of other issues such as reusing code. See the queries I posted earlier. I'm sure if they were coding how they were actually used to they'd have thought it through a bit more and made a function to generate the query parameters. It seems that people learn a new concept, in this case MVC try to implement it but then forget about other things.

    One of the previous developers LOVED huge sprintf() statements like that. I see them everywhere in his code and they are the bane of working on it. Trying to match up the parameters is not an enjoyable task.

    That's begging for a code snippet.
    Well I don't know if i can do that without posting all the framework code for something

    An an example, one time it looked like urls were auto-mapping like this (and they were for most of the site!):

    /controller/action/arg/arg/

    So the client wanted something changing on

    /clothing/

    I figured I'd open up clothing.php from the controllers directory. The file didn't exist.

    After stepping through half the front controller code, I found out that it was loading a (rather large, i might add!) XML file which contained every possible route to every controller action it then looped through each action segment and matched to the url using preg_match() (and didn't even break when it found the right one!). A nice, unnecessary overhead both for the server and me working out where I need to look. Turned out the /clothing/ url mapped to a controller called "shop". Which was a nice waste of half an hour or so.


    What I want to know is what makes something legacy code.
    I'd say when nobody really understands how it works and it cant be updated without someone having to learn how it works first :P

    On any large, long-term project I've worked on there's always large pieces of code people daren't touch because they're hacked together, messy and incomprehensible. Generally it gets to the point where it's easier and faster to rewrite it than to try to fathom the inner workings of it.

  21. #21
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    989
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by lastcraft View Post
    Why is it the framework authors seem to think they are going to tell the poor little pleb application developers how to code? They create conventions where perfectly good PHP mechanisms already exist (PEAR::Error anyone?), force the creation of entire classes for trivial validation tests, make everything extend the framework base class, insist on their own configuration system and factories...grrr.

    Listen Mr. Framework author - the reason I don't publish an OS framework is because I am gainfully employed. The reason you can write one is because obviously you are not. Don't tell me how to code. Don't be clever (you aren't), dump the magic and keep out of my way.

    Well, I feel better now .

    yours, Marcus
    Heh, isn't that the point of a using a framework? To keep everything consistent and let you quickly build into it? I'd like to see a framework where your controllers don't extend a base class. You'll get lots of repeated code :P As for a framework having its own config file, i think that's again is not something you're going to be able to avoid.

    It sounds to me like you're using the wrong framework and ORM. All code has to have a usability scope of some description. There's no way anyone can make an ORM which caters to everyone's possible needs or a framework that will satisfy everyone. Some people will want high flexibility while others will just want to be able to quickly develop on it. There's always a balance, I don't think you can really blame framework authors for this.

  22. #22
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by TomB View Post
    Heh, isn't that the point of a using a framework? To keep everything consistent and let you quickly build into it?
    No. That's the framework author's egotistical fantasy.

    I want to automate repetitive tasks and get leverage by using prebaked code for common tasks. I want no other interference. I have no use for "consistency" any more than "conventions". My app will always be different (otherwise I'd use a CMS).

    "Consistency" is an overhead that confuses everyone and costs money in ramp up time every time a new dev has to work on it. It's evil, and the framework author as an uphill struggle to convince me it's a necessary evil that will pay it's way. That explanation had better be good as I'm starting from sceptical.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  23. #23
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft View Post
    1) What is the last non-feature thing you did? Could be right now, ten minutes ago or whatever. However small.
    Took a bunch of code out of my own "framework" because for the first time I am using it for a public only system (no authentication, no database). Still works exactly the same for the most part, just less lines and less complication.

    Quote Originally Posted by lastcraft View Post
    2) What was the biggest hold up so far this week? Something where you were out of action for 2 hours plus. A bad rollout, difficult bug, training, working around a framework, figuring out how something poorly documented worked, a long meeting. Anything you want, but at least a couple of hours of delay. Name and shame dud libraries.
    Copied some code between projects that basically groups database results alphabetically, showing the letter above each result set.

    Rather than slowing down and thinking about how well it will work in this new implementation, I dumped it in, spent about 90 minutes trying to bend it to work, before finally giving up, re-thinking the strategy and getting a finished result in 30 minutes.

    Quote Originally Posted by lastcraft View Post
    3) What typically wases your time? You can rant on this one.
    Client communication

    Besides that, trying to mold every feature request into something that is re-usable and flexible for other purposes. I hate the idea of writing code I can never re-use.

    Lastly, I probably try to do way too much in each method, which means when I want to extend something I have to repeat too much code.
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  24. #24
    SitePoint Addict webaddictz's Avatar
    Join Date
    Feb 2006
    Location
    Netherlands
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft View Post
    What concrete differences are there? If you look back at your old code, what were you doing wrong?
    Repetition all over the place, the incredibly dumb tendency to be "smart" and use what other people considered "smart", such as singletons. There were no tests, at all. None. There is zero documentation. The API sucks, the database has well over 100 tables, while it could probably do with less than 10. Mixing languages together. Did I mention repetition?

    When it comes to repetition, I can show you something that illustrates:

    Code:
    berry@pc:/www/project/controllers% uniq controller.php | wc -l
    810
    berry@pc:/www/project/controllers% cat controller.php | wc -l 
    849
    In that controller, "sections" and "subsections" are defined in an array, which is not the controllers' task at all. I shouldn't mind that much, I could just move it. Hah, but wait... The array is redefined in local method scope three times. Lots of copy and paste programming back in the ol' days. Another nice example of what my "model" looks like:

    Code:
    berry@pc:/www/project/model% cat model.php | grep "function" | wc -l
    94
    Now, normally I wouldn't mind this: I stick classes which closely relate to one another in a single file, so 94 methods is not entirely uncommon, if I had quite a few related classes. In this case however:

    Code:
    berry@pc:/www/project/model% cat model.php | grep "class" | wc -l
    1
    That's 94 methods in one single class. 94 methods. Well. Luckily I have the deal with myself to always leave code cleaner than I found it, so most of the repetition will be killed, and a lot of tests will be added.


    Quote Originally Posted by lastcraft View Post
    It sounds like you have everything mostly under control, process wise. Hats off to you for being 95% productive!
    I said more than 5% I try to be as productive as I can, and one day differs from the next, but I do try to keep it up and stay in the coding-spree for as long as I can. Truth be told though: there are days I can't even get in it.

    The process here is good, I think. I like the way I currently work, and so do my co-workers and customers. We hit deadlines, and things are clear and apparent. Version control, unit-testing, automated deployment scripts, I think the process is better than at several other companies around.

    Quote Originally Posted by lastcraft View Post
    In a perfect world you'd write just a single line of code to add a feature (kind of). What causes you to write more? What caused you to need the documentation?
    The tests cause me to write more. Then again, it also allows me to sleep at night, knowing that our tests pass, so there are no known bugs in the software that is used by a lot of people. It gives confidence and allows for easier refactoring in the future, if necessary.

    The documentation causes me to write more too. I write three different kinds of documentation: first, the functional specification, which usually takes up a lot of time, but it makes for clear communication between us and customers, and it definitely gives you a guide-line, so that you know when you're done and, ultimately, can send your bill. It also provides a clear image of what exactly has to be done, and - in the words of Joel Spolsky - it's easier to change text than it is to change code.

    The second type of documentation is system documentation: the kind of stuff I'd let new employees read to get a grip of the general workings of the system.

    Quote Originally Posted by lastcraft View Post
    You demand readability, so you are spending a lot of time reading old code, yes? What proportion are you spending reading to writing?
    That's very dependent of the project at hand, of course. Older projects cause me to read a lot more, because of the lack of documentation and the lack of readable code. I think the current project (which is an old one) is about 30% of reading, 20% of writing tests so I don't ruin anything, 20% of improving (DRY'ing the code) 30% of writing new features. I never clocked this though, so I will do so today, and hopefully let you know later.

    Quote Originally Posted by lastcraft View Post
    Do you grep much, read logs, write tests?
    I don't grep that much, really. I have an IDE and a step-debugger. I do read logs when I don't get what's going on, and I (usually) write tests before I start hacking at the code.

    Quote Originally Posted by lastcraft View Post
    I've just moved from a super productive environment (it took 8 years to get it there) to one...er...less supportive.
    That's an adventure, a challenge
    Yes, I blog, too.

  25. #25
    SitePoint Zealot
    Join Date
    Feb 2009
    Location
    Bristol
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft View Post
    What I want to know is what makes something legacy code.
    Oh dear - whatever that definition is, I've just been handed some...

    Legacy Code:
    You know you're working on legacy code when -

    • There is no documentation inline or otherwise and the author is either retired, fired or dead
    • You have to step through at least 3 files to locate the origin of a variable
    • You have to step through a function to know what it expects and what it returns
    • You find 100 line+ blocks of code commented out - and those are the only comments you've found so far
    • It resembles a famous italian dish
    • You get the distinct impression you've just boarded the Mary Celeste - i.e. somebody left in a hurry...


    (any more? add as you feel appropriate

    Sad thing is, I know I've written a fair bit of this myself. To all of those who work on my appalling code, I repent! I'm doing my best to redeem the sins of the past with reams of Docblocks and legions of Unit Tests...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •