Globally Fiscal Year

  • Pacifisto 2012-08-20 08:05
    "For loops? Of course I know what loops are for!"
  • Dennis 2012-08-20 08:08
    The WTF of the coder seems to be hiding inside the WTF of the language for me.
  • Some Jerk 2012-08-20 08:08
    Cobal programmers give me gas... or... well... this one just did.
  • Warren 2012-08-20 08:15
    But what happens if there's a June 31 one of those years? Huh?
  • Accalia.de.Elementia 2012-08-20 08:16
    You know there is something special in your code when it includes a global variable named "stirfry"
  • PedanticCurmudgeon 2012-08-20 08:32
    COBOL: 5 decades of giving dimwit programmers the illusion of competence.
  • Ron 2012-08-20 08:34
    I don't think that will be a problem very often. However, if the test date is either 6/30 or 7/1, then the answer will be wrong by as much as 20 years.
  • Rodnas 2012-08-20 08:35
    TRWTF is global variables </facepalm>
  • Ron 2012-08-20 08:38
    Never mind. That boundary actually works okay.
  • cobalistic 2012-08-20 08:40
    Even without object oriented programming, this programmer doesn't even understand the concept of data types. Also, he couldn't even give the function a clear name like strGetCurrentFiscalYear.

    CAPTCHA: incassum

    switch(myval)
    {
    incassum 1:
    // do something here
    break;
    incassum 2:
    // do something here
    break;


    }
  • Ana 2012-08-20 08:40
    Dim nnnnoooo As Comment
  • Smug Unix User 2012-08-20 08:45
    I call shenanigans. Real COBOL programmers only type in all caps.

  • taixzo 2012-08-20 08:51
    This makes two Remy Porter articles in a row with no HTML comments. And that, my friends, is the real WTF.
  • Bob 2012-08-20 08:51
    I don't get the COBOL reference. COBOL tends toward verbosity. Unless you're using the indicators...

    I would have thought that regular WTF readers would have grown out of the "language x is bad" mentality. There are few bad languages but many bad programmers. There's little correlation between the two. Apart from PHP.
  • Diego 2012-08-20 08:52
    Accalia.de.Elementia:
    You know there is something special in your code when it includes a global variable named "stirfry"


    It's actually strFY, which I guess means str(ing)F(iscal)Y(ear). The thing I wonders is what value does date3 have, I can't see an assignment anywhere.
  • Diego 2012-08-20 08:54
    Diego:
    Accalia.de.Elementia:
    You know there is something special in your code when it includes a global variable named "stirfry"


    It's actually strFY, which I guess means str(ing)F(iscal)Y(ear). The thing I wonders is what value does date3 have, I can't see an assignment anywhere.


    I correct myself, I found the assignment for date3. I'm getting old, I get easily confused betwen date1, date2, date3 or n-nn-nnnn-nnnnnnnnnnnnnnnnn. At least he didn't name variables _, __ or ____...
  • Some Jerk 2012-08-20 09:02
    Actually... it simply looks like novice code to me. It takes practice for a mind to refactor code so that it makes sense while creating it, and then experience to produce it with meaningfully named variables and such. This is the kind of thing that I would expect from a noob. I have trouble believing that his/her COBAL code was much better. This may be an example of someone who goes through the motions but clearly does not understand what they are doing.
  • John Hensley 2012-08-20 09:12
    Dim ffffuuuu
  • Zapp Brannigan 2012-08-20 09:12
    I've seen COBOL coders code in VB and this doesn't look very COBOL-like. The easiest way to tell is that some COBOLers have trouble with event oriented GUI. This programmer could just be a generic idiot.
  • Steve The Cynic 2012-08-20 09:22
    Diego:
    Diego:
    Accalia.de.Elementia:
    You know there is something special in your code when it includes a global variable named "stirfry"


    It's actually strFY, which I guess means str(ing)F(iscal)Y(ear). The thing I wonders is what value does date3 have, I can't see an assignment anywhere.


    I correct myself, I found the assignment for date3. I'm getting old, I get easily confused betwen date1, date2, date3 or n-nn-nnnn-nnnnnnnnnnnnnnnnn. At least he didn't name variables _, __ or ____...

    The confusion arises from the fact that date2 should be endOfPreviousFY and date3 should be startOfNextFY, which is what makes the < and > correct.

    Well, perhaps that should be "less brutally incorrect"...

    The worst, I think, is that the function returns an empty string or a NULL or something equally unsuitable if the year in PRF_strFY is before the year in strTest_Date.
  • some dude in Europa 2012-08-20 09:25
    Once again it shows the stupidity of the American date format.
  • the beholder 2012-08-20 09:27
    Some Jerk:
    Actually... it simply looks like novice code to me. It takes practice for a mind to refactor code so that it makes sense while creating it, and then experience to produce it with meaningfully named variables and such. This is the kind of thing that I would expect from a noob. I have trouble believing that his/her COBAL code was much better. This may be an example of someone who goes through the motions but clearly does not understand what they are doing.
    Maybe, but isn't he supposed to have that practice and mainly experience? He's a freaking COBOL coder, FFS! Anybody who works on it is near or past his sixties and have been using it since his early or mid-twenties.
  • radarbob 2012-08-20 09:37
    Its not COBOL the language, its the mind set. Once upon a time.... Coming into a shop that had moved the code base from UNISYS mainframe to PCs, I discovered our compiler supported COBOL 85 so I used the newer COBOL standard for a significant project. You should have seen the shock, yes, shock I say, on a couple of co-workers when they saw the code. No, it was not the "impressive, cool" kind, rather the "what the hell is this!" kind.

    The mainframe is a very isolating environment, if you know what I mean. That and a managerial in-breeding program makes for a very deeply rutted coding shop. And there are very common, classic "forms" in COBOL due the the nature (and limitations) of the language and the task at hand - generally sequential processing of very large record sets.

  • Mainframe Web Dev 2012-08-20 09:43

    This doesn't look like COBOL / CICS in any fashion.

    I would expect a function to create a data structure and a separate function for moving data into that structure.

    Or possibly, some bizare attempt of avoiding conditional statements since Cobol guys tend to write a log of JCL.

    Or maybe an implementation of the PICTURE command to format a string.

    Sorry, not seeing the COBOL influence here.

  • PiisAWheeL 2012-08-20 09:44
    Dim n As Integer
    Dim nn As Integer
    Dim nnn As Integer
    Dim nnnn As Integer

    C'mon... Everyone knows you use x, y, z, and sometimes a as generic counters.
  • Some Jerk 2012-08-20 09:49
    the beholder:
    Some Jerk:
    Actually... it simply looks like novice code to me. It takes practice for a mind to refactor code so that it makes sense while creating it, and then experience to produce it with meaningfully named variables and such. This is the kind of thing that I would expect from a noob. I have trouble believing that his/her COBAL code was much better. This may be an example of someone who goes through the motions but clearly does not understand what they are doing.
    Maybe, but isn't he supposed to have that practice and mainly experience? He's a freaking COBOL coder, FFS! Anybody who works on it is near or past his sixties and have been using it since his early or mid-twenties.


    Not really. There were plenty of psuedo-geeks in the 80s using cobal for BBS systems and dial-in RPGs and such. You will find that there are plenty of COBAL hacks in their 30s and 40s, who likely bought all of them source code magazines and books so they could make their own game of snake and whatever else.

    I guess the other explaination is that (s)he never actually understood coding to begin with... but instead learned specific patterns to use in specific situations, and his/her mind is too limited to produce something more elegant.
  • Remy Porter 2012-08-20 09:57
    I used to do a lot of training. A big part of my job was teaching state employees, who had done COBOL for longer than I had been alive, to do Java, C++ and .NET (not all at the same time). It's not COBOL that's a problem, but COBOL programmers are built into their habits. The idea of modeling an application as a collection of things and not a collection of steps is a really hard thing to grasp if you have 30 years of practice working the other way.
  • Accalia.de.Elementia 2012-08-20 10:08
    Diego:
    Diego:
    Accalia.de.Elementia:
    You know there is something special in your code when it includes a global variable named "stirfry"


    It's actually strFY, which I guess means str(ing)F(iscal)Y(ear). The thing I wonders is what value does date3 have, I can't see an assignment anywhere.


    I correct myself, I found the assignment for date3. I'm getting old, I get easily confused betwen date1, date2, date3 or n-nn-nnnn-nnnnnnnnnnnnnnnnn. At least he didn't name variables _, __ or ____...


    strFY is the correct name, however i think stirfry nicely encapsulates the effect of code that relies on global variables like this on a developer's brain.
  • Some Jerk 2012-08-20 10:53
    Why the OO red herring? It's not like there's an object oriented language in this story.
  • ubersoldat 2012-08-20 10:58
    Bob:
    I would have thought that regular WTF readers would have grown out of the "language x is bad" mentality. There are few bad languages but many bad programmers. There's little correlation between the two. Apart from PHP.


    +1!
  • C-Octothorpe 2012-08-20 10:59
    That's far too clear. For nested loops, you need to first start with i, then l, then j (for added job security).
  • foxyshadis 2012-08-20 11:05
    Some Jerk:
    Actually... it simply looks like novice code to me. It takes practice for a mind to refactor code so that it makes sense while creating it, and then experience to produce it with meaningfully named variables and such. This is the kind of thing that I would expect from a noob. I have trouble believing that his/her COBAL code was much better. This may be an example of someone who goes through the motions but clearly does not understand what they are doing.

    The Cabal is going to revoke your Code Card if you don't stop calling COBOL that.
  • Clayton 2012-08-20 11:09
    PiisAWheeL:
    Dim n As Integer
    Dim nn As Integer
    Dim nnn As Integer
    Dim nnnn As Integer

    C'mon... Everyone knows you use x, y, z, and sometimes a as generic counters.


    As a one-time COBOL programmer, my immediate fear upon seeing these was that they were carry-overs from part of the ENVIRONMENT DIVISION's WORKING-STORAGE SECTION. I'm a little sad (but mostly happy), to not see them shoehorned into a huge formatting mess.

    if( year < 10 ) { n = year } else if( year < 100 ) { nn = year } ...


    What a nightmare that would've been.
  • Some Jerk 2012-08-20 11:10
    foxyshadis:

    The Cabal is going to revoke your Code Card if you don't stop calling COBOL that.


    HE HE HE. Maybe if they give it a new name... people will start using it again :p

    Spelling wasn't always listed among my strengths... but I am good enough with respect to consistency that it more or less offsets the problem.
  • Zylon 2012-08-20 11:42
    PiisAWheeL:
    C'mon... Everyone knows you use x, y, z, and sometimes a as generic counters.

    You are TRWTF.
  • fa2k 2012-08-20 11:43
    It guarantees the ex-Cobol programmer some work in year PRF_strFY+21, when it starts returning NULL (or whatever the default return value in VB is)
  • ByNagesh 2012-08-20 11:47
    I saw this code before at a presentation given by Nagesh in HyperaBad ... All US companies with outsourced IT now have code like this.

    Soon, congress will change Fiscal year definitions (at the last moment, offcourse) because of problems with leap years
  • sagaciter 2012-08-20 11:52
    PiisAWheeL:
    Dim n As Integer
    Dim nn As Integer
    Dim nnn As Integer
    Dim nnnn As Integer

    C'mon... Everyone knows you use x, y, z, and sometimes a as generic counters.

    For counting loops I use the prefix LI (loop iterator) for clarity, i.e. lI1, lI2, ...
  • RichP 2012-08-20 11:53
    Um no, you use i, j, k and sometimes m as generic counters.

    (cue religious war akin to camelCase versus name_with_underscore)
  • dkallen 2012-08-20 12:03
    PiisAWheeL:
    Dim n As Integer
    Dim nn As Integer
    Dim nnn As Integer
    Dim nnnn As Integer

    C'mon... Everyone knows you use x, y, z, and sometimes a as generic counters.


    I think you're confusing FORTRAN with COBOL. And doing it incorrectly.
  • PiisAWheeL 2012-08-20 12:26
    dkallen:
    PiisAWheeL:
    Dim n As Integer
    Dim nn As Integer
    Dim nnn As Integer
    Dim nnnn As Integer

    C'mon... Everyone knows you use x, y, z, and sometimes a as generic counters.


    I think you're confusing FORTRAN with COBOL. And doing it incorrectly.
    Fortran? Cobol? I make php alphabet soup with those variables.
  • kbiel 2012-08-20 12:58
    Should have gotten the COBOL programmer a license for a .NET COBOL compiler, because VB.NET wasn't WTF enough for s/he/it.
  • Some Jerk 2012-08-20 13:09
    More EBiggotry ... eh?
  • Some Jerk 2012-08-20 13:35
    Double-click the pretty print code for lulz.
  • Minos 2012-08-20 13:59
    n nnn, nnnn, hey hey hey, good bye!
  • PedanticCurmudgeon 2012-08-20 14:15
    sagaciter:
    PiisAWheeL:
    Dim n As Integer
    Dim nn As Integer
    Dim nnn As Integer
    Dim nnnn As Integer

    C'mon... Everyone knows you use x, y, z, and sometimes a as generic counters.

    For counting loops I use the prefix LI (loop iterator) for clarity, i.e. lI1, lI2, ...
    +1, very evil, but not very original.
  • Nagesh 2012-08-20 14:25
    PedanticCurmudgeon:
    COBOL: 5 decades of giving dimwit programmers the illusion of competence.


    Everyone know many big systems developed by big company like IBM still run on COBOL. COBOL: giving lot of business to developers in India.
  • PedanticCurmudgeon 2012-08-20 14:57
    Nagesh:
    PedanticCurmudgeon:
    COBOL: 5 decades of giving dimwit programmers the illusion of competence.


    Everyone know many big systems developed by big company like IBM still run on COBOL. COBOL: giving lot of business to developers in India.


    Your honor, I rest my case.
  • Soviut 2012-08-20 15:06
    Bob:
    I would have thought that regular WTF readers would have grown out of the "language x is bad" mentality. There are few bad languages but many bad programmers. There's little correlation between the two. Apart from PHP.


    It isn't a matter of one language being worse than another, it's a matter of a developer coming from one language and treating the new language like it's the old one. Coding python like it's C#, coding Ruby like it's Javascript, etc.
  • Spewin Coffee 2012-08-20 15:09
    TRWTF is your incredibly false assumption that PHP is a bad language and all programmers who write in PHP are writing bad code. I will agree with anyone that says that PHP makes it easy to write bad code because you can do the same thing about 25 different ways of which only two of those ways is correct. Although, the same can be said of C++ and other languages that hand you powerful tools to work with. In the hands of a novice, you get crap output for both of the languages I mentioned because it takes years to master which of the 25 different ways to accomplish a task is the correct approach.

    There are many bad languages (APL, Prolog, LISP, COBOL, any assembly language, Ruby without Rails, etc.) and many bad programmers - the latter are what this site is dedicated to exposing to the world. Worse Than Fails happen any time you mix the two. If you think otherwise, you haven't been programming as long as I have. Interestingly, I can generally identify bad programmers a mile away by how poorly they use whitespace, where they place their comments, variable and function names, and the content of the comments. Basically, is the code elegant or not? That tells me more about their coding and personal habits (including hygiene) than anything else.

    Your inane comment, Bob, indicates you might be a bad programmer. Or at least clueless.
  • PedanticCurmudgeon 2012-08-20 15:29
    Spewin Coffee:
    Interestingly, I can generally identify bad programmers a mile away by how poorly they use whitespace, where they place their comments, variable and function names, and the content of the comments.
    So where do bad programmers place their comments?
  • Some Jerk 2012-08-20 15:33
    :p EBiggotry is the 2nd biggest activity on the daily wtf... though I wish it would go away.

    I should point out (however) that Bob's comment was somewhat ambiguous... and he was not necessarily saying what you seem to have taken away from that message. I read it as (the quality of php is fully subject to the quality of the developer, unlike most other languages).. which I take to mean that PHP has a significant number of options that are unusual to find in programming languages (which is true) and bad programmers tend to be inconsistent. Inconsistency with php makes a much bigger mess than it does with more rigid languages.

    That said... I disagree with your comment about "the right way". In the programming world, "the right way" is an amorphis ideal that is given form only by the collection of individuals who interact with it and the competence with which the technology is leveraged. Coupled with consistency and adherance to more publically accepted standards, there are still a hundred paths to the same door (as it were).

    Still... I stand behind my previous comments that the programming language of choice for a developer says about as much about their competance, intelligence and ability as their height and eye color.
  • Some Jerk 2012-08-20 15:34
    PedanticCurmudgeon:
    Spewin Coffee:
    Interestingly, I can generally identify bad programmers a mile away by how poorly they use whitespace, where they place their comments, variable and function names, and the content of the comments.
    So where do bad programmers place their comments?


    // TODO: Place a comment here.
  • AE 2012-08-20 15:36
    PiisAWheeL:
    C'mon... Everyone knows you use x, y, z, and sometimes a as generic counters.


    Ah but by just using one letter repeated multiple times he can change the naming convention for all counters across the board by Find and Replace 'n'. Really it's very foresighted.
  • Unisol 2012-08-20 15:40
    Goddamn it, Remy, I come here to see unicorns and now you're dissapointing me.
  • Kasper 2012-08-20 15:42
    Bob:
    I don't get the COBOL reference.
    And I have never touched COBOL, so I don't get it either. But could it have something to do with the way he is passing parameters to a function through global variables?

    (CAPTCHA: vindico. I didn't even have to type it all, as my browser could remember it from last time I got the same.)
  • Old fart 2012-08-20 15:44
    A "real" COBOL fanatic would have used thirty-two character variable names, at the least. Longer if the eighty-character punched cards had additional space before column seventy-two.

    Ask me how I know.
  • Daniel 2012-08-20 15:49
    The "COBOL" was the self-professed skill of the original author. That's the reference. Also, if you've done any COBOL, the block of declaration at the top is eerily reminiscent of the WORKING-STORAGE SECTION. Heck, at least this one is actually in the function!

    But, even in COBOL, this is crappy COBOL; to determine an FY, you just need the cut-off date. Then, a quick comparison of the month in numeric format will render an easy answer (the year, or the year plus one). An up-to-20-iteration loop to figure that out? Just because the cycles are quick doesn't mean we should use more than we need. :)

    To me, this illustrates perfectly the adage that "you can code crappy COBOL in any language".
  • SG_01 2012-08-20 16:33

    stryear2 = stryear2 - 1

    Can someone tell me what this is even supposed to do? Remove a 1 character from the string or somesuch?

    "abcdefg" - 1 does not make much sense to me.
  • PiisAWheeL 2012-08-20 16:41
    AE:
    PiisAWheeL:
    C'mon... Everyone knows you use x, y, z, and sometimes a as generic counters.
    Ah but by just using one letter repeated multiple times he can change the naming convention for all counters across the board by Find and Replace 'n'. Really it's very foresighted.
    Whats wrong with find and replace 'x'. Your keyboard missing the "x" key?
    PedanticCurmudgeon:
    Spewin Coffee:
    Interestingly, I can generally identify bad programmers a mile away by how poorly they use whitespace, where they place their comments, variable and function names, and the content of the comments.
    So where do bad programmers place their comments?
    I want to play. I'll tell you where I place my comments and you tell me, on a scale of 1-10, where I stand.
    I put my "Explain what the function does" comment right above the function. I put all my "block explaination" comments right above the if/while/whatever statement. My "individual line" comments (when required) are either at the end of the line in question or right above it.


    //This function bla bla bla
    function func_name(x,y,and,z)
    {
    //someshit deals with someshit
    if (x >= wtfery)
    {
    //something not obvious or complicated
    x++; //Sometimes i put something not obvious or complicated here.
    }
    ...
    }

    How'd I do?
  • PiisAWheeL 2012-08-20 16:44
    SG_01:

    stryear2 = stryear2 - 1

    Can someone tell me what this is even supposed to do? Remove a 1 character from the string or somesuch?

    "abcdefg" - 1 does not make much sense to me.
    My best guess (without context of the global variable) is that the variable is the current year, and we are subtracting to get last year, so we can fiscally balance between then and the current year. Does it work? I don't know.
  • Zylon 2012-08-20 16:47
    Unisol:
    Goddamn it, Remy, I come here to see unicorns and now you're dissapointing me.

    Then go visit www.comeheretoseeunicorns.com.
  • Cbuttius 2012-08-20 16:48
    Does it work? Does it do what it is supposed to do?

    I am not sure what it means to subtract 1 from a string. I am surprised that compiles, even in VB.

  • Cbuttius 2012-08-20 16:49
    except of course I forgot:

    it makes no sense. It doesn't compile. It doesn't work with any business logic. And it doesn't exist. It's a made up WTF as usual.
  • AGray 2012-08-20 17:00
    So, I counted some WTFs in this snippet:

    1: Variables.
    nn, nnn, nnnn are not used in any way.
    All the names are undescriptive.
    strYear2 could have just been passed into this function (bonus points would have been given for effort if it was abbreviated, but descriptive, for instance 'curFiscalYr'.)

    2: Execution
    n = 20 ... Do Until n = 0 ... n = n - 1 ... Loop is a For loop that should have happened, but did not. :(
    Date2 and Date3 should be defined and used within the loop. Oh, and named something that makes sense, without performing mental mapping.

    CAPTCHA: tristique - This code has a certain 'tristique'...ok, that sounded cooler in my head.
  • rfoxmich 2012-08-20 17:23
    I don't get it. Where are the PICTURE clauses?
  • DaveK 2012-08-20 17:28
    PiisAWheeL:
    Dim n As Integer
    Dim nn As Integer
    Dim nnn As Integer
    Dim nnnn As Integer

    C'mon... Everyone knows you use x, y, z, and sometimes a as generic counters.
    Ever since the days of BASIC (where spaces were not significant), I always used i, j and k. That way, if you are ever tempted to write a triply-nested loop, you find yourself writing "FORK=....".

    Which reminds you that you have indeed forked up.

  • Some Jerk 2012-08-20 17:29
    '' VB.NET
    public Function FiscalYear(dateItem As DateTime)
    return IIF( dateItem.Month > 6, dateItem.Year +1, dateItem.Year )
    End Function

    ''' Call with FiscalYear(DateTime.Now).ToString() to get string version


    '' VB6
    Function FiscalYear(dateItem As Date)
    FiscalYear = IIF( dateItem.Month > 6, dateItem.Year +1, dateItem.Year )
    end Function
    '' call with cstr(FiscalYear(Now()))



    ''' THE REAL WTFs.... why return a string to represent an int? And this role can be performed with one line of code.
  • Z 2012-08-20 17:29
    A new software developed in VB6 by a COBOL programmer... what can possibly go wrong?
  • soei 2012-08-20 17:41
    Oh, I get it....nn, nnn and nnnn are never used? Or is it that they break the convention used for other variables, and should have been n1, n2, n3, n4 ?
  • Jim 2012-08-20 18:02
    RichP:
    Um no, you use i, j, k and sometimes m as generic counters.

    (cue religious war akin to camelCase versus name_with_underscore)
    in CS101 they taught me to use meaningful names. I have:
    counter, loopCounter, iter, count and a plethora of others...
    Of course, to avoid a massive increase in typing, I still use i and then find-replace all i's with count.

    on a totally unrelated note, I found some serious issues in a program I inherited the other day. I don't even know how it compiled for my predecessor:

    publcountc countnt macountn(vocountd)
    {
    for(count=0; count<1000; count++)
    {
    countf(count%5 == 0)
    {
    System.out.prcountntln(count + "counts Dcountvcountscountble by fcountve");
    }
    }
    }
  • wooly 2012-08-20 18:09
    Spewin Coffee:
    TRWTF is your incredibly false assumption that PHP is a bad language and all programmers who write in PHP are writing bad code. I will agree with anyone that says that PHP makes it easy to write bad code because you can do the same thing about 25 different ways of which only two of those ways is correct. Although, the same can be said of C++ and other languages that hand you powerful tools to work with. In the hands of a novice, you get crap output for both of the languages I mentioned because it takes years to master which of the 25 different ways to accomplish a task is the correct approach.

    There are many bad languages (APL, Prolog, LISP, COBOL, any assembly language, Ruby without Rails, etc.) and many bad programmers - the latter are what this site is dedicated to exposing to the world. Worse Than Fails happen any time you mix the two. If you think otherwise, you haven't been programming as long as I have. Interestingly, I can generally identify bad programmers a mile away by how poorly they use whitespace, where they place their comments, variable and function names, and the content of the comments. Basically, is the code elegant or not? That tells me more about their coding and personal habits (including hygiene) than anything else.

    Your inane comment, Bob, indicates you might be a bad programmer. Or at least clueless.
    I agree with some of this.

    Bad programmers can make any language look bad - and unfortunately a language that forced people to be good programmers wouldn't be very useful...(that's the job of the tertiary educators).

    Coding Style speaks volumes, partly because you can see whether the mindset is thinking maintainability, partly because you can really see whether someone understands (or conversely has copied StackOverflow) based on the structure and commenting and partly (tying back into point 1) someone who structures code readably has probably learnt (likely the hard way) that they will need to be able to find bugs in it later.

    Interestingly, you can often even pick the dick who thinks he's clever (and may be) by writing (possibly unintentionally) obfuscated code vs the dick who has no clue to what he's doing....
  • wooly 2012-08-20 18:09
    PedanticCurmudgeon:
    Spewin Coffee:
    Interestingly, I can generally identify bad programmers a mile away by how poorly they use whitespace, where they place their comments, variable and function names, and the content of the comments.
    So where do bad programmers place their comments?
    on TDWTF of course....
  • ok 2012-08-20 18:29
    Old fart:
    A "real" COBOL fanatic would have used thirty-two character variable names, at the least. Longer if the eighty-character punched cards had additional space before column seventy-two.

    Ask me how I know.
    How do you know?
  • Remy Porter 2012-08-20 18:43
    I code every language like I'm programming LISP. Or, worded another way, (like (code (languages)) LISP).
  • Gary Olson 2012-08-20 19:01

    Dim date1 As Date
    Dim date2 As Date
    Dim date3 As Date

    Yes, I've met these 3 ladies. Thank God for beer.
  • Meep 2012-08-20 19:05
    Remy Porter:
    I used to do a lot of training. A big part of my job was teaching state employees, who had done COBOL for longer than I had been alive, to do Java, C++ and .NET (not all at the same time). It's not COBOL that's a problem, but COBOL programmers are built into their habits. The idea of modeling an application as a collection of things and not a collection of steps is a really hard thing to grasp if you have 30 years of practice working the other way.


    Seems more like the problem is the blind are leading the blind.
  • Ken 2012-08-20 19:33
    I am not biased I have 10 years of cobol under my belt and worked on the programming standard for cobol.

    Cobol is a globally scoped programming language and while you can call other modules from one source to another and have good scoping rules it is universally never taught and frowned upon by the top coders. For any serious cobol program it is a minimum of 10,000 lines with declarations at the top and a hopefully a naming and grouping standard to keep them grouped for to you make sense of it.

    While the language is not universally bad as a rule of thumb the application of it is.

    I have taught new languages a few cobol coders in my time and it is always 'interesting' at first as they learn for the first time to modularise.
  • Meep 2012-08-20 19:47
    Spewin Coffee:
    TRWTF is your incredibly false assumption that PHP is a bad language and all programmers who write in PHP are writing bad code.


    Except that the reason certain features were changed in PHP was that they were security holes.

    Everyone who was writing to the spec was writing bad code. When they disallowed those constructs, they forced everyone to write better code.

    So are you going to argue that PHP 4 is just as good as PHP 5.5? When the majority of code written in a language is shit, it means the language itself is flawed, and good coders will gravitate towards a better language.

    If it's all just the fault of bad programmers, no one would ever bother fixing languages.

    For example: Java was greatly improved by adding an Enum type. Why? The idioms actual programmers used were half-baked, and the Enum type meant that you didn't have to carefully study the perfect enumerated type class just to do something that should have been simple. That caused programmers to write better code.

    But there are many things about PHP that are just fundamentally broken, like the awful type system, the awful object system, their love of global state and so forth. But there's a group-think among web developers that takes pride in a kludgey mess, and people who don't want to code that way don't use PHP. So the language *and* the larger community are responsible for the fact that it still sucks. What's sad is that all this web stuff will before long become fossilized like all the horrible awk and sed stuff.
  • facilisis 2012-08-20 20:11
    Jim:
    RichP:
    Um no, you use i, j, k and sometimes m as generic counters.

    (cue religious war akin to camelCase versus name_with_underscore)
    in CS101 they taught me to use meaningful names. I have:
    counter, loopCounter, iter, count and a plethora of others...
    Of course, to avoid a massive increase in typing, I still use i and then find-replace all i's with count.

    on a totally unrelated note, I found some serious issues in a program I inherited the other day. I don't even know how it compiled for my predecessor:

    publcountc countnt macountn(vocountd)
    {
    for(count=0; count<1000; count++)
    {
    countf(count%5 == 0)
    {
    System.out.prcountntln(count + "counts Dcountvcountscountble by fcountve");
    }
    }
    }



    I don't see why some pissants mind single-char variables for controlling short loops. They are insignificant in terms of the purpose of the loop - why bloat the code with a mile-long variable, just so that you can avoid seeing "n" or "i" or whatever?

    Now, I can understand wanting something better than a bunch of different single-char loop-counters in nested loops, but otherwise - in a single-level loop - if you replace my i's with your dumb counter's, for no other apparent reason, expect them to be replaced back (for no other apparent reason).
  • Veldan 2012-08-20 20:12
    Meep:
    Spewin Coffee:
    TRWTF is your incredibly false assumption that PHP is a bad language and all programmers who write in PHP are writing bad code.


    ...

    But there are many things about PHP that are just fundamentally broken, like the awful type system, the awful object system, their love of global state and so forth. But there's a group-think among web developers that takes pride in a kludgey mess, and people who don't want to code that way don't use PHP. So the language *and* the larger community are responsible for the fact that it still sucks. What's sad is that all this web stuff will before long become fossilized like all the horrible awk and sed stuff.


    http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/

    This is pretty much the handbook behind why PHP is fundamentally broken. I am usually the first to jump to the defense of languages and am very willing to blame developers. However, with PHP it just isn't that simple.

    You can develop well in PHP but it is a much harder task than basically every other language. This makes it a bad language. Your tools should assist you, not hinder you.
  • kbar 2012-08-20 20:21
    If you grew up on Fortran everyone knows that I thru N are integers, everything else is a real.
  • VB6? 2012-08-20 20:54
    VB6 is an object oriented language?
  • GOML 2012-08-20 20:57
    Or he was one of those who picked it up during the Y2K bug and just never quit like he should have.

    Captcha: damnum

    Damnum! Damnum all to hell!
  • Jimbo 2012-08-20 21:21
    Meep:
    Spewin Coffee:
    TRWTF is your incredibly false assumption that PHP is a bad language and all programmers who write in PHP are writing bad code.


    Except that the reason certain features were changed in PHP was that they were security holes.

    Everyone who was writing to the spec was writing bad code. When they disallowed those constructs, they forced everyone to write better code.

    So are you going to argue that PHP 4 is just as good as PHP 5.5? When the majority of code written in a language is shit, it means the language itself is flawed, and good coders will gravitate towards a better language.

    If it's all just the fault of bad programmers, no one would ever bother fixing languages.

    For example: Java was greatly improved by adding an Enum type. Why? The idioms actual programmers used were half-baked, and the Enum type meant that you didn't have to carefully study the perfect enumerated type class just to do something that should have been simple. That caused programmers to write better code.

    But there are many things about PHP that are just fundamentally broken, like the awful type system, the awful object system, their love of global state and so forth. But there's a group-think among web developers that takes pride in a kludgey mess, and people who don't want to code that way don't use PHP. So the language *and* the larger community are responsible for the fact that it still sucks. What's sad is that all this web stuff will before long become fossilized like all the horrible awk and sed stuff.
    NEWS FLASH: Programmers gravitate toward the languages that there are plenty of jobs advertised for. Hobby programmers (or people running their own shops) might have the luxury of choosing their favourite languages, but most of us plebs have to suffer whatever is convenient for the organisation we work for - which often means something that was chosen 10 years ago by a mnagemnt type who had a vague idea that his underlings did nothing but played solitaire all day and the magick happened because he held meetings...

    As the web developed to the point where CGI (Common Gateway interface, not any of the other CGIs) became cumbersome (C programmers using perl, anyone?) the like of PHP (and to a degree JavaScript) became real common. As a lot of traditional programmers were a little anti web development (a web page/site is something any idiot graphic designer can do, right?) a lot of roles in PHP were available, and not a lot of talent was really going for it (there were far more important things to do in the very trendy Java and C# became pretty popular for app development too) so a lot of "google'n'learn" types picked up the most basic ideas of PHP and made a career out of it....

    This still doesn't make PHP itself crap. Nor does it make any of the other languages better...

    I actually think modern languages over-simplify a lot of concepts. While this helps the experienced developer finish tasks more quickly, it often encourages inexperienced developers to right code that is memory (and often time) inefficient. In the old days (you know like before the 80s and 90s ;) ) the programmers would create their own little tools to auto-generate bits of code or simplify little tasks. That is, the individual would have an overhead of crafting their own tools to increase their efficiency. THis obviously would mean that projects take a little longer, because the effort to design these tools is absorbed somewhere, but it also generally meant a better result, because the programmer would have a better understanding of how any auto-generation occured and (more importanbtly) would have a far better understanding of how system resources work and are managed.

    I often get on a hobby horse about inefficient code, and the usual response is "Who cares? We have shirtloads of resources these days". I find this attitude a bit scary - while our resources often can absorb a lot of inefficiency it's no excuse to produce crap. The system you desing for 10 users today might have 100 users tomorrow, and 1000 users next week. The only time you are allowed to write stuff inefficiently is when you are making an app for yourself that will only ever run on your desktop - and even then, why limit the number of programs you can have open at any given time?
  • jumentum 2012-08-20 21:23
    facilisis:
    Jim:
    RichP:
    Um no, you use i, j, k and sometimes m as generic counters.

    (cue religious war akin to camelCase versus name_with_underscore)
    in CS101 they taught me to use meaningful names. I have:
    counter, loopCounter, iter, count and a plethora of others...
    Of course, to avoid a massive increase in typing, I still use i and then find-replace all i's with count.

    on a totally unrelated note, I found some serious issues in a program I inherited the other day. I don't even know how it compiled for my predecessor:

    publcountc countnt macountn(vocountd)
    {
    for(count=0; count<1000; count++)
    {
    countf(count%5 == 0)
    {
    System.out.prcountntln(count + "counts Dcountvcountscountble by fcountve");
    }
    }
    }



    I don't see why some pissants mind single-char variables for controlling short loops. They are insignificant in terms of the purpose of the loop - why bloat the code with a mile-long variable, just so that you can avoid seeing "n" or "i" or whatever?

    Now, I can understand wanting something better than a bunch of different single-char loop-counters in nested loops, but otherwise - in a single-level loop - if you replace my i's with your dumb counter's, for no other apparent reason, expect them to be replaced back (for no other apparent reason).
    I thinks ye been trolled....
  • Frogger 2012-08-20 21:25
    Jimbo:
    Meep:
    Spewin Coffee:
    TRWTF is your incredibly false assumption that PHP is a bad language and all programmers who write in PHP are writing bad code.


    Except that the reason certain features were changed in PHP was that they were security holes.

    Everyone who was writing to the spec was writing bad code. When they disallowed those constructs, they forced everyone to write better code.

    So are you going to argue that PHP 4 is just as good as PHP 5.5? When the majority of code written in a language is shit, it means the language itself is flawed, and good coders will gravitate towards a better language.

    If it's all just the fault of bad programmers, no one would ever bother fixing languages.

    For example: Java was greatly improved by adding an Enum type. Why? The idioms actual programmers used were half-baked, and the Enum type meant that you didn't have to carefully study the perfect enumerated type class just to do something that should have been simple. That caused programmers to write better code.

    But there are many things about PHP that are just fundamentally broken, like the awful type system, the awful object system, their love of global state and so forth. But there's a group-think among web developers that takes pride in a kludgey mess, and people who don't want to code that way don't use PHP. So the language *and* the larger community are responsible for the fact that it still sucks. What's sad is that all this web stuff will before long become fossilized like all the horrible awk and sed stuff.
    NEWS FLASH: Programmers gravitate toward the languages that there are plenty of jobs advertised for. Hobby programmers (or people running their own shops) might have the luxury of choosing their favourite languages, but most of us plebs have to suffer whatever is convenient for the organisation we work for - which often means something that was chosen 10 years ago by a mnagemnt type who had a vague idea that his underlings did nothing but played solitaire all day and the magick happened because he held meetings...

    As the web developed to the point where CGI (Common Gateway interface, not any of the other CGIs) became cumbersome (C programmers using perl, anyone?) the like of PHP (and to a degree JavaScript) became real common. As a lot of traditional programmers were a little anti web development (a web page/site is something any idiot graphic designer can do, right?) a lot of roles in PHP were available, and not a lot of talent was really going for it (there were far more important things to do in the very trendy Java and C# became pretty popular for app development too) so a lot of "google'n'learn" types picked up the most basic ideas of PHP and made a career out of it....

    This still doesn't make PHP itself crap. Nor does it make any of the other languages better...

    I actually think modern languages over-simplify a lot of concepts. While this helps the experienced developer finish tasks more quickly, it often encourages inexperienced developers to right code that is memory (and often time) inefficient. In the old days (you know like before the 80s and 90s ;) ) the programmers would create their own little tools to auto-generate bits of code or simplify little tasks. That is, the individual would have an overhead of crafting their own tools to increase their efficiency. THis obviously would mean that projects take a little longer, because the effort to design these tools is absorbed somewhere, but it also generally meant a better result, because the programmer would have a better understanding of how any auto-generation occured and (more importanbtly) would have a far better understanding of how system resources work and are managed.

    I often get on a hobby horse about inefficient code, and the usual response is "Who cares? We have shirtloads of resources these days". I find this attitude a bit scary - while our resources often can absorb a lot of inefficiency it's no excuse to produce crap. The system you desing for 10 users today might have 100 users tomorrow, and 1000 users next week. The only time you are allowed to write stuff inefficiently is when you are making an app for yourself that will only ever run on your desktop - and even then, why limit the number of programs you can have open at any given time?
    Uhm....no
  • Some Jerk 2012-08-20 21:51
    VB6?:
    VB6 is an object oriented language?

    no ... it emulates some object oriented practices. For one thing, vb6 does not support inherritence... wich limits the capacity for reusable code. The data types are generally adaptive and interchangable, though you can enforce some degree of strong typing. For all that however, it was damned useful in the classic ASP days.
  • Coder Hero 2012-08-20 21:52
    Zylon:
    Unisol:
    Goddamn it, Remy, I come here to see unicorns and now you're dissapointing me.

    Then go visit www.comeheretoseeunicorns.com.


    I was really hoping that was a real domain.
  • Some Jerk 2012-08-20 21:56
    soei:
    Oh, I get it....nn, nnn and nnnn are never used? Or is it that they break the convention used for other variables, and should have been n1, n2, n3, n4 ?
    I don't care what language you are using... if the names of your variables are not either 1: meaningful, or 2: obvious based on direct usage, they are simply wrong. Also... yes, it is a bad practice to declare variables that you are not using. In most languages, memory is reserved for these variables... but more to the point, it is misleading.

    One aspect of coding that should always be observed is that other coders should generally have as easy of a time maintaining your code as possible. The less time we spend trying to figure out whether a variable named nnnn is used, and if so then where... the more time we can spend on doing something useful with the software we are charged to maintain.
  • hewey 2012-08-20 22:12
    Is it just me, or are today's trolls more successful than usual?

  • Cheong 2012-08-20 22:15
    Every programming language has it's own set of idomatic expressions.

    Just don't bring them into another obviously different programming languages.
  • foo2 2012-08-21 01:59
    Cbuttius:
    Does it work? Does it do what it is supposed to do?

    I am not sure what it means to subtract 1 from a string. I am surprised that compiles, even in VB.


    VB happily 'fixes' the types for you, and as expected is not a good idea. It will usually compile, and often fail when run. Consider:

    Dim A As String
    A = 5
    A = A - 1

    VB convert the 5 to a string, and then converts A to an integer before doing the decrement.

    Decent programmers force the type changes:

    Dim A As String
    A = Str(5)
    A = Str(Val(A) - 1)

    (In this simple case both bits of code with run identically.)

    Programmers with a clue make A an integer in the first place.

    Then you get stuff like this:

    A = "1" + "1"

    The result, of course, is 11. However:

    A = "1" + 1

    ...is 2, either a string or integer depending on how A was declared. As a bonus the string has a space in from of it (a placeholder for the - sign), ie " 11", not "11". Most people use Format() instead of Str() to avoid that.

    MS deprecated using + for string concatenation, replacing it with & instead to prevent this stuff.

    As for the WTF, VB has a bunch of date calculation functions, again showing the real WTF is people, not the language.
  • Soviut 2012-08-21 02:33
    Spewin Coffee:
    I will agree with anyone that says that PHP makes it easy to write bad code because you can do the same thing about 25 different ways of which only two of those ways is correct.


    It's an "enough rope to hang themselves with" language. VB and C++ fall into this category as well. While C++ gives Rube-Goldberg-like powers to the over engineering veteran, VB lets the amateur get their feet wet enough that they're soon neck deep, while PHP simply drowns the child given long enough.

    One might attach the "easy to pick up, difficult to master" adage to PHP. Which is great for games, but not for writing manageable, secure websites.
  • Soviut 2012-08-21 02:36
    foo2:
    VB happily 'fixes' the types for you, and as expected is not a good idea. It will usually compile, and often fail when run.


    Isn't there a strict mode you can set that requires variables be explicitly typed?

    EDIT: Ah yes, Option Explicit is what it was called. It's been a long long while.
  • Soviut 2012-08-21 02:39
    Some Jerk:
    I don't care what language you are using... if the names of your variables are not either 1: meaningful, or 2: obvious based on direct usage, they are simply wrong. Also... yes, it is a bad practice to declare variables that you are not using. In most languages, memory is reserved for these variables... but more to the point, it is misleading.


    Agreed! It would be like a book having a table of contents that referred to chapters that didn't actually exist. It doesn't "break" the book, but it's certainly confusing to discover the mismatch. Or perhaps a more practical example would be finding extra parts after assembling your Ikea furniture, leaving you to wonder if they were necessary or not.
  • Soviut 2012-08-21 02:51
    Jimbo:
    I often get on a hobby horse about inefficient code, and the usual response is "Who cares? We have shirtloads of resources these days". I find this attitude a bit scary - while our resources often can absorb a lot of inefficiency it's no excuse to produce crap. The system you desing for 10 users today might have 100 users tomorrow, and 1000 users next week. The only time you are allowed to write stuff inefficiently is when you are making an app for yourself that will only ever run on your desktop - and even then, why limit the number of programs you can have open at any given time?


    Remember the "triangle of requirements" (as I'm titling it just now). On each corner is marked "fast", "cheap" and "good" respectively. Now you have to pick a side. If you want it fast and cheap, it won't be good; If you want it fast and good, it won't be cheap, etc.

    Optimization is good, but only when it's valuable. For example, a script that's run once a month and takes 1 second to complete does not need a developer spending months, days, or even hours optimizing it, since the value on the return is negligible. When someone disregards an optimization pass on their software, it's usually because it isn't worth it.

    Optimization should be reactive. If a website only gets 5 visitors a day, it isn't valuable enough to warrant the optimization. However, if traffic increases to 50,000 visitors a day then the value of optimization increases and becomes worth pursuing. Software is never "done" and it's never perfect, so trying to pre-optimize often just leads to a lost of wasted time...far more than the optimizations would have saved.
  • ochrist 2012-08-21 03:01
    This is nothing, and as other people have pointed out it doesn't look very much like COBOL.

    Btw. it's spelled C O B O L (COmmon Business Oriented Language), not to be confused with COMAL (COMmon Algorithmic Language), which is a BASIC variant.

    I once had to clean up code after an old COBOL coder, and it was a complete and utter mess. At the time I was lead developer/team leader in a small shop, and one of my colleagues was asked to implement something in Delphi (this was way back with Delphi 2, as far as I remember). The task involved reading a few input files, compute something, and then produce some output files.

    So how did this genius solve this not too complicated problem? By reading and writing all kinds of temporary files with strange filenames and short unintelligble record names. There was no system in it at all, and I'm not even sure he had read any of the requirements. It looked like he expected to be able to reinvent JCL and COBOL in Delphi and mix it all together in something best described as spaghetti code.

    We didn't understand why it didn't work as expected, and it was only when that guy left the company, we discovered this mess. I had to rewrite most of the code from scratch (and I believe my successor eventually moved the whole codebase to another platform).

    PS: COBOL is actually not that bad. It's paid my salary for several years, and I occasionally still work with COBOL or something very similar.
  • Zero_Cool 2012-08-21 03:51
    Really weird, I used to use exactly the same "naming convention" when I started programming. When I was 6 years old.

    This is the first time I see the exact same names. It's kind of weird. and sad.
  • minime 2012-08-21 04:21
    please fix this goddamn "cant find brush for java" bug on the frontpage, it is fucking annoying.
  • David Martensson 2012-08-21 04:48
    Bob:
    I don't get the COBOL reference. COBOL tends toward verbosity. Unless you're using the indicators...

    I would have thought that regular WTF readers would have grown out of the "language x is bad" mentality. There are few bad languages but many bad programmers. There's little correlation between the two. Apart from PHP.


    Cobol is, at least last I looked at it, very iterative and very verbose.

    The reference is not that cobol is a bad language but rather that it is more distant from modern OOL than normal English.

    In that respect a Cobol programmer might keep on using coding styles that you have to use in Cobol that are unnecessary cumbersome for other language.

    A new programmer do not have any old fashion styles.
  • exquisitus 2012-08-21 05:02
    I do not get the "regular WTF readers" reference. If you are a "WTF reader", how can you be regular?
  • Nagesh 2012-08-21 06:21
    exquisitus:
    I do not get the "regular WTF readers" reference. If you are a "WTF reader", how can you be regular?


    Regular mean people who sign on daily like Cockthorpe and PedanticCurdleman.

  • Cbuttius 2012-08-21 07:12
    I am looking at the code. It is obvious what the logic is:

    If the date is in the first half of the year, then the result is the current year, otherwise it is year + 1.

    The fact the code works is a WTF of the language, albeit that VB supports Excel where you type in text and it gets interpreted into dates or numbers. Now I can sort-of understand that in Excel but in a proper language I would expect type safety so a string doesn't suddenly convert to a number or a date.

    I don't mind variant types so you can do:

    x = 3;
    x = "foo";

    So first x was an int, then it becomes a string. Casts are also ok so

    x = "06/25/2010";
    (with some locale setting that parses as American style)

    x = date(x) + 1;

    if that makes sense (although wouldn't it add a single day, not a year).

    however simply
    x = "06/25/2010";
    x = x - 1;

    makes no sense, you cannot subtract 1 from a string. (Hey, in C or C++ that will compile assuming x is const char *... And x will be an invalid pointer after the subtraction)

    There is no real explanation to the unused variables that begin with 'n'

    Using n or i as a loop counter is not a WTF. Everybody knows that 'i' means array index and 'n' is often used as the pre-cached number of iterations you wish to do, so you don't have to do container.size() every iteration when it doesn't change.

    The algorithm used to implement is very WTF. There is no need to use a loop to calculate this. Just work out what the current year and current month are, and if the month is greater than 6, i.e. 7 or higher, add one to the year. That is the primary WTF, and it is difficult to know what obsessed this programmer to do anything else. There's probably a correct COBOL way of doing it too, and it isn't the way it's done in the code here.

    On the subject of PHP, my own personal feeling when I looked at the language and learnt how to use it is that it has its limitations, and ideally should be used only in small measures, as a layer between the main engine of your application and the end user.

    Validating user input? yes. Passing queries through to MySQL? - yes. As a main logic engine? No.

    Using programming languages out of their proper domain is a WTF.

    For me, the ideal model would be:
    - primary development engine written in C++.
    - Libraries written with C interface for integration purpose
    - Scripting language front-end that can interact with C interfaces. A lot of scripting languages can do that.

    For that you actually need to build your team properly, with both types of developers and good communication. Not necessarily one-fits-all unless it's a very small development team.
  • Cbuttius 2012-08-21 07:16
    Bob:
    I don't get the COBOL reference. COBOL tends toward verbosity. Unless you're using the indicators...

    I would have thought that regular WTF readers would have grown out of the "language x is bad" mentality. There are few bad languages but many bad programmers. There's little correlation between the two. Apart from PHP.


    Yeah but attitude when hiring is always:

    "have you used such and such... what experience do you hav with such and such..." and some test on the language syntax...

    Deciding between
    1. Very good programmer who hasn't used the language
    2. Mediocre programmer who has

    and no other option they will always choose the latter. After all the can "hit the ground running..."

    In the short term, (1) has a bit of a learning curve but in the long term (1) will be your better bet. If it's a short-term contract I can understand although even then I'd question your decision.


  • Jay 2012-08-21 07:38
    Soviut:
    foo2:
    VB happily 'fixes' the types for you, and as expected is not a good idea. It will usually compile, and often fail when run.


    Isn't there a strict mode you can set that requires variables be explicitly typed?

    EDIT: Ah yes, Option Explicit is what it was called. It's been a long long while.


    Option Explicit forces you to define the variables; since VB creates the variables for you a typo meant you wound up with two variables (of Variant type) with similar names. There's an IDE option that automatically inserts that when you create a new module.

    That got added after using symbols to define the variables (A$, B& and all that) was deprecated.

    That doesn't stop the auto type casting stuff like "1" + 1

    A real WTF was the DEF stuff, that let you assign variable types based on their first letter, so "DefInt I" means all variables starting with I are integers. Our friend here could have added:

    DefStr S
    DefInt N
    DefDat D

    ...and skipped the Dim statements. What a time saver! And job security!

    Those are global, so much fun to be had; eg Fortran folk can have "DefInt I-K". I'd forgotten about that, and thankfully so has everyone else.
  • foo2 2012-08-21 07:52
    Cbuttius:
    Casts are also ok so

    x = "06/25/2010";
    (with some locale setting that parses as American style


    No, auto casting is bad, leading to many WTF's. VB has DateValue() for that.


    Cbuttius:
    x = date(x) + 1;

    if that makes sense (although wouldn't it add a single day, not a year).


    VB does dates like everyone else, in its case "days since 1900" so that code adds a day. VB does have a DateAdd() function that should be used instead (not that many do).


    Cbuttius:
    however simply
    x = "06/25/2010";
    x = x - 1;

    makes no sense, you cannot subtract 1 from a string.


    It makes sense when VB automatically casts the string literal for you (assuming X is defined as a Date).

    I'm not sure why you're unhappy with this, you seemed happy with the first two bits.
  • QJo 2012-08-21 08:10
    facilisis:
    Jim:
    RichP:
    Um no, you use i, j, k and sometimes m as generic counters.

    (cue religious war akin to camelCase versus name_with_underscore)
    in CS101 they taught me to use meaningful names. I have:
    counter, loopCounter, iter, count and a plethora of others...
    Of course, to avoid a massive increase in typing, I still use i and then find-replace all i's with count.

    on a totally unrelated note, I found some serious issues in a program I inherited the other day. I don't even know how it compiled for my predecessor:

    publcountc countnt macountn(vocountd)
    {
    for(count=0; count<1000; count++)
    {
    countf(count%5 == 0)
    {
    System.out.prcountntln(count + "counts Dcountvcountscountble by fcountve");
    }
    }
    }



    I don't see why some pissants mind single-char variables for controlling short loops. They are insignificant in terms of the purpose of the loop - why bloat the code with a mile-long variable, just so that you can avoid seeing "n" or "i" or whatever?

    Now, I can understand wanting something better than a bunch of different single-char loop-counters in nested loops, but otherwise - in a single-level loop - if you replace my i's with your dumb counter's, for no other apparent reason, expect them to be replaced back (for no other apparent reason).


    Rule of thumb: if your loop is small enough to comprehend its scope in a glance (i.e. it's indented neatly and can be seen in one small window in your editor) then using i etc. for loop counters is acceptable. Otherwise (i.e. it's a long loop and/or with possible multiple exits) you'd be advised to pick a descriptive name for your loop counter. If you can't think of one, then either (a) your code requires redesigning in order to make the loop structure more comprehensible, or (b) your brain cells are insufficiently powerful for you to operate effectively in your current career path.

    The other suggestion is that if you have a long loop, extract the contents into a separate method (or subroutine if you're using a 3GL) into which you pass the loop counter (if needed).
  • QJo 2012-08-21 08:11
    kbar:
    If you grew up on Fortran everyone knows that I thru N are integers, everything else is a real.


    No, not a "real", a "float".
  • barry 2012-08-21 09:56
    yep - but in this case they are not *used* for anything
  • Chris A 2012-08-21 10:59
    Jay:
    Soviut:
    foo2:
    VB happily 'fixes' the types for you, and as expected is not a good idea. It will usually compile, and often fail when run.


    Isn't there a strict mode you can set that requires variables be explicitly typed?

    EDIT: Ah yes, Option Explicit is what it was called. It's been a long long while.


    Option Explicit forces you to define the variables; since VB creates the variables for you a typo meant you wound up with two variables (of Variant type) with similar names. There's an IDE option that automatically inserts that when you create a new module.

    That got added after using symbols to define the variables (A$, B& and all that) was deprecated.

    That doesn't stop the auto type casting stuff like "1" + 1

    <snip>

    VB.NET also has an Option Strict directive which apparently prevents most implicit casts.
  • foo2 2012-08-21 11:18
    Some Jerk:
    '' VB6
    Function FiscalYear(dateItem As Date)
    FiscalYear = IIF( dateItem.Month > 6, dateItem.Year +1, dateItem.Year )
    end Function

    Close. VB6 dates aren't objects, so:

    FiscalYear = IIF( Month(dateItem) > 6, Year(dateItem)+1, Year(dateItem) )

    But yeah, still a one-liner.
  • PedanticCurmudgeon 2012-08-21 11:43
    hewey:
    Is it just me, or are today's trolls more successful than usual?

    It's just you. Trolls here are always successful.
  • JJ 2012-08-21 14:49
    Soviut:
    foo2:
    VB happily 'fixes' the types for you, and as expected is not a good idea. It will usually compile, and often fail when run.


    Isn't there a strict mode you can set that requires variables be explicitly typed?

    EDIT: Ah yes, Option Explicit is what it was called. It's been a long long while.

    No. Option Explicit requires that variables be explicitly declared. It does not enforce type strictness on them; VB6 never does that. Evil Type Correction is always a possibility.
  • JJ 2012-08-21 14:54
    Cbuttius:
    however simply
    x = "06/25/2010";
    x = x - 1;

    makes no sense, you cannot subtract 1 from a string.

    You have made an incorrect assumption. In the WTF code, strYear1 does not contain a date but rather a year (basically an integer). The following VB code works just fine:

    Dim x As String
    x = "2010"
    x = x - 1

    x now contains "2009". And yes, it's still a string.
  • JJ 2012-08-21 14:58
    JJ:
    Evil Type Correction

    Whoops! Evil Type Coercion. Correction is part of what ETC really stands for.
  • PiisAWheeL 2012-08-21 16:00
    Soviut:
    Some Jerk:
    I don't care what language you are using... if the names of your variables are not either 1: meaningful, or 2: obvious based on direct usage, they are simply wrong. Also... yes, it is a bad practice to declare variables that you are not using. In most languages, memory is reserved for these variables... but more to the point, it is misleading.


    Agreed! It would be like a book having a table of contents that referred to chapters that didn't actually exist. It doesn't "break" the book, but it's certainly confusing to discover the mismatch. Or perhaps a more practical example would be finding extra parts after assembling your Ikea furniture, leaving you to wonder if they were necessary or not.
    I don't think I've ever assembled something from ikea and NOT had extra parts left over. I've even had things showup in the box that I'm sure did not go to whatever I was trying to assemble.
  • Jimbo 2012-08-21 17:47
    Soviut:
    Jimbo:
    I often get on a hobby horse about inefficient code, and the usual response is "Who cares? We have shirtloads of resources these days". I find this attitude a bit scary - while our resources often can absorb a lot of inefficiency it's no excuse to produce crap. The system you desing for 10 users today might have 100 users tomorrow, and 1000 users next week. The only time you are allowed to write stuff inefficiently is when you are making an app for yourself that will only ever run on your desktop - and even then, why limit the number of programs you can have open at any given time?


    Remember the "triangle of requirements" (as I'm titling it just now). On each corner is marked "fast", "cheap" and "good" respectively. Now you have to pick a side. If you want it fast and cheap, it won't be good; If you want it fast and good, it won't be cheap, etc.

    Optimization is good, but only when it's valuable. For example, a script that's run once a month and takes 1 second to complete does not need a developer spending months, days, or even hours optimizing it, since the value on the return is negligible. When someone disregards an optimization pass on their software, it's usually because it isn't worth it.

    Optimization should be reactive. If a website only gets 5 visitors a day, it isn't valuable enough to warrant the optimization. However, if traffic increases to 50,000 visitors a day then the value of optimization increases and becomes worth pursuing. Software is never "done" and it's never perfect, so trying to pre-optimize often just leads to a lost of wasted time...far more than the optimizations would have saved.
    Maybe I'm playing Devil's Advocate a bit, but while I understand you don't always need the most optimally efficient code, my point is more that there are certain inefficiencies that can be avoided so easily that it would be stupid not to. In the OO world, this is things like limiting the number of Objects - if the first thing a method does is clone or create new Objects that are essentially the same as ones you've already got then you're probably doing it wrong. I agree, that it's stupid to spend a lot of time optimizing trivial scripts that rarely run, however I think your point on websites is a bit different. If you create a web page, surely you assume that millions will flock to it (even if you only get 5 visitors a day, google will do it's magic soon, right?). So too with any application that is anything beyond a simple tool to aid yourself. Sometimes, optimizations are incredibly complicated if made retrospectively, so it's always important to consider how wide reaching your app/website/whatever could be - this is part of the design phase.

    I also think there's a difference between efficiency and optimization (semantics, perhaps, but fairly important ones given the discussion). You can write efficient code that doesn't spuriously allocate memory because we can - and this can still be optimized. Optimization is the deliberate attempt to make the code as quick or efficient as possible - and possibly sacrificing clarity in the meantime. For example:
    Inefficient code for a bitfield:

    /* We essentially create a new String each time we modifiy it */
    String myBitField = new String("0000");


    Efficient code:

    /* We now use a single byte per bit - sub-optimal on most virtual machines (I think), but we have a fixed and relatively reasonable memory footprint */
    boolean myBitField[4] = {false, false, false, false};


    Optimized code:

    int bitField = 0;

    And we could probably optimize more....

  • Stack 2012-08-21 21:51
    I think it's more notable that those extra variables aren't actually used in the function anyway
  • daveime 2012-08-22 05:40
    Funny that, I always use i,j,k ... throwback to my first program typed from a magazine into a Commodore PET in 1980.
  • Vlad 2012-08-22 09:02
    Ignoring everything else, there's the wtf of this being a function, but the return value isn't set, instead it looks like the programmer used this code to set values of globals instead.

    If you're bothering to use a function, you should:

    myfunctionname=value

    then in the caller you might say:

    foo=myfunctionname(bar)

    But that's just this one issue.
  • Vlad 2012-08-22 09:05
    My bad, I just noticed there in the middle where they actually do assign a returnvalue.
  • Gibbon1 2012-08-23 03:24
    hewey:
    Is it just me, or are today's trolls more successful than usual?



    I'm been wondering if the original author of the code hasn't been trolling other programmers his whole career. As in, lets figure out the most inane way of doing this that is 100% correct but will make other programmers feel ill just to look at it. Double win if other programmers unable to help themselves try to 'improve' the code and break it in the process, then get spanked by management for their trouble.

    Occasionally I look at my own code my past self is trolling me.
  • Neil 2012-08-23 05:45
    Soviut:
    foo2:
    VB happily 'fixes' the types for you, and as expected is not a good idea. It will usually compile, and often fail when run.
    Isn't there a strict mode you can set that requires variables be explicitly typed?

    EDIT: Ah yes, Option Explicit is what it was called. It's been a long long while.
    I didn't think that VB supported the long long type...
  • Neil 2012-08-23 05:47
    Jim:
    publcountc statcountc countnt macountn(Strcountng[] args)
    FTFY
  • Neil 2012-08-23 05:53
    Jay:
    Fortran folk can have "DefInt I-N".
    FTFY. [The default in Fortran was IMPLICIT REAL(A-H, O-Z), INTEGER(I-N).]
  • Gibbon1 2012-08-23 14:03
    Neil:
    I didn't think that VB supported the long long type...


    VB does support the long while type with internationalization.

    Dim a As String

    a = "millennium"

    Print a + 1 'prints 1001

  • Jay 2012-08-24 07:21
    Neil:
    Jay:
    Fortran folk can have "DefInt I-N".
    FTFY. [The default in Fortran was IMPLICIT REAL(A-H, O-Z), INTEGER(I-N).]

    Well, you learn something new every day.

    So BASIC borrowed the idea of DEF from Fortran (it was probably a good idea at the time).

    Admittedly learning Fortran isn't that useful but anyway. Is that enough for a resume reference?
  • sprezzatura 2012-08-24 21:25
    I once wrote a typesetting program in COBOL. Not trivial. Grace Murray Hopper (shame if you don't know her) once wrote a COBOL compiler... in COBOL.

    A tool is only has bad as the workman who uses it.

    The worst programming language is RPG (Report Program Generator). COBOL is fun compared to RPG. PHP is nirvana. Be grateful you never had to write RPG.
  • Ken 2012-08-26 19:50
    So what is that something special that's on nearly every line? I don't see any periods ending each statement.
  • pantsman 2012-08-31 10:59
    TRWTF is object-oriented languages.
  • Joe Celko 2012-09-01 13:28
    I see this COBOL mindset in SQL all the time. We hae a DATE data type and we use tables (completed sets), but the noob is locked into strings and loops, so he uses code like this instead of a simple table constructor. And the date string format is NEVER the required ISO-8601! Hey, we used "mm/dd/yy" in 1950 and it was fine! Or was it "dd/mm/yy", I forget ..:)
  • Rüdiger 2012-09-04 15:37
    Yeah, but usually a counter is declared only if you need it. That's not the case for nn, nnn and nnnn. They are just corpses - leftovers from former versions (or declared on reserve, which is not better).

    Another strange point is that he avoids parameters and uses global variables as an alternative, without any need.

    But the real hit is that the year is not directly read off from his testDate! Instead, he loops over at most 20 years to perform an interval check. Since most dates will be of the current or the past fiscal year, this is no performance issue. It is just weird. I sometimes encounter this kind of round-the-corner thinking, especially in date computations, and I always find it disturbing. I don't know whether it is related to the language where the programmer comes from. It can be a sort of mentality as well - a different brain structure.
  • TortoiseWrath 2012-10-16 20:30
    JavaScript?

    I am not spam
  • MikeyB 2012-10-26 09:47
    How do I upvote this?