• SomeCoder (unregistered) in reply to Michael
    Michael:
    Alternatively, you could have:

    if (Homer.TVQuantity == "None" && Homer.BeerQuantity == "None) { Homer.action("Something Something");// Go crazy? }

    I think this wins best post of the thread award :)

  • (cs)

    Another programmer went insane after spending too much time with Java. I'm glad that I'm not the only one... :-)))

  • (cs) in reply to anonymous coward
    anonymous coward:
    Can you switch the CAPTCHA to use nonsense text instead of words? Hopefully, that would get people to stop telling everyone what their CAPTCHA phrase was.

    Captcha: sanitarium

    If you really believe that you have NOT spent much time over at Sharktank. Random series of characters can be much more fun as they make non-sense words that might actually seem to be new words that relate. Then you not only get people posting their CAPTCHA text you get another paragraph explaining how it relates.

  • woohoo (unregistered)
    // just need get the &#$*ing class name of a string array String[] blah = new String[1]; Class[] cos = { blah.getClass() };

    Just need to &#$*ing learn the language properly...

    Class cls = String[].class;

    This is the so-called 'class literal' - use it, when you need meta class information about any type you do not have an instance from (and do not want to create one unnecessarily, like above!). 'cls' contains exactly the same information as cos[0] in the above snippet. This works even for primitive types ('int.class' etc.) and the 'Void' meta class.

    This is only the most articulate WTF in this part of the code. Another: if you absolutely have to create an empty array, use [0], not [1]... Yet another: why Class[]? Class cls = blah.getClass(); suffices... This shows that most of the distressed comments could've been avoided, had the programmer known enough of the language in use (Java in this case, but I've seen similar in C, C++, C#, VB(A), Basic, Cobol, Perl, JavaScript, LISP, Fortran and I don't know what else...).

    Know your tools. And if you are too lazy and/or dim to learn them properly, use simpler ones or seek new challenges in different areas than software development. Thank you. ;o)

  • (cs)

    I am working on a DOD contract. And I think you have been LOOKING OVER MY SHOULDER !!!!

  • DavidN (unregistered)

    Just when I thought that the front page posts were going downhill, this was the first to make me laugh out loud at work. "If we're not getting the database, just return some random numbers instead" is an inspired decision indeed.

  • (cs)
    // take a look at the content type String type = "FIIN"; // f**k if I know
    Bonus points for cleverly avoiding the code auditors who, experienced checkers that they are, search for "FIIK".
  • (cs) in reply to mkb
    mkb:
    The real real wtf is that Java doesn't let you overload operators. AT ALL.

    The REAL WTF is that not only Java doesn't let you overload operators, it internally supports SOME types of overloading but not others.

    For example, we have:

    String a = "foo";
    String b = "bar";

    Now saying

    String c = a + b;

    Instead of

    String c = a.concat(b);

    WILL WORK FINE!!! Even though it's an overload of the plus operator which in this case works completely different from when adding two integers (if integer addition would work like string addition in Java, then saying "1 + 2 + 3" would result in 123 instead of 6).

    HOWEVER, saying

    boolean d = (a == b);

    WILL NOT WORK, and you instead have to use

    boolean d = (a.equals(b));

    So plus operator is overloaded but comparison one isn't, and you have to stick to the system because you can't change overloading yourself either. Talk about stupid...

  • Jim Bob (unregistered) in reply to bonzombiekitty
    bonzombiekitty:
    From the project I'm currently working.
    ...
     //OH NOESSSSS!  UI BE DYING!!!
    ...
      //Yeah, yeah, I kinda broke the implied rules for .equals().  
      //Sue me.  You shouldn't ever be using this anyways!  
    ...
      //How the feck did the program get to this line?
    ...
      // Yeah, I shouldn't catch an entire exception.  Leave me alone.
    ...
      //Run this as it's own thread.  YAY! THREADS!!!
    

    Also, when you shut down my program it says "You don't love me. Killing myself :( "

    That's fucking stupid. Fuck you

  • yummy (unregistered) in reply to Jim Bob
    Jim Bob:
    That's fucking stupid. Fuck you
    Thanks, now this site is no longer work-safe for me.
  • (cs) in reply to bonzombiekitty
    bonzombiekitty:
    Also, when you shut down my program it says "You don't love me. Killing myself :( "
    I put a little surprise in an app once. The About screen had my picture on it. If you clicked on the picture a dialog balloon appeared, so that I was saying, "Quit playing and get to work."
  • Simon (unregistered)

    My daemon() function used to have the corresponding getTheeHenceToEndlessNight() signal, when I didn't want the daemon around any more... Yes I know, daemon != demon...

  • Sigivald (unregistered)

    Sometimes, the environment just isn't sane.

    I've seen VB.NET code where if booleanVariable = true then DoSomething end if Executed DoSomething when booleanVariable was false.

    Doubtless due to state corruption in the development environment, since restarting fixed the problem.

    But it's good to remember that sometimes it's not the developer that's crazy - it's the environment.

  • Sigivald (unregistered)

    PS. It helps if you really click "preview" when you mean "preview" rather than "submit".

  • (cs) in reply to bonzombiekitty
    bonzombiekitty:
    From the project I'm currently working.
    ...
     //OH NOESSSSS!  UI BE DYING!!!
    
    

    I've noticed a strong correlation between people who make comments like this and people who think they're funnier than they actually are.

    So I'm glad we aren't friends!

  • (cs) in reply to GeezerGeek
    GeezerGeek:
    Brings back a memory from many years ago. A client I was working with had hired a "programmer" to write a CP/M BIOS. (Yes, this was well back in the day!) He brought the guy in from out of town and holed him up in a cheap motel with no transportation and very little money. The guy was in well over his head, and was being subjected to continual pressure to produce. The first release was buggy as expected, but whas shipped anyway. Soon complaints began filtering in from customers who had gone into DEBUG and viewed the BIOS code, where they encountered this (edited) text string: Eat s*** and die John! Shortly after that I was given the assignment to create a new BIOS, rated G.
    Thirty years ago I was writing programs for a programmable terminal made by a now-defunct company. I amused myself by writing a disassembler for it and disassembling the interpreter. I found this (edited) text string: TONY'S CODE IS F**CKED AND SO IS TONY
  • Harrow (unregistered)

    Sometimes my explanation just makes things worse, and you have to read the code in order to understand the comments. I try to warn people when this happens:

    ;// On dropdown, fill the reasons field presentation list ;// with all the reasons which are valid for the type of ;// the current entity which are not already used in a ;// binding of the current entity to the selected product, ;// plus the value in the current reasons field, to serve ;// as a default selection, but only if it is previously ;// selected, and this will be on the mid-term exam.

    I added the following comment to a wrapper that translates a directory spec into a database spec, hence the reference to the babel fish scene in HHGG:

    ;// Application designs can store general file ;// directory specifications in addition to ISAM ;// database locations as BDE alias definitions in ;// the associated IDAPI configuration file, but ;// you'll need to have this fish in your ear.

    It's a way of saying, yes this comment is exceptionally long and totally opaque but I am not going to lose any sleep over it and I don't think you should either.

    -Harrow.

  • (cs) in reply to SamP
    SamP:
    mkb:
    The real real wtf is that Java doesn't let you overload operators. AT ALL.

    The REAL WTF is that not only Java doesn't let you overload operators, it internally supports SOME types of overloading but not others.

    For example, we have:

    String a = "foo";
    String b = "bar";

    Now saying

    String c = a + b;

    Instead of

    String c = a.concat(b);

    WILL WORK FINE!!! Even though it's an overload of the plus operator which in this case works completely different from when adding two integers (if integer addition would work like string addition in Java, then saying "1 + 2 + 3" would result in 123 instead of 6).

    HOWEVER, saying

    boolean d = (a == b);

    WILL NOT WORK, and you instead have to use

    boolean d = (a.equals(b));

    So plus operator is overloaded but comparison one isn't, and you have to stick to the system because you can't change overloading yourself either. Talk about stupid...

    Y'know what? You're right. You should avoid using Java now and forever. Please.
  • anon (unregistered)

    yeaaah!

  • (cs)

    From various projects I'm working on:

    sptr<Message> msg = *itr;
    if (msg == NULL) {
        cout <<"F*** ME! IN THE ASSHOLE!"<<endl;
    }
    </pre>
    
    /*
     * For those that can't understand my algorithm:
     *  _____             ______
     *       \           /     |
     *        \         /      |
     *         \_______/       |
     *
     * Um, ah... f*#! it, read the code!
     *          
     */
    
    // On Unix, the OpenGL library is written in C and uses (gasp) the C
    // calling convention! Who would've ever guessed? On Win32, for some
    // odd reason, OpenGL calls use the Pascal calling convention, so our
    // callbacks must use the same convention. But CALLBACK isn't defined
    // on most Unix systems, so if it isn't defined, define it to nothing.
    
    #ifndef CALLBACK
    #define CALLBACK
    #endif
    
  • (cs) in reply to Sigivald
    Sigivald:
    Sometimes, the environment just isn't sane.

    I've seen VB.NET code where if booleanVariable = true then DoSomething end if Executed DoSomething when booleanVariable was false.

    Doubtless due to state corruption in the development environment, since restarting fixed the problem.

    But it's good to remember that sometimes it's not the developer that's crazy - it's the environment.

    Ugh, I remember working on a project in an old VB version (6?) that was just a nightmare. I'd decide I didn't want some code and I'd delete it, then I'd run the program and it would _run_the_code_I'd_just_friggin'_deleted, even after doing a full recompile. I'm not joking. Getting VB to work just right and actually do what it was supposed to was sort of black magic, and involved restarting the IDE and inserting/deleting code in just the right places.

  • (cs) in reply to Jim Bob
    Jim Bob:
    That's fucking stupid. Fuck you

    I appreciate your fervor. However can you please direct that to other forums? Ones where people have enough education to respond in a like manner?

  • (cs) in reply to Harrow
    Harrow:
    It's a way of saying, yes this comment is exceptionally long and totally opaque but I am not going to lose any sleep over it and I don't think you should either.

    -Harrow.

    Opaque comments are worse than no comments, because they distract the distraught disassembler with dissembling. If you were shot by a ticked tech, it would be justifiable homicide.
  • MK (unregistered) in reply to Da' Man
    Da' Man:
    The real WTF is that the guy wrote this stuff into the source code rather than talking about it to his psychoanalyst... ;-)
    He obviously tried, but no matter how many times he tried to go there, ELIZA kept dying on him.
  • sol (unregistered)

    '//go go gadget report '//go go gadget search popup '//go go gaddget smurf

    '/* ON ERROR RESUME NEXT IS FOR FUCKING RETARDS YOU FUCK VB ' PROGRAMMING IDIOT IT'S SIMPLE TRY ... code ... CATCH .. USE ' THE EXCEPTION FOR SOMETHING EVEN IF IT IS ONLY TRACE OR 'DEBUG.PRINT ... FINALLY TRY TO RECOVER THE RESOURCES ' WHAT ERROR YOU SAY??? */

  • (cs)

    That's the first time I feel offended by a piece of code...

    My finding is pretty weak compared to those... in the phpBB source, above a major loop that processes the posting data fetched from the database:

    // Ok, now let's do the loop, yeah baby, let's do the loop...

  • MoroS (unregistered) in reply to mkb

    You should be doing it like "No".equals(Jack.PlayQuantity) to avoid the possibility of a NPE. :D

    (NPE = NullPointerException).

    captcha: doom... yes, NPE = DOOM xD

  • woohoo (unregistered) in reply to SamP
    SamP:
    mkb:
    The real real wtf is that Java doesn't let you overload operators. AT ALL.

    The REAL WTF is that not only Java doesn't let you overload operators, it internally supports SOME types of overloading but not others.

    For example, we have:

    String a = "foo";
    String b = "bar";

    Now saying

    String c = a + b;

    Instead of

    String c = a.concat(b);

    WILL WORK FINE!!! Even though it's an overload of the plus operator which in this case works completely different from when adding two integers (if integer addition would work like string addition in Java, then saying "1 + 2 + 3" would result in 123 instead of 6).

    HOWEVER, saying

    boolean d = (a == b);

    WILL NOT WORK, and you instead have to use

    boolean d = (a.equals(b));

    So plus operator is overloaded but comparison one isn't, and you have to stick to the system because you can't change overloading yourself either. Talk about stupid...

    The real WTF (OMG, I hate that phrase...) is people feeling compelled to criticize languages/language features without knowing $.02 about them. No, the "+" operator is not "internally overloaded" in Java, its implementation is merely a compiler trick:

    String c = a + b;

    translates to

    String c = new StringBuffer(a).append(b).toString();

    (or String c = new StringBuffer().append(a).append(b).toString(), which is functionally equivalent).

    A similar thing happens for the concat()-method of String, because String itself is immutable (for very good reasons!).

    BTW, as of Java 1.5, StringBuilder is used instead of StringBuffer (the former unsynchronized and the latter synchronized as the only difference).

    boolean d = (a == b);

    does of course work, it only compares the references (so 'true' means both are pointing to the same instance). The same holds true for the assignment operator ('=') which never works like a C++ copy constructor, i.e. it always copies references, never instances.

    Java does not have operator overloading - whether this was a good decisison or not may be debatable (as is the decision to add the "+"-compiler-trick for Strings). But operator overloading was in fact one of the major sources of misunderstandings and errors in C++, therefore it was left out.

    Think about it - let's assume that the equality operator ('==') was overloaded in the above example. How would you tell whether the developer intended to compare the references (original operator) or the inner states (overloaded operator)? This is the main problem with operator overloading: Additional and potentially confusing implicit behaviour ("side effects") which is hard to see when reading code.

    It is in fact astounding how much inane code is still produced in a language like Java, with most of the problematic and complex stuff of its predecessors (pointers, explicit memory management, operator overloading etc.) left out... but it's no wonder really, regarding the multitude of equally inane comments in these forums...

  • (cs)

    I may be wrong here, but aren't primitive types in Java actually handled by value? As far as I know, that's the different between bool (lower case) and Boolean (upper case, the boxing type).

    Example: bool a = true, b = true; return (a == b) // Comparision between values: true == true -> true

    Boolean x = new Boolean(true); Boolean y = new Boolean(true); return (x == y) // Comparision between references: [Adress of x] != [Adress of y] --> false

    Note that NOTHING of this is a WTF. You just need to understand things before you talk about them. In this regard, I fully agree with the previous poster.

  • Palmyst (unregistered) in reply to Telimaktar
    Telimaktar:
    // just need get the &#$*ing class name of a string array String[] blah = new String[1];

    Lol, how I'd love to put that in my comments. Give the next victim a laugh.

    Correct idiom here is:

    Class cas = String[].class ;

  • Bogglestone (unregistered) in reply to woohoo
    woohoo:
    It *is* in fact astounding how much inane code is still produced in a language like Java, with most of the problematic and complex stuff of its predecessors (pointers, explicit memory management, operator overloading etc.) left out... but it's no wonder really, regarding the multitude of equally inane comments in these forums...

    Nothing astounding about it really. It's simply that most people who actually can program, don't want to program in java. VB has even more complex stuff left out and just look at the number of WTFs written in it. And leaving out features just because people have trouble with it - well, you can't drop the steering wheel out of a car just because some people have trouble steering.

    captcha: ninjas - they don't program in java either.

  • (cs) in reply to yummy
    yummy:
    Jim Bob:
    That's fucking stupid. Fuck you
    Thanks, now this site is no longer work-safe for me.
    You must be really new here.
  • Anonymous (unregistered)

    Not a comment, but always found the following configure script message for Eterm amusing: ... ... checking for life_signs in -lKenny... (cached) no Oh my god, they killed Kenny! You bastards! ... ...

  • Steve (unregistered)

    A buddy of mine told me that at a company he worked, one of the metrics they used for determining when a piece of code was ready for release was the number of occurrences of the "F-word" in the comments. As that number approached zero, the code was closer to release.

  • (cs) in reply to Bogglestone
    Bogglestone:
    Nothing astounding about it really. It's simply that most people who actually *can* program, don't want to program in java. VB has even more complex stuff left out and just look at the number of WTFs written in it. And leaving out features just because people have trouble with it - well, you can't drop the steering wheel out of a car just because some people have trouble steering.

    A couple of notes on people who can program:

    • People who can program choose the best language for the job, and sometimes that's Java or even VB.

    • People who can program sometimes don't get to choose the language they program in, for example, when management suddenly decides to switch to .NET.

    • People who can program can program, and do it well, in any programming language.

    And one note on poor analogies:

    • A steering wheel (or other steering mechanism) is an absolutely essential feature of any car (or other vehicle). Multiple inheritance, operator overloading, generics, aspects, garbage collection, and closures are not absolutely essential to any programming language. Maybe a better analogy would be cruise control, anti-lock brakes, or traction control.

    The ostensible double-you tee eff (captcha!) here is that so many of the commentators think that the fact that those absurd comments were embedded in Java code is somehow important.

  • Paula (unregistered) in reply to Harry

    No, it's Brillant!

  • (cs) in reply to SamP
    SamP:
    if integer addition would work like string addition in Java, then saying "1 + 2 + 3" would result in 123 instead of 6

    Yes, and if floating point addition would work like integer addition in C, then 32768 + 1.5 might equal -0. Are you trying to claim operator overloading where users are not allowed to add new overloads is a bad thing?

  • (cs)

    I just found this in a class I'm looking at to try to find out how to access something:

    <some if statements that return stuff depending on a Type parameter> else return null; // Hmmm.. is that dangerous?
  • (cs)

    those who complain about java have not tried cold fusion's poison

  • bool (unregistered) in reply to chornbe
    chornbe:
    ' // Real simple. Either the file's there, or it ain't!
    Or it's true. Or it's false. You new to TheDailyWTF?
  • Mad Genius (unregistered)

    Mmmhm, seems to familiar, the submitter could be a co-worker of me ?

    No probably not I hope, such coding may be relieving for the dying brain but using such comment in for example vb asp or asp.net pages are no fun. In my experience I've heard too many angry costumer on the phone reading errorcodes like : OMGWTFBBQ!!! or 0w cr4p! from their screen.

    Fortunately they aren't internetgeeks or gamers who know such verbs but the next coworker of mine who uses such comment is bound to be a stress outlet for me. >:)

  • Kiss me, I'm Polish (unregistered)

    I am Jack's poor, damned soul.

  • AnonymousMaintainer (unregistered)

    To all those people who posted their own page-long rambling comments: you are all incompetent hacks. I hope you die in a fire before I'm ever assigned to maintain your code.

    OK, so I didn't mean that. I'm sure you're nice guys who are just trying to make a living. But so am I, and my life would be much better off if you people flipped burgers. So please, consider a career in fast food. It may not be as glamorous as grinding out crappy code for applications that will be used for years on end by people who neither understand nor appreciate your efforts, but you can still earn good money if you rise through the ranks. In the end, I'm sure it'll be better for all of us: you, me, the end users.

    The comments just make things worse. No, really. At least uncommented code allows me to imagine some much smarter person just had a run of unfortunate circumstances. An inner monologue where the programmer struggles with his own incompetence and curses at life takes away all doubt. If you have time to write comments like those, it's obvious that you actually needed much more time writing the actual crappy code -- otherwise you wouldn't be wasting your time on inane comments -- and that just makes it all the sadder.

    To those people who are proud, or at least amused, by comments like those: you are not a professional programmer. The world has enough amateur programmers. Please stop coding. And if you think all this sounds arrogant: you're damn right it is.

    Sorry, had to get that off my chest. We now return to your regular programming.

  • Saemus Heaney (unregistered) in reply to savar
    savar:
    Look, for gods sake, the captcha is always eerily appropriate: this is an IT site and the captcha is stocked with IT terms! So stop posting your captchas already?!

    Aren't we a zealot!

    CAPTCHA: atari cuz thats what I wanna play

  • Biffa (unregistered) in reply to AnonymousMaintainer
    To all those people who posted their own page-long rambling comments: you are all incompetent hacks. I hope you die in a fire before I'm ever assigned to maintain your code.
    There's so much wrong with this comment that it literally made my jaw drop.

    Suffice it to say that you're the kind of person that makes me realise why for so long software professionals were seen as a humourless and socially inadequate underclass and hidden away from the rest of the organisation...

  • PellePlutt (unregistered)

    At least funny comments brings a smile... My legacy code is a I-used-to-write-C-but-now-it-is-C#-but-i-will-NEVER-learn-oo-techiques-heap-of-shit with absolutely no comments!

    Buhu!

    /P

  • sol (unregistered)

    Yeah generally I don't comment the code until I refactor it or I have time to come in and clean up (refactor?) and comment...

  • Steve (unregistered)

    Someone once said "You can write FORTRAN programs in any language."

  • sol (unregistered)

    I am bored so I came back to comment again....

    I think the person who wrote this code could be a madman....

        /// <summary>
    	/// Add a Method to load data from the database to a class.
    	/// </summary>
    	/// <param name="ref">The class.</param>
    	/// <param name="tbl">Table to be queried.</param>
    	/// <param name="filters">ArrayList of SqlDBTableFields used to filter the query.</param>
    	/// <param name="namespace">The namespace the object resides in.</param>
    	/// <param name="proc_name">The name of the stored procedure.</param>
    	/// <param name="findMany">Is this a find one or find many query?</param>
    	public static void GenerateTableQuery(
    		CodeTypeDeclaration @ref,
    		SqlDbTable tbl,
    		QueryFilterList filters,
    		string @namespace,
    		string proc_name,
    		bool findMany,
            Language lang)
    	{
    		CodeMemberMethod qry = new CodeMemberMethod();
    		
    		qry.Name = proc_name; //set method name and protection level
    		qry.Attributes = MemberAttributes.Public | MemberAttributes.Static;
    
    		//determine and set the return type
    		if(findMany == true)
    		{	//setup return type for array list and add the return variable
    			qry.ReturnType = new CodeTypeReference("System.Collections.ArrayList");
    			qry.Statements.Add(
    				new CodeVariableDeclarationStatement(
    					typeof(System.Collections.ArrayList),
    					"ret",
    					new CodePrimitiveExpression(null))
    				);
    		}
    		else
    		{
    			//create a refreace to this type
    			string onm = @namespace + "." + tbl.TableNameFriendly();
    			//setup method to return a single instance of this type and create the return variable
    			qry.ReturnType = new CodeTypeReference(onm);
    			qry.Statements.Add(
    				new CodeVariableDeclarationStatement(
    					onm,
    					"ret",
    					new CodePrimitiveExpression(null))
    				);
    		}
    		
    		//add the connection parameter
    		qry.Parameters.Add(new CodeParameterDeclarationExpression(
    			"OracleSqlTools.Connection.OracleConnectionSource",
    			"conn"));
    
    		string n = "";
    		if(null != filters)
    		{	//loop through and create param list
    			foreach(QueryFilter f in filters)
    			{	//up hold basic naming standard
                    n = f.Field.ColumnNameFriendly()[0].ToString().ToLower() + f.Field.ColumnNameFriendly().Substring(1);
                    qry.Parameters.Add(new CodeParameterDeclarationExpression(f.Field.ValueType, n));
    			}
    
    			if(null != filters && filters.Count > 0)
                    n = ((QueryFilter)filters[0]).Field.ColumnNameFriendly()[0].ToString().ToLower() + ((QueryFilter)filters[0]).Field.ColumnNameFriendly().Substring(1);
    		}
    
    		//create a datareader variable
    		CodeVariableDeclarationStatement reader = new CodeVariableDeclarationStatement(
    			typeof(System.Data.OleDb.OleDbDataReader),
    			"r", 
    			new CodePrimitiveExpression(null));
    
    
    		CodeAssignStatement setReader = null;
    
    		//add the data reader to the method
    		qry.Statements.Add(reader);
    
    
    
            //Rewrite Here:
    
            string sql = SqlGenerator.CreateQuery(tbl, filters);
            CodeVariableDeclarationStatement vSql = new CodeVariableDeclarationStatement(typeof(string), "sql");
    
            vSql.InitExpression = new CodeSnippetExpression("\"" + sql + "\"");
            qry.Statements.Add(vSql);
    
            foreach (QueryFilter f in filters)
            {
                CodeMethodInvokeExpression repToken = new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression(new CodeVariableReferenceExpression("sql"), "Replace"),
                    new CodeExpression[] { new CodeSnippetExpression("\"@" + f.Field.ColumnNameFriendly() + "\""), new CodeVariableReferenceExpression(f.Field.ColumnNameFriendly()[0].ToString().ToLower() + f.Field.ColumnNameFriendly().Substring(1)) });
    
                System.CodeDom.CodeAssignStatement setSql = new System.CodeDom.CodeAssignStatement(
                   new System.CodeDom.CodeVariableReferenceExpression("sql"), repToken);
    
    
                qry.Statements.Add(setSql);
            }
    
            //End Rewrite HERE
            //fugly code to create code to run the procedure
    		CodeMethodInvokeExpression runSql = null;
            runSql = new System.CodeDom.CodeMethodInvokeExpression(
                    new System.CodeDom.CodePropertyReferenceExpression(new System.CodeDom.CodePropertyReferenceExpression(new System.CodeDom.CodeVariableReferenceExpression("conn"), "DbAccessor"), "ExecuteOleDb"),
                    "ExecuteReader",
                    new System.CodeDom.CodeExpression[] { new System.CodeDom.CodeVariableReferenceExpression("sql") });
    
    		setReader = new CodeAssignStatement(new CodeVariableReferenceExpression("r"), runSql);
    
    		//add the code to init the reader
    		qry.Statements.Add(setReader);
    
    		CodeConditionStatement readerIsNull = new CodeConditionStatement();
    
    		readerIsNull.Condition = new CodeBinaryOperatorExpression(
    			new CodePrimitiveExpression(null),
    			CodeBinaryOperatorType.ValueEquality,
    			new CodeVariableReferenceExpression("r")
    			);
    
    		//will run the Build/BuildArray method
    		CodeAssignStatement exc = null;
    
    		//invoke the right Build
    		exc = new CodeAssignStatement(new CodeVariableReferenceExpression("ret"),
    				new CodeMethodInvokeExpression(
    				new CodeVariableReferenceExpression(@namespace + "." + tbl.TableNameFriendly()), 
    				(findMany == true) ? "BuildArray" : "Build", 
    				new CodeExpression[]{new CodeVariableReferenceExpression("r")}
    			));
    
    		if(!findMany)
    		{
    			CodeConditionStatement ifRead = new CodeConditionStatement();
    			ifRead.Condition = new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("r"), "Read", new CodeExpression[]{});
    			ifRead.TrueStatements.Add(exc);
    
    			readerIsNull.FalseStatements.Add(ifRead);
    		}
    		else
    		{
    			readerIsNull.FalseStatements.Add(exc);//build ret, close reader, and set reader = null;
    		}
    
    		readerIsNull.FalseStatements.Add(new CodeMethodInvokeExpression(
    			new CodeVariableReferenceExpression("r"),
    			"Close",
    			new CodeExpression[]{}));
    		readerIsNull.FalseStatements.Add(
    			new CodeAssignStatement(
    			new CodeVariableReferenceExpression("r"),
    			new CodePrimitiveExpression(null)));
    		
    		//add if statement
    		qry.Statements.Add(readerIsNull);
    
    		//return
    		qry.Statements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("ret")));
    
    		@ref.Members.Add(qry);
    	}
    

    But, then I've always thought I was madman.... CAPTCHA: darwin (yes I know you really wanted to know what it was)

  • 10 (unregistered)

    looks fake...

Leave a comment on “Comments from a Madman”

Log In or post as a guest

Replying to comment #:

« Return to Article