There were no mentioning of the trade beeing a mistake, so human verification might not have changed anythnig.
Posts made by tiller
-
RE: The cause of the 'flash crash'
-
RE: Any thoughts on this password behaviour?
It might do it if login page is storing a md5 hash of the users password in a cookie when the user login. And each page then check this md5 checksum up against the password to verify that the user have entered the correct password.
-
RE: When libraries aren't good enough ...
@Someone You Know said:
The documentation for that method states explicitly that it creates a new object. Compilers shouldn't be going against that; the one from
SunOracle certainly doesn't.The same documentation also basically says that you should never use that constructor for anything, ever, but I doubt if the people who wrote this code have ever read it.
@tiller said:
But the java compiler wil not rewrite the += anyware in this program to use a StringBuffer.
The language spec allows compilers to optimize this sort of thing wherever they want. I admit that I don't know exactly where it's done in practice, but it may differ from compiler to compiler.
The compiler can optimize what it want as long as it don't change the semantic of the program. So it might in this case notice that no other function is given a reference of the string in the loop, and add usage of a StringBuffer.But I really don't think the compiler wil do that. I mean sun have added StringBuffer/StringBuilder for people who want Strings which can change so there is no reason to assume that += should be optimized for strings. (Unless you optimize your compiler for code submitted to thedailywtf.
Ofcause the real wtf is that the only Object in java which can use is += is String which is also specified as immutable and thus the only class which in no way can make an effective append operation.
-
RE: When libraries aren't good enough ...
@Someone You Know said:
@tiller said:
@Someone You Know said:
@zelmak said:
Indeed. I'm trying to break the other programmers of this habit, but it's slow going.
So there's more than one person who does this? Where did they all get the idea that using a copy constructor on a literal of the same type makes any kind of sense?
It's java(I guess, looks like it). so there is no copy constructor, and the code is not really more ineffective then just writing s="." (But s="." is more readable).
What is really ineffective is that strings in java are imutable so each time it does a += it creates a new string and throw the old string away.
The String(String) constructor being used here takes a String as an argument and constructs a new String object that is a value copy of that String. In what way is that not a copy constructor?
It is "more ineffective" than String s = "."; because it creates two String objects — the literal "." and s — and discards one of them without using it for anything.
I wouldn't worry about the concatenations as much, though; newer versions of Java are reasonably clever about that, and will convert String += String expressions to use StringBuffer or StringBuilder behind the scenes if there are a significant number of them in rapid succession.
You are right, it is a copy constructor unless the java compiler does some fancy optimization. Is someone bored enough to try and compile and then dis-assable the program to se if java compiler does the obvious optimization :}
But the java compiler wil not rewrite the += anyware in this program to use a StringBuffer.It will only insert an extra StringBuffer when you do something like "Some" + myVar + "other things" but in this case the right side is always a single char/string so it wil generate a new string for each +=. But given the number of wtf's in this code and the fact that this is most likely not in a performence critical place that is rather low on the list of things to fix.
-
RE: When libraries aren't good enough ...
@Someone You Know said:
@zelmak said:
Indeed. I'm trying to break the other programmers of this habit, but it's slow going.
So there's more than one person who does this? Where did they all get the idea that using a copy constructor on a literal of the same type makes any kind of sense?
It's java(I guess, looks like it). so there is no copy constructor, and the code is not really more ineffective then just writing s="." (But s="." is more readable).
What is really ineffective is that strings in java are imutable so each time it does a += it creates a new string and throw the old string away.
-
RE: The data doesn't have to be accurate
That's one solution, but a better solution would most likely be using a transaction and doing a "select ... for update"
-
RE: We can always deal with it manually
Can't you atleast use transactions to prevent the "some subset of the original tables and some subset of the "marked" tables, with who-knows-what set of constraints, triggers and indices." problem? Ok I admit i have newer tried to see if drop table/trigger/indices work in a transaction with rollback, but I seems to remember that PostgreSQL did implement transaction/rollback support for drop table and drop column.
And please don't quit your job, the design you need to work with make anything else sane by comparison :}
-
RE: Representative line
@synecdoche said:
@tiller said:
The original problem that malloc is fixing* is not a memory leak, but a stack overflow which is kinda the opposite of a memory leak(More data then allocated ram).
But this code does create a new leak :-}
*Fixing as in: Works for me now, don't touch anything.
The malloc fixes a buffer overflow by actually creating a memory leak: that's what's funny/worrying about the comment.
Immediately before this the program declares a variable-sized array:
<font face="Lucida Console" size="2">float *some_array = malloc(sizeof(float) * (1 + magical_size_variable));</font>
Running <font face="Lucida Console" size="2">malloc(4096);</font> "works" because the new memory is allocated straight after the array. A more subtle and slightly less brittle way of doing the same stupid thing is to add 4096 to the malloc where the array is allocated, and a proper solution would be to fix whatever horrendous calculation is used to come up with the magical_size_variable.
I ended up not touching this code at all: it's executed once per page hit, so with a generous 1,000 hits per day = leaks 4MB per day. If I started fixing everything wrong with this code, I could keep going for years, and worse, I'd get a reputation as "the guy who knows about FooProject". Everything about this code is poison by now: the source control system before we inherited it was a bunch of folders named fooproject_1, fooproject_2 etc., up to fooproject_20.
Those numbers represent "branches", by the way, not revisions.
Once per page hit? Are the company writing a webservice in c++. And with only 1000 expected hits per day. I think we have the true wtf right here :}
Why would anyone write a website with very low performance requirements in c++ ????
-
RE: Representative line
@PJH said:
@tiller said:
But this code does create a new leak :-}
Only if it's executed more than once, without freeing the result from the previous invocation. What you're saying is akin to saying "declaring global variables creates memory leaks," in that memory is reserved at start up, and there's no user code to free that memory. In both cases (assuming the code is executed only once), there's a single allocation and in both cases it's freed when the program exits.[1]
Both are bad practise, but neither necessarily create 'memory leaks' in the conventional sense of the term.
I used to hear rumours that GameOS used to *really* leak memory under such circumstances - i.e. not free it up once the program had exited, but that was years ago, and I'm sure they've fixed it now. Firefox has now taken up the gauntlet...But as can be seen from the code, he newer store a pointer to the value allocated by malloc, so he can't free it again.
-
RE: Representative line
The original problem that malloc is fixing* is not a memory leak, but a stack overflow which is kinda the opposite of a memory leak(More data then allocated ram).
But this code does create a new leak :-}
*Fixing as in: Works for me now, don't touch anything.
-
RE: GetAllCastingWTFs()
The true wtf is: Using statement instead of preparedStatement.
Calling getMember with a new query, instead of just using a join.
Implementing your own getMember methods(And all the other similary methods) instead of using an oo mapper such as torque or Hibernate.
(And yes, returning an array instead of a List is stupid too).
-
RE: Twitter and Present.ly Initiative
@Wrongfellow said:
it can allow us to communicate quickly, without the bulk of email.
Bulk of email? Are they by any change using Lotus Notes? I can't find any other way that email can be called bulky.ED: added a quote for you and italicized this line. -btk
-
RE: Java's Applet layout tools.
The swing layout system is not THAT bad, but and semantic of the 3 different widths a component may have is complicated and not that well designed/documented. But once you learn it it's not that difficult. (And the javadoc layout documentation sucks).
The reason you can't just use x/y is: Imagine you have a bar with 5 buttons where each button have a text. And you want to put them next to each other. You can't give x/y because you don't want the buttons to scale, you want them to have their "natural" size, which is based on the size of the text in the button.
I think the best way to do layout is just using nested box layouts. It is simply and can do almost anything you need.
-
RE: The good news is, I can write about it now.
The true wtf in part 1, is that they don't use a system to seperate html and the code.You don't want graphics guys to edit your code at all. (Especially if they use dreamweaver. ARG!)
The true wtf in the auto_increment part, is that last time i checked with mysql, you CAN specify a value for an auto_increment field, so you could just insert an row with id=0. (Yes, that would still be a wtf solution, but hey).
And the md5 thing is funny. Don't mysql support a unique/distinct on a field? That way you could just do the insert in a single query, and if it failed the row were already there. And if you calculate the md5 from just the comment_text you would get the bonus that if multiple different users mede a "First post!" message, only the first one would be saved in the database :}
-
RE: Better way to compare booleans
But please for the sake of the next guy maintaining your code, use
(bool) instead of !! to cast a non bool to a bool in php.
-
RE: Java and primitives
Hu? If in.next(...) throws an Exception which does not extend Extension, then u will be uninitiaziled in the if(!u) line.
Only wtf is that Exception is not the root of the java exception type system. To fix it, change Exception to Throwable
-
RE: I'm no DBA....
You do not have 3 different primary keys(There can by definition only be one primary key, hence primary).
You have one composit primary key with 3 fields. So 2 questions: Why do you have a primary key at all. Do you really need it? I know some dbas are going to hate me for saying this, but I think that logging is one of the very very few cases where you don't have to define a primary key.
And what the hell is up with date and time beeing 2 different fields, instead of just a datetime(Or what your database calls that type). That is a true wtf which indicate that the database is really fucked up. So looking forward to more entries about that database in the future :}
-
RE: The try{ throw(...); } catch(...){ log(...); } pattern
This code is not as stupid as it seems. Because mkdir can signal "directory creation failed" by either throwing an exception or by simply returning false. And if you want to handle theese 2 cases without duplicating the error.logger(Error handling) call then this is the way to do it.
The true wtf is that if the directory exists, mkdir will return false and log an error saying "Could not create backup directory", but if the there is a file_exists() someware before then this might be the best way to do it. (And yes the true wtf is that java can signal error either by exception or by returning false(And how do you find out why it could not create the directory if it just return false??)
-
RE: This is how we get TDWTF style code.
It's not really that bad. I imagine the original code were javascript or a similary language which only have floatingpoints.
The purpose of the loop is to find out which bracket the given income is in. When the loop terminates count is the correct bracket. No magic there, and quite easy to understand. But yes, count is a bad name for that variable, should have been userBracket or something similary. (Well, it really should have been its own function, but I disgress).
ps: I think you miss a count=0; before the loop.
-
RE: She didn't like 'like'
And just to learn something. If you insist on enumerating all options, how about doing it with a in with
where someCol in ('AAA001','AAA002','AAA003, .....);
And write a loop to generate the strings, instead of doing it by hand for gods sake! -
RE: This is a pretty easy question...
Sorry, you are right. I forgot that the search function for functions on the php website don't find members. (http://dk.php.net/manual-lookup.php?pattern=valid&lang=en)
-
RE: This is a pretty easy question...
For extra bonus, realize that not all theese five functions are members of the iterator interface, so it might just be a really really evil question
-
RE: Who the f*ck came up with this idea?
You all forget the worst wtf. It's TALKING! (try to connect audio to your computer).
-
RE: Premature optimization...
The funny thing is that this is most likely not even an optimization.
The case 1: might be(Don't think so, but even if it is, it's still stupid) but I am pretty sure that a compare+branch+shift is slower then a multiplication in most cases.
Not to talk about the fact that if rec_size is not in(1,2,4,8,16) then the function will have to make 5 compares before the multiplication. (And why is the function not inlined. Calling it most likely cost much much more then a multiplication anyway :}
-
RE: Return what?
Quoete: For many C++ implementations, false == 0 and NULL == 0. Therefore, false == NULL.
Hopefully all implementations. Because the c++ standard say that false evaluate to the integer value 0. (And true evaluate to 1. Always).
And any constant expression(Such as false) that evaluate to 0 is a null pointer. (Who got that idear??? Even Bjarne thought this was a bad idear first time he saw it).
-
An interesting php snippet
I just found the following code in some code i am bugfixing(Aka rewriting)
if($endtime == 00) {
$endtime = 0;
}The code had a comment, saying that it was removing the extra 0 if it was there. ($endTime is a string)
The funny thing about this code is that it actuelly DOES work, and for all practical purposes does what the original author intended
(That is transform the string "00" to "0") but the reason it does work are by a combination of pure change, and the wierdness that is implicit typecast and transformation in php
-
Php: mysql_close does interesting things
Have a look at the documentation for the php function mysql_close()
bool mysql_close ( [resource $link_identifier] )mysql_close() closes the non-persistent connection to the MySQL server .........
Parameters
- link_identifier
The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated.
----------------
So if you call mysql_close and there is no open connection, it will try to open a new connection, just to close it again.
Very clewer :}
-
RE: Primary Key WTF
Why does a primary key called id, make writing SQL terribly complicated?
The only problem I can se, is that you can't make natural joins.
And I kinda hate natural joins, because they compare all fields that are named the same, so if you got table called club, and an table called player,
and each player belong to a club, you might want to do a natural join between player and club, BUT if both the club and player table also contains a field called name(Which is normal, because
both a club, and a player does have a name, but there is no connection between a player name, and a club name), you can't do a natural join between them. (If you care about standard sql that is).
I always thought that the natural join semantic: "If it's called the
same, then it is the same" was really fucked up. They should do as Oralce do, and do a natural join on forign key, so you just do a
select * from club natural join player;
It should join, on the previously defined forigen key).
-
RE: I hate to write code like that
Using the NumberSpinnerModel is the correct solution IF you want to show numbers only.
A not tested example :}
JSpinner mySpinner; // Your JSpinner
SpinnerNumberModel myModel=new SpinnerNumberModel(0.5,0,1,0.1); // The args are default,min,max,stepsize
mySpinner.setModel(myModel);
///
To get the value as a number, you can either do
double value=((SpinnerNumberModel)mySpinner.getModel()).getNumber().doubleValue();
// Or simple keep a reference to your model and call
double value=myModel.getNumber.doubleValue()
-
RE: A flamewar on java dev forums WTF
It's also a good example of what happens if you make a wrong statement, and insted of admitting it, try to redefine the rest of the world, so your statement become true
(I had not time to read it all, so I just did read the first 4 pages, and the last 4). Still funny thou -
RE: The Wacky World of Visual Basic
I don't have a java compiler at hand, but let my try to answer anyway :}
(So the following might be wrong, it's a few months since I had to implement that check in our compiler writer course)if ( false ) {
System.out.println( "Hello, world!" );
}
The code above wil compile fine, but it will not have any effect.while ( false ) {
System.out.println( "Hello, world!" );
}
The code above will cause the compiler to complain about the fact that system.out.println("Hello, World") is unreachable code.
But the real question is: Why this difference :}
The reason is that java have a special rule for handling final boolean in if. (And afair only in if)
final boolean myBool = (true or false);
Because myBool is final, Java is allowed to substitute all tests for myBool with the value of bool when doing if(myBool).
That is: For java the following code is equivalent:
if(false) {
doSomething();
}
---------------
boolean myBool=false;
if(myBool) {
doSomething();
}
So if java did not allow if(false) testing a final boolean in an if, would not be legal.
The reason that the same rule does not apply for the while(false) case is that
writing
final boolean doDebug=false;
// Code ...
if(doDebug) {
printf("Debugging");
}
Is normal but I can't come to any reason while anyone would want a for/while loop
which tests a final boolean.
But sorry, I am not looking for a job right now :}
Martin Tilsted.