• Tractor (unregistered) in reply to geoffrey, MCP, PMP
    geoffrey:
    Some requirements may call for an engine that can run dynamic code. I challenge anyone to find a better way to do this in C#.

    Change the requirements.

  • qbolec (unregistered)

    C# is NOT case sensitive:

    switch(x){
    case 1:
       foo();
    case 2://C# doesn't notice the "case" and falls trough!
       bar();
    }
    
  • (cs) in reply to Tractor
    Tractor:
    geoffrey:
    Some requirements may call for an engine that can run dynamic code. I challenge anyone to find a better way to do this in C#.
    Change the requirements.
    Suggesting changing major technical requirements just because you don't like a particular solution… Either you're a somewhat-clever troll or a stupid code hermit. Can't tell which. Either way, you must be a real fun person to work with when doing web development, since either trait would mark you out as a jackass. (Did you know that the CPU interprets instructions? Oh noes!!!)

    Not a patch on TopCoder though, who was skilled enough to effectively troll everyone even if they were watching out for it. That's talent which you conspicuously lack.

  • (cs) in reply to Tim
    Tim:
    Steve The Cynic:
    It occurs to me that TRWTF is the anonymiser. And the submitter. It's a Remypost, so you can read more in the HTML comments.

    It doesn't make much sense in Java either...

    (All use of eval() is automatically a WTF, but apparently this does not go without saying. It's worth noting that eval() is not new as a concept, as an instruction existed in the IBM System/370 instruction set that would execute an instruction found in a register.)

    It seems to me that the whole point of a stored program computer (as envisioned by Turing) is that program = data. it's the very programmability that comes from storing the program in memory along with the data which is what makes a computer what it is.

    Turing never had to deal with hackers. In a security context, conflating code with data is a huge problem. Every time you hear about some website that got hacked and exposed millions of users' private data due to a SQL injection vulnerability, that's because some developer out there didn't understand how to properly separate code and data.

  • Yawn (unregistered) in reply to mott555
    mott555:
    pjt33:
    Hatshepsut:
    Hah. Kids' stuff. I once worked with a processor that could execute a whole array of instructions stored in memory.
    Don't be ridiculous. That would be a major security flaw.

    Definitely a security flaw. That's why I worked with a processor that couldn't execute any instructions ever! It's the most secure computing platform in the world!

    All existing processors can be modified to operate in this more secure mode. One simple way to activate this secure mode is to remove the heatsink from your processor, then power up your machine. This sends a signal to the processor to operate in this more secure mode. Unfortunately, I have not yet found a way to turn this feature off.

  • (cs)

    This one made me wanna hurl!

  • Anon (unregistered) in reply to Kuba

    The problem with eval is that most programmers aren't coding:

    Kuba:
    just-in-time compilers for javascript that are present in almost every web browser out there, CLR and JVM, but that's obvious and those aren't exactly your random enterprisey applications. ... JIT-ing shaders (Apple did it to emulate shaders on oldish hardware), generating ideal hashes (used in routers and firewalls), optimizing SQL stored procedures, ...
    (though admittedly, I don't know how eval optimizes SQL stored procedures.)

    Most programmers using eval at best are just causing unnecessary overhead and harder maintenance and at worst causing security problems for their clients.

  • uberanon (unregistered) in reply to qbolec
    qbolec:
    C# is NOT case sensitive:
    switch(x){
    case 1:
       foo();
    case 2://C# doesn't notice the "case" and falls trough!
       bar();
    }
    

    you sir, are brilliant!

  • Jim (unregistered) in reply to Josh
    Josh:
    This is clearly JavaScript (which does have an eval function). The authenticity of this entire WTF is in question.
    OMG!!!!!!!!!! This entire WTF?
  • miguel (unregistered)

    whadd'yall talikn' 'bout with tha single quotes?

    tha sigle quotes be in tha Javascript, not tha C# (Java).

  • JoX (unregistered)

    What's a compiled language anyway?

  • MightyM (unregistered) in reply to qbolec
    qbolec:
    C# is NOT case sensitive:
    switch(x){
    case 1:
       foo();
    case 2://C# doesn't notice the "case" and falls trough!
       bar();
    }
    

    Compiler Error: Control cannot fall through from one case label ('case 1:') to another

  • Gunslinger (unregistered)

    Bloody hell! WTF!

  • Warbo (unregistered)

    The irony, of course, is that source files are already text. I would propose a "streamlining" effort:

    Phase 1) To increase maintainability, move whatever's currently in the strings into separate files. Read these into eval at runtime. Phase 2) To increase performance, run eval once on these files and cache the results. Phase 3) To remove redundant code, use the real compiler instead of eval.

    Ta da, no more monstrosity!

    FYI I've found eval useful on occasion, for example I've had a few times in Javascript where I've needed to run something like "foo(bar[0], bar[1], bar[2], bar[3], bar[4], ...)" for an arbitrary number of bar. I think the following is a pretty clean solution:

    var args = map(bar, function(v, k) { return 'bar['+k+']'; }).join(','); eval('foo('+args+')');

  • TheJonB (unregistered) in reply to Tractor
    Tractor:
    geoffrey:
    Some requirements may call for an engine that can run dynamic code. I challenge anyone to find a better way to do this in C#.

    Change the requirements.

    I agree, if the answer involves a javascript interpreter then change the question.

  • just me (unregistered) in reply to Warbo
    Warbo:
    The irony, of course, is that source files are already text. I would propose a "streamlining" effort:

    Phase 1) To increase maintainability, move whatever's currently in the strings into separate files. Read these into eval at runtime. Phase 2) To increase performance, run eval once on these files and cache the results. Phase 3) To remove redundant code, use the real compiler instead of eval.

    Ta da, no more monstrosity!

    FYI I've found eval useful on occasion, for example I've had a few times in Javascript where I've needed to run something like "foo(bar[0], bar[1], bar[2], bar[3], bar[4], ...)" for an arbitrary number of bar. I think the following is a pretty clean solution:

    var args = map(bar, function(v, k) { return 'bar['+k+']'; }).join(','); eval('foo('+args+')');

    Please don't. Use Function.apply() to do this sort of thing, no need for eval.

  • rfoxmich (unregistered) in reply to Julia

    ... Or in an XML configuration file.

  • Hmmmm (unregistered)

    All you people saying that using eval is bad seem to be missing TRWTF here. This code is using an eval-like function in a language that doesn't natively have it to run a bit of JavaScript that splits a large string into an array and loops through it calling the JavaScript eval on each element in turn. Not only using eval, but using it 100+ times when once would be plenty (or arguably too much) and wouldn't significantly reduce the "flexibility"...

    If I had to guess I would say that someone had to migrate a classic ASP JScript app to .NET and felt like writing some of it in C# for whatever reason and then didn't get around to (or wasn't allowed to) refactoring this ridiculous bit of legacy crap^H^H^Hode...

  • Another Byte on the Web (unregistered)

    This one made my cry a little. This kind of stuff seems to be coded by Cthulhu himself.

  • Shen Anigans (unregistered)

    A post by Remy without the unicorns?!? Clearly fake.

  • Jeff (unregistered)

    There are a few details of this that are a little off. For one the original code comes from classic asp/jscript not C#. This does actually come from a classic asp application I was so fortunate to inherit and maintain. The entire application is not stored in the application cache, only "commonFunctions". The mistaken reference to C# and ASP.net is probably due to the fact that I mention that being what I primarily work in. Which is much better written than this hunk of crap.

  • (cs)

    TRWTF is Remy. >:( GTFO of my TDWTF with your FAIL.

  • Kevin Thorpe (unregistered)

    But that pales into insignificance when you start to browse through the database behind an inherited codebase and find a whole table containing code fragments <ugh!>.

  • systemeng (unregistered) in reply to History Teacher

    Sounds a lot like TCL to me ;)

  • Jay (unregistered) in reply to dkf
    dkf:
    Tractor:
    geoffrey:
    Some requirements may call for an engine that can run dynamic code. I challenge anyone to find a better way to do this in C#.
    Change the requirements.
    Suggesting changing major technical requirements just because you don't like a particular solution… Either you're a somewhat-clever troll or a stupid code hermit. Can't tell which. Either way, you must be a real fun person to work with when doing web development, since either trait would mark you out as a jackass. (Did you know that the CPU interprets instructions? Oh noes!!!)

    Not a patch on TopCoder though, who was skilled enough to effectively troll everyone even if they were watching out for it. That's talent which you conspicuously lack.

    Unless we're talking about an infrastructure tool, "an engine that can run dynamic code" is not a REQUIREMENT, it is a proposed SOLUTION to meet the requirement. The requirement is surely something more like, "accepts orders from customers and prepare a shipping manifest and an invoice". Choices of language, database engine, etc, are solutions that should be irrelevant to the user as long as they ultimately work. If your users are putting statements like that in a requirements paper, you need to sit down and explain to them the difference between a problem and a solution. Or simply ignore such statements as suggestions to be taken or ignored as you see fit.

    More likely, somebody on the IT side came up with this as a solution.

  • geoffrey, MCP, PMP (unregistered) in reply to Jay
    Jay:
    dkf:
    Tractor:
    geoffrey:
    Some requirements may call for an engine that can run dynamic code. I challenge anyone to find a better way to do this in C#.
    Change the requirements.
    Suggesting changing major technical requirements just because you don't like a particular solution… Either you're a somewhat-clever troll or a stupid code hermit. Can't tell which. Either way, you must be a real fun person to work with when doing web development, since either trait would mark you out as a jackass. (Did you know that the CPU interprets instructions? Oh noes!!!)

    Not a patch on TopCoder though, who was skilled enough to effectively troll everyone even if they were watching out for it. That's talent which you conspicuously lack.

    Unless we're talking about an infrastructure tool, "an engine that can run dynamic code" is not a REQUIREMENT, it is a proposed SOLUTION to meet the requirement. The requirement is surely something more like, "accepts orders from customers and prepare a shipping manifest and an invoice". Choices of language, database engine, etc, are solutions that should be irrelevant to the user as long as they ultimately work. If your users are putting statements like that in a requirements paper, you need to sit down and explain to them the difference between a problem and a solution. Or simply ignore such statements as suggestions to be taken or ignored as you see fit.

    More likely, somebody on the IT side came up with this as a solution.

    Where I come from, we call what you're proposing "going rogue."

    In a real business, it's crucial for programmers to trust that stakeholders know what they need. Otherwise, chaos ensues.

  • (cs) in reply to geoffrey, MCP, PMP
    geoffrey:
    Jay:
    dkf:
    Tractor:
    geoffrey:
    Some requirements may call for an engine that can run dynamic code. I challenge anyone to find a better way to do this in C#.
    Change the requirements.
    Suggesting changing major technical requirements just because you don't like a particular solution… Either you're a somewhat-clever troll or a stupid code hermit. Can't tell which. Either way, you must be a real fun person to work with when doing web development, since either trait would mark you out as a jackass. (Did you know that the CPU interprets instructions? Oh noes!!!)

    Not a patch on TopCoder though, who was skilled enough to effectively troll everyone even if they were watching out for it. That's talent which you conspicuously lack.

    Unless we're talking about an infrastructure tool, "an engine that can run dynamic code" is not a REQUIREMENT, it is a proposed SOLUTION to meet the requirement. The requirement is surely something more like, "accepts orders from customers and prepare a shipping manifest and an invoice". Choices of language, database engine, etc, are solutions that should be irrelevant to the user as long as they ultimately work. If your users are putting statements like that in a requirements paper, you need to sit down and explain to them the difference between a problem and a solution. Or simply ignore such statements as suggestions to be taken or ignored as you see fit.

    More likely, somebody on the IT side came up with this as a solution.

    Where I come from, we call what you're proposing "going rogue."

    In a real business, it's crucial for programmers to trust that stakeholders know what they need. Otherwise, chaos ensues.

    You, sir, have no idea how much chaos I have survived.

  • (cs) in reply to frits
    frits:
    The Great Lobachevsky:
    am I the only one that saw this and thought of Geoff Peterson's Facebook page? :)

    anyways, I love how people complain about cornify, and then there are complaints when there isn't one. Personally, I obsessively have to keep clicking until I get the My Little Pony one...

    So are you a female bronie?

    I guess you can call me that... :)

    I'm sitting here with 5 stitches in my hand (not my mouse hand, thankfully) that I managed to give myself with a sword... that's kinda something a guy would be typically more likely to do, huh?

  • That isn't how you use the application state variable in C# (unregistered)

    In C#:

    Application["TheRealWTF"] = "VisualBasic";

    In VB.Net:

    Application("TheRealWTF") = "Javascript";

    Whatever this code is; it wouldn't compile as c#...

  • AGray (unregistered) in reply to mott555

    C# is a great language for using C# as a scripting language, apparently.

Leave a comment on “Pure Eval”

Log In or post as a guest

Replying to comment #:

« Return to Article