Woopsies are annoying, arent they?



  • 	/**
    	 * In order to avoid annoying woopsies there was not a space between my 'and' and another clause I added this util method that adds an AND with spaces around it.
    	 */
    	public void addAnd() {
    		add(" AND ");
    	}
    
    	/**
    	 * In order to avoid annoying woopsies there was not a space between my 'or' and another clause I added this util method that adds an OR with spaces around it.
    	 */
    	public void addOr() {
    		add(" OR ");
    	}
    
    	/**
    	 * In order to avoid annoying woopsies there was not a space between my 'not' and another clause I added this util method that adds a NOT with spaces around it.
    	 */
    	public void addNot() {
    		add(" NOT ");
    	}
    
    	/**
    	 * In order to avoid annoying woopsies there was not a space between my 'group by' and another clause I added this util method that adds a group by with spaces around it and
    	 * then the given clause
    	 */
    	public void addGroupBy(String groupBy) {
    		add(" GROUP BY ");
    		add(groupBy);
    	}
    
    	/**
    	 * In order to avoid annoying woopsies there was not a space between my 'order by' and another clause I added this util method that adds a order by with spaces around it and
    	 * then the given clause
    	 */
    	public void addOrderBy(String orderBy) {
    		add(" ORDER BY ");
    		add(orderBy);
    	}
    
    
    
    

  • Dupa

    That's the wrong way to do it.

    This is the right way:

    public void addSpace() {
    	add(" ");
    }
    
    public void addAnd() {
    	add("AND");
    }
    

    Correct usage, well... I think you can figure it out.



  • Bonus wtf (unless earlier versions of java had mutable strings that I didn't know about):

    
      QueryResultImpl(ObjectSurface surface, MetaTypeProxy typeProxy, String queryText, ShellSetStatus shellSetStatus) {
        this.surface = surface;
        this.typeProxy = typeProxy;
    
        if (queryText != null) {
          this.queryText = new String(queryText);   // copy rather than reference, just in case the caller decides to update it
        }
    
        // incomprehensible garbage follows. I just don't get how someone this ignorant of the language could have been trusted to build something this complex
        // NB: I don't actually know who wrote this; source control only goes back to September last year
        
    

  • Winner of the 2016 Presidential Election



  • @kt_ said:

    That's the wrong way to do it.

    I think you forgot to add constants

    static String spaceString = " ";
    static String andString = "AND";

    You can never know when addAnd() should really print something else. Hey, don't laugh. Have you never experienced international versions of Excel, where they would localize the string for SUM(), AVERAGE(), etc.?



  • Argh, void?! Sheesh, at least return a this pointer so you can string them together.



  • TRWTF are those long >80 char lines.


  • Winner of the 2016 Presidential Election

    I shudder to think exactly what add is doing, probably some global var they append to.



  • Yeah, why even bother with a multi-line comment if all the text is in one really long line in the middle?



  • TRW is the code highlighting on that snippet



  • it seems to think it's visual basic, but I can't figure out why it would have guessed that.


  • Winner of the 2016 Presidential Election

    The In?



  • With an asterisk to the left of it? Is that possible in vb?


  • Winner of the 2016 Presidential Election

    I have no idea, I haven't had the misfortune to have to use that particular hellstewlanguage


  • Winner of the 2016 Presidential Election

    So I guess this is to prevent "woopsies" of the Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ANDcustomer = ' at line 1 type?

    I think trwtf is the existence of these methods in the first place (and the funkyness they're doing with that add method, wtf is that all about :interrobang:). I sense building a SQL string by hand/concatenation and a possible visit by our friend Bobby Tables.

    And as @boomzilla said, at least let me chain them for the love of $diety

    (@OP: I'm well aware that you're probably not the perpetrator and you probably agree entirely. Just wanted to point it out :) )


  • Discourse touched me in a no-no place

    @Buddy said:

    Bonus wtf (unless earlier versions of java had mutable strings that I didn't know about):

    Strings were immutable before Java 1.0. That was a very early design decision.

    @Buddy said:

    ```java
    this.queryText = new String(queryText); // copy rather than reference, just in case the caller decides to update it

    
    That's actually not too big a problem IIRC. They share the same underlying backing store behind the scenes. Still a waste, but not a terrible one.

Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.