What is the current year?



  • It wasn't long after I was hired that I took over an entire application from a developer who got there before me. At first it was just to speed things up. Mostly that involved not creating objects for everything under the sun when running reports (already stressful even without unnecessary overhead).

    Now that the speed complains have been falling off and I've been through a few iterations of this project and believe that I understand it pretty well, I decided to go through tidying up code and seeing if there are any other ultra-low-hanging fruit.

    Then I found the attached. Yes, we have a custom DateTime class. The worst part is that it was named DateTime originally, which bit us when we moved to PHP 5. This was the same developer that was pushing us to move to PHP 5 yesterday. While this is a good idea and we needed to move off of the now deprecated PHP 4 before we actually did, you would think that he would have tested his stuff on PHP 5 before making a stink.

    The entirity of the functionality could be replaced with date("Y"). Even without PHP 5's DateTime class.

    This guy REALLY wants to program in Java.

    <?php
    require_once("{$_SERVER['DOCUMENT_ROOT']}includes/dateTimeObjects/timeRanges/ThisYear.php");

            $thisYear = new ThisYear();
            $thisYearsStartingSSDateTime = $thisYear->getStartingSSDateTime();
    ?>
        </td>
      </tr>
      <!--<tr>
        <td height="15"><img src="images/spacer.gif" width="1" height="15" border="0"></td>
      </tr>-->
      <tr>
        <td class="bg_ftr">&copy; <?=$thisYearsStartingSSDateTime->getYear();?> My Company - All Rights Reserved.</td>
      </tr>
    </table>

    </body>
    </html>



  • What's funny about this is that the copyright date advances with the current year :) Isn't the point of a dated copyright symbol to establish when copyright was first claimed?



  • @pinkduck said:

    What's funny about this is that the copyright date advances with the current year :) Isn't the point of a dated copyright symbol to establish when copyright was first claimed?

    The year can be changed if the content is added too or revised within the newer year.  But technically, it should include each relevant year, or a range like 2004-2008.  But the importance or relevance of copyright notices altogether is questionable.   I think most people update the date just so it looks like the site has been updated and attended to regularly.



  • @negativeview said:

    require_once("{$_SERVER['DOCUMENT_ROOT']}includes/dateTimeObjects/timeRanges/ThisYear.php");
     

    Rather stupid to keep your includes/libraries within the document root... Especially if some of the code in those includes isn't encapsulated in function definitions. And even more so if there's a possibility of the raw content being served up somehow, i.e. stored as .inc files which would get served up as plain text, and not run through the PHP interpreter..

     



  •  I must admit that I'm guilty of this as well, though the $_SERVER['DOCUMENT_ROOT'] part was him. Before they were referenced without that part, as doc root is part of our include path. But then he started putting includes for cli scripts in there as well, and they couldn't find the OTHER include files, as it's not part of the path for the cli php.ini, so he started doing all includes as $_SERVER['DOCUMENT_ROOT']. This likely didn't fix his real problem (as is true for many of his "solutions") because $_SERVER shouldn't be defined in cli mode if I understand correctly, but I'm not aware how he got those working.

     I'm a bit miffed at the moment too, because I just got done debugging 56K of PHP cli app that I could write with five lines. Mostly because there's an object for every table in our database. There is a sql/MyTableNameTable.php file for every. Friggin'. One. With getters and setters that do naive sql statements, meaning that if you use these you invariable kill performance.

     I know why they took the code away from him, but oh god WHY did I get it? And why is he still employed here? THAT is the true WTF. They obviously recognize his failure, but he's still here. A few desks behind me. sigh



  • @negativeview said:

     I must admit that I'm guilty of this as well, though the $_SERVER['DOCUMENT_ROOT'] part was him. Before they were referenced without that part, as doc root is part of our include path. But then he started putting includes for cli scripts in there as well, and they couldn't find the OTHER include files, as it's not part of the path for the cli php.ini, so he started doing all includes as $_SERVER['DOCUMENT_ROOT']. This likely didn't fix his real problem (as is true for many of his "solutions") because $_SERVER shouldn't be defined in cli mode if I understand correctly, but I'm not aware how he got those working.

     I'm a bit miffed at the moment too, because I just got done debugging 56K of PHP cli app that I could write with five lines. Mostly because there's an object for every table in our database. There is a sql/MyTableNameTable.php file for every. Friggin'. One. With getters and setters that do naive sql statements, meaning that if you use these you invariable kill performance.

     I know why they took the code away from him, but oh god WHY did I get it? And why is he still employed here? THAT is the true WTF. They obviously recognize his failure, but he's still here. A few desks behind me. sigh

     

    If you could have implemented this in 5 lines, then what is the big issue? Rewrite it in 5 lines, pretend it was a huge problem, charge for time, and move on with your life. Sounds like an easy project to me!



  • @negativeview said:

    This likely didn't fix his real problem (as is true for many of his "solutions") because $_SERVER shouldn't be defined in cli mode if I understand correctly
     

    Nope, it's not, since those are web-server defined properties (ie: Apache data).

    @negativeview said:

    but I'm not aware how he got those working.

    Either by hard-coding the path into the include statements ( include('/path/to/file'); ) or by adding the dir(s) to the include_path with ini_set() at the start of each script.

    @negativeview said:

    Mostly because there's an object for every table in our database.

    If I'm reading this correctly, they've taken all the power and ease-of-use of a relational database, slapped on a front-end that converts it essentially into a flat file storage medium, and then use all the power and ease-of-use of objects to make PHP do what the DB server should have been doing in the first place? i.e.: Joins, order bys, and all that optimization magic which includes where clauses?

    aiiiiieeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee. You should post some sample code from one of those objects. I'm curious to see just how deep this rabbit hellhole goes. Right after I don my peril-sensitive sunglasses (which are no doubt so dark by now they look clear) 



  • @MarcB said:

    If I'm reading this correctly, they've taken all the power and ease-of-use of a relational database, slapped on a front-end that converts it essentially into a flat file storage medium, and then use all the power and ease-of-use of objects to make PHP do what the DB server should have been doing in the first place? i.e.: Joins, order bys, and all that optimization magic which includes where clauses?
     

     It looks like it's limited to rows selected by the primary key, not individual data elements. So it's not as bad as I first surmised. The code is gone in the dev branch, as it was only really used by the report code (which is rewritten) and deleting it caused literally nothing to stop working. But production code had it! This has been sanitized, so things like "---" are intentional.

     Also note his love of pontificating in comments about how he has learned about separation of responsibilities. But there is no way to join using these objects. There are a few "twoTableJoin/" objects, but those were created for even more special purposes. And isn't the fact that you have to include them from the twoTableJoins directory sortof exposing the very interface he's so desperate to cover up?

     <?php
    /

     
    AbandonedCalls.php
     * Apr 30, 2007
     * Author: -----
     
     
          a simple wrapper for the abandoned_calls table
     */

     require_once("{$_SERVER['DOCUMENT_ROOT']}db/---DBImpl.php");
     require_once("{$_SERVER['DOCUMENT_ROOT']}includes/dateTimeObjects/Now.php");

     class AbandonedCalls extends ---DBImpl {
            function AbandonedCalls($configValues=null) {
                    parent::---DBImpl();

                    if(!is_null($configValues)) {
                            $this->setConfiguration($configValues);
                    }
            }

            function load() {
                    $selAbandonedCallById = "SELECT * FROM abandoned_calls WHERE id = '" . $this->callId . "';";
                    $abandonedCallResult = mysql_query($selAbandonedCallById);

                    $this->setDataBuffer($abandonedCallResult, false);
            }

            function loadAll() {
                    $selAllAbandonedCalls = "SELECT * FROM abandoned_calls";
                    $abandonedCallsResult = mysql_query($selAllAbandonedCalls);

                    $this->setDataBuffer($abandonedCallsResult, true);
            }

            function setConfiguration($configValues) {
                    $this->callId = $configValues['callId'];
                    $this->agentId = $configValues['agentId'];
            }


    //// logical stuff that does not belong in this class
    ///             the following method is based upon data which AbanandonedCalls provided; therefore it is not the responsibility of AbandonedCalls to provide such a method; the below method is
    ///             deprecated and marked for removal
            function hasBeenReturned() {
                    $hasBeenReturned = false;

                    $theAbandonedCall = $this->load();
                    if($theAbandonedCall->was_returned == 1) {
                            $hasBeenReturned = true;
                    }

                    return $hasBeenReturned;
            }}

    //// NOTE: this is an update method; once a standard interface is created for insert, update, delete; this will have to be renamed and client code will have to be modified
            function markAsReturned() {
                    $creationSuccess = true;
                    $curDateTime = new Now($creationSuccess);
                    $updtAbandonedCall = "UPDATE abandoned_calls SET was_returned = 1, time_return_reported = '" . $curDateTime->toMySQL()  . "', returned_agent_id ='" . $this->agentId . "' WHERE id = '" . $this->callId . "';";
                    $updtSuccess = mysql_query($updtAbandonedCall);
                    return $updtSuccess;
            }
     }
    ?>

    This isn't the worst code in the world, but it's pretty bad compared to what he's trying to replace -- a single select statement. 

     And yes, we're in the habit of using mysql_query directly. The next version won't do that, either.



  • Welcome to Enterprise Hell. 

    Where unnecessary objects, interfaces, substandard practices (if they can even be called that), and general WTF'ery abound. 
    Where words like Pattern and Anti-Pattern are used without regard for definition and implemented regardless of necessity.
    Where you must be doing something wrong if it only took a few lines of code.
    Where everything must be cached, serialized, passed between services of varying flavors, deserialized, and operated on by untold legions for the shear purpose of displaying the curernt date on a screen.

     



  • @clively said:

    Where you must be doing something wrong if it only took a few lines of code.

    &copy; 2008 <!-- TODO: Change to "2009" next year --> My Company - All Rights Reserved



  • @pinkduck said:

    What's funny about this is that the copyright date advances with the current year :) Isn't the point of a dated copyright symbol to establish when copyright was first claimed?

     

     

    Copyright is automatic as soon as you create the work. Filing just helps the lawyers and judges later down the line but a lack of filing in no way makes it public domain. 



  • @medialint said:

    Copyright is automatic as soon as you create the work. Filing just helps the lawyers and judges later down the line but a lack of filing in no way makes it public domain. 
     

    No, copyright is automatic once you slap on the (c) tag and associated text. AT&T found that out the hard way when they sued Berkeley over Unix for copyright violations. The old copyright act required explicity (c) tags, and AT&T Unix source had none, so it became public domain by default. Ironically, Berkeley counter-sued AT&T for misappropriating BSD sources into SysVR, and would have won. Instead they settled out of court.

    Filing paperwork with the copyright office might just be to keep the lawyers happy, since all you need to do is slap a (c) onto your stuff, but it does give you a legal groundwork to prove that your copyright is valid. It's one thing to put (c) 2005 on something and sue someone for violations, it's another entirely to be able to prove that you really did copyright that stuff in '05, and didn't just slap the tag on '08 and pretend it was really '05.



  • @MarcB said:

    It's one thing to put (c) 2005 on something and sue someone for violations, it's another entirely to be able to prove that you really did copyright that stuff in '05, and didn't just slap the tag on '08 and pretend it was really '05.

    This is why you print a copy, mail it to yourself and don't open it.  Postmark is your proof, and can be opened under proper evidentiary proceedings to demonstrate.

    [code]// TODO: work wooden table into process somehow[/code]

     

     



  • @MarcB said:

    No, copyright is automatic once you slap on the (c) tag and associated text. 

     

    No. That is extremely false information. The (c) notice itself has no bearing on legal copyright itself. Copyright is automatic just try proving it. Same goes with perception, but the legal ownership of the right to copy is that with the original author unless explicitly granted otherwise (or work for hire). See: copyright.gov for info and the actual legal text.

     



  •  It sounds like the original designer tried to write an Object Relational mapper, but failed.

     I'm currently architecting (scary word!) an entity services based database abstraction layer for an enterprise project, and there are a lot of ways to go wrong on these.  However, when done right, they can be an absolute joy.

     I give the guy kudo's for at least attempting to abstract concepts and program using OO in PHP, something that is pretty rare as is :)

     



  • @Jonathan Holland said:

    I give the guy kudo's for at least attempting to abstract concepts and program using OO in PHP, something that is pretty rare as is :)
     

     As much as I complain, I usually explain this guy to other developers as follows:

     He reads much of the same articles that I do. He takes away some of the important concepts, but then he either goes slightly astray (his concept of a unit test is amusing) defeating much of the point or he goes PAST the original idea into absurdity. Good ideas are good ideas, but they have their limits and he doesn't know them.

     ORM I very vaguely understand, but I don't really see the "absolute joy" moment. Granted, I'm working my way up the smaller shops (though the place I'm at now actually has well over 100 employees instead of the 8 at my last place (though only eight of these are developers)) and I probably haven't worked on applications the scale that would truly benefit from ORB (is it an ORB or just ORB?).

     Then again, that's anoter WTF. Trying to build multi-million dollar applications because that's how the big-boys do it when there is no real reason to build those things in. Is there some law akin to premature optimization for this stuff that's already been coined? Premature enterprisization?

     But let the record show that I do give him some credit. I just wish that he was able to sometimes, sometimes see the err of his ways and that the massive libraries he writes get in the way and don't solve a real problem in every real case this company has.



  • A properly designed ORM would consist of a base class that has templates for all the CRUD operations that is inherited by subclasses that actual represent the table entities (Examine Hibernate or ActiveRecord). This abstracts the actual CRUD code to one location, in fact, properly designed, most of this can be codegenned.

     It sounds to me like he wrote classes for table entities without much thought of an overall design. He gets an A for effort, but an F in design :)

     Btw, "Premature Enterprisation" needs to become a buzzword, that is awesome.



  • @MarcB said:

    No, copyright is automatic once you slap on the (c) tag and associated text. AT&T found that out the hard way when they sued Berkeley over Unix for copyright violations. The old copyright act required explicity (c) tags, and AT&T Unix source had none, so it became public domain by default.

    The "old copyright act" that you're referring to is the series of US-specific laws that ceased to apply in 1988. Unless you're living in some kind of bizarre relativistic time fold, this has not been true for the past twenty years. The case that you are referring to deals with software written in the period 1978-1988, so it is no longer relevant.



  • @MarcB said:

    Rather stupid to keep your includes/libraries within the document root... Especially if some of the code in those includes isn't encapsulated in function definitions. And even more so if there's a possibility of the raw content being served up somehow, i.e. stored as .inc files which would get served up as plain text, and not run through the PHP interpreter..
     

    Unless you want them to be served up as plain text (so you can include files over HTTP), why would you give them a .inc extension rather than .php?! This seems one of the craziest conventions I've seen, though not much of a WTF in the context of PHP.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.