• Martin (unregistered) in reply to KattMan
    KattMan:

    Actually, code like this is the accepted norm.  Offshoring is just filling the need of the majority of companies.

    They don't want it done right, just right now.

    And in most cases, you don't actually get either. . . 

  • (cs) in reply to Sam

    I like this better:

    The last of Feb., or of Jan. will do
    (Except that in Leap Years it's Jan. 32)
    Then for even months use the month's own day,
    And for odd ones add 4, or take it away*

    Now to work out your doomsday the orthodox way
    Three things you should add to the century day
    Dozens, remainder, and fours in the latter,
    (If you alter by sevens of course it won't matter)

    In Julian times, lackaday, lackaday
    Zero was Sunday, centuries fell back a day
    But Gregorian 4 hundreds are always Tues.
    And now centuries extra take us back twos.

    *According to length or simply remember,
    you only subtract for September, or November.


    *************************
    J. H. Conway, Jan., 1976
    *************************

    Explaination @ http://www.cs.wustl.edu/~ksl2/mathpoem.html

  • wwalker (unregistered) in reply to Sam

     

    Anonymous:
    Excuse me while I vomit.

    Code like this from "offshore" developers is in line with my experience. We always get told that these "offshore" developers have such a great education. But they know shit. In this case they have apparently never heard of Zeller's congruence algorithm. Yeah, just memorizing the name and a few control constructs of a language doesn't make you a good programmer.

     

    I learned  Zeller's congruence algorithm. in 8th grade...29 years ago...  avout page 20 of my algebra book. 

    wwalker 

  • (cs) in reply to Boo
    Boo:

    :) Why can't the CAPTCHA also be displayed as text?  That would be so much easier.  Look, I'll let you in on a little secret. I have my images turned off and I am not a robot so please let me in. :)

    Register. The captchas will never bother you again. ;) 

  • (cs)
    David:
    It seemed to be working fine, so I decided to look into source codes.

    Please please please people, stop pluralizing the word "code" with an "s", computer code is already plural.

    "Codes" makes me think of cryptography, and makes me want to smash your head in.
  • (cs)

    the best implementation of this would be:

    function weekday($year,$month,$day) {
        if ($month < 3){
            $month += 12;
            $year--;
        }

        $Cent = $year/100;
        $YearOfCent = $year % 100;

        return ($day + ((($month+1)*26)/10) + $YearOfCent + ($YearOfCent/4) +

                ($Cent/4) - 2*$Cent ) % 7;
    }

  • (cs) in reply to Maurits

    Maurits:
    Another thing that bugs me is that they're mixing 0-based and 1-based indexing.  They're requiring the month to be passed in as a number between 1 and 12, but returning the day of the week as a number between 0 and 6. (1 to 12, 1 to 7) I could understand (very BASIC.)  (0 to 11, 0 to 6) I could understand (very C.)  But this is confusing.

    Maybe it's copied from Java's Calendar class, the central WTF that all other Java WTFs emanate from.

    intval($leap_years % 25)
    Since when has a modulo ever returned a fraction (float)?
    Anonymous:
    Actually, read the caveats -- MCAL is not part of core PHP distro, and it's not even available on Windows, so it's highly possible that your code wouldn't work.
    Personally, I'd go with idate('w', mktime(0, 0, 0, $month, $day, $year));

    For the love of God, quote when you reply to someone 30 posts above yours. (POS forum can't get this quote right no matter how I format it. Ironic.)

    brendan:

    the best implementation of this would be:

    function weekday($year,$month,$day) {
        if ($month < 3){
            $month += 12;
            $year--;
        }

        $Cent = $year/100;
        $YearOfCent = $year % 100;

        return ($day + ((($month+1)*26)/10) + $YearOfCent + ($YearOfCent/4) +

                ($Cent/4) - 2*$Cent ) % 7;
    }

    I think you forgot an intval() in there. (If this is PHP.) Otherwise it should work, but definitely begs for a comment or three to ease maintainers' minds.

     

  • (cs) in reply to Boo
    Anonymous:

    Derrick Pallas:
    ... he found the code so he gets to rewrite the module.

    I hate that: "You find it, so you own it".

    That's why I'll never stop to help when I see a broken down car full of helpless little kittens, burning to a crisp on the side of the road.

     

    I bet you they would taste like chicken. Yum!

  • (cs) in reply to foxyshadis
    foxyshadis:

    I think you forgot an intval() in there. (If this is PHP.) Otherwise it should work, but definitely begs for a comment or three to ease maintainers' minds. 

    Apparently PHP convert the the operands to an integer when using the % operator, So it has no effect whether I use intval() or not. As for the comments, I think the code is simply enough to not need comment (although I should comment the preconditions and postconditions).

  • (cs) in reply to cheesy
    cheesy:
    David:
    It seemed to be working fine, so I decided to look into source codes.

    Please please please people, stop pluralizing the word "code" with an "s", computer code is already plural.

    "Codes" makes me think of cryptography, and makes me want to smash your head in.

    I had a teacher once (grade 3) that always tried to correct me on grammar and I would always reply, "who cares". So I will say the same thing to you, really who cares whether his spelling was incorrect, as long we know what he meant, it's fine.

  • Hank Miller (unregistered) in reply to brendan
    brendan:
    I had a teacher once (grade 3) that always tried to correct me on grammar and I would always reply, "who cares". So I will say the same thing to you, really who cares whether his spelling was incorrect, as long we know what he meant, it's fine.

    I used to feel the same way. Then someone explained it to me: language is only useful if we all agree EXACT meaning. If I do not use exactly the same definition for a word that you use, we cannot communicate. This is already a big problem, and the only solution is to care enough use only words where everyone agrees on the exact meaning (given context).

    There are some words/phrases that should not be used because definitions are not agreed on. (To table an item has a different meaning in England and the US) Others should not be used because in the few cases where you need the difference it isn't clear what you mean. (Normally 'can' and 'may' could be used for the same meaning, but once in a while it is critical to get the right meaning)

    Not that I'm very good at it, but I've come around. Language must be used carefully and precisely; otherwise we are not communicating even though we exchange sounds.

  • Hank Miller (unregistered) in reply to sigh
    Anonymous:
    Some folks tend to take the concept of magic numbers a bit too far. Yes, we could make the number of days in a week a constant, but really, do we ever really need that much generality? On the other hand...

    Yes. While the number of days in the week is unlikely to ever change, we still need a named constant so that you know that days of the week is really meant.

    Think of some of the longer WTFs posted here over the years.

    Now suppose you are refactoring such code because the company went from 7 to 8 branch offices. No surprise that the number of offices was hardcoded in as a number all over. While doing this you come across the following line:

    s = u/7;

    Is this a simple date calculation (day = totaldays / DaysInWeek) or is this an attempt to evenly split the CEOs time between all offices? (DaysCeoSpendsAtEachOffice = DaysCeoSpendsOnMoral / NumberOfBranchOffices) In both cases you are dealing with dates, but you need to change one instance. In typical WTF fashion the variable names themselves are worthless for helping you. So do you change the 7 above?

  • Watson (unregistered) in reply to darin
    darin:
    Am I missing something here.  The code does what it's supposed to.  If you look inside those mktime routines, you'll see code very similar to this.
    So because it's already written correctly and available that means it's okay to write it again (assuming it's correct, which apparently it's not)?

    darin:
    Mktime isn't in my Perl reference.
    Good point - it's only the submitter's contention that this is PHP, not Perl.

  • (cs) in reply to Watson
    Anonymous:
    darin:
    Am I missing something here.  The code does what it's supposed to.  If you look inside those mktime routines, you'll see code very similar to this.
    So because it's already written correctly and available that means it's okay to write it again (assuming it's correct, which apparently it's not)?

    darin:
    Mktime isn't in my Perl reference.
    Good point - it's only the submitter's contention that this is PHP, not Perl.

    Slightly off-topic, but I do wonder what "isn't in my Perl reference" means.  I suppose, at least, that Darin doesn't use google et al, so he won't be able to screen-scrape the Perl abortion equivalent to this.  I can't remember whether it's in the standard distribution (presumably it is), but if you need Unixy APIs like mktime, Darin, I strongly recommend downloading the POSIX module from CPAN.  And then checking things up through pod2man, obviously...

    Can't be bothered to quote the post from way up above, but what is this concept of "optimising PHP," anyway? The whole point of PHP is that it's simple and you don't bother to optimise it.  If you want an optimised web-site, use a more suitable language. (Or write your own PHP extension.  Yeuch.)

     

  • (cs) in reply to Maurits

    Maurits:

              + ($leap_years % 25 < 0 ? 1 : 0) + // WTF

    Suspend disbelief for the moment and pretend that people might want to use this function on negative years, ignoring the fact that our calendar system hadn't been invented yet. We assume that intval($leap_years/25) rounds towards zero, but we want to always round down. Bear in mind that for negative a, a % 25 returns a number in the range [-24,0] and this WTF line of code almost makes sense.

    floor($x / 25) == intval($x / 25) - ($x % 25 < 0 ? 1 : 0)

    The real WTF is that similar treatment is not given to intval((intval($leap_years/25))/4) so that even after all this work, we'll still get the wrong answer for negative years.

    Maurits:
     

    ) % 7
          ) + 7 // WTF
        ) % 7 // WTF
     

    This is actually not a WTF. As I mentioned before, the % operator sometimes returns negative values for negative inputs (in PHP, as well as C and Java) but we want this function to return a number in the range [0,6]. Hence the little fiddle at the end.

    Edit: The real WTF is I didn't notice this thread has a page 2.  Sorry if all this is redundant :(

  • (cs) in reply to Ownage Personified

    Ownage Personified:

    + ($leap_years % 25 < 0 ? 1 : 0)  isn't a wtf either, it is there because one leap year is otherwise lost in the leap year calculation for pre-1970 dates as -2 / 4 = 0.

    The value $leap_years is calculated from the original $years, before we subtracted 1970. So the point where we start losing leap years is actually the year zero.

    Ownage Personified:

    The real wtf is that this apparently only works correctly for dates from year 1801 onwards.

    As far as I can tell it works fine... anyone care to enlighten me on this one? (Though of course it won't work if you enter a date in the Julian calendar).
     

  • Nice Beard (unregistered)
    Derrick Pallas:
    so I decided to look into source codes. I shouldn't have do it.

     

     I'm intrigued to know where David himself comes from. He either himself works in an outsourcing company somewhere in Asia, or he's a script-kiddie whose pwn3d everyone with his m4d c0d3z.
     

  • Broken (unregistered)

    Well, it seems David did the biggest WTF... Why on Earth did he think that a function called "Weekday" ending with a modulo-seven - was supposed to return a timetamp? Even now, he might be breaking what wasn't broken.

  • (cs) in reply to Autophile
    David:
    In his own words,
    They helped us to develop some modules, and my boss asked me to review one of them. It seemed to be working fine, so I decided to look into source codes. I shouldn't have do it. </div></BLOCKQUOTE>
    

    Did David offshore his grammar too? At first I couldn't tell if this was David's words or a Chinese programmer's.

  • Ownage Personififed (unregistered) in reply to Giles
    Giles:
    Ownage Personified:
    + ($leap_years % 25 < 0 ? 1 : 0)  isn't a wtf either, it is there because one leap year is otherwise lost in the leap year calculation for pre-1970 dates as -2 / 4 = 0.
    The value $leap_years is calculated from the original $years, before we subtracted 1970. So the point where we start losing leap years is actually the year zero.
    Ownage Personified:
    The real wtf is that this apparently only works correctly for dates from year 1801 onwards.
    As far as I can tell it works fine... anyone care to enlighten me on this one? (Though of course it won't work if you enter a date in the Julian calendar). 
    Ah, I only looked at the paraphrased version I was replying to, not the original, and that lacked the calculation of $leap_years. In that case the real wtf is that there was no year 0.
  • Gabriel (unregistered) in reply to Gnoople
    Gnoople:
    This is one of the reasons why IT people in the western world (the free world according to a certain American president) will still have a job after the deployment of "offshore developer centers" (ODC) in every major IT company. If it is any concelation to David, a certain ODC in India could have done the same. I have seen it myself. regs,Gnoople - Employed system developer in Scandinavia.

    Consider that for a Chinese developer, these calendar issues are alien to him. China does not use the Gregorian calendar (ending year 4704 now), have years as short as 353 days or as long as 385 days (leap years with 13 months) and the "week" concept is not as important. So probably the chinese programmer just searched for the code somewhere and copy&pasted it.

  • (cs) in reply to brendan

    I care. It's not like I'm one of those people who regularly corrects people's spelling, but "codes" in particular bugs the hell out of me. I'm not really sure why, it's just a huge pet peeve of mine.

    And yes, I will think less of you if you use the word "codes" in place of "code".

  • laowai (unregistered) in reply to Gabriel

    Bullcrap.

    The traditional Chinese calendar is different, but China has been using the modern Gregorian calendar for years now. Anyone who has been trained enough to do software development understands the Gregorian calendar. (U.S. addresses on the other hand, are a different story. I spent hours trying to explain why sometimes zip codes had 5 digits, sometimes 9. And the whole "middle initial" of people's names? Mass confusion)

    Overall, though, this code isn't surprising to me. I spent 2 years working at a Chinese outsourcing shop (maybe even the one from this story). People there think differently than we Westerners do.

    But on top of that, it's like it is in the U.S....unglamorous outsourcing companies won't attract the best programmers. They have to hire lots of developers. So they will by default churn out a lot of crap. The good developers, be it in China or here, will be more expensive. You pay for cheap development, you get crappy development.

  • (unregistered) in reply to darin
    darin:
    Wait, I have to do that! No generic C Runtime Library is able to know how to obtain your particular machine's current time and convert that to a standard "time_t". And then there's the cross conversion between different time standards that tend to occur underneath the hood (most file systems don't use "time_t"). And of course the libraries themselves have to be written by someone; and they're often written in modern languages.
    time and gettimeofday are both POSIX, and also present on pretty much every system capable running compiled C that has a clock. Both give a standard "time_t" for your particular machine's current time.

    On real systems, the time_t returned is specified to be in UTC, but if you need to ensure it is UTC, or need to ensure it is the local time, you should use gmtime or localtime (respectively). Both of those are C89, and I hope you're not going to tell me C89 isn't generic. You should never need a time_t in the local timezone: All internal manipulation should be UTC (or whatever the system's time_t is), and the time should only be converted to display to the user.

    Also, most filesystems do use a "time_t". (most filesystems are *NIX filesystems, and are required to use something that is at the very least equivilant to time_t, for unix filesystem semantics to work.)

    The C runtime libraries are indeed generally written in C, and unless you're writing them, you shouldn't even consider implementing the same functionality yourself.

  • CleverShark (unregistered)

    A place where I used to work -- a very big bank, it might even be the world's biggest by now -- used to mandate that each one of their top-level managers offsource a certain percentage of their work. That was when I worked there. I have no reason to believe that things have changed since.

    THAT's why there's little incentive for offshore contractors to improve the product -- the money's gonna keep comin' anyway. Remember, these are the people who handle your money on a daily basis.

  • foo (unregistered)

    All of you don't seem to have much experience with PHP... before version 5.1 php could not reliably handle dates befor 1970, so if this code was supposed to handle them (which is suggested by the %7)+7)%7) stuff) in no way could they have used any of the built-in functions...

  • offshore one (unregistered)

    Yes, the code is terrible, in particular if the last line (return) was written as presented.

    But, David is also really bad programmer, if he thinks what was written. Also, calling PHP coder "programmer" is really stilted. I will not repeat where he is wrong and it suprises me how many people in these comments call themselves programmers that think that they can read and comment or even correct someone else's code - they can't.

    Let me share a funny experience with outsourcing. A major (Fortune 500) US company created a center in Central Europe. It happend that people on a project running in US needed some help, so they hired one man in that center. After five years, there was the same number of US based and CE based developers. The US based programmers were not able to do anything useful (except one, which was really excellent programmer), they didn't know even basics of object-oriented programming ("I was not trained to do ..." was their favorite sentence), and they even took GPL code and copied it into the (closed source) product - just deleted some of the comments. And that didn't happen only once. After seven years, only higher management stayed in US - there was no US developer on the project. 3/4 of them were fired, the rest went to steal GPL code to other projects within that company, the only good programmer left the company. Of course, the project continues, better than before, because it could be redesigned and rewritten when the US staff left, and the product sells pretty well.

    That's my experience about how good and honest are some programmers...

    Yes, I am biased - I am a former CE-based programmer on that project, I worked on it for a few years.

  • It's not as good as mine... (unregistered)

    int DateToDay(int InDay,int InMonth,int InYear) { // Returns the day of the week from the date int OutDayID;if(InMonth<3){InMonth+=12;InYear--;}OutDayID=(InDay+(((InMonth+1)26)/10)+(InYear%100)+((InYear%100)/4)+((InYear/100)/4)-(2(InYear/100)))%7;if(OutDayID<0)OutDayID+=7;return OutDayID-1;}

  • cheap jerseys (unregistered)

    cheap NFL Jersey Lewis says the Magic knew they couldcheap jordan jersey beat the Cavaliers in the Eastern Conference Finals cheap mlb jerseys when the the two teams cheap kobe jersey met for Game 2. cheap Paul Smith Shoes It took a miracle shot from LeBron James to beat Orlando cheap nfl jerseys amazing cheap nfl jerseys Bucks are looking very closely at every point guard available in the draft would make you cheap g star think Sessions replica jerseys walk, cheap lebron jersey but it's far replica NFL jerseys, NHL jerseys too early to know. In truth, the Bucks nfl jerseysthemselves haven't f teams are starting to think about what cheap diesel Villanueva would cheap football jerseys look like in their nba jerseysuniforms. One of themcheap penguins jersey might be the cheap baseball jerseys Cleveland Cavaliers. cheap NFL Jersey mlb jerseys cheap nfl jerseys James' no-show after Game 6, we're finally getting down to business. Dwight Howard nfl jerseys and Kobe Bryant will lace them up o decide cheap uggs the best team in cheap north face jacket the NBA. The Magic swept the season cheap jerseysseries from the Lakers, one of that feat (Charlotte was the other) cheap nhl jersey Raptors are they'd cheap tommy bahama also like to another selection there. With cheap moss jersey teams like L.A., Chicago, and Minnesota cheap nhl jersey selling that cheap mlb jerseys area, they're replica NFL jerseys, NHL jerseys likely to find cheap hockey jerseys someone they can work with.cheap nba jersey Portland, Houston cheap pierce jersey failed to shifts lebron james jersey back to Houston for Game 6 on Thursday as the Rockets scurry to make Jordan jerseys adjustments cheap nhl jerseys of the Blazers cheap ugg boots Grizzlies, and it's been cheap nba jerseys mentioned that that cheap nfl jerseys pick could be had as well. Most teamsbrady jersey looking to buy in cheap owens jersey are looking to buy into cheap ugg boots the late first/early second round. kobe jerseys Memphis has cheap baseball jersey picks potentially available cheap baseball jerseys in both those areas.cheap mlb jerseys Timberwolves use all three of their first round picks this year (6-18-28), and while it's all but certain they'll use cheap true religion jeans their #6 pick and probably the #18, replica jerseys that #28 could absolutely be had. For teamscheap nhl jerseys looking to buy into cheap nhl jerseys that part of the draft (see below), the Wolves cheap nhl jerseys

  • cheap jerseys (unregistered)

    City Original (www.cityoriginal.com) offers cheap NFL jerseys, cheap NHL jerseys, cheap NBA jerseys, cheap MLB Jerseys, cheap Ed Hardy, cheap UGGs, cheap True Religion, cheap Diesel, cheap G-Star, cheap paul smith shoes, cheap tommy bahama, and cheap North Face products. They guarantee the lowest and cheapest price possible.

  • cbd gummies (unregistered)
    Comment held for moderation.
  • HildamUp (unregistered)
    Comment held for moderation.

Leave a comment on “Making Time for UNIX”

Log In or post as a guest

Replying to comment #:

« Return to Article