- 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
Admin
That's just a weak hearted attempt to write bash in it's own scripting language.
IF
// Huergh!
FI
Bit like the chicken and the egg :P
Admin
I think Perl might already support something like this. Which shouldn't be too surprising, really...
Admin
in the case of comparing boolean variables I prefer to use 'and', 'xor' and the likes. But that's personal preference I suppose. It's funnier when ppl start comparing boolean variables with booleans...
reminds me of some great code I once found in some project:
x = a < b;
if(x == true)
doStuff;
elseif(x == false)
doOtherStuff;
else
throw UnexpectedValueError
Admin
Surely you never used Haskell or another language with redefinable syntax, do you?
In Haskell you not only can redefine basic operators and funtions, but define new operators like #, [, .<. or whatever you want.
After a time you just get used to it and work on a higher level of thinking.
So a big narrow-minded WTF? ;)
Admin
You do know that won't work don't you?
I had a colleague who's code was sprinkled with lines like this :
DEBUG printf("whatever");
When he was done debugging he changed the "#define DEBUG" at the top of the file to "#define DEBUG //". Nothing changed, the preprocessor processed comments before #defines [8-|]
Admin
WHILE (parent=fork()) == -1
DO sigchk(); alarm(10); pause() OD /* crack overdose */
Admin
This code is correct.
Admin
This looks like some kind of really naïve localization technique.
(This editor is a WTF BTW)
Admin
blasterz, thanks for this URL:
http://www.conman.org/software/amc/docs/html/amc_usersguide.html
This is absolutely the most plausible and normal-looking I have ever seen a net kook be, while still being a kook.
His autobiographical story about how he wanted polymorphism in C and it gradually grew into his life's work -- all the while aware of C++, but never quite understanding why it does what it does -- is absolutely priceless.
Admin
<FONT color=#0000ff><FONT size=+0>#define finally(code) catch(...) { code; throw; } code;</FONT> </FONT>
<FONT color=#0000ff>Resource r = allocateResource();
try {
do_stuff(r);
}
finally(freeResource(r));</FONT>
Please don't do this. Google for RAII (Resource Acquisition Is Initialisation).
Admin
I did liked the usefull:
#define do_nothing
lol
Admin
Also, 'and', 'and_eq' etc. are actually standard C++ keywords. If your compiler doesn't support them, it's not a C++ compiler. Not that I've ever used them myself.
Microsoft define this header to reintroduce these names as macros, as enabling language extensions disables the keywords. Why? I don't know. It all seems a bit backwards to me.
Admin
Admin
...or, the maintainer could just run it through cpp. Lighten up, Francis.
Admin
Over 20 years ago, when I used to code 68k assembly language for a living, I wrote a suite of macros that made my asm look a whole lot more like the pascal I was being taught at university. But that didn't make me laugh like this did.
Admin
I have no doubt that you don't care. You'll start pulling your hair out when you inherit some code like this though.
Why pull your hair out? Just write a quick perl script that fixes it. Or (if this is how they do things at company X) learn the new language. It is not like you don't have access to the key.
Admin
heck, "Better C" rocks,it probably can compile both c and pascal code in same file [;)]
Admin
I don't work with Windows :D, nor any other OS API.
Anyway, my post was just a little joke Geeked [8-|]
Admin
These could actually make sense in C, if enforced by the compiler. Ie "forever"-loop mustn't contain break or return, it would essentially generate "no-return" function implicitly. Similarily, "untilbreak" would have to contain (reachable) break etc, and any code after "untilreturn" would be known to be unreachable, etc. And then there also should be warnings about having break or return from within a standard while loop. But without compiler enforcing these, they're pretty much pointless and just using plain comments would be better.
Admin
Admin
Don't like your current language? Don't want to go to the hassle of writing your own language and compiler? Just pick a language that's close enough and skin it.
C (crappy macros), Common Lisp (true macros), Perl (Filter::Simple) all allow you to do this. In some cases it even makes sense (ESQL/C, domain specific languages, etc.).
Admin
#define FI if
#define huergh! FI
huergh! (foo) {
//hello
}
Admin
Better yet, as a TA I once saw this at the top of a program that a student was having issues with.
#define BEGIN {
#define END }
Admin
preprocess this:
/
Sorry ... The C preprocessor strips out comments before dealing with macros. So, the definition of COMMENT is in fact blank. Although you can use macros in place of C keywords, you can't use them for preprocessor directives. So while you could do
#define if while
it would only affectif (something) { do_stuff(); }
and not#if some_macro void do_stuff(void); #endif
/
Admin
This one must have been recommended by Paula.
Admin
Actually, many languages (primarily Lisp, though another poster also pointed out Haskell) provide formal ways to extend the syntax of a language, thus allowing the programmer to make his code clearer. Mostly by bringing the language closer to the problem domain (that is, implementing domain-specific embedded languages) but convenience syntax extensions are very common as well. It is not a bad thing as code using properly designed syntax extensions can be easier to read than code which spells out its meaning explicitly in the built-in syntax.
While such extensions may not be a very good idea in C, due to the rather crude design of the C-preprocessor, this days WTF isn't that bad (though it would still make me go WTF to begin with). I have a hard time believing that anyone with enough programming knowledge to find this site interesting, would have a hard time figuring out what this code means:
repeat {
do_stuff();
} until (stuff_no_longer_needs_doing())
Admin
The only wtf here are the useless translation of logical/comparison operators, bitwise operators, and the aritmetic operators.
The constrol constructs document themselves and are obvious in their function.
Admin
I feel violated please stop.
Admin
Oh yeah the old, write once, blue screen everywhere chessnut.
Perhaps this guy works for Microsoft, they seem to skilled in defining different Syntaxs that do the same thing (a BIG WTF).
Admin
What a bunch of big whiny babies. Now I know this term came into vogue after C, but there's this newfangled process called "refactoring" that came into wide use recently, and it's capable of undoing these modifications or even changing these macros to more annoying ones. Sadly, for those droves of you still tied down to punchcard operated machines, this will be a difficult process, but for those of you with *any text editor at all* and a high school education, you should be kicked to the curb faster than the original author if you're a C programmer and don't konw how to fix it.
The reaction I'm seeing here makes it sound like this guy made a binary mod to the compiler that can only be undone by going back in time and changing the past. Where's the DeLorean and that pesky mad scientist when you need him?
Admin
Even better:
#define I /*
#define go */
I think we should implement this sturcture thus:
a = number kjasdfkasdf
b = foofaa
So let's go
struct m00
{
int a;
int b;
I am not sure. Perhaps the next one is unnecessary.
int c;
}
struct f00
{
int c;
int d;
We really should let this one go
int e;
}
Admin
Wow, this combine the power and great syntax of both Pascal and Fortran! :D
--
The keyboard is a sword of freedom. Coding is an act of rebellion.
Admin
This would have worked, though, assuming that his DEBUG lines only contained one statement:
#define DEBUG if (0)
Admin
So what? Syntax is just syntax. Learning syntax is the easy bit [that anyone can do]
Admin
Genius! Looks like you don't even know what's the return value of the comma-operator.
Admin
Is it possible to...
#define IM IDIOT PLEASE REPLACE THE FIRST WORD BY THE SECOND #define
[6]
Admin
well i forgot the underscores but you understand :P
Admin
Yep! Obviously, Java will stagnate horribly when it doesn't have a preprocessor! If it had a preprocessor, everyone could easily build BETTER_JAVA! We must add preprocessor to every language to avoid this horrible language stagnation, and let people come up with their own fun!
But no might in the world can create a BETTER_VISUAL_BASIC. :)
Admin
Reaaaaaaally... enlighten me, if you would.
Admin
"Awww, I saw the GT, GE, and LTs and thought FORTRAN. "
FORTRAN always had >, >= and <, but it allowed GT, GE and LT because a lot of keypunch machines didn't have many special characters.
Admin
imagine my suprise when i found this code at my old job. it does compile in g++ 4.0.2.
anybody have a good reason for this? cause g++ guys think its cool.
int i = 0; ... if (i>=1 or i<=-1) //print some shit to console.
Admin
FORTRAN always had the characters for greater than, equal or greater, and less than, but it allowed GT, GE and LT because a lot of keypunch machines didn't have many special characters.
I think the fact that WTF doesn't have a post preview is a WTF.
Admin
Knowing how to fix a WTF and being given the time/money to do it are two completely different things. What if this WTF is spread throughout out a 10 million line code base? Do you know what the cost would be of refactoring it? Can you even imagine the cost of testing everything you would touch by converting all the code? (Oh yeah, simple script it won't break anything...) Because after all if one moron did this there could of been some one else that preferred Ada or COBOL or what ever other language.
Just because it maybe simple change in the project you are used to doesn't mean it would be easy in all cases.
Admin
Easy. Create a translation table as follows
a'NE' '!='
a'EQ' '=='
a'GT' '>'
a'LT' '<'
a'GE' '>='
a'LE' '<='
a'AND' '&&'
a'OR' '||'
a'NOT' '!'
a'bNOT' '~'
a'bAND' '&'
a'bOR' '|'
a'bXOR' '^'
a'MOD' ' %'
a'repeat' 'do'
a'until(p)' 'while(NOT (p))'
a'forever' 'while(1)'
a'untilbreak' 'forever'
a'untilreturn' 'forever'
a'unless(p)' 'if(NOT (p))'
a'ifnot(p)' 'if(NOT (p))'
a'do_nothing' a''
call it wtf.trf
use your handy-dandy translation program (written in un-improved C)
bmtran improved.c old_shitty.c wtf.trf
out comes old_shitty.c, but readable.
Admin
oops, should have been:
a'NE' a'!='
a'EQ' a'=='
a'GT' a'>'
a'LT' a'<'
a'GE' a'>='
a'LE' a'<='
a'AND' a'&&'
a'OR' a'||'
a'NOT' a'!'
a'bNOT' a'~'
a'bAND' a'&'
a'bOR' a'|'
a'bXOR' a'^'
a'MOD' a' %'
a'repeat' a'do'
a'until(p)' a'while(NOT (p))'
a'forever' a'while(1)'
a'untilbreak' a'forever'
a'untilreturn' a'forever'
a'unless(p)' a'if(NOT (p))'
a'ifnot(p)' a'if(NOT (p))'
a'do_nothing' a''
Admin
That some people don't think this is that big of a deal frightens me. As a developer that is solely responsible for approximately 500k lines of C++ code, most of which I am not the original author, allow me to state that encountering something like this would bring out murderous tendencies.
Consider the following:
#include <IOSTREAM>
#include <VECTOR>
#define begin {
#define end }
static const int numbers[] = { 1, 3, 5, 7, 9 };
const size_t n_numbers = sizeof(numbers) / sizeof(*numbers);
int main(int argc, const char** argv)
begin
std::vector<INT> nums(numbers, numbers + n_numbers);
for (std::vector<INT>::const_iterator iter = nums.begin(); iter != nums.end(); ++iter)
begin
std::cout << *iter << std::endl;
end
end
This now won't compile. Weeeeee. This is just one example for the infinite many about why using macros to change language syntax is a bad idea. Macros have their purpose, this isn't one of them.
Admin
Umm...official standard for Fortran66 indicates that the official Fortran Character Set inclused alphanumerics, space, and =. +, -, *, /, (, ), ,, ., and $. Maybe a later version has em or maybe some companies had different flavors, but <'s, >'s, and ='s weren't in the 66 standard.
Admin
And then the next guy gets to go back and fix all the now-busted comments, string literals, etc., that get changed as collateral damage. I was that next guy. I had to grovel through thousands of lines of comments and string literals changing all occurrences of "&&" back to "and", "||" back to "or", etc. We had defects come back for months because a prompt read "Press Return to {" or some such nonsense. All because someone thought that making C look more like Pascal would make it behave more like Pascal.
Preprocessor abuse is a capital crime.
Admin
This is even better:
if (someTestPasses())
{
/* do stuff */
}
Corollary: if you're going to put in an else branch, have it do something useful (if nothing else, log that the test failed). Otherwise it's just visual noise.