- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.
Admin
I do not get the "regular WTF readers" reference. If you are a "WTF reader", how can you be regular?
Admin
Regular mean people who sign on daily like Cockthorpe and PedanticCurdleman.
Admin
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:
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.
Admin
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
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.
Admin
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.
Admin
No, auto casting is bad, leading to many WTF's. VB has DateValue() for that.
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).
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.
Admin
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).
Admin
No, not a "real", a "float".
Admin
yep - but in this case they are not used for anything
Admin
Admin
FiscalYear = IIF( Month(dateItem) > 6, Year(dateItem)+1, Year(dateItem) )
But yeah, still a one-liner.
Admin
Admin
Admin
Dim x As String x = "2010" x = x - 1
x now contains "2009". And yes, it's still a string.
Admin
Admin
Admin
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:
Efficient code:
Optimized code:
And we could probably optimize more....
Admin
I think it's more notable that those extra variables aren't actually used in the function anyway
Admin
Funny that, I always use i,j,k ... throwback to my first program typed from a magazine into a Commodore PET in 1980.
Admin
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.
Admin
My bad, I just noticed there in the middle where they actually do assign a returnvalue.
Admin
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.
Admin
Admin
Admin
Admin
VB does support the long while type with internationalization.
Dim a As String
a = "millennium"
Print a + 1 'prints 1001
Admin
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?
Admin
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.
Admin
So what is that something special that's on nearly every line? I don't see any periods ending each statement.
Admin
TRWTF is object-oriented languages.
Admin
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 ..:)
Admin
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.
Admin
JavaScript?
I am not spam
Admin
How do I upvote this?
Admin
PHP is fine
Admin
APL and Prolog are not bad languages, they're just unconventional and in many ways more powerful than what your typical blub programmer (a.k.a., you) is used to. And you keep talking about the "correct" approach but that doesn't exist. There may be several approaches, each with advantages and disadvantages; a few of those approaches may be conventional, but that doesn't make them "correct." You sound pretty clueless yourself.